לדלג לתוכן

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

מתוך צפונות ויקי
רווחים אחידים, חלק ב׳
רווחים אחידים, חלק אחרון כנראה
שורה 29: שורה 29:
mw.log.deprecate( window, 'getParamValue', mw.util.getParamValue, 'Use mediawiki.util instead.' );
mw.log.deprecate( window, 'getParamValue', mw.util.getParamValue, 'Use mediawiki.util instead.' );


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


שורה 121: שורה 121:
*  Maintainers: [[User:Dschwen]]
*  Maintainers: [[User:Dschwen]]
*/
*/
( function () {
( function () {
        if ( $( 'a.external.text[href*=geohack], div.kmldata' ).length ) {
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' );
mw.loader.load( '//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript' );
        }
}
} )();
} )();


/*
/*
שורה 131: שורה 131:
* Originally created by [[:en:User:Cacycle]]
* Originally created by [[:en:User:Cacycle]]
*/
*/
$(function () {
$( function () {
if ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgUserName' )) {
if ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgUserName' ) ) {
                        var pageName = mw.config.get( 'wgPageName' );
            var pageName = mw.config.get( 'wgPageName' );
var slash = pageName.indexOf('/');
var slash = pageName.indexOf( '/' );
var norm = pageName.substr(0, slash) + mw.config.get( 'wgPageName' ).substr(slash).toLowerCase();
var norm = pageName.substr( 0, slash ) + mw.config.get( 'wgPageName' ).substr( slash ).toLowerCase();
var test = 'משתמש:' + mw.config.get( 'wgUserName' ).replace(/ /g, '_') + '/skin.';
var test = 'משתמש:' + mw.config.get( 'wgUserName' ).replace( / /g, '_' ) + '/skin.';
var ext = null;
var ext = null;
if (norm === test + 'js') {
 
if ( norm === test + 'js' ) {
ext = 'js';
ext = 'js';
} else if (norm === test + 'css') {
} else if (norm === test + 'css') {
ext = 'css';
ext = 'css';
}
}
if (ext !== null) {
 
window.location.href = window.location.href.replace(/\/skin.(css|js)/i, '/' + mw.config.get( 'skin' ) + '.' + ext);
if ( ext !== null ) {
window.location.href = window.location.href.replace(
/\/skin.(css|js)/i,
'/' + mw.config.get( 'skin' ) + '.' + ext
);
}
}
}
}
שורה 150: שורה 155:
// create an event when "addportellink" is called, so scripts that manipulate menus ca readjust.
// create an event when "addportellink" is called, so scripts that manipulate menus ca readjust.
var oldFunc = mw.util.addPortletLink;
var oldFunc = mw.util.addPortletLink;
if (typeof oldFunc === 'function') {
if ( typeof oldFunc === 'function' ) {
mw.util.addPortletLink = function() {
mw.util.addPortletLink = function () {
var res = oldFunc.apply( this, arguments );
var res = oldFunc.apply( this, arguments );
$( document ).trigger( 'new-portlet-link' );
$( document ).trigger( 'new-portlet-link' );
return res;
return res;
};
};
}
}
});
} );


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


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


// Adding results from Wikidata to search, when a page doesn't exist:
// Adding results from Wikidata to search, when a page doesn't exist:


if (mw.config.get('wgCanonicalSpecialPageName') === 'Search' || (mw.config.get('wgArticleId') === 0 && mw.config.get('wgCanonicalSpecialPageName') === false)) {
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' ||
mw.loader.load("//en.wikipedia.org/w/index.php?title=MediaWiki:Wdsearch.js&action=raw&ctype=text/javascript");
( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgCanonicalSpecialPageName' ) === false )
) {
mw.loader.load( '//en.wikipedia.org/w/index.php?title=MediaWiki:Wdsearch.js&action=raw&ctype=text/javascript' );
}
}


שורה 190: שורה 200:
restrictionEdit[0] === 'autopatrol'
restrictionEdit[0] === 'autopatrol'
) &&
) &&
$('#pl-noprotectionnotice, #pl-autoconfirmed, #pl-protected').length === 0 &&
$( '#pl-noprotectionnotice, #pl-autoconfirmed, #pl-protected' ).length === 0 &&
($.inArray(mw.config.get('wgAction'), ['view','submit']) + 1)
( $.inArray( mw.config.get( 'wgAction' ), [ 'view', 'submit' ] ) + 1 )
) {
) {
var restrictionEditMapping = {
var restrictionEditMapping = {
שורה 199: שורה 209:
};
};


$.get( mw.util.wikiScript('api'), {
$.get( mw.util.wikiScript( 'api' ), {
action: 'parse',
action: 'parse',
format: 'json',
format: 'json',
שורה 205: שורה 215:
prop: 'text',
prop: 'text',
title: mw.config.get('wgPageName'),
title: mw.config.get('wgPageName'),
contentmodel:'wikitext'
contentmodel: 'wikitext'
}, function(data) {
}, function( data ) {
$(function() {
$( function () {
$('.printfooter').before($('<div>', {
$( '.printfooter' ).before( $( '<div>', {
'class': 'plprotected',
'class': 'plprotected',
'html': data.parse.text['*']
'html': data.parse.text['*']
}));
} ) );
});
} );
 
} );
});
}
}


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


