د نور تفصيل لپاره د غځول په تنۍ کلېک وکړئيادښت: د غوره توبونو د خوندي کولو وروسته، خپل د کتنمل (بروزر) ساتل شوې حافظه تازه کړی.د نور تفصيل لپاره د غځول په تنۍ کلېک وکړئ.

  • فايرفاکس/ سفري: په دې کتنمل کې د Reload د ټکوهلو په وخت د Shift تڼۍ نيولې وساتی، او يا هم Ctrl-F5 يا Ctrl-Rتڼۍ کېښکاږۍ (په Apple Mac کمپيوټر باندې ⌘-R کېښکاږۍ)
  • گووگل کروم: په دې کتنمل کې د Ctrl-Shift-R تڼۍ کېښکاږۍ (د مک لپاره ⌘-Shift-R)
  • انټرنټ اېکسپلورر: په دې کتنمل کې د Refresh د ټکوهلو په وخت کې د Ctrl تڼۍ کېښکاږلې ونيسۍ، او يا هم د Ctrl-F5 تڼۍ کېښکاږۍ
  • اوپرا: په دې کتنمل کې د خپل براوزر ساتل شوې حافظه پدې توگه سپينولی شی Tools→Preferences
لاسوند[جوړول]
/* تحميل صندوق أدوات التحرير وصندوق البحث */
if ($.inArray(mw.config.get('wgAction'), ['edit' , 'submit']) !== -1) {

	mw.loader.load( '/w/index.php?title=Mediawiki:Edittools.js&action=raw&ctype=text/javascript' );
	mw.loader.load( '/w/index.php?title=Mediawiki:CustomizedEditTool.js&action=raw&ctype=text/javascript' );
} else if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Watchlist' ) {

    mw.loader.load( '/w/index.php?title=MediaWiki:Common.js/watchlist.js&action=raw&ctype=text/javascript' );
} else if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Upload' ) {

	mw.loader.load( '/w/index.php?title=Mediawiki:Upload-description.js&action=raw&ctype=text/javascript' );
}

/*إضافات عامة*/

mw.loader.load( '/w/index.php?title=Mediawiki:Autoedit.js&action=raw&ctype=text/javascript' );
/**
 * Collapsible tables
 *
 * Allows tables to be collapsed, showing only the header. See [[Wikipedia:NavFrame]].
 *
 * @version 2.0.3 (2014-03-14)
 * @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js
 * @author [[User:R. Koot]]
 * @author [[User:Krinkle]]
 * @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which
 * is supported in MediaWiki core.
 */
 
var autoCollapse = 2;
var collapseCaption = '˅';
var expandCaption = '˂';
 
function collapseTable( tableIndex ) {
    var Button = document.getElementById( 'collapseButton' + tableIndex );
    var Table = document.getElementById( 'collapsibleTable' + tableIndex );
 
    if ( !Table || !Button ) {
        return false;
    }
 
    var Rows = Table.rows;
    var i;
 
    if ( Button.firstChild.data === collapseCaption ) {
        for ( i = 1; i < Rows.length; i++ ) {
            Rows[i].style.display = 'none';
        }
        Button.firstChild.data = expandCaption;
    } else {
        for ( i = 1; i < Rows.length; i++ ) {
            Rows[i].style.display = Rows[0].style.display;
        }
        Button.firstChild.data = collapseCaption;
    }
}
 
function createClickHandler( tableIndex ) {
    return function ( e ) {
        e.preventDefault();
        collapseTable( tableIndex );
    };
}
 
function createCollapseButtons() {
    var tableIndex = 0;
    var NavigationBoxes = {};
    var Tables = document.getElementsByTagName( 'table' );
    var i;
 
    for ( i = 0; i < Tables.length; i++ ) {
        if ( $( Tables[i] ).hasClass( 'collapsible' ) ) {
 
            /* only add button and increment count if there is a header row to work with */
            var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0];
            if ( !HeaderRow ) {
                continue;
            }
            var Header = HeaderRow.getElementsByTagName( 'th' )[0];
            if ( !Header ) {
                continue;
            }
 
            NavigationBoxes[ tableIndex ] = Tables[i];
            Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );
 
            var Button     = document.createElement( 'span' );
            var ButtonLink = document.createElement( 'a' );
            var ButtonText = document.createTextNode( collapseCaption );
            // Styles are declared in [[MediaWiki:Common.css]]
            Button.className = 'collapseButton';
 
            ButtonLink.style.color = Header.style.color;
            ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
            ButtonLink.setAttribute( 'href', '#' );
            $( ButtonLink ).on( 'click', createClickHandler( tableIndex ) );
            ButtonLink.appendChild( ButtonText );
 
            //Button.appendChild( document.createTextNode( '[' ) );
            Button.appendChild( ButtonLink );
            //Button.appendChild( document.createTextNode( ']' ) );
 
            Header.insertBefore( Button, Header.firstChild );
            tableIndex++;
        }
    }
 
    for ( i = 0;  i < tableIndex; i++ ) {
        if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) ||
            ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) )
        ) {
            collapseTable( i );
        }
        else if ( $( NavigationBoxes[i] ).hasClass ( 'innercollapse' ) ) {
            var element = NavigationBoxes[i];
            while ((element = element.parentNode)) {
                if ( $( element ).hasClass( 'outercollapse' ) ) {
                    collapseTable ( i );
                    break;
                }
            }
        }
    }
}
 
mw.hook( 'wikipage.content' ).add( createCollapseButtons );
 
/**
 * Dynamic Navigation Bars (experimental)
 *
 * Description: See [[Wikipedia:NavFrame]].
 * Maintainers: UNMAINTAINED
 */
 
/* set up the words in your language */
var NavigationBarHide =  collapseCaption;
var NavigationBarShow = expandCaption;
 
/**
 * Shows and hides content and picture (if available) of navigation bars
 * Parameters:
 *     indexNavigationBar: the index of navigation bar to be toggled
 **/
