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

מתוך ויקיפדיה, האנציקלופדיה החופשית
תוכן שנמחק תוכן שנוסף
מאין תקציר עריכה
מ ישן נורא...
שורה 25: שורה 25:
// Deprecated
// Deprecated
}
}

/* פונקציה לקבלת ערך של פרמטר משורת הכתובת */
mw.log.deprecate( window, 'getParamValue', mw.util.getParamValue, 'Use mediawiki.util instead.' );


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

גרסה מ־21:06, 29 באפריל 2017

// 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' );  // פורטלים מתחלפים בעמוד הראשי
		}
	}

	// סקריפטים כלליים
	importScript( 'MediaWiki:Collapsetables.js' ); // טבלאות מוסתרות
	importScript( 'MediaWiki:Tabs.js' ); // תמיכה בלשוניות
	importScript( 'MediaWiki:ImgToggle.js' ); // החלפת תמונות, עבור [[תבנית:מפת מיקום]]
	importScript( 'MediaWiki:LoadingContent.js' ); // הצגת טקסטים הנטענים באופן דינמי
	importScript( 'Mediawiki:Imagemap-Highlight.js' ); // עבור [[תבנית:מפת תמונה]] עם סימון=כן

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

	if ( mw.config.get( 'wgNamespaceNumber' ) === 6 ) {
		try {
			mw.loader.load( '//tools.wmflabs.org/imagemapedit/ime.js' );
		}
		catch( e ) {
		} // surround with try/catch in case other server behaves badly.
	}

	// סקריפטים עבור אנונימיים ו/או חדשים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] === 'autopatrol'
			) &&
			$( '#pl-noprotectionnotice, #pl-autoconfirmed, #pl-protected' ).length === 0 &&
			( $.inArray( mw.config.get( 'wgAction' ), [ 'view', 'submit' ] ) + 1 )
		) {
			var restrictionEditMapping = {
				'sysop': 'מוגן',
				'templateeditor': 'הגנת ממשק',
				'autopatrol': 'הגנה מוגברת',
				'autoconfirmed': 'מוגן חלקית'
			};
	
			$.get( mw.util.wikiScript( 'api' ), {
				action: 'parse',
				format: 'json',
				text: '{{' + restrictionEditMapping[restrictionEdit[0]] + '}}',
				prop: 'text',
				title: mw.config.get('wgPageName'),
				contentmodel: 'wikitext'
			}, function( data ) {
				$( function () {
					$( '.printfooter' ).before( $( '<div>', {
						'class': 'plprotected',
						'html': data.parse.text['*']
					} ) );
				} );
			} );
		}
	 });

	/* Use http redirect for Haaretz links until there's a less ad-hoc solution */
	if ( location.protocol === 'https:' ) {
		$( 'a.external[href^="http://www.haaretz.co.il"]' ).each( function() {
			$( this ).attr( 'href', 'http://tools.wmflabs.org/hewiki-tools/redirect.php?q=' + $( this ).attr( 'href' ) );
		});
	}
} );

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

// check to see if page contains pgnwrapper, and if so, load pgnviewer
mw.hook( 'wikipage.content' ).add( function( content ) {
	if ( $( '.pgn-source-wrapper', content ).length ) {
		mw.loader.load( 'ext.gadget.pgnViewer' );
	}
} );

// if paramvalidator wrappers are visible, add a 'close' button, make them close on click, and tile them.
mw.hook( 'wikipage.content' ).add( function( content ) {
	$( '.paramvalidator-wrapper:visible',  content )
		.prepend( 
			$( '<input>', { 'type': 'button' } )
				.val( 'סימון' )
				.click( function( e ) {
					e.stopPropagation();
					var elem = $( this ).closest( '.paramvalidator-wrapper:visible' ).next();
					elem.css( { border: 'solid red 3px' } );
				} )
		)
		.prepend( $( '<input>', { 'type': 'button' } ).val( 'סגירה' ) )
		.click( function() { 
			var $this = $( this ); 
			$this.slideUp( 'slow', function() { $this.remove(); } ); 
		} );
		
	if ( $( '.paramvalidator-wrapper:visible',  content ).length > 1 ) {
		$( '.paramvalidator-wrapper:visible',  content )
			.prepend( 
				$( '<input>', { 'type': 'button' } )
				.val( 'סגירת הכול' ) 
				.click( function() { $( '.paramvalidator-wrapper' ).remove(); } )
			)
			.prepend( 
				$( '<input>', { 'type': 'button' } )
				.val( 'סימון הכול' )
				.click( function( e ) {
					e.stopPropagation();
					$( '.paramvalidator-wrapper:visible' ).next().css( { border: 'solid red 3px' } );
				} )
			);
	}
} );