// search meta-commands: make the table display clickabe keywords.
// search meta-commands: make the table display clickabe keywords.
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' )
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' ) {
$( function() {
$( function() {
$( 'span.mw-search-meta-string' )
$( 'span.mw-search-meta-string' ).wrap( $( '<a>' )
.wrap( $( '<a>' )
.click( function( e ) {
.click( function( e ) {
e.preventDefault();
e.preventDefault();
var  
var t = $( this ).text(),
t = $( this ).text(),
searchBox = $( 'input#searchText' ),  
searchBox = $( 'input#searchText' ),  
current = searchBox.val();
current = searchBox.val();
searchBox.val ( current + t );
searchBox.val ( current + t );
} )
} )
);
);
} );
} );
}


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


שורה 252: שורה 262:
.prepend(  
.prepend(  
$( '<input>', { 'type': 'button' } )
$( '<input>', { 'type': 'button' } )
.val( 'סימון' )
.val( 'סימון' )
.click( function( e ) {
.click( function( e ) {
e.stopPropagation();
e.stopPropagation();
var elem = $( this ).closest( '.paramvalidator-wrapper:visible' ).next();
var elem = $( this ).closest( '.paramvalidator-wrapper:visible' ).next();
elem.css( { border: 'solid red 3px' } );
elem.css( { border: 'solid red 3px' } );
} )
} )
)
)
.prepend( $( '<input>', { 'type': 'button' } ).val( 'סגירה' ) )
.prepend( $( '<input>', { 'type': 'button' } ).val( 'סגירה' ) )
שורה 264: שורה 274:
$this.slideUp( "slow", function() { $this.remove(); } );  
$this.slideUp( "slow", function() { $this.remove(); } );  
} );
} );
if ( $( '.paramvalidator-wrapper:visible',  content ).length > 1 )
if ( $( '.paramvalidator-wrapper:visible',  content ).length > 1 ) {
$( '.paramvalidator-wrapper:visible',  content )
$( '.paramvalidator-wrapper:visible',  content )
.prepend(  
.prepend(  
$( '<input>', { 'type': 'button' } )
$( '<input>', { 'type': 'button' } )
.val( 'סגירת הכול' )  
.val( 'סגירת הכול' )  
.click( function() { $( '.paramvalidator-wrapper' ).remove(); } )
.click( function() { $( '.paramvalidator-wrapper' ).remove(); } )
).prepend(  
)
$( '<input>', { 'type': 'button' } )
.prepend(  
.val( 'סימון הכול' )
$( '<input>', { 'type': 'button' } )
.click( function( e ) {
.val( 'סימון הכול' )
e.stopPropagation();
.click( function( e ) {
$( '.paramvalidator-wrapper:visible' ).next().css( { border: 'solid red 3px' } );
e.stopPropagation();
} )
$( '.paramvalidator-wrapper:visible' ).next().css( { border: 'solid red 3px' } );
);
} )
 
);
}
} );
} );

גרסה מ־11:08, 9 באוקטובר 2016

// 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.log.deprecate( window, 'getParamValue', mw.util.getParamValue, 'Use mediawiki.util instead.' );

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.
	}

	// סקריפטים עבור אנונימיים ו/או חדשים
	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:Edittoolbar.js' ); // תוספות לסרגל העריכה
		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 "addportellink" 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' );
	}

	// Adding results from Wikidata to search, when a page doesn't exist:

	if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' ||
		( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgCanonicalSpecialPageName' ) === false )
	) {
		mw.loader.load( '//en.wikipedia.org/w/index.php?title=MediaWiki:Wdsearch.js&action=raw&ctype=text/javascript' );
	}

	/*
	 * 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]]
	 *
	 */
	var restrictionEdit = mw.config.get('wgRestrictionCreate') || mw.config.get('wgRestrictionEdit');
	if( restrictionEdit &&
		restrictionEdit.length > 0 &&
		(
			restrictionEdit[0] === 'sysop' ||
			restrictionEdit[0] === 'autoconfirmed' ||
			restrictionEdit[0] === 'autopatrol'
		) &&
		$( '#pl-noprotectionnotice, #pl-autoconfirmed, #pl-protected' ).length === 0 &&
		( $.inArray( mw.config.get( 'wgAction' ), [ 'view', 'submit' ] ) + 1 )
	) {
		var restrictionEditMapping = {
			'sysop': 'מוגן',
			'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' ) {
	$( function() {
		$( 'span.mw-search-meta-string' ).wrap( $( '<a>' )
			.click( function( e ) {
				e.preventDefault();
				var t = $( this ).text(),
					searchBox = $( 'input#searchText' ), 
					current = searchBox.val();

				searchBox.val ( current + t );				
			} )
		);
	} );
}

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