window.toggleNavigationBar = function ( indexNavigationBar, event ) {
    var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
    var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
    var NavChild;
 
    if ( !NavFrame || !NavToggle ) {
        return false;
    }
 
    /* if shown now */
    if ( NavToggle.firstChild.data === NavigationBarHide ) {
        for ( NavChild = NavFrame.firstChild; NavChild !== null; NavChild = NavChild.nextSibling ) {
            if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
                NavChild.style.display = 'none';
            }
        }
    NavToggle.firstChild.data = NavigationBarShow;
 
    /* if hidden now */
    } else if ( NavToggle.firstChild.data === NavigationBarShow ) {
        for ( NavChild = NavFrame.firstChild; NavChild !== null; NavChild = NavChild.nextSibling ) {
            if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
                NavChild.style.display = 'block';
            }
        }
        NavToggle.firstChild.data = NavigationBarHide;
    }
 
    event.preventDefault();
};
 
/* adds show/hide-button to navigation bars */
function createNavigationBarToggleButton() {
    var indexNavigationBar = 0;
    var NavFrame;
    var NavChild;
    /* iterate over all < div >-elements */
    var divs = document.getElementsByTagName( 'div' );
    for ( var i = 0; (NavFrame = divs[i]); i++ ) {
        /* if found a navigation bar */
        if ( $( NavFrame ).hasClass( 'NavFrame' ) ) {
 
            indexNavigationBar++;
            var NavToggle = document.createElement( 'a' );
            NavToggle.className = 'NavToggle';
            NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
            NavToggle.setAttribute( 'href', '#' );
            $( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) );
 
            var isCollapsed = $( NavFrame ).hasClass( 'collapsed' );
            /**
             * Check if any children are already hidden.  This loop is here for backwards compatibility:
             * the old way of making NavFrames start out collapsed was to manually add style="display:none"
             * to all the NavPic/NavContent elements.  Since this was bad for accessibility (no way to make
             * the content visible without JavaScript support), the new recommended way is to add the class
             * "collapsed" to the NavFrame itself, just like with collapsible tables.
             */
            for ( NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling ) {
                if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
                    if ( NavChild.style.display === 'none' ) {
                        isCollapsed = true;
                    }
                }
            }
            if ( isCollapsed ) {
                for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
                    if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
                        NavChild.style.display = 'none';
                    }
                }
            }
            var NavToggleText = document.createTextNode( isCollapsed ? NavigationBarShow : NavigationBarHide );
            NavToggle.appendChild( NavToggleText );
 
            /* Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) */
            for( var j = 0; j < NavFrame.childNodes.length; j++ ) {
                if ( $( NavFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
                    NavToggle.style.color = NavFrame.childNodes[j].style.color;
                    NavFrame.childNodes[j].appendChild( NavToggle );
                }
            }
            NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
        }
    }
}
 
$( createNavigationBarToggleButton );


/**/
if ( $.inArray( mw.config.get( 'wgPageName' ), [ "ويكيبيديا:طلبات_صلاحيات/إعطاء",
	"ويكيبيديا:طلبات_صلاحيات/إزالة",
	"ويكيبيديا:إخطار_الإداريين/حماية/الحالية",
	"ويكيبيديا:إخطار_الإداريين/إزالة_حماية/الحالية",
	"ويكيبيديا:إخطار_الإداريين/منع/الحالية",
	"ويكيبيديا:إخطار_الإداريين/إزالة_منع/الحالية",
	"ويكيبيديا:إخطار_الإداريين/استرجاع/الحالية",
	"ويكيبيديا:طلبات_النقل/الحالية"
] ) !== -1 ) {
	if ($.inArray("editor", mw.config.get( 'wgUserGroups' )) == -1) {
            mw.loader.using(['mediawiki.util']).then(function() {
		mw.util.addCSS(" .mw-summary { display:none !important;}");
            });
	}
}


/*[[قالب:قائمة أفقية]]*/ 
var arrowimages={down:["downarrowclass","//upload.wikimedia.org/wikipedia/commons/f/f1/MediaWiki_Vector_skin_action_arrow.svg",10],left:["leftarrowclass","//upload.wikimedia.org/wikipedia/commons/8/8e/MediaWiki_Vector_skin_left_arrow.svg"]};var jqueryslidemenu={animateduration:{over:300,out:300},buildmenu:function(e,t){jQuery(document).ready(function(n){var r=n("#"+e+">ul");var i=r.find("ul").parent();i.each(function(e){var r=n(this);var i=n(this).find("ul:eq(0)");this._dimensions={w:this.offsetWidth,h:this.offsetHeight,subulw:i.outerWidth(),subulh:i.outerHeight()};this.istopheader=r.parents("ul").length==1?true:false;i.css({top:this.istopheader?this._dimensions.h+"px":0});r.children("a:eq(0)").css(this.istopheader?{paddingLeft:t.down[2]}:{}).append('<img src="'+(this.istopheader?t.down[1]:t.left[1])+'" class="'+(this.istopheader?t.down[0]:t.left[0])+'" style="border:0;" />');r.hover(function(e){var t=n(this).children("ul:eq(0)");this._offsets={right:n(this).offset().right,top:n(this).offset().top};var r=this.istopheader?0:this._dimensions.w;r=this._offsets.right+r+this._dimensions.subulw>n(window).width()?this.istopheader?-this._dimensions.subulw+this._dimensions.w:-this._dimensions.w:r;if(t.queue().length<=1){t.css({right:r+"px",width:this._dimensions.subulw+"px"}).slideDown(jqueryslidemenu.animateduration.over)}},function(e){var t=n(this).children("ul:eq(0)");t.slideUp(jqueryslidemenu.animateduration.out)});r.click(function(){n(this).children("ul:eq(0)").hide()})});r.find("ul").css({display:"none",visibility:"visible"})})}};jqueryslidemenu.buildmenu("myslidemenu",arrowimages)

/* [[قالب:مبوبة]] */

mw.loader.load( '/w/index.php?title=MediaWiki:Tabs.js&action=raw&ctype=text/javascript' );
/* قالب:تبديل محتوى */


