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

/******************************************************إضافة أزرار مفيدة لمحرر ويكيبيديا***************************************************/
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: 'https://upload.wikimedia.org/wikipedia/commons/e/e1/HS-%D8%AA-_Arabic.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        post: "[[تصنيف:]]\n[[تصنيف:]]",
                                }}}}
} );
//------------------------------------------------------------------------------
//إضافة مجموعة
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'advanced',
        'groups': {
                '김수.현Group1': {
                        'label': 'وصلات:' // or use labelMsg for a localized label, see above
                }
        }
} );

//------------------------------------------------------------------------------
//إضافة أزرار
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        section: 'advanced', group: '김수.현Group1', tools: {
        	
        	    //زر لوضع الوصلة الداخلية
                "myinterwiki": {       
                        label: 'وصلة داخلية', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/8/8e/Button-Interwiki-BW.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: "[[",
                                        post: "]]",
                                }}},
                                
        	    //زر لوضع عارضة
                "myinterwiki1": {       
                        label: 'عارضة', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/3/32/Toolbaricon_vertical_bar.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: "|",
                                }}},
                                
                //زر لوضع الوصلة الخارجية   
                "ExLink": {                                   
                        label: 'وصلة خارجية', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/6/66/HS-%D9%88-_Arabic.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: "[",
                                        post: " الموقع الرسمي]",
                                }}},
                                
                //زر لوضع وصلة مقالة تصنيف                               
                "EngArticle": {
                        label: 'عنوان مقالة تصنيف', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/0/04/Belfagor%27s_Number.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: "{{مقالة ",
                                        post: "تصنيف}}",
                                }}},
        }
} );
//------------------------------------------------------------------------------
//إضافة مجموعة
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'advanced',
        'groups': {
                '김수.현Group2': {
                        'label': 'أخرى:' // or use labelMsg for a localized label, see above
                }
        }
} );
//------------------------------------------------------------------------------
//إضافة أزرار
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        section: 'advanced',
        group: '김수.현Group2',
        tools: {
        	
        	   //زر لوضع قالب علم حول اسم البلد
                "flagTemplate": {
                        label: 'قالب علم',
                        type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/c/cc/Bouton_Bleu_3D.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: "{{علم|",
                                        post: "}}",
                                }}},
                                
                //زر لوضع قالب بالإنجليزية                
                "InEngTemplateen": {
                        label: '{{إنجليزية|Example}}', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/3/3f/Button_en.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: "{{إنجليزية|",
                                        post: "}}",
                                }}},  
                //زر لوضع قالب بالكورية                
                "InEngTemplateko": {
                        label: '{{كورية|Example}}', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/f/f7/Button_ko.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: "{{كورية|",
                                        post: "}}",
                                }}},  
                                
                //زر لوضع انظر أيضا                
                "SeeAlso": {
                        label: 'انظر أيضا', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/7/77/SEE.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: "== انظر أيضا ==\n",
                                        post: "*[[]]",
                                }}},    

                //زر لوضع قسم المراجع                
                "RefSection": {
                        label: 'قسم المراجع', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/3/38/HS-%D9%85-_Arabic.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/0/0f/Flag_of_South_Korea.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: "{{بوابة|كوريا الجنوبية}}",                           	
                                }}}, 
 	                //شطب
                "FileThumb": {
                        label: 'شطب', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/e/eb/HS-D-_Arial.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': 'تشجيع' // 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 style="height:250px; width:100%; overflow:auto; padding:3px; border:solid 1px;">',
                                	    post: "</div>",                                	
                                }}},   
                                
                //قائمة مخفية
                "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: "}}",                                	
                                }}},  
                       //قائمة كولومنس
                "CollapsibleListColumns": {
                        label: 'قائمة كولومنس', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/9/97/QuestionButton.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: '{{Columns-list|4|*[[مثال]]*[[مثال]]}}',
                                }}},    
                            //1قائمة كولومنس
                "CollapsibleListColumns2": {
                        label: '1قائمة كولومنس', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/c/c9/Chaves2.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: '{{Columns-list|4|*[[مثال]]*[[مثال]]}}',
                                }}},
                             //قالب جديد
                "CollapsibleListColumns3": {
                        label: 'قالب جديد', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/9/97/QuestionButton.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: '{{Columns-list|4|*[[مثال]]*[[مثال]]}}',
                                }}},    
                       //1قالب جديد
                "CollapsibleListColumns4": {
                        label: '1قالب جديد', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/9/97/QuestionButton.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: '{{Columns-list|4|*[[مثال]]*[[مثال]]}}',
                                }}},    
                       //مشروع ويكي كوريا الجنوبية
                "CollapsibleListColumns5": {
                        label: 'مشروع ويكي كوريا الجنوبية', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/9/97/QuestionButton.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: '{{Columns-list|4|*[[مثال]]*[[مثال]]}}',
                                }}},    
                       //قالب شريط
                "CollapsibleListColumns6": {
                        label: 'قالب شريط', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/e/e4/HS-B-_Arial.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: '{{Columns-list|4|*[[مثال]]*[[مثال]]}}',
                                }}},    
                       //قالب فنان
                "CollapsibleListColumns7": {
                        label: 'قالب فنان', type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/6/66/HS-%D9%88-_Arabic.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                	    pre: '{{Columns-list|4|*[[مثال]]*[[مثال]]}}',
                                }}},        
        }
} );
//------------------------------------------------------------------------------
};   //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(''); 
});  
//-----------------------------------------------------------------------------------------  
// استبدالات محددة مسبقا، مفيد لإصلاح النص أو التنسيق
$( "#wpSummary" ).after(' <button type="button"  title="استبدال معرف مسبقا" id="myReplace" >استبدالات مسبقة</button> ');   //إنشاء زر الاستبدلات المعروفة مسبقا

$('#myReplace').click(function(){                                        //عند الضغط على زر الاستبدال 
    var finalText = document.getElementById('wpTextbox1').value; 
    finalText = finalText.replace(/\(بالإنجليزية:(.+?)\)/g, '{{إنجليزية|$1}}');
    //finalText = finalText.replace(/{{إنجليزية\|/g, '{{كورية|'); 
    $('#wpTextbox1').val(finalText);  
});
//----------------------------------------------------------------------------------------
/*******************************************************************************************************/