پرش به محتوا

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

از دانشنامه علوم انسانی
imported>Huji
+1
imported>Huji
substantial rewrite, switch to OOUI, better support for parameters
خط ۱: خط ۱:
/**
/**
  * This gadget is a rewrite of the UserMessages gadget, which was influenced by
  * This gadget is a substantial rewrite of the UserMessages gadget, influenced by
  * [[n:en:MediaWiki:Gadget-UserMessages.js]] and [[n:MediaWiki:Gadget-UserMessages.js]]
  * [[n:en:MediaWiki:Gadget-UserMessages.js]] and [[n:MediaWiki:Gadget-UserMessages.js]]
  *  
  *  
  * Unlike the previous version, this uses Morebits simple windows and accepts
  * Unlike the previous versions, this uses OOUI and can accept one or more
  * parameters for the messages that are being posted on the user's talk page.
  * parameters for the messages that are being posted on the user's talk page.
*
* The addPortletLink() function is adopted from Twinkle. See
* https://github.com/azatoth/twinkle for copyright information.
  */
  */


( function ( window, document, $, undefined ) { // Wrapper for anonymous function
(function($, mw) {
  'use strict';
  var windowManager;
  var UM;
  var UMOptions = {
    install: function() {
      if (mw.config.get('wgAction') === 'view') {
        $(mw.util.addPortletLink( 'p-cactions', '#', 'تذکر', 'ca-warn', 'ارسال سریع پیام/تذکر مبتنی بر الگو', '*')).click(function(e) {
          mw.loader.using(['oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows', 'mediawiki.api']).done(UMOptions.createWindow);
          e.preventDefault();
        });
        // Late pre-loading
        mw.loader.load(['oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows', 'mediawiki.api']);
      }
    },
    createWindow: function() {
      function PreviewPanel(config) {
        PreviewPanel.parent.call(this, config);
       
        this.$content = $('<div>').addClass('oo-ui-PreviewPanel');
      }
      OO.inheritClass(PreviewPanel, OO.ui.PanelLayout);
      PreviewPanel.prototype.setContent = function ($content) {
        this.$element.children().detach();
        this.$element.append($content);
        windowManager.getCurrentWindow().updateSize();
      };
      function UserMessages(config) {
        UserMessages.super.call(this, config);
      }
      OO.inheritClass(UserMessages, OO.ui.ProcessDialog);
      UserMessages.static.name = 'Warn dialog';
      UserMessages.static.title = 'ارسال پیام یا تذکر';
      UserMessages.static.actions = [
        {
          action: 'warn',
          label: 'ثبت',
          flags: 'primary'
        },
        {
          label: 'لغو',
          flags: 'safe'
        }
      ];
      UserMessages.prototype.initialize = function() {
        var dialog = this;
        UserMessages.super.prototype.initialize.apply(this, arguments);
       
        this.buttons = [];
        this.buttons['Groups'] = [];
        this.buttons['Noobs'] = [];
        this.buttons['Tools'] = [];
        this.buttons['Article'] = [];
        this.buttons['Copyright'] = [];
        this.buttons['Advanced'] = [];
        this.buttons['Spam'] = [];
        this.buttons['Block'] = [];
        this.buttons['Rights'] = [];


var UserMessages = {};
        this.buttons['Groups']['Noobs'] = new OO.ui.ButtonOptionWidget({
window.UserMessages = UserMessages; // global acecss
          label: 'تازه‌کاران',
          data: {
            group: 'Noobs'
          }
        });
        this.buttons['Groups']['Tools'] = new OO.ui.ButtonOptionWidget({
          label: 'ابزارها',
          data: {
            group: 'Tools'
          }
        });
        this.buttons['Groups']['Article'] = new OO.ui.ButtonOptionWidget({
          label: 'مقاله',
          data: {
            group: 'Article'
          }
        });
        this.buttons['Groups']['Copyright'] = new OO.ui.ButtonOptionWidget({
          label: 'حق تکثیر',
          data: {
            group: 'Copyright'
          }
        });
        this.buttons['Groups']['Advanced'] = new OO.ui.ButtonOptionWidget({
          label: 'پیشرفته',
          data: {
            group: 'Advanced'
          }
        });
        this.buttons['Groups']['Spam'] = new OO.ui.ButtonOptionWidget({
          label: 'هرزنگاری',
          data: {
            group: 'Spam'
          }
        });
        this.buttons['Groups']['Block'] = new OO.ui.ButtonOptionWidget({
          label: 'بستن',
          data: {
            group: 'Block'
          }
        });
        this.buttons['Groups']['Rights'] = new OO.ui.ButtonOptionWidget({
          label: 'دسترسی',
          data: {
            group: 'Rights'
          }
        });


UserMessages.addNewSection = function( summary, content ) {
        this.buttonSelectGroups = new OO.ui.ButtonSelectWidget({
    api = new mw.Api();
          items: [
    api.get( {
            this.buttons['Groups']['Noobs'],
        action : 'query',
            this.buttons['Groups']['Tools'],
        titles : mw.config.get( 'wgPageName' ),
            this.buttons['Groups']['Article'],
        prop  : 'revisions',
            this.buttons['Groups']['Copyright'],
        rvprop : 'content'
            this.buttons['Groups']['Advanced'],
    } ).done( function( data ) {
            this.buttons['Groups']['Spam']
        pages = data.query.pages;
          ]
        page_id = Object.keys(pages)[0];
        });
         if( page_id == -1 ) {
        if ($(mw.config.get('wgUserGroups')).filter(['eliminator', 'sysop']).length > 0) {
            wikitext = content;
          this.buttonSelectGroups.addItems([
        } else {
            this.buttons['Groups']['Block']
             wikitext = pages[page_id].revisions[0]["*"] + '\n\n' + content;
          ]);
        }
         if ($(mw.config.get( 'wgUserGroups' )).filter(['sysop']).length > 0) {
          this.buttonSelectGroups.addItems([
             this.buttons['Groups']['Rights']
          ]);
         }
         }
         api.post( {
         this.buttonSelectGroups.selectItem(this.buttons['Groups']['Noobs']);
            action  : 'edit',
        this.buttonSelectGroups.on('choose', function(item) {
            title  : mw.config.get( 'wgPageName' ),
          dialog.buttonSelectChoices = new OO.ui.ButtonSelectWidget({
            summary : summary,
             items: dialog.buttonSelectChoicesItems[item.data.group]
             text    : wikitext,
          });
            token  : mw.user.tokens.get('editToken')
          dialog.buttonSelectChoices.selectItem();
        } ).done ( function( data ) {
          dialog.panelChoices.$element.children().detach();
            mw.log( "Saved successfully" );
          dialog.panelChoices.$element.append(dialog.buttonSelectChoices.$element);
            location.reload();
          dialog.setChooseAction();
        } ).fail( function( code, result ) {
          dialog.panelParams.toggle(false);
            if ( code === "http" ) {
          dialog.previewResult.toggle(false);
                mw.log( "HTTP error: " + result.textStatus );
          windowManager.getCurrentWindow().updateSize();
            } else if ( code === "ok-but-empty" ) {
         });
                mw.log( "Got an empty response from the server" );
            } else {
                mw.log( "API error: " + code );
            }
         } );
    } );
}


UserMessages.dialog = null;
        this.buttons['Noobs']['WelcomeUser'] = new OO.ui.ButtonOptionWidget({
          label: 'خوشامد (کاربر)',
          data: {
            template: 'خوشامد',
            params: [
              {
                id: '1',
                label: 'پیام تکمیلی (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Noobs']['WelcomeIP'] = new OO.ui.ButtonOptionWidget({
          label: 'خوشامد (آی‌پی)',
          data: {
            template: 'خوشامد-آی‌پی'
          }
        });
        this.buttons['Noobs']['Sign'] = new OO.ui.ButtonOptionWidget({
          label: 'امضا کنید',
          data: {
            template: 'امضا کنید',
            params: [
              {
                id: '1',
                label: 'پیام تکمیلی (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Noobs']['DoNotSign'] = new OO.ui.ButtonOptionWidget({
          label: 'امضا مکنید',
          data: {
            template: 'امضا مکنید',
            params: [
              {
                id: '1',
                label: 'عنوان مقاله (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Noobs']['UploadGuide'] = new OO.ui.ButtonOptionWidget({
          label: 'بارگذاری در ویکی‌فا',
          data: {
            template: 'راهنمای بارگذاری پرونده در ویکی‌فا'
          }
        });
        this.buttons['Noobs']['CommonsGuide'] = new OO.ui.ButtonOptionWidget({
          label: 'بارگذاری در ویکی‌انبار',
          data: {
            template: 'راهنمای بارگذاری پرونده در ویکی‌انبار'
          }
        });
        this.buttons['Noobs']['Keyboard'] = new OO.ui.ButtonOptionWidget({
          label: 'صفحه کلید فارسی',
          data: {
            template: 'استفاده از صفحه کلید فارسی'
          }
        });
        this.buttons['Noobs']['Preview'] = new OO.ui.ButtonOptionWidget({
          label: 'پیش‌نمایش',
          data: {
            template: 'از پیش‌نمایش استفاده کنید',
            params: [
              {
                id: '1',
                label: 'عنوان مقاله (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Noobs']['SisterProjects'] = new OO.ui.ButtonOptionWidget({
          label: 'ویکی خواهر',
          data: {
            template: 'ویرایش در ویکی‌های خواهر',
            params: [
              {
                id: '1',
                label: 'نام پروژهٔ خواهر (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Noobs']['EditSummary'] = new OO.ui.ButtonOptionWidget({
          label: 'خلاصه ویرایش',
          data: {
            template: 'تذکر خلاصه ویرایش'
          }
        });
        this.buttons['Noobs']['Vandalism'] = new OO.ui.ButtonOptionWidget({
          label: 'هشدار خرابکاری',
          data: {
            template: 'تذکر خرابکاری'
          }
        });
        this.buttons['Noobs']['VandalismFinal'] = new OO.ui.ButtonOptionWidget({
          label: 'آخرین هشدار خرابکاری',
          data: {
            template: 'تذکر خرابکاری (آخرین)'
          }
        });
        this.buttons['Noobs']['Disruption'] = new OO.ui.ButtonOptionWidget({
          label: 'هشدار اخلالگری',
          data: {
            template: 'هشدار ویرایش اخلالگرانه',
            params: [
              {
                id: '1',
                label: 'نام صفحه (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Noobs']['Responsiveness'] = new OO.ui.ButtonOptionWidget({
          label: 'هشدار پاسخگویی',
          data: {
            template: 'پاسخ به بحث'
          }
        });
        this.buttons['Noobs']['Sandbox'] = new OO.ui.ButtonOptionWidget({
          label: 'صفحه تمرین',
          data: {
            template: 'صفحه تمرین'
          }
        });
        this.buttons['Noobs']['SockPupptery'] = new OO.ui.ButtonOptionWidget({
          label: 'زاپاس‌بازی',
          data: {
            template: 'تذکر زاپاس'
          }
        });
        this.buttons['Noobs']['FakeArticle'] = new OO.ui.ButtonOptionWidget({
          label: 'صفحهٔ کاربری مقاله‌نما',
          data: {
            template: 'هشدار مقاله‌نما',
            params: [
              {
                id: '1',
                label: 'نام صفحه (اختیاری)'
              }
            ]
          }
        });


UserMessages.addTemplate = function( template, param ) {
        this.buttons['Tools']['VE'] = new OO.ui.ButtonOptionWidget({
    summary = 'الگوی «' + template + '» به بحث کاربر افزوده شد. ([[ویکی‌پدیا:ابزار تذکر به کاربران|با استفاده از ابزار]])'
          label: 'ویرایشگر دیداری',
    content = '{{subst:' + template + param + '}}\n~~' + '~~';
          data: {
    UserMessages.addNewSection( summary, content );
            template: 'کار با ویرایشگر دیداری'
    return true;
          }
}
        });
        this.buttons['Tools']['ToWikifa'] = new OO.ui.ButtonOptionWidget({
          label: 'به ویکی‌فا',
          data: {
            template: 'به ویکی‌فا'
          }
        });
        this.buttons['Tools']['Translator'] = new OO.ui.ButtonOptionWidget({
          label: 'کمک‌مترجم',
          data: {
            template: 'ابزار کمک‌مترجم'
          }
        });
        this.buttons['Tools']['ExtraEditTools'] = new OO.ui.ButtonOptionWidget({
          label: 'ابزارهای ویرایشی',
          data: {
            template: 'ابزارهای ویرایشی'
          }
        });
        this.buttons['Tools']['Abar'] = new OO.ui.ButtonOptionWidget({
          label: 'ابرابزار',
          data: {
            template: 'ابرابزار'
          }
        });
        this.buttons['Tools']['Applications'] = new OO.ui.ButtonOptionWidget({
          label: 'ابزارهای کاربردی',
          data: {
            template: 'ابزارهای کاربردی'
          }
        });
        this.buttons['Tools']['AWD'] = new OO.ui.ButtonOptionWidget({
          label: 'ویرایشگر خودکار',
          data: {
            template: 'ویرایشگر خودکار'
          }
        });
        this.buttons['Tools']['Patrol'] = new OO.ui.ButtonOptionWidget({
          label: 'ابزار گشت سریع',
          data: {
            template: 'ابزار گشت‌زنی سریع'
          }
        });
        this.buttons['Tools']['CheckDictation'] = new OO.ui.ButtonOptionWidget({
          label: 'اشتباه‌یاب',
          data: {
            template: 'ابزار اشتباه‌یاب'
          }
        });


UserMessages.prepareTemplate = function( template, param_array ){
        this.buttons['Article']['Tutorial'] = new OO.ui.ButtonOptionWidget({
    param_str = '';
          label: 'آموزش ویکی‌نویسی',
    if( param_array ) {
          data: {
         UserMessages.dialog = new Morebits.simpleWindow( 600, 400 );
            template: 'ویکی‌نویسی'
         UserMessages.dialog.setTitle( 'افزودن الگوی {{' + template + '}} با پارامتر' );
          }
         var form = new Morebits.quickForm( function(){
        });
             param_str = '';
        this.buttons['Article']['Student'] = new OO.ui.ButtonOptionWidget({
            for( i=0; i < param_array.length; i++ ) {
          label: 'ویرایش دانشجویی',
                 p = param_array[i];
          data: {
                param_str += '|' + p.param + '=';
            template: 'ویرایش دانشجویی'
                param_str += $(UserMessages.dialog.content).find('[name=' + p.param + ']').val();
          }
             }
        });
            UserMessages.addTemplate( template, param_str );
         this.buttons['Article']['Incomplete'] = new OO.ui.ButtonOptionWidget({
          label: 'نوشتار نامناسب',
          data: {
            template: 'نوشتار نامناسب',
            params: [
              {
                id: '1',
                label: 'عنوان مقاله (اختیاری)'
              }
            ]
          }
        });
         this.buttons['Article']['TooShort'] = new OO.ui.ButtonOptionWidget({
          label: 'زیادی کوتاه',
          data: {
            template: 'بیش از حد کوتاه',
            params: [
              {
                id: '1',
                label: 'عنوان مقاله (اختیاری)'
              }
            ]
          }
        });
         this.buttons['Article']['Minima'] = new OO.ui.ButtonOptionWidget({
          label: 'حداقل‌ها',
          data: {
             template: 'حداقل‌های مقاله'
          }
        });
        this.buttons['Article']['Deleted'] = new OO.ui.ButtonOptionWidget({
          label: 'حذف شده',
          data: {
            template: 'مقاله حذف شده',
            params: [
              {
                 id: '1',
                label: 'پیام تکمیلی (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Article']['Redirect'] = new OO.ui.ButtonOptionWidget({
          label: 'تغییرمسیر',
          data: {
            template: 'از تغییرمسیر استفاده کنید'
          }
        });
        this.buttons['Article']['Move'] = new OO.ui.ButtonOptionWidget({
          label: 'انتقال',
          data: {
            template: 'از انتقال استفاده کنید'
          }
        });
        this.buttons['Article']['Titles'] = new OO.ui.ButtonOptionWidget({
          label: 'القاب ممنوع',
          data: {
            template: 'هشدار القاب ممنوع'
          }
        });
       
        this.buttons['Copyright']['DoNotCopy'] = new OO.ui.ButtonOptionWidget({
          label: 'کپی مکنید',
          data: {
            template: 'کپی مکنید',
            params: [
              {
                id: '1',
                label: 'عنوان مقاله (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Copyright']['UseCitation'] = new OO.ui.ButtonOptionWidget({
          label: 'یادکرد دقیق',
          data: {
            template: 'یادکرد دقیق منبع',
            params: [
              {
                id: '1',
                label: 'عنوان مقاله (اختیاری)'
              }
             ]
          }
        });
        this.buttons['Copyright']['CiteNotCopy'] = new OO.ui.ButtonOptionWidget({
          label: 'ارجاع به جای کپی',
          data: {
            template: 'نحوه استفاده از مقالات علمی'
          }
        });
        this.buttons['Copyright']['ReliableSources'] = new OO.ui.ButtonOptionWidget({
          label: 'منابع معتبر',
          data: {
            template: 'منابع معتبر'
          }
         });
         });
         form.append({
         this.buttons['Copyright']['CitationTutorial'] = new OO.ui.ButtonOptionWidget({
            type: 'div',
          label: 'آموزش یادکرد',
            name: 'what-to-do',
          data: {
             label: 'مقدار پارامترهای زیر را وارد کنید.',
             template: 'ارجاع صحیح'
          }
         });
         });
         for( i=0; i < param_array.length; i++ ) {
         this.buttons['Copyright']['License'] = new OO.ui.ButtonOptionWidget({
            p = param_array[i];
          label: 'مجوز نگاره',
            form.append({
          data: {
                type: 'input',
             template: 'مجوز نگاره'
                name: p.param,
          }
                label: p.label + ': '
            });
        }
        form.append({
            type: 'div',
            name: 'preview-what-to-do',
             label: 'اگر می‌خواهید پیش‌نمایشی از نتیجه را ببینید روی دکمهٔ پیش‌نمایش کلیک کنید:',
         });
         });
         form.append({
         this.buttons['Copyright']['Copyvio'] = new OO.ui.ButtonOptionWidget({
            type: 'button',
          label: 'هشدار نگاره',
            name: 'preview-btn',
          data: {
            label: 'پیش‌نمایش',
            template: 'هشدار نقض حق تکثیر'
            event: function(){
          }
                param_str = '';
                for( i=0; i < param_array.length; i++ ) {
                    p = param_array[i];
                    param_str += '|' + p.param + '=';
                    param_str += $(UserMessages.dialog.content).find('[name=' + p.param + ']').val();
                }
                api = new mw.Api();
                api.get({
                    action: 'parse',
                    text: '{{subst:' + template + param_str + '}}',
                    pst: true
                }).done(function( data ){
                    $('[name=preview-warn]').html(data.parse.text['*']);
                });
            }
         });
         });
         form.append({
         this.buttons['Copyright']['Ownership'] = new OO.ui.ButtonOptionWidget({
            type: 'div',
          label: 'قانون مالکیت',
            name: 'preview-warn',
          data: {
             label: ''
             template: 'هشدار نقض قانون مالکیت محتوا'
          }
         });
         });
        form.append( { type:'submit' } );
            var result = form.render();
        UserMessages.dialog.setContent( result );
        UserMessages.dialog.display();


         return false;
         this.buttons['Advanced']['Coord'] = new OO.ui.ButtonOptionWidget({
    }
          label: 'مختصات',
}
          data: {
            template: 'مختصات‌دهی'
          }
        });
        this.buttons['Advanced']['Categories'] = new OO.ui.ButtonOptionWidget({
          label: 'رده‌بندی',
          data: {
            template: 'رده‌دهی'
          }
        });
        this.buttons['Advanced']['Interwiki'] = new OO.ui.ButtonOptionWidget({
          label: 'میان‌ویکی',
          data: {
            template: 'افزودن میان‌ویکی'
          }
        });


UserMessages.messages = [
        this.buttons['Spam']['Advertisement'] = new OO.ui.ButtonOptionWidget({
    [{
          label: 'تبلیغ',
        tpl    : 'خوشامد',
          data: {
        params  : [{param : 1, label : 'پیام تکمیلی'}],
            template: 'تبلیغ مکنید',
        label  : 'خوشامد (کاربر)',
            params: [
        id      : 'p-warn-welcome',
              {
    },
                id: '1',
    {
                label: 'عنوان مقاله (اختیاری)'
        tpl    : 'خوشامد-آی‌پی',
              }
        params  : false,
            ]
        label   : 'خوشامد (آی‌پی)',
          }
        id      : 'p-warn-welcome-ip',
         });
    }],
         this.buttons['Spam']['Notability'] = new OO.ui.ButtonOptionWidget({
    [{
          label: 'سرشناسی',
        tpl    : 'امضا کنید',
          data: {
        params : [{param : 1, label : 'پیام تکمیلی'}],
            template: 'پیام سرشناسی',
        label  : 'تازه‌کاران: امضا کنید',
            params: [
        id     : 'p-warn-sign',
              {
    },
                id: '1',
    {
                label: 'عنوان مقاله (اختیاری)'
        tpl    : 'امضا مکنید',
              },
        params  : [{param : 1, label : 'عنوان مقاله'}],
              {
        label  : 'تازه‌کاران: امضا مکنید',
                id: '2',
        id      : 'p-warn-dont-sign',
                label: 'پیام تکمیلی (اختیاری)'
    },
              }
    {
            ]
        tpl    : 'راهنمای بارگذاری پرونده در ویکی‌فا',
          }
        params  : false,
         });
        label  : 'تازه‌کاران: بارگذاری در ویکی‌فا',
         this.buttons['Spam']['Sereh'] = new OO.ui.ButtonOptionWidget({
        id      : 'p-warn-upload-at-fawiki',
          label: 'سره‌نویسی',
    },
          data: {
    {
            template: 'سره‌نویسی'
        tpl    : 'راهنمای بارگذاری پرونده در ویکی‌انبار',
          }
        params  : false,
         });
        label  : 'تازه‌کاران: بارگذاری در ویکی‌انبار',
         this.buttons['Spam']['3RR'] = new OO.ui.ButtonOptionWidget({
         id      : 'p-warn-upload-at-commons',
          label: 'سه‌برگردان',
    },
          data: {
    {
            template: 'هشدار نقض قانون سه‌برگردان',
         tpl    : 'استفاده از صفحه کلید فارسی',
            params: [
        params  : false,
              {
        label  : 'تازه‌کاران: صفحه‌کلید فارسی',
                id: '1',
        id      : 'p-warn-keyboard',
                label: 'عنوان مقاله (اختیاری)'
    },
              }
    {
            ]
        tpl    : 'از پیش‌نمایش استفاده کنید',
          }
        params  : [{param : 1, label : 'عنوان مقاله'}],
         });
        label   : 'تازه‌کاران: پیش‌نمایش',
         this.buttons['Spam']['Autobiography'] = new OO.ui.ButtonOptionWidget({
        id      : 'p-warn-preview',
          label: 'خودنوشته',
    },
          data: {
    {
            template: 'خودنوشته'
        tpl    : 'ویرایش در ویکی‌های خواهر',
          }
        params : [{param : 1, label : 'جای مطلب در کدام پروژه خواهر؟'}],
         });
        label  : 'تازه‌کاران: ویکی خواهر',
         this.buttons['Spam']['WP:NOT'] = new OO.ui.ButtonOptionWidget({
        id      : 'p-warn-sister',
          label: 'اشتباه گرفته‌اید',
    },
          data: {
    {
            template: 'اشتباه گرفته‌اید',
        tpl    : 'تذکر خلاصه ویرایش',
            params: [
        params  : false,
              {
        label  : 'تازه‌کاران: خلاصه ویرایش',
                id: '1',
        id     : 'p-warn-summary',
                label: 'با چه اشتباه گرفته؟ (اختیاری)'
    },
              }
    {
            ]
        tpl    : 'تذکر خرابکاری',
          }
        params  : false,
         });
        label   : 'تازه‌کاران: هشدار خرابکاری',
         this.buttons['Spam']['Username'] = new OO.ui.ButtonOptionWidget({
        id      : 'p-warn-vandalism',
          label: 'نام کاربری',
    },
          data: {
    {
            template: 'نام کاربری نامناسب',
        tpl    : 'تذکر خرابکاری (آخرین)',
            params: [
        params  : false,
              {
        label  : 'تازه‌کاران: آخرین هشدار خرابکاری',
                id: '1',
        id      : 'p-lastwarn-vandalism',
                label: 'دلیل (اختیاری)'
    },
              }
    {
            ]
        tpl    : 'هشدار ویرایش اخلالگرانه',
          }
        params  : [{param : 'صفحه', label : 'عنوان صفحه'}],
         });
        label  : 'تازه‌کاران: ویرایش اخلالگرانه',
         this.buttons['Spam']['Canvassing'] = new OO.ui.ButtonOptionWidget({
        id     : 'p-lastwarn-disruptive',
          label: 'جارزنی',
    },
          data: {
    {
            template: 'جارزنی'
        tpl    : 'پاسخ به بحث',
          }
        params  : false,
         });
        label   : 'تازه‌کاران: هشدار برای پاسخگویی',
        id      : 'p-warn-answer-talkpage',
    },
    {
        tpl    : 'صفحه تمرین',
        params  : false,
        label  : 'تازه‌کاران: صفحه تمرین',
        id      : 'p-warn-sandbox',
    },
    {
        tpl    : 'تذکر زاپاس',
        params  : false,
        label  : 'تازه‌کاران: زاپاس‌بازی',
         id      : 'p-warn-sockpuppets',
    },
    {
         tpl    : 'هشدار مقاله‌نما',
        params  : [{param : 1, label : 'عنوان صفحه'}],
        label  : 'تازه‌کاران: صفحهٔ کاربری مقاله‌نما',
        id      : 'p-warn-userpage-like-article',
    }],
    [{
        tpl    : 'کار با ویرایشگر دیداری',
        params  : false,
        label   : 'ابزارها: ویرایشگر دیداری',
        id      : 'p-warn-visual-editor',
    },
    {
        tpl    : 'به ویکی‌فا',
        params  : false,
        label  : 'ابزارها: به ویکی‌فا',
        id      : 'p-warn-to-wikifa',
    },
    {
        tpl    : 'ابزار کمک‌مترجم',
        params  : false,
        label  : 'ابزارها: کمک‌مترجم',
         id      : 'p-warn-translate-tool',
    },
    {
         tpl    : 'ابزارهای ویرایشی',
        params  : false,
        label  : 'ابزارها: ابزارهای ویرایشی',
        id      : 'p-warn-edittools',
    },
    {
        tpl    : 'ابرابزار',
        params  : false,
        label   : 'ابزارها: ابرابزار',
        id      : 'p-warn-supertool',
    },
    {
        tpl    : 'ابزارهای کاربردی',
        params : false,
        label  : 'ابزارها: کاربردی',
        id      : 'p-warn-useful-tools',
    },
    {
        tpl    : 'ویرایشگر خودکار',
        params  : false,
        label  : 'ابزارها: ویرایشگر خودکار',
        id     : 'p-warn-AWB',
    },
    {
        tpl    : 'ابزار گشت‌زنی سریع',
        params  : false,
        label   : 'ابزارها: گشت‌زنی سریع',
        id      : 'p-warn-QP',
    },
    {
        tpl    : 'ابزار اشتباه‌یاب',
        params  : false,
        label  : 'ابزارها: اشتباه‌یاب',
        id      : 'p-warn-checkDictation-tools',
    }],
    [{
        tpl    : 'ویکی‌نویسی',
        params  : false,
        label  : 'مقاله: آموزش ویکی‌نویسی',
        id      : 'p-warn-style',
    },
    {
        tpl    : 'ویرایش دانشجویی',
         params  : false,
        label  : 'مقاله: ویرایش دانشجویی',
        id      : 'p-warn-student',
    },
    {
         tpl    : 'نوشتار نامناسب',
        params  : [{param : 1, label : 'عنوان مقاله'}],
        label  : 'مقاله: نوشتار نامناسب',
        id      : 'p-warn-poor-quality',
    },
    {
        tpl    : 'بیش از حد کوتاه',
        params  : [{param : 1, label : 'عنوان مقاله'}],
        label  : 'مقاله: زیادی کوتاه',
        id      : 'p-warn-too-short',
    },
    {
        tpl    : 'حداقل‌های مقاله',
        params  : false,
        label   : 'مقاله: حداقل‌ها',
        id      : 'p-warn-minimum-req',
    },
    {
        tpl    : 'مقاله حذف شده',
        params  : [{param : 1, label : 'پیام تکمیلی'}],
        label  : 'مقاله: حذف شده',
        id      : 'p-warn-deleted',
    },
    {
         tpl    : 'از تغییرمسیر استفاده کنید',
        params  : false,
        label  : 'مقاله: تغییرمسیر',
        id      : 'p-warn-redir',
    },
    {
         tpl    : 'از انتقال استفاده کنید',
        params  : false,
        label  : 'مقاله: انتقال',
        id      : 'p-warn-move',
    },
    {
        tpl    : 'هشدار القاب ممنوع',
        params  : false,
        label  : 'مقاله: القاب ممنوع',
        id      : 'p-warn-titles',
    }],
    [{
        tpl    : 'کپی مکنید',
        params  : [{param : '1', label : 'عنوان مقاله'}],
        label   : 'حق تکثیر: کپی‌کاری',
        id      : 'p-warn-copyright',
    },
    {
        tpl    : 'یادکرد دقیق منبع',
        params : [{param : 1, label : 'عنوان مقاله'}],
        label  : 'حق تکثیر: یادکرد دقیق',
        id      : 'p-warn-good-citation',
    },
    {
        tpl    : 'نحوه استفاده از مقالات علمی',
        params  : false,
        label  : 'حق تکثیر: ارجاع به جای کپی',
        id     : 'p-warn-cite-source',
    },
    {
        tpl    : 'منابع معتبر',
        params  : false,
        label   : 'حق تکثیر: منابع معتبر',
        id      : 'p-warn-good-source',
    },
    {
        tpl    : 'ارجاع صحیح',
        params  : false,
        label  : 'حق تکثیر: آموزش یادکرد',
        id      : 'p-warn-correct-citation',
    },
    {
        tpl    : 'مجوز نگاره',
        params  : false,
        label  : 'حق تکثیر: مجوز نگاره',
         id      : 'p-warn-file-license',
    },
    {
         tpl    : 'هشدار نقض حق تکثیر',
        params  : false,
        label  : 'حق‌تکثیر: هشدار نگاره',
        id      : 'p-warn-copyvio',
    },
    {
        tpl    : 'هشدار نقض قانون مالکیت محتوا',
        params  : false,
        label  : 'حق تکثیر: قانون مالکیت',
        id      : 'p-warn-content-license',
    }],
    [{
        tpl    : 'مختصات‌دهی',
        params  : false,
        label  : 'پیشرفته: مختصات',
        id      : 'p-warn-coord',
    },
    {
        tpl    : 'رده‌دهی',
        params  : false,
        label   : 'پیشرفته: رده‌بندی',
        id      : 'p-warn-cat',
    },
    {
        tpl    : 'افزودن میان‌ویکی',
        params : false,
        label  : 'پیشرفته: میان‌ویکی',
        id      : 'p-warn-iw',
    }],
    [{
        tpl    : 'تبلیغ مکنید',
        params  : [{param : 1, label : 'عنوان مقاله'}],
        label  : 'هرزنگاری: تبلیغ',
        id     : 'p-warn-ad',
    },
    {
        tpl    : 'پیام سرشناسی',
        params  : [{param : 1, label : 'عنوان مقاله'}, {param : 2, label : 'پیام تکمیلی'}],
        label   : 'هرزنگاری: سرشناسی',
        id      : 'p-warn-notability',
    },
    {
        tpl    : 'سره ننویسید',
        params  : false,
        label  : 'هرزنگاری: سره‌نویسی',
        id      : 'p-warn-ultra-persian',
    },
    {
        tpl    : 'هشدار نقض قانون سه برگردان',
        params  : [{param : 1, label : 'عنوان مقاله'}],
        label  : 'هرزنگاری: سه‌برگردان',
        id      : 'p-warn-3RR',
    },
    {
         tpl    : 'خودنوشته',
        params  : false,
        label  : 'هرزنگاری: خودنوشته',
        id      : 'p-warn-autobio',
    },
    {
         tpl    : 'اشتباه گرفته‌اید',
        params  : [{param : 1, label : 'با چه اشتباه گرفته؟'}],
        label  : 'هرزنگاری: اشتباه‌گرفته‌اید',
        id      : 'p-warn-wrong-place',
    },
    {
        tpl    : 'نام کاربری نامناسب',
        params  : [{param : 1, label : 'دلیل نامناسب بودن'}],
        label   : 'هرزنگاری: نام کاربری',
        id      : 'p-warn-bad-username',
    },
    {
        tpl    : 'جارزنی',
        params  : false,
         label  : 'هرزنگاری: جارزنی',
        id      : 'p-warn-canvass',
    }]
];


if( mw.config.get( 'wgUserGroups' ).indexOf( 'eliminator' ) > -1) {
        this.buttons['Block']['Username'] = new OO.ui.ButtonOptionWidget({
    UserMessages.messages.push([{
          label: 'نام کاربری تبلیغی',
        tpl    : 'بستن نام تبلیغی',
          data: {
        params  : false,
            template: 'بستن نام تبلیغی'
        label  : 'بستن: نام تبلیغی',
          }
         id      : 'p-block-bad-username',
        });
    },
         this.buttons['Block']['OneDay'] = new OO.ui.ButtonOptionWidget({
    {
          label: 'یک‌روزه',
        tpl    : 'قطع دسترسی موقت',
          data: {
        params : [{param : 'دلیل', label : 'دلیل قطع دسترسی'}],
            template: 'قطع دسترسی موقت',
         label   : 'بستن: موقت',
            params: [
        id     : 'p-block-temporary',
              {
    },
                id: 'دلیل',
    {
                label: 'دلیل (اختیاری)'
    tpl : 'قطع دسترسی بی‌پایان',
              }
    params : [{param: 'دلیل', label: 'علت قطع دسترسی'}],
            ]
    label : 'بستن: بی‌پایان',
          }
    id : 'p-block-unlimited'
        });
    }]);
         this.buttons['Block']['Indefinite'] = new OO.ui.ButtonOptionWidget({
}
          label: 'بی‌پایان',
          data: {
            template: 'قطع دسترسی بی‌پایان',
            params: [
              {
                id: 'دلیل',
                label: 'دلیل (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Block']['Detailed'] = new OO.ui.ButtonOptionWidget({
          label: 'با ذکر مدت و دلیل',
          data: {
            template: 'قطع دسترسی',
            params: [
              {
                id: 'مدت',
                label: 'مدت (اختیاری)'
              },
              {
                id: 'دلیل',
                label: 'دلیل (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Block']['AbuseFilter'] = new OO.ui.ButtonOptionWidget({
          label: 'اشتباه پالایه',
          data: {
            template: 'پوزش پالایه'
          }
        });


if( mw.config.get( 'wgUserGroups' ).indexOf( 'eliminator' ) > -1 ) {
        this.buttons['Rights']['Autopatrol'] = new OO.ui.ButtonOptionWidget({
    UserMessages.messages.push([{
          label: 'گشت خودکار',
        tpl    : 'قطع دسترسی',
          data: {
         params  : [{param : 'توضیح', label : 'دلیل بستن'}, {param : 'مدت', label : 'مدت بستن'}],
            template: 'اعطای گشت خودکار'
         label   : 'بستن: قطع دسترسی',
          }
        id      : 'p-block-user',
        });
    }]);
        this.buttons['Rights']['Revert'] = new OO.ui.ButtonOptionWidget({
}
          label: 'واگردان',
          data: {
            template: 'اعطای واگردان'
          }
        });
        this.buttons['Rights']['Patroller'] = new OO.ui.ButtonOptionWidget({
          label: 'گشت‌زن',
          data: {
            template: 'اعطای گشت‌زن'
          }
        });
         this.buttons['Rights']['TemplateEditor'] = new OO.ui.ButtonOptionWidget({
          label: 'ویرایشگر الگو',
          data: {
            template: 'اعطای ویرایشگر الگو'
          }
        });
        this.buttons['Rights']['Eliminator'] = new OO.ui.ButtonOptionWidget({
          label: 'ویکی‌بان',
          data: {
            template: 'اعطای ویکی‌بان'
          }
        });
        this.buttons['Rights']['Sysop'] = new OO.ui.ButtonOptionWidget({
          label: 'مدیر',
          data: {
            template: 'اعطای مدیریت'
          }
        });
         this.buttons['Rights']['ReinstateEliminator'] = new OO.ui.ButtonOptionWidget({
          label: 'تمدید ویکی‌بانی',
          data: {
            template: 'تمدید ویکی‌بانی'
          }
        });


if( mw.config.get( 'wgUserGroups' ).indexOf( 'sysop' ) > -1) {
        this.buttonSelectChoicesItems = [];
    UserMessages.messages.push([{
        this.buttonSelectChoicesItems['Noobs'] = [
        tpl    : 'قطع دسترسی',
          this.buttons['Noobs']['WelcomeUser'],
        params  : [{param : 'توضیح', label : 'دلیل بستن'}, {param : 'مدت', label : 'مدت بستن'}],
          this.buttons['Noobs']['WelcomeIP'],
        label  : 'بستن: قطع دسترسی',
          this.buttons['Noobs']['Sign'],
        id      : 'p-block-user',
          this.buttons['Noobs']['DoNotSign'],
    },
          this.buttons['Noobs']['UploadGuide'],
    {
          this.buttons['Noobs']['CommonsGuide'],
        tpl    : 'بستن نام تبلیغی',
          this.buttons['Noobs']['Keyboard'],
        params  : false,
          this.buttons['Noobs']['Preview'],
        label  : 'بستن: نام تبلیغی',
          this.buttons['Noobs']['Sandbox'],
        id      : 'p-block-bad-username',
          this.buttons['Noobs']['SisterProjects'],
    },
          this.buttons['Noobs']['EditSummary'],
    {
          this.buttons['Noobs']['FakeArticle'],
    tpl    : 'قطع دسترسی بی‌پایان',
          this.buttons['Noobs']['Vandalism'],
    params : [{param: 'دلیل', label: 'علت قطع دسترسی'}],
          this.buttons['Noobs']['VandalismFinal'],
    label : 'بستن: بی‌پایان',
          this.buttons['Noobs']['Disruption'],
    id : 'p-block-unlimited'
          this.buttons['Noobs']['Responsiveness'],
    },
          this.buttons['Noobs']['SockPupptery']
    {
        ];
        tpl    : 'پوزش پالایه',
        this.buttonSelectChoicesItems['Tools'] = [
         params  : false,
          this.buttons['Tools']['VE'],
         label  : 'بستن: اشتباه پالایه',
          this.buttons['Tools']['ToWikifa'],
        id      : 'p-unblock-mistake',
          this.buttons['Tools']['Translator'],
    },
          this.buttons['Tools']['ExtraEditTools'],
    {
          this.buttons['Tools']['Abar'],
        tpl    : 'اعطای گشت خودکار',
          this.buttons['Tools']['Applications'],
        params  : false,
          this.buttons['Tools']['AWD'],
        label  : 'دسترسی: گشت‌خودکار',
          this.buttons['Tools']['Patrol'],
        id      : 'p-warn-autopatrol',
          this.buttons['Tools']['CheckDictation']
    },
         ];
    {
         this.buttonSelectChoicesItems['Article'] = [
         tpl    : 'اعطای واگردان',
          this.buttons['Article']['Tutorial'],
        params  : false,
          this.buttons['Article']['Student'],
        label  : 'دسترسی: واگردان',
          this.buttons['Article']['Incomplete'],
        id      : 'p-warn-revert',
          this.buttons['Article']['TooShort'],
    },
          this.buttons['Article']['Minima'],
    {
          this.buttons['Article']['Deleted'],
        tpl    : 'اعطای گشت‌زن',
          this.buttons['Article']['Redirect'],
         params  : false,
          this.buttons['Article']['Move'],
         label  : 'دسترسی: گشت‌زن',
          this.buttons['Article']['Titles']
        id      : 'p-warn-patrol',
        ];
    },
         this.buttonSelectChoicesItems['Copyright'] = [
    {
          this.buttons['Copyright']['DoNotCopy'],
         tpl    : 'اعطای ویرایشگر الگو',
          this.buttons['Copyright']['UseCitation'],
        params  : false,
          this.buttons['Copyright']['CiteNotCopy'],
        label  : 'دسترسی: ویرایشگر الگو',
          this.buttons['Copyright']['ReliableSources'],
        id      : 'p-warn-TemplateEditor',
          this.buttons['Copyright']['CitationTutorial'],
    },
          this.buttons['Copyright']['License'],
    {
          this.buttons['Copyright']['Copyvio'],
        tpl    : 'اعطای ویکی‌بان',
          this.buttons['Copyright']['Ownership']
         params  : false,
         ];
         label  : 'دسترسی: ویکی‌بان',
         this.buttonSelectChoicesItems['Advanced'] = [
        id      : 'p-warn-eliminator',
          this.buttons['Advanced']['Coord'],
    },
          this.buttons['Advanced']['Categories'],
    {
          this.buttons['Advanced']['Interwiki']
        tpl    : 'اعطای مدیریت',
        ];
         params  : false,
         this.buttonSelectChoicesItems['Spam'] = [
         label  : 'دسترسی: مدیر',
          this.buttons['Spam']['Advertisement'],
        id      : 'p-warn-sysop',
          this.buttons['Spam']['Notability'],
    },
          this.buttons['Spam']['Sereh'],
    {
          this.buttons['Spam']['3RR'],
        tpl    : 'تمدید ویکی‌بانی',
          this.buttons['Spam']['Autobiography'],
        params  : false,
          this.buttons['Spam']['WP:NOT'],
        label  : 'تمدید ویکی‌بانی',
          this.buttons['Spam']['Username'],
        id      : 'p-warn-re_eliminator',
          this.buttons['Spam']['Canvassing']
    }]);
         ];
}
         this.buttonSelectChoicesItems['Block'] = [
          this.buttons['Block']['Username'],
          this.buttons['Block']['OneDay'],
          this.buttons['Block']['Indefinite'],
          this.buttons['Block']['Detailed'],
          this.buttons['Block']['AbuseFilter']
         ];
         this.buttonSelectChoicesItems['Rights'] = [
          this.buttons['Rights']['Autopatrol'],
          this.buttons['Rights']['Revert'],
          this.buttons['Rights']['Patroller'],
          this.buttons['Rights']['TemplateEditor'],
          this.buttons['Rights']['Eliminator'],
          this.buttons['Rights']['Sysop'],
          this.buttons['Rights']['ReinstateEliminator']
        ];


UserMessages.addPortletLink = function( tpl, params, text, id, tooltip ) {
        // The default choice
    var link = mw.util.addPortletLink( 'p-warn' , "#", text, id, tooltip );
        this.buttonSelectChoices = new OO.ui.ButtonSelectWidget({
          items: this.buttonSelectChoicesItems['Noobs']
        });


    $( link ).click( function( ev ) {
        this.setChooseAction = function() {
        ev.preventDefault();
          dialog.buttonSelectChoices.on('choose', function(item) {
        UserMessages.addTemplate(tpl, '');
            dialog.previewResult.toggle(false);
    });
            if (item.data !== undefined & item.data.params !== undefined) {
              dialog.panelParams.toggle(true);
              dialog.buttonPreview.toggle(true);
              dialog.buttonReset.toggle(true);
              if (item.data.params.length > 0) (
                dialog.textParamOneLayout.toggle(true);
                dialog.textParamOneLayout.setLabel(item.data.params[0].label);
                dialog.textParamOneLayout.setData(item.data.params[0].id);
                dialog.textParamOne.setValue('');
              } else {
                dialog.textParamOneLayout.toggle(false);
              }
              if (item.data.params.length > 1) (
                dialog.textParamTwoLayout.toggle(true);
                dialog.textParamTwoLayout.setLabel(item.data.params[1].label);
                dialog.textParamTwoLayout.setData(item.data.params[1].id);
                dialog.textParamTwo.setValue('');
              } else {
                dialog.textParamTwoLayout.toggle(false);
              }
            } else {
              dialog.textParamOneLayout.toggle(false);
              dialog.textParamTwoLayout.toggle(false);
              dialog.panelParams.toggle(true);
              dialog.buttonPreview.toggle(true);
              dialog.buttonReset.toggle(true);
            }
            windowManager.getCurrentWindow().updateSize();
          });         
        }
        this.setChooseAction();


    if( params ) {
        this.textParamOne = new OO.ui.TextInputWidget({
         $( link ).find( 'a' ).append( '<span href="#" id="' + id + '-parametric" class="p-warn-param"><small>(+)</small></span>' );
          placeholder: 'متنی وارد کنید'
        $( link ).find( '.p-warn-param' ).click( function( evt ) {
        });
             evt.stopPropagation();
        this.textParamTwo = new OO.ui.TextInputWidget({
            evt.preventDefault();
          placeholder: 'متنی وارد کنید'
            UserMessages.prepareTemplate(tpl, params);
         });
            return false;
        this.textParamOneLayout = new OO.ui.FieldLayout( this.textParamOne, {
          label: 'پارامتر اول'
        });
        this.textParamTwoLayout = new OO.ui.FieldLayout( this.textParamTwo, {
          label: 'پارامتر دوم'
        });
        this.paramFieldset = new OO.ui.FieldsetLayout({
          items: [
            this.textParamOneLayout,
            this.textParamTwoLayout
          ]
        });
        this.buttonPreview = new OO.ui.ButtonWidget({
          label: 'پیش‌نمایش',
          icon: 'check',
          title: 'پیش‌نمایش',
          flags: 'progressive'
        });
        this.buttonPreview.on('click', function() {
          dialog.previewResult.toggle(true);
          dialog.previewResult.setContent(''); // Makes any previous preview results go away, so the user notices the change
          windowManager.getCurrentWindow().updateSize();
          var wikitext = UserMessages.static.prepareWikitext(dialog);
          var api = new mw.Api();
          api.get({
            action: 'parse',
            text: wikitext,
            pst: true
          }).done(function( data ) {
             dialog.previewResult.setContent($(data.parse.text['*']));
          });
        });
        this.buttonReset = new OO.ui.ButtonWidget({
          label: 'پاک کردن',
          icon: 'reload',
          title: 'پاک کردن',
          flags: 'destructive'
        });
        this.buttonReset.on('click', function() {
          dialog.textParamOne.setValue('');
          dialog.textParamTwo.setValue('');
          dialog.previewResult.toggle(false);
          dialog.buttonPreview.toggle(true);
          dialog.buttonReset.toggle(true);
          windowManager.getCurrentWindow().updateSize();
        });
        this.panelParams = new OO.ui.PanelLayout({
          expanded: true,
          padded: true
        });
        this.previewResult = new PreviewPanel({
          expanded: true,
          padded: true,
          $content: ''
         });
         });
    }
        this.previewResult.toggle(false);
};
        this.panelParams.$element.append(this.paramFieldset.$element);
        this.panelParams.$element.append(this.buttonPreview.$element);
        this.panelParams.$element.append(this.buttonReset.$element);
        this.textParamOneLayout.toggle(false);
        this.textParamTwoLayout.toggle(false);
        this.buttonPreview.toggle(false);
        this.buttonReset.toggle(false);
        this.panelGroups = new OO.ui.PanelLayout({
          expanded: true,
          padded: true,
          classes: ['panelGroups']
        });
        this.panelGroups.$element.append(this.buttonSelectGroups.$element);
        this.panelChoices = new OO.ui.PanelLayout({
          expanded: true,
          padded: true,
          classes: ['panelChoices']
        });
        this.panelChoices.$element.append(this.buttonSelectChoices.$element);
        this.panelPreview = new OO.ui.PanelLayout({
          expanded: true,
          padded: true
        });
        this.panelPreview.$element.append(this.previewResult.$element);


UserMessages.load = function () {
        this.stackLayout = new OO.ui.StackLayout({
    if( mw.config.get('wgNamespaceNumber') != 3) return false;
          items: [
 
            this.panelGroups,
    $('#p-views').after('<div id="p-warn" class="vectorMenu"><h3><span><a href="#"></a>تذکر</span></h3><div class="menu"><ul></ul></div></div>');
            this.panelChoices,
 
            this.panelParams,
    for( g=0; g < UserMessages.messages.length; g++ ) {
            this.panelPreview
         for( i=0; i < UserMessages.messages[g].length; i++ ) {
          ],
             m = UserMessages.messages[g][i];
          continuous: true,
            UserMessages.addPortletLink( m.tpl, m.params, m.label, m.id, 'افزودن {{' + m.tpl + '}} با امضای شما' );
          scrollable: false
        });
        this.$body.append(this.stackLayout.$element);
      };
      UserMessages.static.prepareWikitext = function(dialog) {
        var btn = dialog.buttonSelectChoices.findSelectedItem().getData();
        var prm1name = dialog.textParamOneLayout.getData();
        var prm1val = dialog.textParamOne.getValue();
        var prm2name = dialog.textParamTwoLayout.getData();
        var prm2val = dialog.textParamTwo.getValue();
        var wikitext = '{{subst:' + btn.template;
        if (dialog.textParamOneLayout.isVisible()) (
          wikitext += '|' + prm1name + '=' + prm1val
        }
        if (dialog.textParamTwoLayout.isVisible()) (
          wikitext += '|' + prm2name + '=' + prm2val
        }
        wikitext += '}}';
        return wikitext;
      }
      UserMessages.prototype.getSetupProcess = function(data) {
        data = data || {};
        return UserMessages.super.prototype.getSetupProcess.call( this, data )
          .next( function () {
            // Do something
          }, this );
      };
      UserMessages.prototype.getActionProcess = function(action) {
         var dialog = this;
        if (action === 'warn') {
          var wikitext = UserMessages.static.prepareWikitext(dialog);
          wikitext += '\n~~' + '~~';
          return new OO.ui.Process(function() {
             UMOptions.savePage(mw.config.get('wgPageName'), wikitext, function() {
              location.reload();
            });
            dialog.close({
              action: action
            }).done(function() {
              // Page will be reloaded once saved
            });
          });
         }
         }
         if( g != UserMessages.messages.length - 1 ) {
         return UserMessages.super.prototype.getActionProcess.call(this, action);
             $('#p-warn .menu ul').append('<li class="sep"><hr /></li>');
      };
      if (!windowManager) {
        windowManager = new OO.ui.WindowManager();
        $('body').append(windowManager.$element);
      }
      UM = new UserMessages({
        size: 'large'
      });
      windowManager.addWindows([UM]);
      windowManager.openWindow(UM);
    },
    savePage: function(title, text, callback) {
      (new mw.Api()).post({
        action: 'edit',
        section: 'new',
        title: title,
        text: text,
        token: mw.user.tokens.get('editToken')
      }).done(function(data) {
        if (data.error && data.error.info) {
          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);
 
      });
$(UserMessages.load);
     },
 
  };
} ( window, document, jQuery )); // End wrapper for anonymous function
  if (mw.config.get('wgNamespaceNumber') === 3 | mw.config.get('wgPageName') === 'ویکی‌پدیا:صفحه_تمرین') {
    $(UMOptions.install);
  }
})(jQuery, mediaWiki);

نسخهٔ ۱۶ آوریل ۲۰۱۹، ساعت ۱۴:۲۶

/**
 * This gadget is a substantial rewrite of the UserMessages gadget, influenced by
 * [[n:en:MediaWiki:Gadget-UserMessages.js]] and [[n:MediaWiki:Gadget-UserMessages.js]]
 * 
 * Unlike the previous versions, this uses OOUI and can accept one or more
 * parameters for the messages that are being posted on the user's talk page.
 */

(function($, mw) {
  'use strict';
  var windowManager;
  var UM;
  var UMOptions = {
    install: function() {
      if (mw.config.get('wgAction') === 'view') {
        $(mw.util.addPortletLink( 'p-cactions', '#', 'تذکر', 'ca-warn', 'ارسال سریع پیام/تذکر مبتنی بر الگو', '*')).click(function(e) {
          mw.loader.using(['oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows', 'mediawiki.api']).done(UMOptions.createWindow);
          e.preventDefault();
        });
        // Late pre-loading
        mw.loader.load(['oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows', 'mediawiki.api']);
      }
    },
    createWindow: function() {
      function PreviewPanel(config) {
        PreviewPanel.parent.call(this, config);
        
        this.$content = $('<div>').addClass('oo-ui-PreviewPanel');
      }
      OO.inheritClass(PreviewPanel, OO.ui.PanelLayout);
      PreviewPanel.prototype.setContent = function ($content) {
        this.$element.children().detach();
        this.$element.append($content);
        windowManager.getCurrentWindow().updateSize();
      };
      function UserMessages(config) {
        UserMessages.super.call(this, config);
      }
      OO.inheritClass(UserMessages, OO.ui.ProcessDialog);
      UserMessages.static.name = 'Warn dialog';
      UserMessages.static.title = 'ارسال پیام یا تذکر';
      UserMessages.static.actions = [
        {
          action: 'warn',
          label: 'ثبت',
          flags: 'primary'
        },
        {
          label: 'لغو',
          flags: 'safe'
        }
      ];
      UserMessages.prototype.initialize = function() {
        var dialog = this;
        UserMessages.super.prototype.initialize.apply(this, arguments);
        
        this.buttons = [];
        this.buttons['Groups'] = [];
        this.buttons['Noobs'] = [];
        this.buttons['Tools'] = [];
        this.buttons['Article'] = [];
        this.buttons['Copyright'] = [];
        this.buttons['Advanced'] = [];
        this.buttons['Spam'] = [];
        this.buttons['Block'] = [];
        this.buttons['Rights'] = [];

        this.buttons['Groups']['Noobs'] = new OO.ui.ButtonOptionWidget({
          label: 'تازه‌کاران',
          data: {
            group: 'Noobs'
          }
        });
        this.buttons['Groups']['Tools'] = new OO.ui.ButtonOptionWidget({
          label: 'ابزارها',
          data: {
            group: 'Tools'
          }
        });
        this.buttons['Groups']['Article'] = new OO.ui.ButtonOptionWidget({
          label: 'مقاله',
          data: {
            group: 'Article'
          }
        });
        this.buttons['Groups']['Copyright'] = new OO.ui.ButtonOptionWidget({
          label: 'حق تکثیر',
          data: {
            group: 'Copyright'
          }
        });
        this.buttons['Groups']['Advanced'] = new OO.ui.ButtonOptionWidget({
          label: 'پیشرفته',
          data: {
            group: 'Advanced'
          }
        });
        this.buttons['Groups']['Spam'] = new OO.ui.ButtonOptionWidget({
          label: 'هرزنگاری',
          data: {
            group: 'Spam'
          }
        });
        this.buttons['Groups']['Block'] = new OO.ui.ButtonOptionWidget({
          label: 'بستن',
          data: {
            group: 'Block'
          }
        });
        this.buttons['Groups']['Rights'] = new OO.ui.ButtonOptionWidget({
          label: 'دسترسی',
          data: {
            group: 'Rights'
          }
        });

        this.buttonSelectGroups = new OO.ui.ButtonSelectWidget({
          items: [
            this.buttons['Groups']['Noobs'],
            this.buttons['Groups']['Tools'],
            this.buttons['Groups']['Article'],
            this.buttons['Groups']['Copyright'],
            this.buttons['Groups']['Advanced'],
            this.buttons['Groups']['Spam']
          ]
        });
        if ($(mw.config.get('wgUserGroups')).filter(['eliminator', 'sysop']).length > 0) {
          this.buttonSelectGroups.addItems([
            this.buttons['Groups']['Block']
          ]);
        }
        if ($(mw.config.get( 'wgUserGroups' )).filter(['sysop']).length > 0) {
          this.buttonSelectGroups.addItems([
            this.buttons['Groups']['Rights']
          ]);
        }
        this.buttonSelectGroups.selectItem(this.buttons['Groups']['Noobs']);
        this.buttonSelectGroups.on('choose', function(item) {
          dialog.buttonSelectChoices = new OO.ui.ButtonSelectWidget({
            items: dialog.buttonSelectChoicesItems[item.data.group]
          });
          dialog.buttonSelectChoices.selectItem();
          dialog.panelChoices.$element.children().detach();
          dialog.panelChoices.$element.append(dialog.buttonSelectChoices.$element);
          dialog.setChooseAction();
          dialog.panelParams.toggle(false);
          dialog.previewResult.toggle(false);
          windowManager.getCurrentWindow().updateSize();
        });

        this.buttons['Noobs']['WelcomeUser'] = new OO.ui.ButtonOptionWidget({
          label: 'خوشامد (کاربر)',
          data: {
            template: 'خوشامد',
            params: [
              {
                id: '1',
                label: 'پیام تکمیلی (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Noobs']['WelcomeIP'] = new OO.ui.ButtonOptionWidget({
          label: 'خوشامد (آی‌پی)',
          data: {
            template: 'خوشامد-آی‌پی'
          }
        });
        this.buttons['Noobs']['Sign'] = new OO.ui.ButtonOptionWidget({
          label: 'امضا کنید',
          data: {
            template: 'امضا کنید',
            params: [
              {
                id: '1',
                label: 'پیام تکمیلی (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Noobs']['DoNotSign'] = new OO.ui.ButtonOptionWidget({
          label: 'امضا مکنید',
          data: {
            template: 'امضا مکنید',
            params: [
              {
                id: '1',
                label: 'عنوان مقاله (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Noobs']['UploadGuide'] = new OO.ui.ButtonOptionWidget({
          label: 'بارگذاری در ویکی‌فا',
          data: {
            template: 'راهنمای بارگذاری پرونده در ویکی‌فا'
          }
        });
        this.buttons['Noobs']['CommonsGuide'] = new OO.ui.ButtonOptionWidget({
          label: 'بارگذاری در ویکی‌انبار',
          data: {
            template: 'راهنمای بارگذاری پرونده در ویکی‌انبار'
          }
        });
        this.buttons['Noobs']['Keyboard'] = new OO.ui.ButtonOptionWidget({
          label: 'صفحه کلید فارسی',
          data: {
            template: 'استفاده از صفحه کلید فارسی'
          }
        });
        this.buttons['Noobs']['Preview'] = new OO.ui.ButtonOptionWidget({
          label: 'پیش‌نمایش',
          data: {
            template: 'از پیش‌نمایش استفاده کنید',
            params: [
              {
                id: '1',
                label: 'عنوان مقاله (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Noobs']['SisterProjects'] = new OO.ui.ButtonOptionWidget({
          label: 'ویکی خواهر',
          data: {
            template: 'ویرایش در ویکی‌های خواهر',
            params: [
              {
                id: '1',
                label: 'نام پروژهٔ خواهر (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Noobs']['EditSummary'] = new OO.ui.ButtonOptionWidget({
          label: 'خلاصه ویرایش',
          data: {
            template: 'تذکر خلاصه ویرایش'
          }
        });
        this.buttons['Noobs']['Vandalism'] = new OO.ui.ButtonOptionWidget({
          label: 'هشدار خرابکاری',
          data: {
            template: 'تذکر خرابکاری'
          }
        });
        this.buttons['Noobs']['VandalismFinal'] = new OO.ui.ButtonOptionWidget({
          label: 'آخرین هشدار خرابکاری',
          data: {
            template: 'تذکر خرابکاری (آخرین)'
          }
        });
        this.buttons['Noobs']['Disruption'] = new OO.ui.ButtonOptionWidget({
          label: 'هشدار اخلالگری',
          data: {
            template: 'هشدار ویرایش اخلالگرانه',
            params: [
              {
                id: '1',
                label: 'نام صفحه (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Noobs']['Responsiveness'] = new OO.ui.ButtonOptionWidget({
          label: 'هشدار پاسخگویی',
          data: {
            template: 'پاسخ به بحث'
          }
        });
        this.buttons['Noobs']['Sandbox'] = new OO.ui.ButtonOptionWidget({
          label: 'صفحه تمرین',
          data: {
            template: 'صفحه تمرین'
          }
        });
        this.buttons['Noobs']['SockPupptery'] = new OO.ui.ButtonOptionWidget({
          label: 'زاپاس‌بازی',
          data: {
            template: 'تذکر زاپاس'
          }
        });
        this.buttons['Noobs']['FakeArticle'] = new OO.ui.ButtonOptionWidget({
          label: 'صفحهٔ کاربری مقاله‌نما',
          data: {
            template: 'هشدار مقاله‌نما',
            params: [
              {
                id: '1',
                label: 'نام صفحه (اختیاری)'
              }
            ]
          }
        });

        this.buttons['Tools']['VE'] = new OO.ui.ButtonOptionWidget({
          label: 'ویرایشگر دیداری',
          data: {
            template: 'کار با ویرایشگر دیداری'
          }
        });
        this.buttons['Tools']['ToWikifa'] = new OO.ui.ButtonOptionWidget({
          label: 'به ویکی‌فا',
          data: {
            template: 'به ویکی‌فا'
          }
        });
        this.buttons['Tools']['Translator'] = new OO.ui.ButtonOptionWidget({
          label: 'کمک‌مترجم',
          data: {
            template: 'ابزار کمک‌مترجم'
          }
        });
        this.buttons['Tools']['ExtraEditTools'] = new OO.ui.ButtonOptionWidget({
          label: 'ابزارهای ویرایشی',
          data: {
            template: 'ابزارهای ویرایشی'
          }
        });
        this.buttons['Tools']['Abar'] = new OO.ui.ButtonOptionWidget({
          label: 'ابرابزار',
          data: {
            template: 'ابرابزار'
          }
        });
        this.buttons['Tools']['Applications'] = new OO.ui.ButtonOptionWidget({
          label: 'ابزارهای کاربردی',
          data: {
            template: 'ابزارهای کاربردی'
          }
        });
        this.buttons['Tools']['AWD'] = new OO.ui.ButtonOptionWidget({
          label: 'ویرایشگر خودکار',
          data: {
            template: 'ویرایشگر خودکار'
          }
        });
        this.buttons['Tools']['Patrol'] = new OO.ui.ButtonOptionWidget({
          label: 'ابزار گشت سریع',
          data: {
            template: 'ابزار گشت‌زنی سریع'
          }
        });
        this.buttons['Tools']['CheckDictation'] = new OO.ui.ButtonOptionWidget({
          label: 'اشتباه‌یاب',
          data: {
            template: 'ابزار اشتباه‌یاب'
          }
        });

        this.buttons['Article']['Tutorial'] = new OO.ui.ButtonOptionWidget({
          label: 'آموزش ویکی‌نویسی',
          data: {
            template: 'ویکی‌نویسی'
          }
        });
        this.buttons['Article']['Student'] = new OO.ui.ButtonOptionWidget({
          label: 'ویرایش دانشجویی',
          data: {
            template: 'ویرایش دانشجویی'
          }
        });
        this.buttons['Article']['Incomplete'] = new OO.ui.ButtonOptionWidget({
          label: 'نوشتار نامناسب',
          data: {
            template: 'نوشتار نامناسب',
            params: [
              {
                id: '1',
                label: 'عنوان مقاله (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Article']['TooShort'] = new OO.ui.ButtonOptionWidget({
          label: 'زیادی کوتاه',
          data: {
            template: 'بیش از حد کوتاه',
            params: [
              {
                id: '1',
                label: 'عنوان مقاله (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Article']['Minima'] = new OO.ui.ButtonOptionWidget({
          label: 'حداقل‌ها',
          data: {
            template: 'حداقل‌های مقاله'
          }
        });
        this.buttons['Article']['Deleted'] = new OO.ui.ButtonOptionWidget({
          label: 'حذف شده',
          data: {
            template: 'مقاله حذف شده',
            params: [
              {
                id: '1',
                label: 'پیام تکمیلی (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Article']['Redirect'] = new OO.ui.ButtonOptionWidget({
          label: 'تغییرمسیر',
          data: {
            template: 'از تغییرمسیر استفاده کنید'
          }
        });
        this.buttons['Article']['Move'] = new OO.ui.ButtonOptionWidget({
          label: 'انتقال',
          data: {
            template: 'از انتقال استفاده کنید'
          }
        });
        this.buttons['Article']['Titles'] = new OO.ui.ButtonOptionWidget({
          label: 'القاب ممنوع',
          data: {
            template: 'هشدار القاب ممنوع'
          }
        });
        
        this.buttons['Copyright']['DoNotCopy'] = new OO.ui.ButtonOptionWidget({
          label: 'کپی مکنید',
          data: {
            template: 'کپی مکنید',
            params: [
              {
                id: '1',
                label: 'عنوان مقاله (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Copyright']['UseCitation'] = new OO.ui.ButtonOptionWidget({
          label: 'یادکرد دقیق',
          data: {
            template: 'یادکرد دقیق منبع',
            params: [
              {
                id: '1',
                label: 'عنوان مقاله (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Copyright']['CiteNotCopy'] = new OO.ui.ButtonOptionWidget({
          label: 'ارجاع به جای کپی',
          data: {
            template: 'نحوه استفاده از مقالات علمی'
          }
        });
        this.buttons['Copyright']['ReliableSources'] = new OO.ui.ButtonOptionWidget({
          label: 'منابع معتبر',
          data: {
            template: 'منابع معتبر'
          }
        });
        this.buttons['Copyright']['CitationTutorial'] = new OO.ui.ButtonOptionWidget({
          label: 'آموزش یادکرد',
          data: {
            template: 'ارجاع صحیح'
          }
        });
        this.buttons['Copyright']['License'] = new OO.ui.ButtonOptionWidget({
          label: 'مجوز نگاره',
          data: {
            template: 'مجوز نگاره'
          }
        });
        this.buttons['Copyright']['Copyvio'] = new OO.ui.ButtonOptionWidget({
          label: 'هشدار نگاره',
          data: {
            template: 'هشدار نقض حق تکثیر'
          }
        });
        this.buttons['Copyright']['Ownership'] = new OO.ui.ButtonOptionWidget({
          label: 'قانون مالکیت',
          data: {
            template: 'هشدار نقض قانون مالکیت محتوا'
          }
        });

        this.buttons['Advanced']['Coord'] = new OO.ui.ButtonOptionWidget({
          label: 'مختصات',
          data: {
            template: 'مختصات‌دهی'
          }
        });
        this.buttons['Advanced']['Categories'] = new OO.ui.ButtonOptionWidget({
          label: 'رده‌بندی',
          data: {
            template: 'رده‌دهی'
          }
        });
        this.buttons['Advanced']['Interwiki'] = new OO.ui.ButtonOptionWidget({
          label: 'میان‌ویکی',
          data: {
            template: 'افزودن میان‌ویکی'
          }
        });

        this.buttons['Spam']['Advertisement'] = new OO.ui.ButtonOptionWidget({
          label: 'تبلیغ',
          data: {
            template: 'تبلیغ مکنید',
            params: [
              {
                id: '1',
                label: 'عنوان مقاله (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Spam']['Notability'] = new OO.ui.ButtonOptionWidget({
          label: 'سرشناسی',
          data: {
            template: 'پیام سرشناسی',
            params: [
              {
                id: '1',
                label: 'عنوان مقاله (اختیاری)'
              },
              {
                id: '2',
                label: 'پیام تکمیلی (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Spam']['Sereh'] = new OO.ui.ButtonOptionWidget({
          label: 'سره‌نویسی',
          data: {
            template: 'سره‌نویسی'
          }
        });
        this.buttons['Spam']['3RR'] = new OO.ui.ButtonOptionWidget({
          label: 'سه‌برگردان',
          data: {
            template: 'هشدار نقض قانون سه‌برگردان',
            params: [
              {
                id: '1',
                label: 'عنوان مقاله (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Spam']['Autobiography'] = new OO.ui.ButtonOptionWidget({
          label: 'خودنوشته',
          data: {
            template: 'خودنوشته'
          }
        });
        this.buttons['Spam']['WP:NOT'] = new OO.ui.ButtonOptionWidget({
          label: 'اشتباه گرفته‌اید',
          data: {
            template: 'اشتباه گرفته‌اید',
            params: [
              {
                id: '1',
                label: 'با چه اشتباه گرفته؟ (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Spam']['Username'] = new OO.ui.ButtonOptionWidget({
          label: 'نام کاربری',
          data: {
            template: 'نام کاربری نامناسب',
            params: [
              {
                id: '1',
                label: 'دلیل (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Spam']['Canvassing'] = new OO.ui.ButtonOptionWidget({
          label: 'جارزنی',
          data: {
            template: 'جارزنی'
          }
        });

        this.buttons['Block']['Username'] = new OO.ui.ButtonOptionWidget({
          label: 'نام کاربری تبلیغی',
          data: {
            template: 'بستن نام تبلیغی'
          }
        });
        this.buttons['Block']['OneDay'] = new OO.ui.ButtonOptionWidget({
          label: 'یک‌روزه',
          data: {
            template: 'قطع دسترسی موقت',
            params: [
              {
                id: 'دلیل',
                label: 'دلیل (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Block']['Indefinite'] = new OO.ui.ButtonOptionWidget({
          label: 'بی‌پایان',
          data: {
            template: 'قطع دسترسی بی‌پایان',
            params: [
              {
                id: 'دلیل',
                label: 'دلیل (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Block']['Detailed'] = new OO.ui.ButtonOptionWidget({
          label: 'با ذکر مدت و دلیل',
          data: {
            template: 'قطع دسترسی',
            params: [
              {
                id: 'مدت',
                label: 'مدت (اختیاری)'
              },
              {
                id: 'دلیل',
                label: 'دلیل (اختیاری)'
              }
            ]
          }
        });
        this.buttons['Block']['AbuseFilter'] = new OO.ui.ButtonOptionWidget({
          label: 'اشتباه پالایه',
          data: {
            template: 'پوزش پالایه'
          }
        });

        this.buttons['Rights']['Autopatrol'] = new OO.ui.ButtonOptionWidget({
          label: 'گشت خودکار',
          data: {
            template: 'اعطای گشت خودکار'
          }
        });
        this.buttons['Rights']['Revert'] = new OO.ui.ButtonOptionWidget({
          label: 'واگردان',
          data: {
            template: 'اعطای واگردان'
          }
        });
        this.buttons['Rights']['Patroller'] = new OO.ui.ButtonOptionWidget({
          label: 'گشت‌زن',
          data: {
            template: 'اعطای گشت‌زن'
          }
        });
        this.buttons['Rights']['TemplateEditor'] = new OO.ui.ButtonOptionWidget({
          label: 'ویرایشگر الگو',
          data: {
            template: 'اعطای ویرایشگر الگو'
          }
        });
        this.buttons['Rights']['Eliminator'] = new OO.ui.ButtonOptionWidget({
          label: 'ویکی‌بان',
          data: {
            template: 'اعطای ویکی‌بان'
          }
        });
        this.buttons['Rights']['Sysop'] = new OO.ui.ButtonOptionWidget({
          label: 'مدیر',
          data: {
            template: 'اعطای مدیریت'
          }
        });
        this.buttons['Rights']['ReinstateEliminator'] = new OO.ui.ButtonOptionWidget({
          label: 'تمدید ویکی‌بانی',
          data: {
            template: 'تمدید ویکی‌بانی'
          }
        });

        this.buttonSelectChoicesItems = [];
        this.buttonSelectChoicesItems['Noobs'] = [
          this.buttons['Noobs']['WelcomeUser'],
          this.buttons['Noobs']['WelcomeIP'],
          this.buttons['Noobs']['Sign'],
          this.buttons['Noobs']['DoNotSign'],
          this.buttons['Noobs']['UploadGuide'],
          this.buttons['Noobs']['CommonsGuide'],
          this.buttons['Noobs']['Keyboard'],
          this.buttons['Noobs']['Preview'],
          this.buttons['Noobs']['Sandbox'],
          this.buttons['Noobs']['SisterProjects'],
          this.buttons['Noobs']['EditSummary'],
          this.buttons['Noobs']['FakeArticle'],
          this.buttons['Noobs']['Vandalism'],
          this.buttons['Noobs']['VandalismFinal'],
          this.buttons['Noobs']['Disruption'],
          this.buttons['Noobs']['Responsiveness'],
          this.buttons['Noobs']['SockPupptery']
        ];
        this.buttonSelectChoicesItems['Tools'] = [
          this.buttons['Tools']['VE'],
          this.buttons['Tools']['ToWikifa'],
          this.buttons['Tools']['Translator'],
          this.buttons['Tools']['ExtraEditTools'],
          this.buttons['Tools']['Abar'],
          this.buttons['Tools']['Applications'],
          this.buttons['Tools']['AWD'],
          this.buttons['Tools']['Patrol'],
          this.buttons['Tools']['CheckDictation']
        ];
        this.buttonSelectChoicesItems['Article'] = [
          this.buttons['Article']['Tutorial'],
          this.buttons['Article']['Student'],
          this.buttons['Article']['Incomplete'],
          this.buttons['Article']['TooShort'],
          this.buttons['Article']['Minima'],
          this.buttons['Article']['Deleted'],
          this.buttons['Article']['Redirect'],
          this.buttons['Article']['Move'],
          this.buttons['Article']['Titles']
        ];
        this.buttonSelectChoicesItems['Copyright'] = [
          this.buttons['Copyright']['DoNotCopy'],
          this.buttons['Copyright']['UseCitation'],
          this.buttons['Copyright']['CiteNotCopy'],
          this.buttons['Copyright']['ReliableSources'],
          this.buttons['Copyright']['CitationTutorial'],
          this.buttons['Copyright']['License'],
          this.buttons['Copyright']['Copyvio'],
          this.buttons['Copyright']['Ownership']
        ];
        this.buttonSelectChoicesItems['Advanced'] = [
          this.buttons['Advanced']['Coord'],
          this.buttons['Advanced']['Categories'],
          this.buttons['Advanced']['Interwiki']
        ];
        this.buttonSelectChoicesItems['Spam'] = [
          this.buttons['Spam']['Advertisement'],
          this.buttons['Spam']['Notability'],
          this.buttons['Spam']['Sereh'],
          this.buttons['Spam']['3RR'],
          this.buttons['Spam']['Autobiography'],
          this.buttons['Spam']['WP:NOT'],
          this.buttons['Spam']['Username'],
          this.buttons['Spam']['Canvassing']
        ];
        this.buttonSelectChoicesItems['Block'] = [
          this.buttons['Block']['Username'],
          this.buttons['Block']['OneDay'],
          this.buttons['Block']['Indefinite'],
          this.buttons['Block']['Detailed'],
          this.buttons['Block']['AbuseFilter']
        ];
        this.buttonSelectChoicesItems['Rights'] = [
          this.buttons['Rights']['Autopatrol'],
          this.buttons['Rights']['Revert'],
          this.buttons['Rights']['Patroller'],
          this.buttons['Rights']['TemplateEditor'],
          this.buttons['Rights']['Eliminator'],
          this.buttons['Rights']['Sysop'],
          this.buttons['Rights']['ReinstateEliminator']
        ];

        // The default choice
        this.buttonSelectChoices = new OO.ui.ButtonSelectWidget({
          items: this.buttonSelectChoicesItems['Noobs']
        });

        this.setChooseAction = function() {
          dialog.buttonSelectChoices.on('choose', function(item) {
            dialog.previewResult.toggle(false);
            if (item.data !== undefined & item.data.params !== undefined) {
              dialog.panelParams.toggle(true);
              dialog.buttonPreview.toggle(true);
              dialog.buttonReset.toggle(true);
              if (item.data.params.length > 0) (
                dialog.textParamOneLayout.toggle(true);
                dialog.textParamOneLayout.setLabel(item.data.params[0].label);
                dialog.textParamOneLayout.setData(item.data.params[0].id);
                dialog.textParamOne.setValue('');
              } else {
                dialog.textParamOneLayout.toggle(false);
              }
              if (item.data.params.length > 1) (
                dialog.textParamTwoLayout.toggle(true);
                dialog.textParamTwoLayout.setLabel(item.data.params[1].label);
                dialog.textParamTwoLayout.setData(item.data.params[1].id);
                dialog.textParamTwo.setValue('');
              } else {
                dialog.textParamTwoLayout.toggle(false);
              }
            } else {
              dialog.textParamOneLayout.toggle(false);
              dialog.textParamTwoLayout.toggle(false);
              dialog.panelParams.toggle(true);
              dialog.buttonPreview.toggle(true);
              dialog.buttonReset.toggle(true);
            }
            windowManager.getCurrentWindow().updateSize();
          });          
        }
        this.setChooseAction();

        this.textParamOne = new OO.ui.TextInputWidget({
          placeholder: 'متنی وارد کنید'
        });
        this.textParamTwo = new OO.ui.TextInputWidget({
          placeholder: 'متنی وارد کنید'
        });
        this.textParamOneLayout = new OO.ui.FieldLayout( this.textParamOne, {
          label: 'پارامتر اول'
        });
        this.textParamTwoLayout = new OO.ui.FieldLayout( this.textParamTwo, {
          label: 'پارامتر دوم'
        });
        this.paramFieldset = new OO.ui.FieldsetLayout({
          items: [
            this.textParamOneLayout,
            this.textParamTwoLayout
          ]
        });
        this.buttonPreview = new OO.ui.ButtonWidget({
          label: 'پیش‌نمایش',
          icon: 'check',
          title: 'پیش‌نمایش',
          flags: 'progressive'
        });
        this.buttonPreview.on('click', function() {
          dialog.previewResult.toggle(true);
          dialog.previewResult.setContent(''); // Makes any previous preview results go away, so the user notices the change
          windowManager.getCurrentWindow().updateSize();
          var wikitext = UserMessages.static.prepareWikitext(dialog);
          var api = new mw.Api();
          api.get({
            action: 'parse',
            text: wikitext,
            pst: true
          }).done(function( data ) {
            dialog.previewResult.setContent($(data.parse.text['*']));
          });
        });
        this.buttonReset = new OO.ui.ButtonWidget({
          label: 'پاک کردن',
          icon: 'reload',
          title: 'پاک کردن',
          flags: 'destructive'
        });
        this.buttonReset.on('click', function() {
          dialog.textParamOne.setValue('');
          dialog.textParamTwo.setValue('');
          dialog.previewResult.toggle(false);
          dialog.buttonPreview.toggle(true);
          dialog.buttonReset.toggle(true);
          windowManager.getCurrentWindow().updateSize();
        });
        this.panelParams = new OO.ui.PanelLayout({
          expanded: true,
          padded: true
        });
        this.previewResult = new PreviewPanel({
          expanded: true,
          padded: true,
          $content: ''
        });
        this.previewResult.toggle(false);
        this.panelParams.$element.append(this.paramFieldset.$element);
        this.panelParams.$element.append(this.buttonPreview.$element);
        this.panelParams.$element.append(this.buttonReset.$element);
        this.textParamOneLayout.toggle(false);
        this.textParamTwoLayout.toggle(false);
        this.buttonPreview.toggle(false);
        this.buttonReset.toggle(false);
        this.panelGroups = new OO.ui.PanelLayout({
          expanded: true,
          padded: true,
          classes: ['panelGroups']
        });
        this.panelGroups.$element.append(this.buttonSelectGroups.$element);
        this.panelChoices = new OO.ui.PanelLayout({
          expanded: true,
          padded: true,
          classes: ['panelChoices']
        });
        this.panelChoices.$element.append(this.buttonSelectChoices.$element);
        this.panelPreview = new OO.ui.PanelLayout({
          expanded: true,
          padded: true
        });
        this.panelPreview.$element.append(this.previewResult.$element);

        this.stackLayout = new OO.ui.StackLayout({
          items: [
            this.panelGroups,
            this.panelChoices,
            this.panelParams,
            this.panelPreview
          ],
          continuous: true,
          scrollable: false
        });
        this.$body.append(this.stackLayout.$element);
      };
      UserMessages.static.prepareWikitext = function(dialog) {
        var btn = dialog.buttonSelectChoices.findSelectedItem().getData();
        var prm1name = dialog.textParamOneLayout.getData();
        var prm1val = dialog.textParamOne.getValue();
        var prm2name = dialog.textParamTwoLayout.getData();
        var prm2val = dialog.textParamTwo.getValue();
        var wikitext = '{{subst:' + btn.template;
        if (dialog.textParamOneLayout.isVisible()) (
          wikitext += '|' + prm1name + '=' + prm1val
        }
        if (dialog.textParamTwoLayout.isVisible()) (
          wikitext += '|' + prm2name + '=' + prm2val
        }
        wikitext += '}}';
        return wikitext;
      }
      UserMessages.prototype.getSetupProcess = function(data) {
        data = data || {};
        return UserMessages.super.prototype.getSetupProcess.call( this, data )
          .next( function () {
            // Do something
          }, this );
      };
      UserMessages.prototype.getActionProcess = function(action) {
        var dialog = this;
        if (action === 'warn') {
          var wikitext = UserMessages.static.prepareWikitext(dialog);
          wikitext += '\n~~' + '~~';
          return new OO.ui.Process(function() {
            UMOptions.savePage(mw.config.get('wgPageName'), wikitext, function() {
              location.reload();
            });
            dialog.close({
              action: action
            }).done(function() {
              // Page will be reloaded once saved
            });
          });
        }
        return UserMessages.super.prototype.getActionProcess.call(this, action);
      };
      if (!windowManager) {
        windowManager = new OO.ui.WindowManager();
        $('body').append(windowManager.$element);
      }
      UM = new UserMessages({
        size: 'large'
      });
      windowManager.addWindows([UM]);
      windowManager.openWindow(UM);
    },
    savePage: function(title, text, callback) {
      (new mw.Api()).post({
        action: 'edit',
        section: 'new',
        title: title,
        text: text,
        token: mw.user.tokens.get('editToken')
      }).done(function(data) {
        if (data.error && data.error.info) {
          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);
      });
    },
  };
  if (mw.config.get('wgNamespaceNumber') === 3 | mw.config.get('wgPageName') === 'ویکی‌پدیا:صفحه_تمرین') {
    $(UMOptions.install);
  }
})(jQuery, mediaWiki);