mw.loader.load( '/w/index.php?title=MediaWiki:LoadingContent.js&action=raw&ctype=text/javascript' ); // يتم تحميل المحتوى المعروض على الشاشة بشكل ديناميكي
/* [[قالب:ص.م/موقع جغرافي متعدد]] */
if ($.inArray(mw.config.get( 'wgAction' ), [ "view", "purge", "submit" ]) !== -1) {
	$(GeoBox_Init)
}
function GeoBox_Init(Element) {
	if (!Element) {
		Element = document.body
	}
	var cont = document.getElementsByTagName("div");
	if (cont.length == 0) {
		return
	}
	for (var i = 0, ii = 0, m = cont.length; i < m; i++) {
		if (!$(cont[i]).hasClass("img_toogle")) {
			continue
		} else {
			ii++
		}
		cont[i].id = "img_toogle_" + ii;
		// FIXME
		var Boxes = cont[i].getElementsByClassName("geobox");
		var ToggleLinksDiv = document.createElement("ul");
		ToggleLinksDiv.id = "geoboxToggleLinks_" + ii;
		for (var a = 0, l = Boxes.length; a < l; a++) {
			var ThisBox = Boxes[a];
			ThisBox.id = "geobox_" + ii + "_" + a;
			ThisBox.style.borderTop = "0";
			var ThisAlt = ThisBox.getElementsByTagName("img")[0].alt;
			var toggle = document.createElement("a");
			toggle.id = "geoboxToggle_" + ii + "_" + a;
			toggle.appendChild(document.createTextNode(ThisAlt));
			toggle.href = "javascript:;";
			toggle.onclick = function () {
				GeoBox_Toggle(this);
				return false
			};
			var Li = document.createElement("li");
			Li.appendChild(toggle);
			ToggleLinksDiv.appendChild(Li);
			if (a == (l - 1)) {
				Li.style.display = "none"
			} else {
				ThisBox.style.display = "none"
			}
		}
		cont[i].appendChild(ToggleLinksDiv)
	}
}
function GeoBox_Toggle(link) {
	var ImgToggleIndex = link.id.split("geoboxToggle_").join("").replace(/_.*/g, "");
	var GeoBoxIndex = link.id.replace(/.*_/g, "");
	var ImageToggle = document.getElementById("img_toogle_" + ImgToggleIndex);
	var Links = document.getElementById("geoboxToggleLinks_" + ImgToggleIndex);
	var Geobox = document.getElementById("geobox_" + ImgToggleIndex + "_" + GeoBoxIndex);
	var Link = document.getElementById("geoboxToggle_" + ImgToggleIndex + "_" + GeoBoxIndex);
	if ((!ImageToggle) || (!Links) || (!Geobox) || (!Link)) {
		return
	}
	// FIXME
	var AllGeoboxes = ImageToggle.getElementsByClassName("geobox");
	for (var a = 0, l = AllGeoboxes.length; a < l; a++) {
		if (AllGeoboxes[a] == Geobox) {
			AllGeoboxes[a].style.display = ""
		} else {
			AllGeoboxes[a].style.display = "none"
		}
	}
	var AllToggleLinks = Links.getElementsByTagName("a");
	for (var a = 0, l = AllToggleLinks.length; a < l; a++) {
		if (AllToggleLinks[a] == Link) {
			AllToggleLinks[a].parentNode.style.display = "none"
		} else {
			AllToggleLinks[a].parentNode.style.display = ""
		}
	}
}

/* وصلة القائمة الكاملة تحت وصلات لغات الصفحة الرئيسية */
if (mw.config.get('wgIsMainPage')) {
	mw.loader.using(['mediawiki.util']).then(function() {
		mw.util.addPortletLink('p-lang', '//meta.wikimedia.org/w/index.php?title=List_of_Wikipedias/ps&uselang=ps', 'ټولې ژبې', 'interwiki-completelist', 'د ويکيپېډياوو بشپړ ليسټ');
		var nstab = document.getElementById('ca-nstab-main');
		if (nstab && mw.config.get('wgUserLanguage') == 'ps') {
			while (nstab.firstChild) {
				nstab = nstab.firstChild
			}
			nstab.nodeValue = 'لومړی مخ'
		}
	})
}

/* ويكي ميني أطلس */
mw.loader.load('//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400');

/* [[قالب:عنصر مخفي]] */

mw.loader.load( '/w/index.php?title=Mediawiki:EnhancedCollapsibleElements.js&action=raw&ctype=text/javascript' );
/* تحميل سكربت الدردشة الحية */
if (mw.config.get('wgPageName') == 'ويكيبيديا:قناة_الدردشة/حي') {
	mw.loader.load( '/w/index.php?title=Mediawiki:IRC.js&action=raw&ctype=text/javascript' );
}

/* كود يعمل مع بوابة المشاركة */
if (mw.config.get('wgPageName') == 'ويكيبيديا:بوابة_المشاركة/قاعة_الشاي/أسئلة') {
	mw.loader.load( '/w/index.php?title=MediaWiki:Gadget-teahouse.js&action=raw&ctype=text/javascript' );
	mw.loader.load( '/w/index.php?title=MediaWiki:Gadget-teahouse.css&action=raw&ctype=text/css', 'text/css' );
}

/* دالة مساعدة لإضافة زر جديد لأحد قوائم الواجهة */
function addLink(e,t,n,r,i,s,o){var u=document.createElement("a");u.href=t;u.appendChild(document.createTextNode(n));var a=document.createElement("li");if(r)a.id=r;a.appendChild(u);var f=document.getElementById(e).getElementsByTagName("ul")[0];if(!o){f.appendChild(a)}else if(o.cloneNode){f.insertBefore(a,o)}else{f.insertBefore(a,document.getElementById(o))}if(r){if(s&&i){ta[r]=[s,i]}else if(s){ta[r]=[s,""]}else if(i){ta[r]=["",i]}}akeytt();return a}

/* نصوص لإنترنت إكسبلورر */
mw.loader.using( 'jquery.client', function() {
	if ($.client.profile().name === 'msie') {

	mw.loader.load( '/w/index.php?title=MediaWiki:Common.js/IEFixes.js&action=raw&ctype=text/javascript' );
	}
} );

/* [[قالب:اسم مستخدم]] */
function UsernameReplace() {
  if(window.disableUsernameReplace || mw.config.get('wgUserName') == null) return;
  var un = $('span.insertusername');
  for (var i=0;i<un.length;i++) {
    var d = 0;
    for(var j=0;j<un[i].childNodes.length;j++) {
      if(un[i].childNodes[j].nodeType == 3 && d < 1) {
        //find first text node and replace;
        un[i].childNodes[j].nodeValue = mw.config.get('wgUserName');
        d++;
      }
    }
  }
}
$(UsernameReplace);

/* تعريب كلمة تحويل بالإنجليزية المدرجة في شريط أدوات التحرير 
 ** [[phab:T26114]] */
