ميدياويكي:Common.js

من أرابيكا، الموسوعة الحرة
اذهب إلى التنقل اذهب إلى البحث

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

/*إضافات عامة*/
mw.loader.using( [ 'mediawiki.util' ] ).done( function () {
	/**
	 * Collapsible tables; reimplemented with mw-collapsible
	 * Styling is also in place to avoid FOUC
	 *
	 * Allows tables to be collapsed, showing only the header. See [[Help:Collapsing]].
	 * @version 3.0.0 (2018-05-20)
	 * @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js
	 * @author [[User:R. Koot]]
	 * @author [[User:Krinkle]]
	 * @author [[User:TheDJ]]
	 * @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which
	 * is supported in MediaWiki core. Shimmable since MediaWiki 1.32
	 *
	 * @param {jQuery} $content
	 */
	function makeCollapsibleMwCollapsible( $content ) {
		var $tables = $content
			.find( 'table.collapsible:not(.mw-collapsible)' )
			.addClass( 'mw-collapsible' );

		$.each( $tables, function ( index, table ) {
			// mw.log.warn( 'This page is using the deprecated class collapsible. Please replace it with mw-collapsible.');
			if ( $( table ).hasClass( 'collapsed' ) ) {
				$( table ).addClass( 'mw-collapsed' );
				// mw.log.warn( 'This page is using the deprecated class collapsed. Please replace it with mw-collapsed.');
			}
		} );
		if ( $tables.length > 0 ) {
			mw.loader.using( 'jquery.makeCollapsible' ).then( function () {
				$tables.makeCollapsible();
			} );
		}
	}
	mw.hook( 'wikipage.content' ).add( makeCollapsibleMwCollapsible );

	/**
	 * Add support to mw-collapsible for autocollapse, innercollapse and outercollapse
	 *
	 * Maintainers: TheDJ
	 */
	function mwCollapsibleSetup( $collapsibleContent ) {
		var $element,
			$toggle,
			autoCollapseThreshold = 2;
		$.each( $collapsibleContent, function ( index, element ) {
			$element = $( element );
			if ( $element.hasClass( 'collapsible' ) ) {
				$element.find( 'tr:first > th:first' ).prepend( $element.find( 'tr:first > * > .mw-collapsible-toggle' ) );
			}
			if ( $collapsibleContent.length >= autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) {
				$element.data( 'mw-collapsible' ).collapse();
			} else if ( $element.hasClass( 'innercollapse' ) ) {
				if ( $element.parents( '.outercollapse' ).length > 0 ) {
					$element.data( 'mw-collapsible' ).collapse();
				}
			}
			// because of colored backgrounds, style the link in the text color
			// to ensure accessible contrast
			$toggle = $element.find( '.mw-collapsible-toggle' );
			if ( $toggle.length ) {
				// Make the toggle inherit text color
				if ( $toggle.parent()[ 0 ].style.color ) {
					$toggle.find( 'a' ).css( 'color', 'inherit' );
				}
			}
		} );
	}

	mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );

	/**
	 * WikiMiniAtlas
	 *
	 * Description: WikiMiniAtlas is a popup click and drag world map.
	 *              This script causes all of our coordinate links to display the WikiMiniAtlas popup button.
	 *              The script itself is located on the Meta-Wiki because it is used by many projects.
	 *              See [[Meta:WikiMiniAtlas]] for more information.
	 * Note - use of this service is recommended to be replaced with mw:Help:Extension:Kartographer
	 */
	$( function () {
		var requireWikiminiatlas = $( 'a.external.text[href*="geohack"]' ).length || $( 'div.kmldata' ).length;
		if ( requireWikiminiatlas ) {
			mw.loader.load( '//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript' );
		}
	} );

    /**
     * @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
     * @revision 2020-04-04
     */
	var extraCSS = mw.util.getParamValue( 'withCSS' ),
		extraJS = mw.util.getParamValue( 'withJS' );

	if ( extraCSS ) {
		// WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/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 ) {
		// WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against 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' } );
		}
	}
	/**
	 * Load CSS and JS files temporarily through URL.
	 * &use=File1.css|File2.css|File3.js
	 *
	 * Required modules: mediawiki.util
	 * @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL#Load_multiple_files
	 * @revision 2023-09-24
	 */
	(function () {
		var files = mw.util.getParamValue( 'use' ), user, FileRE, ExtRE, path;
	
		if ( !files ) {
			return;
		}
	
		user = mw.util.escapeRegExp( mw.config.get( 'wgUserName', '' ) );
		FileRE = new RegExp( '^(?:MediaWiki:' + ( user ? '|User:' + user + '/' : '' ) + ')[^&<>=%#]*\\.(js|css)$' );
		ExtRE = new RegExp( '^ext\\.[^,]+$' );
		path = mw.config.get('wgServer')
			+ mw.config.get('wgScript')
			+ '?action=raw&ctype=text/';
	
		$.each( files.split( '|' ), function(k, v) {
			var f = $.trim( v ), what = FileRE.exec( f ) || ['', ''];
			switch ( what[1] ) {
				case  'js':
					mw.loader.load( path + 'javascript&title=' + encodeURIComponent( f ) );
					break;
				case 'css':
					mw.loader.load( path + 'css&title=' + encodeURIComponent( f ) );
					break;
				default:
					if ( ExtRE.exec( f ) ) {
						mw.loader.load(f);
					}
			}
		});
	})();
    /* إخفاء ملخص التحرير عن غير المحررين في صفحات طلبات إدارية*/
    if ( $.inArray( mw.config.get( 'wgPageName' ), [ "أرابيكا:طلبات_صلاحيات/إعطاء",
        "أرابيكا:طلبات_صلاحيات/إزالة",
        "أرابيكا:إخطار_الإداريين/حماية/الحالية",
        "أرابيكا:إخطار_الإداريين/إزالة_حماية/الحالية",
        "أرابيكا:إخطار_الإداريين/منع/الحالية",
        "أرابيكا:إخطار_الإداريين/إزالة_منع/الحالية",
        "أرابيكا:إخطار_الإداريين/استرجاع/الحالية",
        "أرابيكا:طلبات_النقل/الحالية"
        ] ) !== -1 ) {
        if ($.inArray("editor", mw.config.get( 'wgUserGroups' )) == -1) {
            mw.util.addCSS(" .mw-summary { display:none !important;}");
        }
    }

    /* وصلة القائمة الكاملة تحت وصلات لغات الصفحة الرئيسية */
    if (mw.config.get('wgIsMainPage')) {
        mw.util.addPortletLink('p-lang', '//meta.wikimedia.org/w/index.php?title=List_of_Wikipedias/ar&uselang=ar', 'القائمة الكاملة', 'interwiki-completelist', 'قائمة الأرابيكات الكاملة');
        var nstab = document.getElementById('ca-nstab-main');
        if (nstab && mw.config.get('wgUserLanguage') === 'ar') {
            while (nstab.firstChild) {
                nstab = nstab.firstChild
            }
            nstab.nodeValue = 'الصفحة الرئيسية'
        }
    }

    /**
     * Redirect User:Name/skin.js and skin.css to the current skin's pages
     * (unless the 'skin' page really exists).
     *
     * Dependencies: mediawiki.util
     *
     * @source https://www.mediawiki.org/wiki/Snippets/Redirect_skin.js
     * @revision 2016-04-13
     */
    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 ) {
            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' );
            }
        }
    }

    /* Enable nulledit=true with <a class="autolink" href="/wiki/User:Splarka/nulledit.js">[[User:Splarka/nulledit.js]]</a> */
	if (mw.config.get("wgAction") === "edit" && mw.util.getParamValue("nulledit") === "true") {
		$(function() {
			document.getElementById("wpSave").click();
		});
	}

})

