ملاحظة: بعد الحفظ، قد يلزمك إفراغ الكاش لرؤية التغييرات.

/******************************************************إضافة أزرار مفيدة لمحرر ويكيبيديا***************************************************/
var customizeToolbar = function() {
//------------------------------------------------------------------------------
//إضافة مجموعة
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'advanced',
        'groups': {
                'BasicGroup': {
                        'label': '' // or use labelMsg for a localized label, see above
                }
        }
} );
//------------------------------------------------------------------------------
//زر لوضع نص مقالة أساسي
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        section: 'advanced',
        group: 'BasicGroup',
        tools: {
                "FastArticle": {
                        label: 'مقالة سريعة',
                        type: 'button',
                        icon: 'http://upload.wikimedia.org/wikipedia/commons/0/04/Article.svg',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        post: 
                                        "\n\'\'\'العنوان\'\'\' {{إنجليزية|XXXXXXXX}} "
                                        +"\n\n==انظر أيضا== \n* "
                                        +"\n\n==مراجع==\n{{مراجع}}"
                                        +"\n\n{{بذرة}}"
                                        +"\n\n[[تصنيف:]]"
                                        +"\n[[en:]]",
                                }
                        }
                }
        }
} );
//------------------------------------------------------------------------------
//زر لوضع المحتوى الأساسي لصفحة تصنيف
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        section: 'advanced',
        group: 'BasicGroup',
        tools: {
                "FastCategory": {
                        label: 'تصنيف سريع',
                        type: 'button',
                        icon: 'http://upload.wikimedia.org/wikipedia/commons/1/11/Button_category.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        post: "[[تصنيف:]]\n[[en:]]",
                                }}}}
} );
//------------------------------------------------------------------------------
//معلومات شخص
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        section: 'advanced',
        group: 'BasicGroup',
        tools: {
                "Fastperson": {
                        label: 'معلومات شخص',
                        type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/Person_icon.png/20px-Person_icon.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        post: "{{صندوق معلومات شخص}}",
                                }}}}
} );


//------------------------------------------------------------------------------
//wd2
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        section: 'advanced',
        group: 'BasicGroup',
        tools: {
                "Fastperson": {
                        label: 'wikidata2',
                        type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/d6/Cametro_line_2.png/20px-Cametro_line_2.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        post: "{{#invoke:Wikidata2\n|formatStatements\n|entityId=\n|property=\n|property1=\n|noref=2\n|formatting =\n|value-module=\n|value-function=\n|langpref=\n|showlang=\n}}",
                                }}}}
} );

//------------------------------------------------------------------------------
// 
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        section: 'advanced',
        group: 'BasicGroup',
        tools: {
                "WD1": {
                        label: 'WD',
                        type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Wikidata-logo.svg/20px-Wikidata-logo.svg.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: "{{subst:"+"مستخدم:Mr._Ibrahem/مشاريع/عسكر|",
                                        post: "}}",
                                }}}}
} );

//------------------------------------------------------------------------------
// 
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        section: 'advanced',
        group: 'BasicGroup',
        tools: {
                "WD1": {
                        label: 'WD',
                        type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Wikidata-logo.svg/20px-Wikidata-logo.svg.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: "{{subst:"+"مستخدم:Mr._Ibrahem/مشاريع/عسكر|{{نسخ",
                                        post: ":#invoke:Wikidata2|pageId}}}}",
                                }}}}
} );