(function () {
	var editor = mw.config.get('wgWikiEditorEnabledModules');
	if (editor && editor.toolbar) {
		$('#wpTextbox1').on('wikiEditor-toolbar-buildSection-advanced', function (event, section) {
			try {
				section.groups.insert.tools.redirect.action.options.pre = '#تحويل [[';
			} catch (e) {
				// Woopsie, die without a notice
			}
		});
	}
})();

/**
 * Redirect User:Name/skin.js and skin.css to the current skin's pages
 * (unless the 'skin' page really exists).
 *
 * Dependencies: mediawiki.util
 *
 * @source www.mediawiki.org/wiki/Snippets/Redirect_skin.js
 * @revision 2014-05-19
 */
if ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgNamespaceNumber' ) === 2 ) {
	var titleParts = mw.config.get( 'wgPageName' ).split( '/' );
	// Make sure there was a part before and after the slash
	// And that the latter is 'skin.js' or 'skin.css'
	if ( titleParts.length == 2 ) {
           mw.loader.using(['mediawiki.util']).then(function() {
		var userSkinPage = titleParts[0] + '/' + mw.config.get( 'skin' );
		if ( titleParts[1] === 'skin.js' ) {
			location.href = mw.util.getUrl( userSkinPage + '.js' );
		} else if ( titleParts[1] === 'skin.css' ) {
			location.href = mw.util.getUrl( userSkinPage + '.css' );
		}
           });
	}
}

/* [[قالب:مب]]
/**
 * @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
 * @revision 2017-05-16
 */
mw.loader.using( ['mediawiki.util'], function () {
	var extraCSS = mw.util.getParamValue( 'withCSS' ),
		extraJS = mw.util.getParamValue( 'withJS' );

	if ( extraCSS ) {
		// DONT REMOVE THIS IF (unless you are OK with CSRF attacks)
		if ( /^MediaWiki:[^&<>=%#]*\.css$/.test( extraCSS ) ) {
			mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraCSS ) + '&action=raw&ctype=text/css', 'text/css' );
		} else {
			mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
		}
	}

	if ( extraJS ) {
		// DONT REMOVE THIS IF (unless you are OK with XSS & CSRF attacks)
		if ( /^MediaWiki:[^&<>=%#]*\.js$/.test( extraJS ) ) {
			mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraJS ) + '&action=raw&ctype=text/javascript' );
		} else {
			mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
		}
	}
});

/* Enable nulledit=true with [[User:Splarka/nulledit.js]] */
if (mw.config.get("wgAction") == "edit" && queryString("nulledit") == "true") {
	$(nullEdit);
}
function nullEdit() {
	document.getElementById("wpSave").click();
}
function queryString(d) {
	var b = RegExp("[&?]" + d + "=([^&]*)");
	var c;
	if (c = b.exec(document.location)) {
		try {
			return decodeURI(c[1]);
		} catch (a) {}
	}
	return null;
}

/* [[قالب:أصد]] و[[قالب:يونيكود]] */
if (navigator.appVersion.search(/windows nt 5/i) !== -1) {
	mw.util.addCSS('.IPA { font-family: "Lucida Sans Unicode", "Arial Unicode MS"; } ' +
		'.Unicode { font-family: "Arial Unicode MS", "Lucida Sans Unicode"; } ');
}

//Help Abuse Filter  to tag Recreated Pages which have delete log
$(function () {
	if ($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1 && $('.mw-warning-with-logexcerpt .mw-logline-delete').length !== 0) {
		$('#editform input[type=submit]').click(function () { $('#wpSummary').val($('#wpSummary').val() + "‌‌‌‌"); });
	}
});

//وسم صفحات النقاش اليتيمة
//يعمل هذا السكربت بالتوازي مع مرشح رقم 80
//يفحص إذا لم يكن هناك صفحة رئيسية لصفحة النقاش
//ويتحقق أن الصفحة في النظاق الرئيسي
//يعمل السكربت فقط في حال كانت صفحة النقاش لصفحة غير موجودة
if (mw.config.get( 'wgNamespaceNumber' ) == 1 
	&& mw.config.get( 'wgArticleId' ) ==0 
	&& $("li#ca-nstab-main").hasClass ("new")){
	$('#editform input[type=submit]').click(function () {
		$('#wpSummary').val("‌‌‌‌وسم صفحات النقاش اليتيمة"); 
	});
}

// منع أوسمة ويكي الحب العشوائية 
if (typeof mw.config.get('wgUserRegistration') !== "undefined"){
    if (mw.config.get('wgUserEditCount') < 150 && mw.config.get('wgUserRegistration') < 2592000) $("div.vectorTabs li#ca-wikilove").css("display","none");
}
//سكربت ترتيب القوالب في أسفل المقالات
mw.loader.load( '/w/index.php?title=Mediawiki:Common.js/sort.js&action=raw&ctype=text/javascript' );

//سكربت لتوقيع الرسائل غير الموقع للجدد

mw.loader.load( '/w/index.php?title=Mediawiki:Common.js/sign.js&action=raw&ctype=text/javascript' );


/**
 *سكربت مساعد لكشف إنشاء صفحات لمستخدمين غير مسجلين
 * يعمل السكربت بالتوازي مع مرشح رقم 149
 * مثال
 * [[خاص:وصلة دائمة/27683606]]
 */
if ( $('.mw-userpage-userdoesnotexist')[0]
	    && (mw.config.get('wgNamespaceNumber') == 2 || mw.config.get('wgNamespaceNumber') == 3) ) {
	    	$('#wpSave').click(function () {
	    		$('#wpSummary').val($('#wpSummary').val() + " " + "صفحة مستخدم غير مسجل");
		    });
}


/**
 * لإخفاء رسالة التحذير التي تظهر عند تعديل صفحة بها
 * تعديلات معلقة فقط للمحررين والمراجعين تلقائيا
 */
 
 //التحقق إذا ما كان المستخدم يملك صلاحية محرر أو مراجع تلقائي
 if (mw.config.get('wgUserGroups').includes ("editor")
    ||
    mw.config.get('wgUserGroups').includes ("autoreview")){
    //إخفاء الرسالة	
    $(".flaggedrevs_editnotice").find (".حذف").hide();
}