// سكربت تجريبي لإضافة التوقيع تلقائياً عند نسيانه 
//التأكد أن عدد تعديلات المستخدم أقل من 1000 تعديل|، وأنه يحرر في نطاق نقاش المستخدم
if ((mw.config.get( 'wgNamespaceNumber' ) % 2) == 1 && mw.config.get( 'wgUserEditCount' ) < 1000 && $('#wpTextbox1').length > 0) {
    var content = $('#wpTextbox1').val().trim(); // نص التعديل
    
    if ((content.endsWith("ع م)"))){
	    $('#wpSave').click(function() {
	        if ((!content.endsWith("\~\~\~") && (!content.endsWith("ع م)")))){
	            $('#wpTextbox1').val($('#wpTextbox1').val().trim() + "--\~\~\~\~"); //إضافة التوقيع
	        }
	   });
   }
   else if ($("h1#firstHeading").text().includes ("إنشاء ")){
   		$('#wpSave').click(function() {
	        if ((!content.endsWith("\~\~\~"))){
	            $('#wpTextbox1').val($('#wpTextbox1').val() + ".--\~\~\~\~"); //إضافة التوقيع
	        }
	   });
   }
}
 
/* تحميل سكربت الدردشة الحية */
if (mw.config.get('wgPageName') === 'أرابيكا:قناة_الدردشة/حي') {
	importScript('Mediawiki:IRC.js');
}