//------------------------------------------------------------------------------
//إضافة مجموعة
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'advanced',
        'groups': {
                'MajedGroup1': {
                        'label': 'وصلات:' // or use labelMsg for a localized label, see above
                }
        }
} );
//------------------------------------------------------------------------------
//إضافة أزرار
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        section: 'advanced', group: 'MajedGroup1', tools: {
        	
        	    //زر لوضع الوصلة الداخلية
                "myinterwiki": {       
                        label: 'وصلة داخلية', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/8/8e/Button-Interwiki-BW.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: "[[",
                                        post: "]]",
                                }}},
                                
                //زر لوضع الوصلة الخارجية   
                "ExLink": {                                   
                        label: 'وصلة خارجية', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/7/73/External_link_icon.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: "[",
                                        post: " الموقع الرسمي]",
                                }}},
                                
                //زر لوضع وصلة مقالة إنجليزية                               
                "EngArticle": {
                        label: 'عنوان مقالة إنجليزية', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/7/7f/Interwiki-button-bg.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: "[[en:",
                                        post: "]]",
                                }}},
        }
} );
//------------------------------------------------------------------------------
//إضافة مجموعة
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'advanced',
        'groups': {
                'MajedGroup2': {
                        'label': 'أخرى:' // or use labelMsg for a localized label, see above
                }
        }
} );
//------------------------------------------------------------------------------
//إضافة أزرار
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        section: 'advanced',
        group: 'MajedGroup2',
        tools: {
        	
        	   //زر لوضع قالب علم حول اسم البلد
                "flagTemplate": {
                        label: 'قالب علم',
                        type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/e/eb/Button_Brazil.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: "{{علم|",
                                        post: "}}",
                                }}},
                                
                //زر لوضع قالب بالإنجليزية                
                "InEngTemplate": {
                        label: '{{إنجليزية|Example}}', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/4/4d/Language-group-infobox_button.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: "{{إنجليزية|",
                                        post: "}} ",
                                }}},  
                                
                //زر لوضع انظر أيضا                
                "SeeAlso": {
                        label: 'انظر أيضا', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/6/6c/Button_see_also.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: "==انظر أيضا==\n",
                                        post: "*[[]]",
                                }}},    

                //زر لوضع قسم المراجع                
                "RefSection": {
                        label: 'قسم المراجع', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/f/fe/Button_refs.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: "==مراجع==\n",
                                        post: "{{مراجع}}",
                                }}},  

                //زر مرجع
                "Ref": {
                        label: 'مرجع', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/8/8a/Ref-button-bg.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: "<ref>",
                                	    post: "</ref>",                                	
                                }}},

                //ملف تصغير
                "FileThumb": {
                        label: 'ملف تصغير', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/d/de/Button_image.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: "[[ملف:",
                                	    post: "|تصغير|]]",                                	
                                }}},  								
        }
} );
//------------------------------------------------------------------------------
// إضافة قسم
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'sections': {
                'MyButtons': {
                        'type': 'toolbar', // Can also be 'booklet'
                        'label': 'أزرار مفيدة'
                        // or 'labelMsg': 'section-emoticons-label' for a localized label
                }
        }
} );
//------------------------------------------------------------------------------
//إضافة مجموعة
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'MyButtons',
        'groups': {
                'Useful': {
                        'label': 'Majed' // or use labelMsg for a localized label, see above
                }
        }
} );
//------------------------------------------------------------------------------
//إضافة أزرار
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        section: 'MyButtons', group: 'Useful', tools: {
        	
        	    //زر قائمة نقطية
                "InList": {
                        label: 'قائمة نقطية', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/a/aa/Button_dot1.PNG',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: "*\n*\n*\n*\n*\n*\n*\n*\n",
                                }}},                                                                 

                //معرض صور
                "ImageSec": {
                        label: 'معرض صور', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/8/8d/Button_image_annotation.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: '<div align="center">\n<gallery perRow="5">\nصورة:xxxxxxxxxxxxxxxxxxxxxxx|الوصف.\n</gallery>\n</div>',
                                }}},    

                //مربع احتواء
                "ContBox": {
                        label: 'مربع احتواء', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/c/c2/Button_box_right.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: '{{div}}',
                                	    post: "{{div2}}",                                	
                                }}},   
                                
                //قائمة مخفية
                "CollapsibleList": {
                        label: 'قائمة مخفية', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/e/e8/Button_box_center_low_list.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: '{{قائمة مخفية|عنوان=العنوان|',
                                	    post: "}}",                                	
                                }}},                                  
        }
} );
//------------------------------------------------------------------------------
};   //Function END//
//==============================================================================
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
        mw.loader.using( 'user.options', function () {
                if ( mw.user.options.get('usebetatoolbar') ) {
                        mw.loader.using( 'ext.wikiEditor', function () {
                                $(document).ready( customizeToolbar );
                        } );
                }
        } );
}

/*******************************************************************************************************/
//--------------------------------------------------------------------------------------
/*
$( "#wpSummary" ).css({ width: 300, });                                     //تصغير حجم مربع الملخص
$( "#wpSummary" ).after(' <button type="button"  title="استبدال النص المحدد وجميع تكراراته بهذا النص" id="ReplaceText" >استبدل المحدد بهذا</button> ');   //إنشاء زر الاستبدال
$( "#wpSummary" ).after('<input type="text" id="NewText" />');              //إنشاء مربع الإدخال الجديد
$( "#wpSummary" ).after('<button type="button" id="EmptyMyText" >مسح النص</button>');        //إنشاء زر المسح
$( "#wpSummary" ).after(' أدوات إضافية: ');       
$("#EmptyMyText").css('color','#B40404');                                  //لون خط زر المسح
//----------------------------------------------------------------------------------------
$('#ReplaceText').click(function(){                                        //عند الضغط على زر الاستبدال

   var textComponent = document.getElementById('wpTextbox1');               //إيجاد منطقة النص
                                 
   // Mozilla يعمل على
   var startPos = textComponent.selectionStart;                             //بداية التحديد
   var endPos = textComponent.selectionEnd;                                 //نهاية التحديد
   var selectedText = textComponent.value.substring(startPos, endPos);       //النص المحدد
  
   var newText = $('#NewText').val();                                        //النص الجديد
   var myRegex = new RegExp(selectedText, 'g');                             //تعبير منطقي
   var finalText = textComponent.value.replace(myRegex, newText);           //استبدال
   $('#wpTextbox1').val(finalText);                                         //وضع في منطقة النص   
   $('#NewText').val('');                                                    //تفريغ مربع الإدخال
});
//-----------------------------------------------------------------------------------------  
$('#EmptyMyText').click(function(){                                        //مسح كل النص
  $('#wpTextbox1').val(''); 
});  
//----------------------------------------------------------------------------------------- 
/*******************************************************************************************************/