/*
*سكربت تجريبي لتتبع المساهمات
*المنسوخة من مواقع أخرى
*ثم يقوم بوضع ملخص التعديل نسخ محتمل
*/
if (!mw.config.get('wgUserGroups').includes ("editor")
    &&
    !mw.config.get('wgUserGroups').includes ("autoreview") 
    && 
    mw.config.get('wgNamespaceNumber') === 0){
	$("#wpTextbox1").one('paste', function(e) {
		var pastedText = e.originalEvent.clipboardData.getData('text');
        if (pastedText.length > 100 && !pastedText.includes ("[[") && !pastedText.includes ("{{") && !pastedText.includes ("http")){
        	$('#wpSave').click(function () {
		    	$('#wpSummary').val($('#wpSummary').val()+" نسخ محتمل"); 
		    });
        }
	});
}
/**
 * Description: Reset align as float style in galleries.
 * Note: This will be fixed in MW 1.19 if $wgHtml5 is enabled.
 * Note: This is still not fixed. :(
 * Maintainers: jeblad, sort of...
 */
mw.hook( 'wikipage.content' ).add(function( $content ) {
    "use strict";
    $('ul.gallery').each(function (i, el) {
        var $e = $(el);
        switch ($e.attr('align')) {
        case 'gleft' :
        case 'left' :
            $e.css({
                'float': 'left',
                'clear': 'left',
                'margin-left': 0,
                'padding-left': 0
            });
            break;
        case 'gright' :
        case 'right' :
            $e.css({
                'float': 'right',
                'clear': 'right',
                'margin-right': 0,
                'padding-right': 0
            });
            break;
        case 'inherit' :
            $e.css({
                'float': 'inherit',
                'clear': 'inherit' // scary...
            });
            break;
        case 'none' :
            $e.css({
                'float': 'none'
            });
            break;
        }
    });
});


/**
 * Description: Adapt multiple columns to the actual size of the bodyContent div.
 * Maintainers:
 */
(function(mw, $) {
    // counter for number of columns
    var count = 0;
    // width of the #bodyContent and its token
    var widths = [
        { size : 450,  name : 'multicol-xx-small' },
        { size : 700,  name : 'multicol-x-small' },
        { size : 950,  name : 'multicol-small' },
        { size : 1200, name : 'multicol-normal' },
        { size : 1500, name : 'multicol-large' },
        { size : 1800, name : 'multicol-x-large' },
        { size : 2100, name : 'multicol-xx-large' }
    ];
    // selectors for default override of large lists
    var selectors = [
        '#bodyContent h2:has(#ريفرینس) + ol.large.references',
        '#bodyContent h2:has(#ادب) + ul.large',
        '#bodyContent h2:has(#ياداښتونه) + ul.large',
        '#bodyContent h2:has(#سرچینې) + ul.large',
        '#bodyContent h2:has(#دا_هم_وګورئ\\.C3\\.A5) + ul.large',
        '#bodyContent h2:has(#ريفرینس) + ul.large',
        '#bodyContent h2:has(#ادب) + ol.large',
        '#bodyContent h2:has(#ياداښتونه) + ol.large',
        '#bodyContent h2:has(#سرچینې) + ol.large',
        '#bodyContent h2:has(#دا_هم_وګورئ\\.C3\\.A5) + ol.large'
    ];
    // calculate number of columns and set its token
    function calc() {
        var found = 0;
        var body = $('#bodyContent');
        var width = body.width();
        // remove any previous definitions
        // this is necessary for resize to work
        for (var i = 0; i<widths.length; i++)
            body.removeClass(widths[i].name);
        // if the width is to small we set a special token and exits
        if (width < widths[0].size) {
            body.addClass('multicol-xx-small');
            body.addClass('multicol-verysmall');
            return;
        }
        // test for increasing sizes and set the token
        for (var i = 1; i<widths.length; i++) {
            count++;
            if (width < widths[i].size) {
                body.addClass( widths[i].name);
                found++;
                break;
            }
        }
        // if we didn't find a matching size we set a special token
        if (!found) {
            body.addClass('multicol-xx-large');
            body.addClass('multicol-verylarge');
        }
        // unless we had a too smalll width we set a common token
        body.addClass('multicol-all');
    }
    // set it all up
    $(function() {
        calc();                 // only on ready
        $(window).resize(calc); // only on resize
        // identify large lists
        count *= 2;               // twice the number of columns
        $('#bodyContent ol, #bodyContent ul').each(function(i, el) {
            if (count < el.children.length) $(el).addClass('large');
        });
        // override for long lists in specific sections, add later
        //$(selectors.join(',')).before('<div class="multicol" style="display:none"></div>');
    });
})(mediaWiki, jQuery);

/**
 * Description: Clean up the list of templates during ordinary article editing for base templates,
 * that is those with a leading dollar ($) sign in the name
 * Maintainers:
 */
(function(mw, $) {
    if (mw.config.get( 'wgNamespaceNumber' ) != 10 && (mw.config.get( 'wgAction' ) == "edit" || mw.config.get( 'wgAction' ) == "submit")) {
        try {
            $(function() {
                var used = $('.templatesUsed');
                var expl = $('.mw-templatesUsedExplanation');
                var links = used.find('> ul > li > a').filter('[href*=":$"], [href*="MediaWiki:"]');
                if (links.length === 0) return;
                links.parent().css('display', 'none');
                expl.find('p').append(' (<a class="show-base-templates" href="#">Vis grunnmaler</a><a class="hide-base-templates" href="#">Skjul grunnmaler</a>)');
                expl.find('a.hide-base-templates').css('display', 'none');
                expl.find('a.show-base-templates').click(function(){
                    links.parent().css('display', 'list-item');
                    $(this).css('display', 'none');
                    $(this).parentsUntil('.mw-templatesUsedExplanation').find('.hide-base-templates').css('display', 'inline');
                    return false;
                });
                expl.find('a.hide-base-templates').click(function(){
                    links.parent().css('display', 'none');
                    $(this).css('display', 'none');
                    $(this).parentsUntil('.mw-templatesUsedExplanation').find('.show-base-templates').css('display', 'inline');
                    return false;
                });
            });
        }
        catch (e) {
          // Woopsie, die without a notice
        }
    }
})(mediaWiki, jQuery);