/* كود يعمل مع بوابة المشاركة 
	معطل لأن الصفحة المقصودة هي الآن تحويلة
*/
/*
if (mw.config.get('wgPageName') === 'أرابيكا:بوابة_المشاركة/قاعة_الشاي/أسئلة') {
	importScript('MediaWiki:Gadget-teahouse.js');
	importStylesheet('MediaWiki:Gadget-teahouse.css');
}
*/

/* <a class="autolink" href="/wiki/قالب:اسم مستخدم">[[قالب:اسم مستخدم]]</a> */
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);


//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");
}

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


if (Array.prototype.includes) {
    /*
    *سكربت تجريبي لتتبع المساهمات
    *المنسوخة من مواقع أخرى
    *ثم يقوم بوضع ملخص التعديل نسخ محتمل
    */
    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()+" نسخ محتمل"); 
                });
            }
        });
    }
}

// إظهار تبصرات تحرير أثناء تعديل: مقالات الأشخاص الأحياء، والمحتوى المتميز، وصفحات التوضيح
importScript('MediaWiki:Defaulteditnotices.js');


// Can be removed when https://global-search.toolforge.org/?q=mwCustomEditButtons&regex=1&namespaces=&title= returns no results for wiki
window.mwCustomEditButtons = [];

function updateUserScriptWarning( msg, newMsg ) {
	return function () {
		var userScript = '/wiki/Special:MyPage/' + mw.config.get('skin') + '.js';
		var commonScript = '/wiki/Special:MyPage/common.js';
		mw.notify(
			$('<div>').html(
				// please translate
				'One of the scripts you are running is broken and using a deprecated function <strong>' + msg + '</strong>. Please check your gadgets, <a href="' + userScript + '">skin scripts</a> and <a href="' + commonScript + '">user scripts</a>, to update the reference to' + newMsg + '.'
			),
			{ type: 'error' }
		); 
	};
}

// Can be removed when https://global-search.toolforge.org/?q=%5B%5E%5C.%5DaddPortletLink&regex=1&namespaces=&title= returns zero ar.wikipedia results.
window.addPortletLink = updateUserScriptWarning('addPortletLink', 'mw.util.addPortletLink');
// Can be removed when https://global-search.toolforge.org/?q=importScriptimportScriptURI&regex=1&namespaces=&title= returns zero ar.wikipedia results.

window.importScriptimportScriptURI = updateUserScriptWarning('importScriptimportScriptURI', 'importScriptURI' );