پرش به محتوا

مدیاویکی:Gadget-close.js: تفاوت میان نسخه‌ها

از دانشنامه علوم انسانی
imported>Huji
خنثی‌سازی ویرایش 18117635 توسط Ladsgroup (بحث) در تاریخچه نامتان نیست؛ جای اشتباه ویرایش کردید؟
imported>Huji
تغییرات اساسی: رابط کاربری مبتنی بر OOjs UI، امکان انتخاب دقیق آن چه نمایش داده می‌شود
خط ۱: خط ۱:
/* by Arash.pt & Ebraminio & Yamaha5 & Huji & Dalba */
/*global jQuery, mediaWiki */
/*global $, mw, prompt, confirm*/
(function($, mw) {
/*jslint regexp: true, vars: true, indent: 2, white: true*/
  'use strict';
$(function () {
  var windowManager;
    'use strict';
  var archiveSection;
    function setIndentation (txt,AddTxt) {
  var commentInSection;
        txt=txt.replace('\r','')
  var archiveSectionOptions = {
        var lrI = txt.lastIndexOf('\n');
    install: function() {
        var Lline=txt.lastIndexOf('\n:');
      if (1 == 1) {
        if (Lline!==-1) {
        $('.mw-editsection').each(function() {
            var txtE = txt.slice(Lline);
          var span = $('<span>', {
            var lrM = txtE.match(/\n[:]+ ?/);
            class: 'mw-editsection mw-archivesection'
            if (lrM) {
          }).insertBefore(this);
                var lrLen = lrM[0].trim().length;
          span.append($('<span>', {
                if (lrLen) {
             class: 'mw-editsection-bracket',
                    txt=txt + '\n' + lrM[0].trim()+': ' + AddTxt.trim()
             text: '['
                }else{
          }));
                    txt=txt + '\n: ' + AddTxt.trim()
          span.append($('<a>', {
                }
             href: '#',
             }else{
             title: 'ثبت نظر (موافق/مخالف/شد/...)',
                txt=txt + '\n: ' + AddTxt.trim()
             style: 'font-size: smaller;',
             }
             text: 'ثبت نظر',
        }else{
          }).click(function(e) {
            txt=txt + '\n: ' + AddTxt.trim()
             e.preventDefault();
        }
             var section = e.target;
        return txt
             mw.loader.using(['oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows']).done(function() {
    }
              archiveSectionOptions.createCommentWindow(section);
    function answered(page, sectionId, type, action) {
             });
        new mw.Api().get({
          }));
             format: 'json',
          span.append($('<span>', {
             action: 'query',
             class: 'mw-editsection-bracket',
             titles: page,
            text: ' / '
            rvsection: sectionId,
          }));
             prop: 'revisions',
          span.append($('<a>', {
            rvprop: 'content'
            href: '#',
        }).then(function (data) {
            title: 'جمع‌بندی این بخش',
             var editsummary = ' (به کمک [[مدیاویکی:Gadget-close.js|ابزار جمع‌بندی]])';
            style: 'font-size: smaller;',
             var str = data.query.pages[Object.keys(data.query.pages)[0]].revisions[0]['*'];
            text: 'جمع‌بندی',
             var title = (str.match(/^(=+)[^=]*?(\1)$/m) || [''])[0];
          }).click(function(e) {
            var title_text = title.replace(/\=/g, '');
             e.preventDefault();
            var the_reason = prompt("توضیح برای " + action + ":");
            var section = e.target;
            if (mw.config.get('wgPageName').search('نظرخواهی') > 0){
             mw.loader.using(['oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows']).done(function() {
                var starting='#';
              archiveSectionOptions.createArchiveWindow(section);
            }else{
                var starting='*';
            }
            if (the_reason.length <= 1) { the_reason = ""; }
             if (type === 'request') {
                var requestStatus = confirm('آیا درخواست انجام شده‌است؟ یا ناموفق بود؟ (برای موفق Ok و برای ناموفق Cancel را بزنید)');
                var the_reason2 = "";
                if (!requestStatus) {
                    the_reason2 = "|ناموفق=بله";
                }
                if(the_reason != "") {
                    the_reason = the_reason + ' – ~~' + '~~';
                    str = str.replace(title, title + "\n{{بسته" + the_reason2 + "}}\n'''" + the_reason + "'''\n");
                } else {
                    str = str.replace(title, title + "\n{{بسته" + the_reason2 + "}}");
                }
                str = str + "\n{{پایان بسته}}";
                editsummary = 'جمع‌بندی شد' + editsummary;
            } else if (type === 'talk') {
                the_reason = "|" + the_reason;
                str = str.replace(title, title + "\n{{بحث بسته" + the_reason + "}}");
                str = str + "\n{{پایان بسته}}";
                editsummary = 'جمع‌بندی شد' + editsummary;
             } else if (type === 'done') {
                if (mw.config.get('wgPageName')=='ویکی‌پدیا:درخواست_انتقال'||mw.config.get('wgPageName')=='ویکی‌پدیا:درخواست_ادغام_تاریخچه'){
                    str=str.replace('{{وضعیت|}}','{{وضعیت|شد}}');
                }
                str = str + "\n:{{شد}} " + the_reason + ' – ~~' + '~~';
                editsummary = 'انجام شد' + editsummary;
            } else if (type === 'requestdone') {
                var requestStatus = confirm('آیا درخواست انجام شده‌است؟ یا ناموفق بود؟ (برای موفق Ok و برای ناموفق Cancel را بزنید)');
                if (!requestStatus) {
                    if (mw.config.get('wgPageName')=='ویکی‌پدیا:درخواست_انتقال' || mw.config.get('wgPageName')=='ویکی‌پدیا:درخواست_ادغام_تاریخچه') {
                        str=str.replace('{{وضعیت|}}','{{وضعیت|نشد}}');
                    }
                    the_reason2 = "|ناموفق=بله";
                    editsummary = 'انجام نشد' + editsummary;
                    str = str + "\n:{{نشد}} " + the_reason + ' – ~~' + '~~';
                }
                else {
                    if (mw.config.get('wgPageName')=='ویکی‌پدیا:درخواست_انتقال' || mw.config.get('wgPageName')=='ویکی‌پدیا:درخواست_ادغام_تاریخچه') {
                        str=str.replace('{{وضعیت|}}','{{وضعیت|شد}}');
                    }
                    the_reason2 = "";
                    editsummary = 'انجام شد' + editsummary;
                    str = str + "\n:{{شد}} " + the_reason + ' – ~~' + '~~';
                }
                str = str.replace(title, title + "\n{{بسته" + the_reason2 + "}}");
                str = str + "\n{{پایان بسته}}";
             } else if (type === 'answer') {
                str=setIndentation (str,the_reason)+ ' – ~~' + '~~';
                editsummary = 'پاسخ داده شد' + editsummary;
             } else if (type === 'notdone') {
                if (mw.config.get('wgPageName')=='ویکی‌پدیا:درخواست_انتقال'||mw.config.get('wgPageName')=='ویکی‌پدیا:درخواست_ادغام_تاریخچه'){
                    str=str.replace('{{وضعیت|}}','{{وضعیت|نشد}}');
                }
                str = str + "\n:{{نشد}} " + the_reason + ' – ~~' + '~~';
                editsummary = 'نشد!' + editsummary;
            } else if (type === 'support') {
                str = str + "\n"+starting+" {{موافق}} " + the_reason + ' – ~~' + '~~';
                editsummary = 'موافقم' + editsummary;
            } else if (type === 'oppose') {
                str = str + "\n"+starting+" {{مخالف}} " + the_reason + ' – ~~' + '~~';
                editsummary = 'مخالفم' + editsummary;
            }
            editsummary = '/*' + title_text + '*/' + editsummary;
            return new mw.Api().post({
                format: 'json',
                action: 'edit',
                title: page,
                section: sectionId,
                summary: editsummary,
                text: str,
                token: mw.user.tokens.get('editToken')
             });
             });
        }).then(function () {
          }));
            mw.notify('انجام شد');
          span.append($('<span>', {
             location.hash = $('.mw-headline')[sectionId - 1].id;
             class: 'mw-editsection-bracket',
            location.reload(true);
            text: ']'
        }, function (error) {
          }));
            mw.notify('به دلیلی موفقیت‌آمیز نبود: ' + error);
          // Late pre-loading
            location.reload(true);
          mw.loader.load(['oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows']);
         });
         });
     }
      }
     },
    createArchiveWindow: function(section) {
      var query = archiveSectionOptions.getQuery(section);
      archiveSectionOptions.currentSectionId = query.section;


    function addLink(section, type, html, color, title) {
      function ArchiveSection(config) {
         $('<a>', {
        ArchiveSection.super.call(this, config);
            href: '#',
      }
            title: title,
      OO.inheritClass(ArchiveSection, OO.ui.ProcessDialog);
            style: 'float: left; color: ' + color,
      ArchiveSection.static.name = 'archive';
            html: html
      ArchiveSection.static.title = 'جمع‌بندی بخش';
         }).click(function (e) {
      ArchiveSection.static.actions = [{
            e.preventDefault();
        action: 'archive',
            var query = new mw.Uri($(section).next().find('a[href*="&action=edit"]')[0].href).query;
        label: 'جمع‌بندی',
            answered(query.title, +query.section.replace('T-', ''), type, title);
        flags: 'primary'
        }).insertBefore(section);
      }, {
    }
        label: 'لغو',
        flags: 'safe'
      }];
      ArchiveSection.prototype.initialize = function() {
        var fieldset = [];
        ArchiveSection.super.prototype.initialize.apply(this, arguments);
        this.panel = new OO.ui.PanelLayout({
          padded: true,
          expanded: false
         });
        this.content = new OO.ui.FieldsetLayout();
        archiveSectionOptions.switchTop = new OO.ui.ToggleSwitchWidget({
          label: 'جمع‌بندی بالای متن باشد',
          value: true,
        });
        archiveSectionOptions.switchSuccess = new OO.ui.ToggleSwitchWidget({
          label: 'بحث در رسیدن به اجماع موفق بود',
          value: true,
        });
        archiveSectionOptions.switchDone = new OO.ui.ToggleSwitchWidget({
          label: 'قبل از جمع‌بندی برچسب {{شد}} اضافه شود',
          value: false,
        });
        archiveSectionOptions.textSummary = new OO.ui.TextInputWidget({
          placeholder: 'متن جمع‌بندی را وارد کنید',
        });
        archiveSectionOptions.textSummary.setRTL(true);
        fieldset.push(new OO.ui.FieldLayout(archiveSectionOptions.switchTop, {
          label: 'جمع‌بندی بالای متن باشد',
          align: 'inline',
         }));
        fieldset.push(new OO.ui.FieldLayout(archiveSectionOptions.switchSuccess, {
          label: 'بحث در رسیدن به اجماع موفق بود',
          align: 'inline',
        }));
        fieldset.push(new OO.ui.FieldLayout(archiveSectionOptions.switchDone, {
          label: 'قبل از جمع‌بندی برچسب {{شد}} اضافه شود',
          align: 'inline',
        }));
        fieldset.push(new OO.ui.FieldLayout(archiveSectionOptions.textSummary, {
          label: 'جمع‌بندی:',
          align: 'top'
        }));
        this.content.addItems(fieldset);
        this.panel.$element.append(this.content.$element);
        this.$body.append(this.panel.$element);
      };
      ArchiveSection.prototype.getActionProcess = function(action) {
        var dialog = this;
        if (action === 'archive') {
          archiveSectionOptions.doEdit(archiveSectionOptions.currentSectionId, action);
        }
        return ArchiveSection.super.prototype.getActionProcess.call(this, action);
      };
      if (!windowManager) {
        windowManager = new OO.ui.WindowManager();
        $('body').append(windowManager.$element);
      }
      if (!archiveSection) {
        archiveSection = new ArchiveSection({
          size: 'medium'
        });
        windowManager.addWindows([archiveSection]);
      }
      windowManager.openWindow(archiveSection);
    },
    createCommentWindow: function(section) {
      var query = archiveSectionOptions.getQuery(section);
      archiveSectionOptions.currentSectionId = query.section;


    if (mw.config.get('wgNamespaceNumber') === 3 && mw.config.get('wgPageName').search(mw.config.get('wgUserName')) > 0) {
      function CommentInSection(config) {
         $('.mw-headline').each(function () {
        CommentInSection.super.call(this, config);
            addLink(this, 'answer', 'پ', '#FFC300', 'پاسخ‌دادن');
      }
            addLink(this, 'talk', '&#x2750;', '#090', 'جمع‌بندی بحث');
      OO.inheritClass(CommentInSection, OO.ui.ProcessDialog);
            addLink(this, 'done', '&#x2713;', '#003A5C', '✓ شد');
      CommentInSection.static.title = 'comment';
            addLink(this, 'notdone', '&#x2717;', '#DF0101', '✗ نشد');
      CommentInSection.static.title = 'ثبت نظر';
      CommentInSection.static.actions = [{
        action: 'comment',
        label: 'ثبت نظر',
        flags: 'primary'
      }, {
         label: 'لغو',
        flags: 'safe'
      }];
      CommentInSection.prototype.initialize = function() {
        var fieldset = [];
        CommentInSection.super.prototype.initialize.apply(this, arguments);
        this.panel = new OO.ui.PanelLayout({
          padded: true,
          expanded: false
        });
        this.content = new OO.ui.FieldsetLayout();
        archiveSectionOptions.radioDone = new OO.ui.RadioOptionWidget({
          label: 'شد',
        });
        archiveSectionOptions.radioSupport = new OO.ui.RadioOptionWidget({
          label: 'موافق',
        });
        archiveSectionOptions.radioOppose = new OO.ui.RadioOptionWidget({
          label: 'مخالف',
        });
        archiveSectionOptions.radioCommentType = new OO.ui.RadioSelectWidget({
          items: [archiveSectionOptions.radioDone,
            archiveSectionOptions.radioSupport,
            archiveSectionOptions.radioOppose
          ]
        });
        archiveSectionOptions.radioCommentType.selectItem(archiveSectionOptions.radioDone);
        archiveSectionOptions.textComment = new OO.ui.TextInputWidget({
          placeholder: 'متن نظر را وارد کنید',
        });
        archiveSectionOptions.textComment.setRTL(true);
        fieldset.push(new OO.ui.FieldLayout(archiveSectionOptions.radioCommentType, {
          label: 'برچسب قبل از نظر',
          align: 'top'
        }));
        fieldset.push(new OO.ui.FieldLayout(archiveSectionOptions.textComment, {
          label: 'متن نظر:',
          align: 'top'
        }));
        this.content.addItems(fieldset);
        this.panel.$element.append(this.content.$element);
        this.$body.append(this.panel.$element);
      };
      CommentInSection.prototype.getActionProcess = function(action) {
        var dialog = this;
        if (action === 'comment') {
          archiveSectionOptions.doEdit(archiveSectionOptions.currentSectionId, action);
        }
        return CommentInSection.super.prototype.getActionProcess.call(this, action);
      };
      if (!windowManager) {
        windowManager = new OO.ui.WindowManager();
        $('body').append(windowManager.$element);
      }
      if (!commentInSection) {
        commentInSection = new CommentInSection({
          size: 'medium'
         });
         });
     } else if (mw.config.get('wgNamespaceNumber') === 4) {
        windowManager.addWindows([commentInSection]);
         if ($([
      }
            '#catlinks a[href="/wiki/%D8%B1%D8%AF%D9%87:%D8%B1%D9%87%D9%86%D9%85%D9%88%D8%AF%D9%87%D8%A7%DB%8C_%D9%88%DB%8C%DA%A9%DB%8C%E2%80%8C%D9%BE%D8%AF%DB%8C%D8%A7"]', //رده:رهنمودهای ویکی‌پدیا
      windowManager.openWindow(commentInSection);
             '#catlinks a[href="/wiki/%D8%B1%D8%AF%D9%87:%D8%B3%DB%8C%D8%A7%D8%B3%D8%AA%E2%80%8C%D9%87%D8%A7%DB%8C_%D9%88%DB%8C%DA%A9%DB%8C%E2%80%8C%D9%BE%D8%AF%DB%8C%D8%A7"]', //رده:سیاست‌های ویکی‌پدیا
     },
             '#catlinks a[href="/wiki/%D8%B1%D8%AF%D9%87:%D8%B1%D8%A7%D9%87%D9%86%D9%85%D8%A7%DB%8C_%D9%88%DB%8C%DA%A9%DB%8C%E2%80%8C%D9%BE%D8%AF%DB%8C%D8%A7"]', //رده:راهنمای ویکی‌پدیا
    getQuery: function(section) {
            '#catlinks a[href="/wiki/%D8%B1%D8%AF%D9%87:%D8%B4%DB%8C%D9%88%D9%87%E2%80%8C%D9%86%D8%A7%D9%85%D9%87%E2%80%8C%D9%87%D8%A7%DB%8C_%D9%88%DB%8C%DA%A9%DB%8C%E2%80%8C%D9%BE%D8%AF%DB%8C%D8%A7"]', //رده:شیوه‌نامه‌های ویکی‌پدیا
      var href = $(section).parent().next().find('a').attr('href');
            '#catlinks a[href="/wiki/%D8%B1%D8%AF%D9%87:%D8%A7%D8%A8%D8%B2%D8%A7%D8%B1%D9%87%D8%A7%DB%8C_%D9%88%DB%8C%DA%A9%DB%8C%E2%80%8C%D9%BE%D8%AF%DB%8C%D8%A7"]', //رده:ابزارهای ویکی‌پدیا
      var query = new mw.Uri(href).query;
            '#catlinks a[href="/wiki/%D8%B1%D8%AF%D9%87:%D8%AE%D9%88%D8%AF%D8%A2%D9%85%D9%88%D8%B2_%D9%88%DB%8C%DA%A9%DB%8C%E2%80%8C%D9%BE%D8%AF%DB%8C%D8%A7"]', //رده:خودآموز ویکی‌پدیا
      return query;
            '#catlinks a[href="/wiki/%D8%B1%D8%AF%D9%87:%D8%A7%D9%86%D8%B4%D8%A7%D9%87%D8%A7%DB%8C_%D9%88%DB%8C%DA%A9%DB%8C%E2%80%8C%D9%BE%D8%AF%DB%8C%D8%A7"]', //رده:انشاهای ویکی‌پدیا
    },
            '#catlinks a[href="/wiki/%D8%B1%D8%AF%D9%87:%D9%85%D8%AF%DB%8C%D8%B1%DB%8C%D8%AA_%D9%88%DB%8C%DA%A9%DB%8C%E2%80%8C%D9%BE%D8%AF%DB%8C%D8%A7"]' //رده:مدیریت ویکی‌پدیا
    setIndentation: function(text, newText) {
         ].join(', ')).length === 0) {
      text = text.replace('\r', '')
            $('.mw-headline').each(function () {
      var lrI = text.lastIndexOf('\n');
                var groups = mw.config.get('wgUserGroups');
      var Lline = text.lastIndexOf('\n:');
                if (groups.indexOf('sysop') > -1 || groups.indexOf('eliminator') > -1) {
      if (Lline !== -1) {
                    addLink(this, 'answer', 'پ', '#FFC300', 'پاسخ‌دادن');
         var textE = text.slice(Lline);
                    addLink(this, 'request', '&#x2750;', '#090', 'جمع‌بندی بحث');
        var lrM = textE.match(/\n[:]+ ?/);
                    addLink(this, 'done', '&#x2713;', '#003A5C', '✓ شد');
        if (lrM) {
                    addLink(this, 'requestdone', '☑', '#003A5C', '☑ شد/نشد و جمع‌بندی');
          var lrLen = lrM[0].trim().length;
                    addLink(this, 'notdone', '&#x2717;', '#DF0101', '✗ نشد');
          if (lrLen) {
                }
             text = text + '\n' + lrM[0].trim() + ': ' + newText.trim()
                addLink(this, 'support', '&#x263A;', '#090', 'موافقم');
          } else {
                addLink(this, 'oppose', '&#x2639;', '#DF0101', 'مخالفم');
             text = text + '\n: ' + newText.trim()
            });
          }
        } else {
          text = text + '\n: ' + newText.trim()
        }
      } else {
        text = text + '\n: ' + newText.trim()
      }
      return text
    },
    doEdit: function(sectionId, action) {
      (new mw.Api()).get({
        format: 'json',
        action: 'query',
        titles: mw.config.get("wgPageName"),
        rvsection: sectionId,
        prop: 'revisions',
        rvprop: 'content',
      }).then(function(data) {
        var page = data.query.pages[Object.keys(data.query.pages)[0]];
        var current = page.revisions[0]['*'];
         var header = current.substr(0, current.indexOf('\n'));
        var content = current.substr(current.indexOf('\n') + 1);
        var newText = '';
        var section_title = (current.match(/^(=+)[^=]*?(\1)$/m) || [''])[0];
        section_title = section_title.replace(/\=/g, '');
        var editSummary = '/' + '*' + section_title + '*' + '/ جمع‌بندی: ';
        if (action == 'archive') {
          editSummary += archiveSectionOptions.textSummary.getValue();
          newText = header + '\n';
          newText += '{{بسته';
          if (archiveSectionOptions.switchSuccess.getValue()) {
            newText += '}}\n';
          } else {
            newText += '|ناموفق=بله}}\n';
          }
          if (archiveSectionOptions.switchTop.getValue()) {
            newText += ':';
            if (archiveSectionOptions.switchDone.getValue()) {
              newText += '{{شد}} ';
            }
            newText += "'''جمع‌بندی:''' ";
            newText += archiveSectionOptions.textSummary.getValue();
            newText += ' ~~' + '~~\n';
            newText += content + '\n{{پایان بسته}}';
          } else {
            var summary = '';
            if (archiveSectionOptions.switchDone.getValue()) {
              summary += '{{شد}} ';
            } else {
              summary += "'''جمع‌بندی:''' ";
            }
            summary += archiveSectionOptions.textSummary.getValue();
            summary += ' ~~' + '~~\n';
            newText = archiveSectionOptions.setIndentation(newText + content, summary);
            newText += '\n{{پایان بسته}}';
          }
          return (new mw.Api()).post({
            format: 'json',
            action: 'edit',
            title: mw.config.get("wgPageName"),
            section: sectionId,
            summary: editSummary,
            text: newText,
            token: mw.user.tokens.get('editToken')
          });
        } else {
          editSummary += archiveSectionOptions.textComment.getValue();
          if (archiveSectionOptions.radioDone.isSelected()) {
            newText = '{{شد}} ';
            editSummary += 'انجام شد';
          } else if (archiveSectionOptions.radioSupport.isSelected()) {
            newText = '{{موافق}} ';
            editSummary += 'ثبت نظر موافق';
          } else {
            newText = '{{مخالف}} ';
            editSummary += 'ثبت نظر مخالف';
          }
          newText += archiveSectionOptions.textComment.getValue();
          newText += ' ~~' + '~~';
          newText = archiveSectionOptions.setIndentation(current, newText);
          return (new mw.Api()).post({
            format: 'json',
            action: 'edit',
            title: mw.config.get("wgPageName"),
            section: sectionId,
            summary: editSummary,
            text: newText,
            token: mw.user.tokens.get('editToken')
          });
        }
      }).then(function() {
        if (action == 'archive') {
          mw.notify('جمع‌بندی شما ثبت شد!');
        } else {
          mw.notify('نظر شما ثبت شد!');
         }
         }
    } else if (mw.config.get('wgNamespaceNumber') % 2 !== 0) { // برای صفحات بحث
        location.hash = $('.mw-headline')[sectionId - 1].id;
        $('.mw-headline').each(function () {
        location.reload(true);
            addLink(this, 'answer', 'پ', '#FFC300', 'پاسخ‌دادن');
      }, function(error) {
            addLink(this, 'request', '&#x2750;', '#090', 'جمع‌بندی بحث');
        mw.notify('ثبت نظر یا جمع‌بندی ناموفق بود: ' + error, {
            addLink(this, 'done', '&#x2713;', '#003A5C', '✓ شد');
          type: 'error'
            addLink(this, 'requestdone', '☑', '#003A5C', '☑ شد/نشد و جمع‌بندی');
            addLink(this, 'notdone', '&#x2717;', '#DF0101', '✗ نشد');
         });
         });
     }
      })
});
    },
     currentSectionId: -1,
  };
  if (mw.config.get('wgNamespaceNumber') >= 0) {
    $(archiveSectionOptions.install);
  }
})(jQuery, mediaWiki);