/* Check if external link targets exists **************************************
 *
 * Description: Make external iw-links through stylyng and make them blue again if they exists
 * Maintainers:
 *
 * Sjekker lenker inni et element merket med CSS-klassen "iwcheck". 
 * Opprinnelig laget for oversikter ála [[Samiske geografiske navn (Alta)]]
 */
 
(function(mw, $, undefined){

    if (!mw.config.get( 'wgIsArticle' )) return;
    // if (mw.config.get( 'wgNamespaceNumber' ) != 0) return;
    if (!/^(view)$/.test(mw.config.get( 'wgAction' ))) return;

    var found = 0;
    for (var x in mw.config.get('wgCategories')) {
        if (mw.config.get('wgCategories')[x] == 'IW-check' && ++found) break;
    }
    if (!found) return;

    var api = '//%%.wikipedia.org/w/api.php';
    var languages = { 'ur' : {}, 'fa' : {}, 'en' : {}, 'ru' : {} };
    var lang = 'ps';
    var numtitles = 50;
    var maxtitles = 2000;
    var query = {
        'action': 'query',
        'prop' : 'info',
        'format': 'json',
        'maxage': 15*60,
        'smaxage': 60*60
    };

    $(function(){
        var iwcheck = $('.iwcheck').find('a.extiw');
        if (!iwcheck || !iwcheck.length) return;
        for (var x in languages) {
            languages[x].titles = {},
            languages[x].found = 0
        }
        iwcheck.each(function(i, el){
            if (el.title) {
                var matches = el.title.match(/^(.*?):(.*)$/);
                if (matches.length == 3 && languages[matches[1]] != undefined) {
                    languages[matches[1]].titles[matches[2]] = true;
                    languages[matches[1]].found++;
                }
            }
        });
        var plang = $('#p-lang');
        for (var x in languages) {
            if (!languages[x].found) continue;
            if (x === lang) continue;
            var a = [];
            for (var y in languages[x].titles)
                if (languages[x].titles[y]) a.push(y);
            var a = a.slice(0, maxtitles);
            for (var i = 0; i < a.length; i+=numtitles) {
                var titles = a.slice(i, (i+numtitles<a.length ? i+numtitles : a.length)).join('|');
                $.ajax({
                    url: api.replace(/%%/, x),
                    dataType: 'jsonp',
                    data: jQuery.extend({'titles': titles, requestid: x}, query),
                    cache: true,
                    context: document.body,
                    success: function(data, textStatus){

                        if (textStatus === null && textStatus != 'success') {
                            alert('Success, but with "' + textStatus + '"');
                            return;
                        }
                        
                        // this shouldn't happen
                        if (!languages[data.requestid] && !languages[data.requestid].found) return;

                        var a = [];
                        for (var x in data.query.pages) {
                            if (x<0) continue;
                            if (languages[data.requestid].titles[data.query.pages[x].title])
                                a.push('[title="' + data.requestid + ':' + data.query.pages[x].title + '"]');
                        }
                        iwcheck.filter(a.join(',')).addClass('exist');
                    }
                });
            }
        }
    });
})(mediaWiki, jQuery);

/**
 * Description: Modify parts of the toolbar to better suit this projects needs
 * Maintainer:
 */
