לדלג לתוכן

מדיה ויקי:Common.js: הבדלים בין גרסאות בדף

מתוך צפונות ויקי
העברת FixHistPage למדיה ויקי:Group-user.js. אין סיבה שהסקריפט הזה ייטען עבור משתמשים אנונימיים, משום שהכפתורים המתקדמים שהסקריפט מסתיר ממילא לא מוצגים עבורם.
אין תקציר עריכה
 
(2 גרסאות ביניים של אותו משתמש אינן מוצגות)
(אין הבדלים)

גרסה אחרונה מ־08:46, 24 בנובמבר 2020

// Global variable hints for JSHint
/* global $, mw, importScript */

/* ייבוא סקריפטים */

/* פונקציה לייבוא סקריפט מ[[ויקיפדיה:סקריפטים]] */
function importUserScript() {
	'use strict';

	var args = arguments;

	mw.loader.using( 'mediawiki.util', function () {
		for ( var arg = 0; arg < args.length; arg++ ) {
			try {
				importScript( 'MediaWiki:סקריפטים/' + args[arg] + '.js' );
			}
			catch( e ) {
			}
		}
	} );
}

/* פונקציה הטוענת פונקציות בעת עליית הדף */
function addLoadEvent() {
	// Deprecated
}

mw.loader.using( 'mediawiki.util', function () {
	'use strict';

	importScript( 'MediaWiki:Functions.js' ); // פונקציות המצויות בשימוש בסקריפטים שונים

	if ( $.inArray( mw.config.get( 'wgPageName' ), [
		'עמוד_ראשי',
		'שיחה:עמוד_ראשי'
	] ) + 1 ) {
		importScript( 'MediaWiki:Mainpage.js' ); // שיפורים שונים בעמוד הראשי

		if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) {
			importScript( 'MediaWiki:Portals.js' );  // פורטלים מתחלפים בעמוד הראשי
		}
	}
	
	if ( mw.config.get( 'wgNamespaceNumber' ) === 6 ) {
		mw.loader.load( 'ext.gadget.ime' );
	}

	

	// סקריפטים עבור אנונימיים ו/או חדשיםs
	if ( $.inArray( 'autoconfirmed', mw.config.get( 'wgUserGroups' ) ) === -1 ) {
		importScript( 'MediaWiki:Autopurge.js' ); // הוספת אפשרות לרענון אוטומטי על ידי אנונימיים, ללא מעבר בטופס
		importScript( 'MediaWiki:Navtip.js' ); // הוספת התיבה "רוצה טיפ?" בצד למשתמשים אנונימיים
	}

	// סקריפטים לדפי עריכה
	if ( ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) + 1 ) &&
		!$( '#wpTextbox1' ).prop( 'readonly' )
	) {
		importScript( 'MediaWiki:Templateslist.js' ); // הצגת רשימת תבניות
		importScript( 'MediaWiki:Nosaving.js' ); // חיוב תצוגה מקדימה למשתמשים אנונימיים
		importScript( 'MediaWiki:Edittools.js' ); // שיפור התווים המיוחדים שמתחת לדף העריכה
		importScript( 'MediaWiki:Ref2template.js' ); //ref סקריפט שמשנה את התנהגות כפתור "הערה": הוספת תבנית הערה. במקום להוסיף תג
	}

	// סקריפטים לעמודים ספציפיים
	if( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Upload' ) {
		importScript( 'MediaWiki:Licenses.js' ); // שיפורים ברשיונות ושינויים בדף ההעלאה
	}

	// הופעת [[תבנית:דיון חדש במזנון]] לפני יצירת פסקה חדשה במזנון
	if( mw.config.get( 'wgPageName' ) === 'ויקיפדיה:מזנון' ) {
		$( document ).ready( function() {
			var $addSectionLink = $( '#ca-addsection a' ),
				currentHref = $addSectionLink.attr( 'href' );

			$addSectionLink.attr( 'href', currentHref + '&editintro=תבנית:דיון_חדש_במזנון' );
		} );
	}

	// link to sub pages
	if ( mw.config.get( 'wgNamespaceNumber' ) > 0 &&
		mw.config.get('wgNamespaceNumber') != 6 &&
		mw.config.get('wgNamespaceNumber') != 14
	) {
		$ ( function() {
			var linkText = mw.config.get( 'wgUserLanguage' ) == 'he' ? 'דפי משנה' : 'Sub pages',
				linkTitle = mw.config.get( 'wgUserLanguage' ) == 'he' ? 'רשימת דפי המשנה של דף זה' : 'List of the sub pages of this page';
	
			$( '#t-recentchangeslinked' ).after( $( '<li>' ).append( $( '<a>', {
				text: linkText,
				href: mw.util.getUrl( 'Special:PrefixIndex/' + mw.config.get( 'wgPageName' ) ),
				title: linkTitle
			} ) ) );
		} );
	}

	/** 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 meta because it is used by many projects.
	 *               See [[Meta:WikiMiniAtlas]] for more information.
	 *  Maintainers: [[User:Dschwen]]
	 */
	( function () {
		if ( $( 'a.external.text[href*=geohack], div.kmldata' ).length ) {
			mw.loader.load( '//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript' );
		}
	} )();

	/*
	 * Description: Redirects from /User:UserName/skin.js or .css to the user's actual skin page. Used (also) in {{תב|דף אישי}}.
	 * Originally created by [[:en:User:Cacycle]]
	 */
	$( function () {
		if ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgUserName' ) ) {
            var pageName = mw.config.get( 'wgPageName' );
			var slash = pageName.indexOf( '/' );
			var norm = pageName.substr( 0, slash ) + mw.config.get( 'wgPageName' ).substr( slash ).toLowerCase();
			var test = 'משתמש:' + mw.config.get( 'wgUserName' ).replace( / /g, '_' ) + '/skin.';
			var ext = null;

			if ( norm === test + 'js' ) {
				ext = 'js';
			} else if (norm === test + 'css') {
				ext = 'css';
			}

			if ( ext !== null ) {
				window.location.href = window.location.href.replace(
					/\/skin.(css|js)/i,
					'/' + mw.config.get( 'skin' ) + '.' + ext
				);
			}
		}

		// create an event when util.addPortletLink() is called, so scripts that manipulate menus ca readjust.
		var oldFunc = mw.util.addPortletLink;
		if ( typeof oldFunc === 'function' ) {
			mw.util.addPortletLink = function () {
				var res = oldFunc.apply( this, arguments );
				$( document ).trigger( 'new-portlet-link' );

				return res;
			};
		}
	} );

	if ( $.inArray( mw.config.get( 'wgPageName' ), [
		'ויקיפדיה:בוקמרקלטים',
		'שיחת_ויקיפדיה:בוקמרקלטים'
	] ) + 1 ) {  
		importScript( 'MediaWiki:bookmarkletsInit.js' ); // דף הבוקמרקלטים
	}

	if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' ) {
		importScript( 'MediaWiki:SearchEngines.js' ); // בחירה במנועי חיפוש שונים
		importScript( 'Mediawiki:Gadget-advanceSearch.js' );
	}

	/*
	 * Adds an automatic '{{תב|מוגן}}' or '{{תב|מוגן חלקית}}' template when the page is protected.
	 * You can use the {{תב|ללא הודעת הגנה אוטומטית}} to prevent the protection notice from being inserted.
	 *
	 * written by [[User:ערן]], [[User:Yonidebest]]
	 *
	 */
	 $(function(){
	 	var restrictionEdit = mw.config.get('wgRestrictionCreate') || mw.config.get('wgRestrictionEdit');
		if( restrictionEdit &&
			restrictionEdit.length > 0 &&
			(
				restrictionEdit[0] === 'sysop' ||
				restrictionEdit[0] === 'autoconfirmed' ||
				restrictionEdit[0] === 'templateeditor' ||
				restrictionEdit[0] === 'editautopatrolprotected'
			) &&
			$( '#pl-noprotectionnotice, #pl-autoconfirmed, #pl-protected' ).length === 0 &&
			( $.inArray( mw.config.get( 'wgAction' ), [ 'view', 'submit' ] ) + 1 )
		) {
			var restrictionEditMapping = {
				'sysop': 'מוגן',
				'templateeditor': 'הגנת ממשק',
				'editautopatrolprotected': 'הגנה מוגברת',
				'autoconfirmed': 'מוגן חלקית'
			};
	
			$.get( mw.util.wikiScript( 'api' ), {
				action: 'parse',
				format: 'json',
				text: '{{' + restrictionEditMapping[restrictionEdit[0]] + '}}',
				prop: 'text|indicators',
				title: mw.config.get('wgPageName'),
				contentmodel: 'wikitext'
			}, function( data ) {
				$( function () {
					$( '.printfooter' ).before( $( '<div>', {
						'class': 'plprotected',
						'html': data.parse.text['*']
					} ) );
					
					var newList = [];
					$.each( data.parse.indicators, function ( name, indicator ) {
						newList.push(
							$( '<div>' )
							        .addClass( 'mw-indicator' )
							        .attr( 'id', mw.util.escapeIdForAttribute( 'mw-indicator-' + indicator.name ) )
							        .html( indicator['*'] )
							        .get( 0 ),
							// Add a whitespace between the <div>s because
							// they get displayed with display: inline-block
							document.createTextNode( '\n' )
						);
					} );
					$( '.mw-indicators' ).append( newList );
				} );
			} );
		}
	 });
} );

