مدیاویکی:Gadget-AfD.js

از ویکی‌پدیا، دانشنامهٔ آزاد

نکته: برای دیدن تغییرات، ممکن است نیاز باشد که حافظهٔ نهانی مرورگر خود را پس از انتشار پاک‌سازی کنید. گوگل کروم، فایرفاکس، مایکروسافت اج و سافاری: کلید Shift را نگه دارید و روی دکمهٔ Reload در نوار ابزار مرورگر کلیک کنید. برای آگاهی از جزئیات و نحوهٔ پاک‌سازی حافظهٔ نهانی سایر مرورگرها، صفحهٔ ویکی‌پدیا:میانگیر مرورگرتان را خالی کنید را ببینید.

/*global jQuery, mediaWiki */
(function($, mw) {
  'use strict';
  var windowManager;
  var archiveAfD;
  var targetPage;
  var archiveOptions = {
    install: function() {
      if (mw.config.get('wgAction') === 'view' &&
        ((mw.config.get('wgPageName').search("ویکی‌پدیا:نظرخواهی_برای_حذف/") > -1) ||
          (mw.config.get('wgPageName').search("ویکی‌پدیا:نظرخواهی_برای_حذف_متفرقه/") > -1))
      ) {
        mw.loader.using(['mediawiki.api']).done(archiveOptions.setUp);
        $(mw.util.addPortletLink(
          'p-views', '#', 'جمع‌بندی', 'ca-afd', 'ابزار مدیریت نبح', null, '#ca-view'
        )).click(function(e) {
          mw.loader.using(['oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows']).done(archiveOptions.createWindow);
          e.preventDefault();
        });
        // Late pre-loading
        mw.loader.load(['oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows']);
      }
    },
    setUp: function() {
      var targetPage;
      var params = {
        action: 'query',
        prop: 'revisions',
        titles: mw.config.get('wgPageName'),
        format: 'json',
        rvprop: 'content',
        rvdir: 'newer',
        rvlimit: '1'
      };
      (new mw.Api()).get(params).done(function(data) {
        var pageId = Object.keys(data["query"]["pages"])[0];
        var pageContent = data["query"]["pages"][pageId]["revisions"][0]["*"];
        var sourceTemplate = pageContent.match(/\{\{مقاله\|(.*?)\}\}/);
        if (sourceTemplate != null) {
          targetPage = sourceTemplate[1];
        } else {
          targetPage = mw.config.get('wgPageName')
            .replace("ویکی‌پدیا:نظرخواهی_برای_حذف/", "")
            .replace(/_\(بار_[^\)]+?\)$/, "").replace(/_\([^\)]+?ین_نامزدی\)$/, "");
        }
        // if the target page has moved, use the redirect destination instead
        var params = {
          action: "query",
          prop: "info",
          redirects: "1",
          titles: targetPage,
          format: "json"
        };
        (new mw.Api()).get(params).done(function(data) {
          if ("redirects" in data["query"]) {
            targetPage = data['query']['redirects'][0]['to'];
          }
          archiveOptions.targetPage = targetPage;
        });
      });
    },
    reason: '',
    shortReason: '',
    decisionCategory: '',
    createWindow: function() {
      if (archiveOptions.targetPage == null) {
        // user tried to use the gadget while it is determining the AfD target
        console.log('Gadget-AfD is still loading...');
        return true; // so that user can click on the gadget link again
      }

      function ArchiveAfD(config) {
        ArchiveAfD.super.call(this, config);
      }
      OO.inheritClass(ArchiveAfD, OO.ui.ProcessDialog);
      ArchiveAfD.static.name = 'AfD dialog';
      ArchiveAfD.static.title = 'مدیریت نظرخواهی حذف';
      ArchiveAfD.static.actions = [{
        action: 'archive',
        label: 'ثبت',
        flags: 'primary'
      }, {
        label: 'لغو',
        flags: 'safe'
      }];
      ArchiveAfD.prototype.initialize = function() {
        var fieldset = [];
        ArchiveAfD.super.prototype.initialize.apply(this, arguments);
        this.panel = new OO.ui.PanelLayout({
          padded: true,
          expanded: false
        });
        this.content = new OO.ui.FieldsetLayout();
        archiveOptions.radioDelete = new OO.ui.RadioOptionWidget({
          id: 'radioDelete',
          label: 'حذف شود',
        });
        archiveOptions.radioMerge = new OO.ui.RadioOptionWidget({
          id: 'radioMerge',
          label: 'ادغام شود',
        });
        archiveOptions.radioKeep = new OO.ui.RadioOptionWidget({
          id: 'radioKeep',
          label: 'بماند',
        });
        archiveOptions.radioExtend = new OO.ui.RadioOptionWidget({
          id: 'radioExtend',
          label: 'تمدید نظرخواهی',
        });
        archiveOptions.radioSelect = new OO.ui.RadioSelectWidget({
          items: [archiveOptions.radioDelete,
            archiveOptions.radioMerge,
            archiveOptions.radioKeep,
            archiveOptions.radioExtend
          ]
        });
        archiveOptions.radioSelect.selectItem(archiveOptions.radioKeep);
        archiveOptions.radioSelect.on('select', function() {
          if (archiveOptions.radioDelete.isSelected()) {
            archiveOptions.switchProtect.setDisabled(false);
          } else {
            archiveOptions.switchProtect.setDisabled(true);
          }
          if (archiveOptions.radioMerge.isSelected()) {
            archiveOptions.textMergeTarget.setDisabled(false);
          } else {
            archiveOptions.textMergeTarget.setDisabled(true);
            if (archiveOptions.radioExtend.isSelected()) {
              archiveOptions.comboCommonReason.setDisabled(true);
            } else {
              archiveOptions.comboCommonReason.setDisabled(false);
            }
          }
        });
        archiveOptions.comboCommonReason = new OO.ui.ComboBoxInputWidget({
          options: [{
              data: '[[وپ:حذف/نبح|اجماعی برای حذف حاصل نشد.]]'
            },
            {
              data: '[[وپ:سرشناسی|سرشناسی موضوع]] احراز نشد.'
            },
            {
              data: 'حذف سریع شده‌است.'
            },
            {
              data: '[[وپ:حذف نرم|حذف نرم]] (در نبود مشارکت کافی)'
            },
            {
              data: 'کاربران بر حذف صفحه اجماع دارند'
            },
            {
              data: 'کاربران بر ماندن صفحه اجماع دارند'
            },
            {
              data: '[[ویکی‌پدیا:ماندن سریع|انصراف نامزدکننده]]'
            },
            {
              data: 'بر پایه [[وپ:برف]] نظرخواهی جمع‌بندی شد.'
            },
          ]
        });
        archiveOptions.textReason = new OO.ui.TextInputWidget({
          placeholder: 'متن جمع‌بندی را وارد کنید',
        });
        archiveOptions.textMergeTarget = new OO.ui.TextInputWidget({
          id: 'textTargetMerge',
          placeholder: 'نام کامل صفحه',
          disabled: true
        });
        archiveOptions.switchProtect = new OO.ui.ToggleSwitchWidget({
          id: 'switchProtect',
          disabled: true
        });
        fieldset.push(new OO.ui.FieldLayout(archiveOptions.radioSelect, {
          label: 'تصمیم شما:',
          align: 'top'
        }));
        fieldset.push(new OO.ui.FieldLayout(archiveOptions.comboCommonReason, {
          label: 'دلایل مرسوم:',
          align: 'inline'
        }));
        fieldset.push(new OO.ui.FieldLayout(archiveOptions.textReason, {
          label: 'توضیح (اختیاری):',
          align: 'top'
        }));
        fieldset.push(new OO.ui.FieldLayout(archiveOptions.textMergeTarget, {
          label: 'ادغام با:',
          align: 'top'
        }));
        fieldset.push(new OO.ui.FieldLayout(archiveOptions.switchProtect, {
          label: 'صفحه پس از حذف محافظت شود',
          align: top
        }));
        this.content.addItems(fieldset);
        this.panel.$element.append(this.content.$element);
        this.$body.append(this.panel.$element);
      };
      ArchiveAfD.prototype.getActionProcess = function(action) {
        var dialog = this;
        if (action === 'archive') {
          archiveOptions.reason = archiveOptions.textReason.getValue();
          if (archiveOptions.comboCommonReason.getValue()) {
            archiveOptions.reason = archiveOptions.comboCommonReason.getValue() + ' ' + archiveOptions.reason
          }
          var debatePage = mw.config.get('wgPageName');
          var talkPrefix = 'بحث:';
          if (archiveOptions.targetPage.search(/کاربر:|الگو:|رده:|ویکی‌پدیا:|درگاه:|راهنما:/) > -1) {
            talkPrefix = 'بحث ';
          }
          if (archiveOptions.targetPage.search(/^بحث/) > -1) {
            talkPrefix = false;
          }
          return new OO.ui.Process(function() {
            // Warn the user if they try to leave the page before we are done
            $(window).bind('beforeunload', function() {
              return 'Archiving has not completed. Please do not leave the page yet.';
            });
            if (archiveOptions.radioExtend.isSelected()) {
              // Update subject page
              summary = 'تمدید نظرخواهی [[وپ:نبح]] ([[مدیاویکی:Gadget-AfD.js|ابزار جمع‌بندی]])';
              archiveOptions.loadSavePageRefresh(debatePage, archiveOptions.extendPage, summary);
            } else {
              var summary = '';
              archiveOptions.checkRedirect(archiveOptions.targetPage);
              // Remove page from WP:AfD
              summary = 'حذف [[' + debatePage.replace(/\_/g, ' ') + ']] از [[وپ:نبح]] ([[مدیاویکی:Gadget-AfD.js|ابزار جمع‌بندی]]): ';
              archiveOptions.loadSavePageRefresh('ویکی‌پدیا:نظرخواهی_برای_حذف', archiveOptions.removeLink, summary);
              if (archiveOptions.radioDelete.isSelected()) {
                archiveOptions.shortReason = 'حذف شود. ';
                archiveOptions.decisionCategory = '[[رده' + ':نظرخواهی برای حذف منجر به حذف]]';
                archiveOptions.reason = 'حذف شود. ' + archiveOptions.reason;
                // Update AfD page
                summary = 'بستن نظرخواهی [[وپ:نبح]] ([[مدیاویکی:Gadget-AfD.js|ابزار جمع‌بندی]])';
                archiveOptions.loadSavePageRefresh(debatePage, archiveOptions.closePage, summary);
                // Update AfD archives
                archiveOptions.creationDate(debatePage, function(archlink) {
                  archiveOptions.archiveMonth(archlink, function(month) {
                    summary = 'بایگانی نظرخواهی [[وپ:نبح]] ([[مدیاویکی:Gadget-AfD.js|ابزار جمع‌بندی]]): ';
                    archiveOptions.loadSavePageRefresh('ویکی‌پدیا:نظرخواهی_برای_حذف/بایگانی/' + month, archiveOptions.archivePage, summary);
                  })
                });
                // Delete the page
                var summary = 'حذف صفحه بر اساس [[' + debatePage + '|نظرخواهی برای حذف]] ([[مدیاویکی:Gadget-AfD.js|ابزار جمع‌بندی]])';
                archiveOptions.deletePageRefresh(archiveOptions.targetPage, summary, archiveOptions.switchProtect.getValue());
              } else {
                if (archiveOptions.radioMerge.isSelected()) {
                  var targetPage = archiveOptions.textMergeTarget.getValue();
                  archiveOptions.shortReason = 'ادغام شود با [[' + targetPage + ']]. ';
                  archiveOptions.decisionCategory = '[[رده' + ':نظرخواهی برای حذف منجر به ادغام]]';
                  archiveOptions.reason = 'ادغام شود با [[' + targetPage + ']]. ' + archiveOptions.reason;
                  // Mention the old AfD on the talk page
                  summary = 'افزودن [[الگو:پیشینه حذف]] به بحث صفحه ([[مدیاویکی:Gadget-AfD.js|ابزار جمع‌بندی]]): ';
                  if (talkPrefix) {
                    archiveOptions.loadSavePageRefresh(talkPrefix + archiveOptions.targetPage, archiveOptions.closeTalkPage, summary);
                  }
                  // Update AfD page
                  summary = 'بستن نظرخواهی [[وپ:نبح]] ([[مدیاویکی:Gadget-AfD.js|ابزار جمع‌بندی]])';
                  archiveOptions.loadSavePageRefresh(debatePage, archiveOptions.closePage, summary);
                  // Update AfD archives
                  archiveOptions.creationDate(debatePage, function(archlink) {
                    archiveOptions.archiveMonth(archlink, function(month) {
                      summary = 'بایگانی نظرخواهی [[وپ:نبح]] ([[مدیاویکی:Gadget-AfD.js|ابزار جمع‌بندی]]): ';
                      archiveOptions.loadSavePageRefresh('ویکی‌پدیا:نظرخواهی_برای_حذف/بایگانی/' + month, archiveOptions.archivePage, summary);
                    })
                  });
                  // Update subject page
                  summary = 'حذف [[الگو:پیشنهاد حذف]] از صفحه ([[مدیاویکی:Gadget-AfD.js|ابزار جمع‌بندی]]): ';
                  archiveOptions.loadSavePageRefresh(archiveOptions.targetPage, function(text) {
                    text = archiveOptions.removeTemplate(text);
                    text = '{{' + 'اجماع ادغام|' + targetPage + '}}\n' + text;
                    return text
                  }, summary);
                } else {
                  archiveOptions.shortReason = 'بماند. ';
                  archiveOptions.decisionCategory = '[[رده' + ':نظرخواهی برای حذف منجر به ماندن]]';
                  archiveOptions.reason = 'بماند. ' + archiveOptions.reason;
                  // Mention the old AfD on the talk page
                  if (talkPrefix) {
                    summary = 'افزودن [[الگو:پیشینه حذف]] به بحث صفحه ([[مدیاویکی:Gadget-AfD.js|ابزار جمع‌بندی]]): ';
                    archiveOptions.loadSavePageRefresh(talkPrefix + archiveOptions.targetPage, archiveOptions.closeTalkPage, summary);
                  }
                  // Update AfD page
                  summary = 'بستن نظرخواهی [[وپ:نبح]] ([[مدیاویکی:Gadget-AfD.js|ابزار جمع‌بندی]])';
                  archiveOptions.loadSavePageRefresh(debatePage, archiveOptions.closePage, summary);
                  // Update AfD archives
                  archiveOptions.creationDate(debatePage, function(archlink) {
                    archiveOptions.archiveMonth(archlink, function(month) {
                      summary = 'بایگانی نظرخواهی [[وپ:نبح]] ([[مدیاویکی:Gadget-AfD.js|ابزار جمع‌بندی]]): ';
                      archiveOptions.loadSavePageRefresh('ویکی‌پدیا:نظرخواهی_برای_حذف/بایگانی/' + month, archiveOptions.archivePage, summary);
                    })
                  });
                  // Update subject page
                  summary = 'حذف [[الگو:پیشنهاد حذف]] از صفحه ([[مدیاویکی:Gadget-AfD.js|ابزار جمع‌بندی]]): ';
                  archiveOptions.loadSavePageRefresh(archiveOptions.targetPage, archiveOptions.removeTemplate, summary);
                }
              }
            }
            dialog.close({
              action: action
            }).done(function() {
              // TODO: Refresh the AfD page after all actions are complete
            });
          });
        }
        return ArchiveAfD.super.prototype.getActionProcess.call(this, action);
      };
      if (!windowManager) {
        windowManager = new OO.ui.WindowManager();
        $('body').append(windowManager.$element);
      }
      if (!archiveAfD) {
        archiveAfD = new ArchiveAfD({
          size: 'medium'
        });
        windowManager.addWindows([archiveAfD]);
      }
      windowManager.openWindow(archiveAfD);
    },
    convertYearToFarsi: function(year) {
      return year.replace(/\d/g, function (x) {
        return String.fromCharCode(x.charCodeAt(0) + 1728); // 1728 is '۰' - '0' code difference
      });
    },
    convertMonthToFarsi: function(month) {
      return {
        0: 'ژانویه',
        1: 'فوریه',
        2: 'مارس',
        3: 'آوریل',
        4: 'مه',
        5: 'ژوئن',
        6: 'ژوئیه',
        7: 'اوت',
        8: 'سپتامبر',
        9: 'اکتبر',
        10: 'نوامبر',
        11: 'دسامبر'
      }[month];
    },
    checkRedirect: function(ar_title) {
      var params = {
        action: "query",
        prop: "info",
        titles: ar_title,
        format: "json"
      };
      (new mw.Api()).get(params).done(function(data) {
        if ("redirect" in data["query"]
          ["pages"][Object.keys(data["query"]["pages"])]) {
          mw.notify("صفحهٔ موضوع نظرخواهی منتقل شده‌است. حواستان باشد که دستی درست کنید!", {
            type: 'error'
          });
        }
      });
    },
    creationDate: function(title, callback) {
      (new mw.Api()).get({
        action: 'query',
        prop: 'revisions',
        titles: title,
        rvprop: 'timestamp',
        rvdir: 'newer',
        format: 'json',
        rvlimit: '1',
      }).done(function(data) {
        var timestamp = data["query"]["pages"][Object.keys(data["query"]
            ["pages"])]["revisions"]
          [0]["timestamp"];
        callback(timestamp);
      });
    },
    archiveMonth: function(timestamp, callback) {
      var crDate = new Date(timestamp);
      var archiveMonthLink = archiveOptions.convertMonthToFarsi(crDate.getUTCMonth()) + ' ' + archiveOptions.convertYearToFarsi(String(crDate.getUTCFullYear()));
      callback(archiveMonthLink);
    },
    loadPage: function(title, callback) {
      (new mw.Api()).get({
        action: 'query',
        prop: 'revisions',
        titles: title,
        rvprop: 'content',
        format: 'json'
      }).done(function(data) {
        try {
          callback($.map(data.query.pages, function(value) {
            return value;
          })[0].revisions[0]['*']);
        } catch (exception) {
          callback('');
        }
      }).fail(function(data) {
        callback($.map(data.query.pages, function(value) {
          return value;
        })[0].revisions[0]);
      });
    },
    protectPageRefresh: function(page, summary) {
      archiveOptions.getProtectToken(function(token) {
        archiveOptions.protectPage(page, summary, token);
      });
    },
    getProtectToken: function(callback) {
      (new mw.Api()).post({
        action: 'query',
        meta: 'tokens',
        type: 'csrf'
      }).done(function(data) {
        if (data.error && data.error.info) {
          console.log(data.error);
          mw.notify(data.error.info, {
            type: 'error'
          });
        } else {
          callback(data.query.tokens.csrftoken);
        }
      }).fail(function(data) {
        mw.notify(data);
      });
    },
    protectPage: function(title, summary, token) {
      (new mw.Api()).post({
        action: 'protect',
        title: title,
        reason: summary,
        token: token,
        protections: 'create=sysop',
        expiry: '1 year',
      }).done(function(data) {
        if (data.error && data.error.info) {
          console.log(data.error);
          mw.notify(data.error.info, {
            type: 'error'
          });
        } else {
          mw.notify('مقاله محافظت شد!');
        }
      }).fail(function(data) {
        mw.notify(data);
      });
    },
    savePage: function(title, text, summary, callback) {
      (new mw.Api()).post({
        action: 'edit',
        title: title,
        text: text,
        summary: summary,
        minor: '',
        token: mw.user.tokens.get('csrfToken')
      }).done(function(data) {
        if (data.error && data.error.info) {
          console.log(data.error);
          if (data.error.info === 'missingtitle') {
            mw.notify('صفحه ' + title + ' موجود نیست!', {
              type: 'error'
            });
          } else {
            mw.notify(data.error.info, {
              type: 'error'
            });
          }
        } else {
          callback();
        }
      }).fail(function(data) {
        mw.notify(data);
      });
    },
    extendPage: function(text) {
      text = text + "\n{{جا:تمدید حذف" + "|" + archiveOptions.textReason.getValue() + "}}";
      $(window).off('beforeunload');
      return text;
    },
    closePage: function(text) {
      text = text.replace(new RegExp('<noinclude' + '>\\{\\{\(?:این الگو را زمان بستن نبح حذف کن\|REMOVE THIS TEMPLATE WHEN CLOSING THIS AfD\)\\|\.+?\\}\\}<\\/noinclude' +
        '>\\n?', 'g'), '');
      text = '{{آغاز بایگانی حذف}}\n\n' + archiveOptions.decisionCategory + '\n' + archiveOptions.reason + '\n~~' + '~~\n' + text + '\n{{پایان بایگانی حذف}}';
      mw.notify('نظرخواهی بسته شد!');
      return text;
    },
    closeTalkPage: function(text) {
      var page_name = mw.config.get("wgPageName");
      text = '{{پیشینه حذف| تاریخ =~~' + '~~' + '~| نتیجه =' + archiveOptions.reason + ' | صفحه =' + page_name.replace(/\_/g, ' ') + ' |کوچک=}}\n\n' + text;
      text = text.replace("صفحه =ویکی‌پدیا:نظرخواهی برای حذف/", "صفحه =")
      mw.notify('الگو پیشینه حذف به بحث صفحه افزوده شد!');
      return text;
    },
    archivePage: function(text) {
      var pagelink = mw.config.get("wgPageName");
      text = text + '\n# [[' + pagelink.replace(/\_/g, ' ') + ']] -- ' + archiveOptions.shortReason + ' ~~' + '~~'
      mw.notify('بایگانی به‌روز شد.');
      // Let the user close the tab without a warning
      $(window).off('beforeunload');
      return text;
    },
    removeLink: function(text) {
      var pagelink = mw.config.get("wgPageName");
      var isDraftPrefixed = pagelink.indexOf('/پیش‌نویس:') !== -1;
      var pagelinkNoPrefix = pagelink.replace(/\/پیش‌نویس:/, '/').replace(/\_/g, ' ');
      var text2 = text;
      pagelink = pagelink.replace(/\_/g, ' ');
      text = text.replace('{{' + pagelink + '}}\n', '')
      // Try the pagename without draft prefix (if there is one)
      if (text2 === text && isDraftPrefixed) {
      	text = text.replace('{{' + pagelinkNoPrefix + '}}\n', '');
      }
      if (text2 === text) {
        mw.notify('توجه:برداشتن نظرخواهی از وپ:نبح با خطا مواجه شد!', {
          type: 'error'
        });
      } else {
        mw.notify('نظرخواهی از وپ:نبح برداشته شد!')
      }
      return text;
    },
    removeTemplate: function(text) {
      var text2 = text;
      text = text.replace(/(\<!--(.+?)--\>\n*|)\{\{(نظرخواهی برای حذف|پیشنهاد حذف\s?۲)(.+?|)\}\}(\n*\<!--(.+?)--\>|)(\n*\<!--(.+?)--\>|)/g, '');
      text = text.replace(/\<!-- قبلاً پیشنهاد حذف داده شده‌است(.+?)--\>/g, '');
      text = text.replace(/\<noinclude\>\n*\<\/noinclude\>/g, '');
      if (text2 === text) {
        mw.notify('توجه:برداشتن الگو از مقاله با مشکل مواجه شد!', {
          type: 'error'
        });
      } else {
        mw.notify('الگو پیشنهاد حذف از صفحه برداشته شد!');
      }
      text = text.trim()
      return text;
    },
    loadSavePageRefresh: function(page, replaceCallback, summary) {
      archiveOptions.loadPage(page, function(text) {
        archiveOptions.savePage(page, replaceCallback(text), summary, function() {
          setTimeout(function() {
            location.reload();
          }, 2000);
        });
      });
    },
    deletePageRefresh: function(page, summary, protect) {
      archiveOptions.getDeleteToken(function(token) {
        if (protect === true) {
          archiveOptions.deletePage(page, summary, token, archiveOptions.protectPageRefresh);
        } else {
          archiveOptions.deletePage(page, summary, token, function() {});
        }
      });
    },
    getDeleteToken: function(callback) {
      (new mw.Api()).post({
        action: 'query',
        meta: 'tokens',
        type: 'csrf'
      }).done(function(data) {
        if (data.error && data.error.info) {
          console.log(data.error);
          mw.notify(data.error.info, {
            type: 'error'
          });
        } else {
          callback(data.query.tokens.csrftoken);
        }
      }).fail(function(data) {
        mw.notify(data);
      });
    },
    deletePage: function(title, summary, token, callback) {
      (new mw.Api()).post({
        action: 'delete',
        title: title,
        reason: summary,
        token: token,
      }).done(function(data) {
        if (data.error && data.error.info) {
          console.log(data.error);
          if (data.error.info === 'missingtitle') {
            mw.notify('صفحه ' + title + ' موجود نیست!', {
              type: 'error'
            });
          } else {
            mw.notify(data.error.info, {
              type: 'error'
            });
          }
        } else {
          mw.notify('مقاله حذف شد!');
          callback(title, 'محافظت صفحه بر اساس [[ویکی‌پدیا:نظرخواهی_برای_حذف/' + title +
            '|نظرخواهی برای حذف]] ([[مدیاویکی:Gadget-AfD.js|ابزار جمع‌بندی]])');
        }
      }).fail(function(data) {
        mw.notify(data);
      });
      if (title.search(/کاربر:|الگو:|رده:|ویکی‌پدیا:|درگاه:|راهنما:/) > -1) {
        var TalkLink = 'بحث ' + title;
      } else {
        var TalkLink = 'بحث:' + title;
      }
      (new mw.Api()).post({
        action: 'delete',
        title: TalkLink,
        reason: summary,
        token: token,
      }).done(function(data) {
        if (data.error && data.error.info) {
          console.log(data.error);
          mw.notify(data.error.info, {
            type: 'error'
          });
        } else {
          mw.notify('بحث مقاله حذف شد!');
        }
      }).fail(function(data) {
        mw.notify(data);
      });
    },
  };
  if (mw.config.get('wgNamespaceNumber') >= 0) {
    $(archiveOptions.install);
  }
})(jQuery, mediaWiki);