(function(mw, $, undefined) {
    
    // function to build complete labels, just to get rid of some pesky errors
    var label = function (msg, txt, before, after) {
        var str = '';
        if (before === undefined ? true : before) str += "{" + "{";
        str += msg;
        if (after === undefined ? true : after) str += "}" + "}";
        if (txt) str += " – " + txt;
        return str;
    };
    
    // function to build pre-parts of the templates, just to get rid of some pesky errors
    var pre = function (msg, txt, before) {
        var str = '';
        if (before === undefined ? true : before) str += "{" + "{";
        str += msg;
        if (txt) str += txt;
        return str;
    };
    
    // function to build peri-parts of the templates, just to get rid of some pesky errors
    var peri = function (msg, txt, before, after) {
        var str = '';
        if (before === undefined ? true : before) str += "{" + "{";
        str += msg;
        if (txt) str += txt;
        if (after === undefined ? true : after) str += "}" + "}";
        return str;
    };
    
    // get timestamp for templates
    var now = new Date();
    var timestamp = now.getUTCFullYear()
        + '-' + (now.getUTCMonth()<9 ? '0' : '') + (now.getUTCMonth()+1)
        + '-' + (now.getUTCDate()<9 ? '0' : '') + now.getUTCDate();

    // customization for the original toolbar
    var customizeOrigToolbar = function () {
    	var buttons = [];
    	buttons.push({
    	    id: "button-nbsp",
            imageFile: "//upload.wikimedia.org/wikipedia/commons/4/4b/Button_nbsp.png",
            speedTip: "Non-breaking space",
            tagOpen: "&nbsp;",
            tagClose: "",
            sampleText: ""
        });
    	buttons.push({
    	    id: "button-redirect",
            imageFile: "//upload.wikimedia.org/wikipedia/en/c/c8/Button_redirect.png",
            speedTip: "Omdirigering",
            tagOpen: "#OMDIRIGERING [[",
            tagClose: "]]",
            sampleText: "Målside"
        });
    	buttons.push({
    	    id: "button-strike",
            imageFile: "//upload.wikimedia.org/wikipedia/en/c/c9/Button_strike.png",
            speedTip: "Overstreking",
            tagOpen: "<s>",
            tagClose: "</s>",
            sampleText: "Overstreket tekst"
        });
    	buttons.push({
    	    id: "button-enter",
            imageFile: "//upload.wikimedia.org/wikipedia/en/1/13/Button_enter.png",
            speedTip: "Linjeskift",
            tagOpen: "<br />",
            tagClose: "",
            sampleText: ""
        });
    	buttons.push({
    	    id: "button_upper",
            imageFile: "//upload.wikimedia.org/wikipedia/en/8/80/Button_upper_letter.png",
            speedTip: "Hevet skrift",
            tagOpen: "<sup>",
            tagClose: "</sup>",
            sampleText: "Hevet tekst"
        });
    	buttons.push({
    	    id: "button-lower",
            imageFile: "//upload.wikimedia.org/wikipedia/en/7/70/Button_lower_letter.png",
            speedTip: "Senket skrift",
            tagOpen: "<sub>",
            tagClose: "</sub>",
            sampleText: "Senket tekst"
        });
    	buttons.push({
    	    id: "button-small",
            imageFile: "//upload.wikimedia.org/wikipedia/en/5/58/Button_small.png",
            speedTip: "Liten skrift",
            tagOpen: "<small>",
            tagClose: "</small>",
            sampleText: "Liten skrift"
        });
    	buttons.push({
    	    id: "button-hide-comment",
            imageFile: "//upload.wikimedia.org/wikipedia/en/3/34/Button_hide_comment.png",
            speedTip: "Sett inn skjult tekst (vises kun i kildekoden)",
            tagOpen: "<!-- ",
            tagClose: " -->",
            sampleText: "Skjult tekst"
        });
    	buttons.push({
    	    id: "button-gallery",
            imageFile: "//upload.wikimedia.org/wikipedia/en/1/12/Button_gallery.png",
            speedTip: "Sett inn bildegalleri",
            tagOpen: "\n<gallery>\n",
            tagClose: "\n</gallery>",
            sampleText: "Image:Example.jpg|Bildetekst1\nImage:Example.jpg|Bildetekst2"
        });
    	buttons.push({
    	    id: "button-blockquote",
            imageFile: "//upload.wikimedia.org/wikipedia/en/f/fd/Button_blockquote.png",
            speedTip: "Siter tekst",
            tagOpen: "{{Sitat|",
            tagClose: "|kilde}}",
            sampleText: "Legg inn sitatet her"
        });
    	buttons.push({
    	    id: "button-insert-table",
            imageFile: "//upload.wikimedia.org/wikipedia/en/6/60/Button_insert_table.png",
            speedTip: "Sett inn tabell",
            tagOpen: '{| class="wikitable"\n|-\n',
            tagClose: "\n|}",
            sampleText: "! overskrift 1\n! overskrift 2\n! overskrift 3\n|-\n| rad 1, celle 1\n| rad 1, celle 2\n| rad 1, celle 3\n|-\n| rad 2, celle 1\n| rad 2, celle 2\n| rad 2, celle 3"
        });
    	buttons.push({
    	    id: "button-latinas",
            imageFile: "//upload.wikimedia.org/wikipedia/commons/2/26/Button_latinas.png",
            speedTip: "Sett inn «»",
            tagOpen: "«",
            tagClose: "»",
            sampleText: "utsagn"
        });
    	buttons.push({
    	    id: "button-ref",
            imageFile: "//upload.wikimedia.org/wikipedia/commons/2/2b/Button_ref_inscription.png",
            speedTip: "Sett inn <ref></ref>",
            tagOpen: "<ref>",
            tagClose: "</ref>",
            sampleText: "referanse"
        });
        for (var i = 0; i < buttons.length; i++) {
		mw.toolbar.addButton(
			buttons[i].imageFile,
			buttons[i].speedTip,
			buttons[i].tagOpen,
			buttons[i].tagClose,
			buttons[i].sampleText,
			buttons[i].id,
			buttons[i].id
		);
	}

    };
    
    // customization for the beta toolbar
    var customizeBetaToolbar = function () {
                
        // Add button for inserting guillemets (popular feature of old toolbar)
        $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
            'section': 'main',
            'group': 'format',
            'tools': {
                'quote': {
                    label: 'Anførselstegn',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/a/ac/Norwegian_quote_sign.png',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre: "«",
                            //peri: "«»",
                            post: "»"
                        }
                    }
                }
            }
        });

        // Add button for inserting double square brackets (popular feature of old toolbar)
        $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
            'section': 'main',
            'group': 'format',
            'tools': {
                'link': {
                    label: 'Lenkeparenteser',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/b/ba/Norwegian_link_sign.png',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre: "[[",
                            //peri: "[[]]",
                            post: "]]"
                        }
                    }
                }
            }
        });
        
        // Add button for inserting double curly brackets
        $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
            'section': 'main',
            'group': 'format',
            'tools': {
                'link': {
                    label: 'Malparenteser',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/4/4a/Norwegian_template_sign.png',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre: "{{",
                            //peri: "{{}}",
                            post: "}}"
                        }
                    }
                }
            }
        });


        // Add button for inserting strikethrough
        // https://no.wikipedia.org/wiki/MediaWiki-diskusjon:Common.js#Strikethrough
        $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
            'section': 'advanced',
            'group': 'format',
            'tools': {
                'strikethrough': {
                    label: 'Gjennomstrykning',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/f/f9/Toolbaricon_regular_S_stroke.png',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre: "<s>",
                            //peri: "<s>&nbsp;</s>",
                            post: "</s>"
                        }
                    }
                }
            }
        });


        // add an article mark menu in the advanced section
        $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
            'section': 'advanced',
            groups: {
                'heading': {
                    tools: {
                        'heading': {
                            label: 'حفظ او مراقبت',
                            type: 'select',
                            list: {
                                'template-neutral' : {
                                    label: label('پيچلې ليکنه', 'ليکنه سم او اسانه لارښوونه نه کوي'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('پيچلې ليکنه', '|ts=' + timestamp + '|'),
                                            post: '}}',
                                            ownline: false
                                        }
                                    }
                                },
                                'template-verifiable' : {
                                    label: label('تاییدونه غواړي', 'ليکنه نه ده تایید سوې'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('تاییدونه غواړي'),
                                            post: '}}',
                                            ownline: false
                                        }
                                    }
                                },
                                'template-research' : {
                                    label: label('Forskning', 'artikkelen inneholder originalforskning'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('Forskning', '|ts=' + timestamp + '|'),
                                            post: '}}',
                                            ownline: false
                                        }
                                    }
                                },
                                'template-accuracy' : {
                                    label: label('Nøyaktighet', 'artikkelen har ikke en nøyaktig fremstilling'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('Nøyaktighet', '|ts=' + timestamp + '|'),
                                            post: '}}',
                                            ownline: false
                                        }
                                    }
                                },
                                'template-spelling' : {
                                    label: label('Språkvask', 'artikkelens språk trenger en gjennomgang'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('Språkvask', '|ts=' + timestamp + '|'),
                                            post: '}}',
                                            ownline: false
                                        }
                                    }
                                },
                                'template-format' : {
                                    label: label('Formatering', 'artikkelen trenger wikifisering'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('Formatering', '|ts=' + timestamp + '|'),
                                            post: '}}',
                                            ownline: false
                                        }
                                    }
                                },
                                'template-workinprogress' : {
                                    label: label('Arbeid pågår', 'artikkelen er under arbeid'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('Arbeid pågår', '|ts=' + timestamp + '|'),
                                            post: '}}',
                                            ownline: false
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        });
// add an article mark menu in the advanced section
        $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
            'section': 'advanced',
            groups: {
                'heading': {
                    tools: {
                        'heading': {
                            label: 'د انځور او نورو سرچینې',
                            type: 'select',
                            list: {
                                'template-neutral' : {
                                    label: label('انځور اړوند', 'د انځور سرچینې او معلومات ورګډ کړئ'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('420', '|ts=' + timestamp + '|'),
                                            post: '}}',
                                            ownline: false
                                        }
                                    }
                                },
                                'template-verifiable' : {
                                    label: label('Verifiserbar', 'artikkelen er ikke verifiserbar'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('421', '|ts=' + timestamp + '|'),
                                            post: '}}',
                                            ownline: false
                                        }
                                    }
                                },
                                'template-research' : {
                                    label: label('Forskning', 'artikkelen inneholder originalforskning'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('422', '|ts=' + timestamp + '|'),
                                            post: '}}',
                                            ownline: false
                                        }
                                    }
                                },
                                'template-accuracy' : {
                                    label: label('Nøyaktighet', 'artikkelen har ikke en nøyaktig fremstilling'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('423', '|ts=' + timestamp + '|'),
                                            post: '}}',
                                            ownline: false
                                        }
                                    }
                                },
                                'template-spelling' : {
                                    label: label('Språkvask', 'artikkelens språk trenger en gjennomgang'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('424', '|ts=' + timestamp + '|'),
                                            post: '}}',
                                            ownline: false
                                        }
                                    }
                                },
                                'template-format' : {
                                    label: label('Formatering', 'artikkelen trenger wikifisering'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('425', '|ts=' + timestamp + '|'),
                                            post: '}}',
                                            ownline: false
                                        }
                                    }
                                },
                                'template-workinprogress' : {
                                    label: label('Arbeid pågår', 'artikkelen er under arbeid'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('426', '|ts=' + timestamp + '|'),
                                            post: '}}',
                                            ownline: false
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        });

        // add a template menu in the advanced sectionined' ) {
        $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
            'section': 'advanced',
            groups: {
                'heading': {
                    tools: {
                        'heading': {
                            label: 'کينډۍ',
                            type: 'select',
                            list: {
                                'template-columns' : {
                                    label: label('kolonner', 'etterfølgende liste fordeles over flere kolonner'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('kolonner', '|'),
                                            //peri: peri('columns'),
                                            post: '}}',
                                            ownline: true
                                        }
                                    }
                                },
                                'template-sorted-columns' : {
                                    label: label('sorterte kolonner', 'etterfølgende liste fordeles over flere sorterbare kolonner'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('sorterte kolonner', '|tittel='),
                                            //peri: peri('columns'),
                                            post: '}}',
                                            ownline: true
                                        }
                                    }
                                },
                                'template-nowrap' : {
                                    label: label('nowrap', 'hindre linjeskift i tekst og tall'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('nowrap', '|'),
                                            post: '}}',
                                            ownline: false
                                        }
                                    }
                                },
                                'template-formatnum' : {
                                    label: label('formatnum', 'tall med mellomrom og desimalkomma'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('formatnum', ':'),
                                            post: '}}',
                                            ownline: false
                                        }
                                    }
                                },
                                'template-defaultsort' : {
                                    label: label('STANDARDSORTERING', 'sortering på etternavn og lignende'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('STANDARDSORTERING', ':'),
                                            post: '}}',
                                            ownline: false
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        });
        
        // add a titles menu in the advanced section
        $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
            'section': 'advanced',
            groups: {
                'heading': {
                    tools: {
                        'heading': {
                            label: 'سرليکونه',
                            type: 'select',
                            list: {
                                'titles-see-also' : {
                                    label: '== دا هم وګورئ == – لاندې نوري پروژې او د اړونده ليکنو نومونه پرېږدی',
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: '== دا هم وګورئ  ==',
                                            ownline: true
                                        }
                                    }
                                },
                                'titles-notes' : {
                                    label: '== يادښتونه== – ورکول سوي يادښتونه په ليکنه کې',
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: "==ياداښتونه ==\n<references group='note'/>\n",
                                            ownline: true
                                        }
                                    }
                                },
                                'titles-references' : {
                                    label: '== ويکيډاټا سرچینې== – د ويکيډاټا څخه اخیستې سرچینې ',
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: "== ويکيډاټا سرچینې==\n* {{رسمي وېبپاڼه}}\n",
                                            ownline: true
                                        }
                                    }
                                },
                                'titles-literature' : {
                                    label: '== ادبيات== – ورکول سوې ادبيات',
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: '== ادبيات==',
                                            ownline: true
                                        }
                                    }
                                },
                                'titles-links' : {
                                    label: '== سرچینې== – د ټولو سرچینو شريکه سيمه',
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: "== سرچینې==",
                                            ownline: true
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        });
    };
    
    /* Check if we are in edit mode and the required modules are available and then customize the toolbar */
    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 () {
    				$(customizeBetaToolbar);
    			});
    		}
            else {
        			$(customizeOrigToolbar);
            }
    	});
    }
    
})(mediaWiki, jQuery);

// Code to set class reflecting number of children for each parent in references
// © John Erling Blad, Creative Commons by Attribution 3.0
(function(){
	"use strict";
	var $references = $( '#mw-content-text' ).find( '.references' );
	$references.each( function(){
		var $ol = $(this);
		$ol.addClass('has-' + $ol.children('li').length + '-children');
	});
}());

/**
 * Collation sequence for Pashto.
 * Note that æ, ø, and å are reordered.
 * For jquery.tablesorter.js
 */
 mw.config.set( 'tableSorterCollation', {
 	'Æ'  : 'Å',
 	'Ø'  : 'Æ',
 	'Å'  : 'Ø',
 	'Ä'  : 'Å',
 	'Ö'  : 'Æ',
 	'Ü'  : 'Y',
 	'Þ'  : 'Th',
 	'æ'  : 'å',
 	'ø'  : 'æ',
 	'å'  : 'ø',
 	'ä'  : 'å',
 	'ö'  : 'æ',
 	'ü'  : 'y',
 	'þ'  : 'th'
} );