نسخهٔ ۵ نوامبر ۲۰۱۶، ساعت ۰۴:۳۴

/*global jQuery, mediaWiki */
(function($, mw) {
  'use strict';
  var windowManager;
  var archiveSection;
  var commentInSection;
  var archiveSectionOptions = {
    install: function() {
      if (1 == 1) {
        $('.mw-editsection').each(function() {
          var span = $('<span>', {
            class: 'mw-editsection mw-archivesection'
          }).insertBefore(this);
          span.append($('<span>', {
            class: 'mw-editsection-bracket',
            text: '['
          }));
          span.append($('<a>', {
            href: '#',
            title: 'ثبت نظر (موافق/مخالف/شد/...)',
            style: 'font-size: smaller;',
            text: 'ثبت نظر',
          }).click(function(e) {
            e.preventDefault();
            var section = e.target;
            mw.loader.using(['oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows']).done(function() {
              archiveSectionOptions.createCommentWindow(section);
            });
          }));
          span.append($('<span>', {
            class: 'mw-editsection-bracket',
            text: ' / '
          }));
          span.append($('<a>', {
            href: '#',
            title: 'جمع‌بندی این بخش',
            style: 'font-size: smaller;',
            text: 'جمع‌بندی',
          }).click(function(e) {
            e.preventDefault();
            var section = e.target;
            mw.loader.using(['oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows']).done(function() {
              archiveSectionOptions.createArchiveWindow(section);
            });
          }));
          span.append($('<span>', {
            class: 'mw-editsection-bracket',
            text: ']'
          }));
          // Late pre-loading
          mw.loader.load(['oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows']);
        });
      }
    },
    createArchiveWindow: function(section) {
      var query = archiveSectionOptions.getQuery(section);
      archiveSectionOptions.currentSectionId = query.section;

      function ArchiveSection(config) {
        ArchiveSection.super.call(this, config);
      }
      OO.inheritClass(ArchiveSection, OO.ui.ProcessDialog);
      ArchiveSection.static.name = 'archive';
      ArchiveSection.static.title = 'جمع‌بندی بخش';
      ArchiveSection.static.actions = [{
        action: 'archive',
        label: 'جمع‌بندی',
        flags: 'primary'
      }, {
        label: 'لغو',
        flags: 'safe'
      }];
      ArchiveSection.prototype.initialize = function() {
        var fieldset = [];
        ArchiveSection.super.prototype.initialize.apply(this, arguments);
        this.panel = new OO.ui.PanelLayout({
          padded: true,
          expanded: false
        });
        this.content = new OO.ui.FieldsetLayout();
        archiveSectionOptions.switchTop = new OO.ui.ToggleSwitchWidget({
          label: 'جمع‌بندی بالای متن باشد',
          value: true,
        });
        archiveSectionOptions.switchSuccess = new OO.ui.ToggleSwitchWidget({
          label: 'بحث در رسیدن به اجماع موفق بود',
          value: true,
        });
        archiveSectionOptions.switchDone = new OO.ui.ToggleSwitchWidget({
          label: 'قبل از جمع‌بندی برچسب {{شد}} اضافه شود',
          value: false,
        });
        archiveSectionOptions.textSummary = new OO.ui.TextInputWidget({
          placeholder: 'متن جمع‌بندی را وارد کنید',
        });
        archiveSectionOptions.textSummary.setRTL(true);
        fieldset.push(new OO.ui.FieldLayout(archiveSectionOptions.switchTop, {
          label: 'جمع‌بندی بالای متن باشد',
          align: 'inline',
        }));
        fieldset.push(new OO.ui.FieldLayout(archiveSectionOptions.switchSuccess, {
          label: 'بحث در رسیدن به اجماع موفق بود',
          align: 'inline',
        }));
        fieldset.push(new OO.ui.FieldLayout(archiveSectionOptions.switchDone, {
          label: 'قبل از جمع‌بندی برچسب {{شد}} اضافه شود',
          align: 'inline',
        }));
        fieldset.push(new OO.ui.FieldLayout(archiveSectionOptions.textSummary, {
          label: 'جمع‌بندی:',
          align: 'top'
        }));
        this.content.addItems(fieldset);
        this.panel.$element.append(this.content.$element);
        this.$body.append(this.panel.$element);
      };
      ArchiveSection.prototype.getActionProcess = function(action) {
        var dialog = this;
        if (action === 'archive') {
          archiveSectionOptions.doEdit(archiveSectionOptions.currentSectionId, action);
        }
        return ArchiveSection.super.prototype.getActionProcess.call(this, action);
      };
      if (!windowManager) {
        windowManager = new OO.ui.WindowManager();
        $('body').append(windowManager.$element);
      }
      if (!archiveSection) {
        archiveSection = new ArchiveSection({
          size: 'medium'
        });
        windowManager.addWindows([archiveSection]);
      }
      windowManager.openWindow(archiveSection);
    },
    createCommentWindow: function(section) {
      var query = archiveSectionOptions.getQuery(section);
      archiveSectionOptions.currentSectionId = query.section;

      function CommentInSection(config) {
        CommentInSection.super.call(this, config);
      }
      OO.inheritClass(CommentInSection, OO.ui.ProcessDialog);
      CommentInSection.static.title = 'comment';
      CommentInSection.static.title = 'ثبت نظر';
      CommentInSection.static.actions = [{
        action: 'comment',
        label: 'ثبت نظر',
        flags: 'primary'
      }, {
        label: 'لغو',
        flags: 'safe'
      }];
      CommentInSection.prototype.initialize = function() {
        var fieldset = [];
        CommentInSection.super.prototype.initialize.apply(this, arguments);
        this.panel = new OO.ui.PanelLayout({
          padded: true,
          expanded: false
        });
        this.content = new OO.ui.FieldsetLayout();
        archiveSectionOptions.radioDone = new OO.ui.RadioOptionWidget({
          label: 'شد',
        });
        archiveSectionOptions.radioSupport = new OO.ui.RadioOptionWidget({
          label: 'موافق',
        });
        archiveSectionOptions.radioOppose = new OO.ui.RadioOptionWidget({
          label: 'مخالف',
        });
        archiveSectionOptions.radioCommentType = new OO.ui.RadioSelectWidget({
          items: [archiveSectionOptions.radioDone,
            archiveSectionOptions.radioSupport,
            archiveSectionOptions.radioOppose
          ]
        });
        archiveSectionOptions.radioCommentType.selectItem(archiveSectionOptions.radioDone);
        archiveSectionOptions.textComment = new OO.ui.TextInputWidget({
          placeholder: 'متن نظر را وارد کنید',
        });
        archiveSectionOptions.textComment.setRTL(true);
        fieldset.push(new OO.ui.FieldLayout(archiveSectionOptions.radioCommentType, {
          label: 'برچسب قبل از نظر',
          align: 'top'
        }));
        fieldset.push(new OO.ui.FieldLayout(archiveSectionOptions.textComment, {
          label: 'متن نظر:',
          align: 'top'
        }));
        this.content.addItems(fieldset);
        this.panel.$element.append(this.content.$element);
        this.$body.append(this.panel.$element);
      };
      CommentInSection.prototype.getActionProcess = function(action) {
        var dialog = this;
        if (action === 'comment') {
          archiveSectionOptions.doEdit(archiveSectionOptions.currentSectionId, action);
        }
        return CommentInSection.super.prototype.getActionProcess.call(this, action);
      };
      if (!windowManager) {
        windowManager = new OO.ui.WindowManager();
        $('body').append(windowManager.$element);
      }
      if (!commentInSection) {
        commentInSection = new CommentInSection({
          size: 'medium'
        });
        windowManager.addWindows([commentInSection]);
      }
      windowManager.openWindow(commentInSection);
    },
    getQuery: function(section) {
      var href = $(section).parent().next().find('a').attr('href');
      var query = new mw.Uri(href).query;
      return query;
    },
    setIndentation: function(text, newText) {
      text = text.replace('\r', '')
      var lrI = text.lastIndexOf('\n');
      var Lline = text.lastIndexOf('\n:');
      if (Lline !== -1) {
        var textE = text.slice(Lline);
        var lrM = textE.match(/\n[:]+ ?/);
        if (lrM) {
          var lrLen = lrM[0].trim().length;
          if (lrLen) {
            text = text + '\n' + lrM[0].trim() + ': ' + newText.trim()
          } else {
            text = text + '\n: ' + newText.trim()
          }
        } else {
          text = text + '\n: ' + newText.trim()
        }
      } else {
        text = text + '\n: ' + newText.trim()
      }
      return text
    },
    doEdit: function(sectionId, action) {
      (new mw.Api()).get({
        format: 'json',
        action: 'query',
        titles: mw.config.get("wgPageName"),
        rvsection: sectionId,
        prop: 'revisions',
        rvprop: 'content',
      }).then(function(data) {
        var page = data.query.pages[Object.keys(data.query.pages)[0]];
        var current = page.revisions[0]['*'];
        var header = current.substr(0, current.indexOf('\n'));
        var content = current.substr(current.indexOf('\n') + 1);
        var newText = '';
        var section_title = (current.match(/^(=+)[^=]*?(\1)$/m) || [''])[0];
        section_title = section_title.replace(/\=/g, '');
        var editSummary = '/' + '*' + section_title + '*' + '/ جمع‌بندی: ';
        if (action == 'archive') {
          editSummary += archiveSectionOptions.textSummary.getValue();
          newText = header + '\n';
          newText += '{{بسته';
          if (archiveSectionOptions.switchSuccess.getValue()) {
            newText += '}}\n';
          } else {
            newText += '|ناموفق=بله}}\n';
          }
          if (archiveSectionOptions.switchTop.getValue()) {
            newText += ':';
            if (archiveSectionOptions.switchDone.getValue()) {
              newText += '{{شد}} ';
            }
            newText += "'''جمع‌بندی:''' ";
            newText += archiveSectionOptions.textSummary.getValue();
            newText += ' ~~' + '~~\n';
            newText += content + '\n{{پایان بسته}}';
          } else {
            var summary = '';
            if (archiveSectionOptions.switchDone.getValue()) {
              summary += '{{شد}} ';
            } else {
              summary += "'''جمع‌بندی:''' ";
            }
            summary += archiveSectionOptions.textSummary.getValue();
            summary += ' ~~' + '~~\n';
            newText = archiveSectionOptions.setIndentation(newText + content, summary);
            newText += '\n{{پایان بسته}}';
          }
          return (new mw.Api()).post({
            format: 'json',
            action: 'edit',
            title: mw.config.get("wgPageName"),
            section: sectionId,
            summary: editSummary,
            text: newText,
            token: mw.user.tokens.get('editToken')
          });
        } else {
          editSummary += archiveSectionOptions.textComment.getValue();
          if (archiveSectionOptions.radioDone.isSelected()) {
            newText = '{{شد}} ';
            editSummary += 'انجام شد';
          } else if (archiveSectionOptions.radioSupport.isSelected()) {
            newText = '{{موافق}} ';
            editSummary += 'ثبت نظر موافق';
          } else {
            newText = '{{مخالف}} ';
            editSummary += 'ثبت نظر مخالف';
          }
          newText += archiveSectionOptions.textComment.getValue();
          newText += ' ~~' + '~~';
          newText = archiveSectionOptions.setIndentation(current, newText);
          return (new mw.Api()).post({
            format: 'json',
            action: 'edit',
            title: mw.config.get("wgPageName"),
            section: sectionId,
            summary: editSummary,
            text: newText,
            token: mw.user.tokens.get('editToken')
          });
        }
      }).then(function() {
        if (action == 'archive') {
          mw.notify('جمع‌بندی شما ثبت شد!');
        } else {
          mw.notify('نظر شما ثبت شد!');
        }
        location.hash = $('.mw-headline')[sectionId - 1].id;
        location.reload(true);
      }, function(error) {
        mw.notify('ثبت نظر یا جمع‌بندی ناموفق بود: ' + error, {
          type: 'error'
        });
      })
    },
    currentSectionId: -1,
  };
  if (mw.config.get('wgNamespaceNumber') >= 0) {
    $(archiveSectionOptions.install);
  }
})(jQuery, mediaWiki);