// search meta-commands: make the table display clickabe keywords.
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' ) {
	mw.hook( 'he.wikipedia.collapsetables.loaded' ).add( function () {
		'use strict';

		var $searchBox = $( '#searchText input' ),
			$metaStringsTable = $( '#mw-search-meta-strings' );
		
		$metaStringsTable.find( 'span.mw-search-meta-string' ).wrap( $( '<a>' )
			.click( function( e ) {
				var currentText, newText;

				e.preventDefault();

				currentText = $searchBox.val();
				newText = $( this ).text();

				$searchBox.val( currentText + newText );				
			} )
		);
		
		// Make the table appear only after the collapsible styles are loaded,
		// so that it won't delay showing the search results
		$metaStringsTable.css( 'display', 'table' );
	} );
}

// On demand loading of scripts and gadgets, initial version from ruwiki.
// Detects uses of template "טען סקריפט"
// and loads specifically-named scripts or gadgets.
// for a gadget, its name as defined in gadgets-definition must begin with "ondemand-"
if ( mw.config.get('wgCanonicalNamespace') !== 'Special' ) 
mw.hook( 'wikipage.content' ).add( function( content ) {
		var beenthere = {};
		$( '.executeJS', content ).each( function () {
			var gadget = $( this ).data( 'gadgetname' );
			if ( gadget && $.trim( gadget ) ) mw.loader.load( 'ext.gadget.ondemand-' + $.trim( gadget ) ); // np repetitions - resourceloader takes care
		} );
} );