לדלג לתוכן

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

מתוך צפונות ויקי
ביטול גרסה של ערן. הפונקציה הזו מופיעה בעשרות דפי js של משתמשים, ומחיקתה תגרום לחריגה והפסקת טעינת הדף. לפני מחיקתה יש להסירה מדפים אלו.
אין תקציר עריכה
 
(38 גרסאות ביניים של 7 משתמשים אינן מוצגות)
שורה 41: שורה 41:
}
}
}
}
 
// סקריפטים כלליים
if ( mw.config.get( 'wgNamespaceNumber' ) === 6 ) {
importScript( 'MediaWiki:Collapsetables.js' ); // טבלאות מוסתרות
mw.loader.load( 'ext.gadget.ime' );
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
// סקריפטים עבור אנונימיים ו/או חדשיםs
שורה 188: שורה 175:
restrictionEdit[0] === 'autoconfirmed' ||
restrictionEdit[0] === 'autoconfirmed' ||
restrictionEdit[0] === 'templateeditor' ||
restrictionEdit[0] === 'templateeditor' ||
restrictionEdit[0] === 'autopatrol'
restrictionEdit[0] === 'editautopatrolprotected'
) &&
) &&
$( '#pl-noprotectionnotice, #pl-autoconfirmed, #pl-protected' ).length === 0 &&
$( '#pl-noprotectionnotice, #pl-autoconfirmed, #pl-protected' ).length === 0 &&
שורה 196: שורה 183:
'sysop': 'מוגן',
'sysop': 'מוגן',
'templateeditor': 'הגנת ממשק',
'templateeditor': 'הגנת ממשק',
'autopatrol': 'הגנה מוגברת',
'editautopatrolprotected': 'הגנה מוגברת',
'autoconfirmed': 'מוגן חלקית'
'autoconfirmed': 'מוגן חלקית'
};
};
שורה 204: שורה 191:
format: 'json',
format: 'json',
text: '{{' + restrictionEditMapping[restrictionEdit[0]] + '}}',
text: '{{' + restrictionEditMapping[restrictionEdit[0]] + '}}',
prop: 'text',
prop: 'text|indicators',
title: mw.config.get('wgPageName'),
title: mw.config.get('wgPageName'),
contentmodel: 'wikitext'
contentmodel: 'wikitext'
שורה 213: שורה 200:
'html': data.parse.text['*']
'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 );
} );
} );
} );
} );
}
}
});
});
/* 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' ) );
});
}
} );
} );


שורה 253: שורה 248:
}
}


// check to see if page contains pgnwrapper, and if so, load pgnviewer
// On demand loading of scripts and gadgets, initial version from ruwiki.
mw.hook( 'wikipage.content' ).add( function( content ) {
// Detects uses of template "טען סקריפט"
if ( $( '.pgn-source-wrapper', content ).length ) {
// and loads specifically-named scripts or gadgets.
mw.loader.load( 'ext.gadget.pgnViewer' );
// for a gadget, its name as defined in gadgets-definition must begin with "ondemand-"
}
if ( mw.config.get('wgCanonicalNamespace') !== 'Special' )
} );
 
// if paramvalidator wrappers are visible, add a 'close' button, make them close on click, and tile them.
mw.hook( 'wikipage.content' ).add( function( content ) {
mw.hook( 'wikipage.content' ).add( function( content ) {
$( '.paramvalidator-wrapper:visible', content )
var beenthere = {};
.prepend(
$( '.executeJS', content ).each( function () {
$( '<input>', { 'type': 'button' } )
var gadget = $( this ).data( 'gadgetname' );
.val( 'סימון' )
if ( gadget && $.trim( gadget ) ) mw.loader.load( 'ext.gadget.ondemand-' + $.trim( gadget ) ); // np repetitions - resourceloader takes care
.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' } );
} )
);
}
} );
} );

גרסה אחרונה מ־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
		} );
} );