MediaWiki:Common.js: Difference between revisions
Till Kraemer (talk | contribs) No edit summary |
Till Kraemer (talk | contribs) Test. |
||
Line 1: | Line 1: | ||
/* | /** | ||
* Keep code in MediaWiki:Common.js to a minimum as it is unconditionally | |||
* loaded for all users on every wiki page. If possible create a gadget that is | |||
* enabled by default instead of adding it here (since gadgets are fully | |||
* optimized ResourceLoader modules with possibility to add dependencies etc.) | |||
* | |||
* Since Common.js isn't a gadget, there is no place to declare its | |||
* dependencies, so we have to lazy load them with mw.loader.using on demand and | |||
* then execute the rest in the callback. In most cases these dependencies will | |||
* be loaded (or loading) already and the callback will not be delayed. In case a | |||
* dependency hasn't arrived yet it'll make sure those are loaded before this. | |||
*/ | |||
/* global mw, $ */ | |||
/* jshint strict:false, browser:true */ | |||
mw.loader.using( ['mediawiki.user', 'mediawiki.util', 'mediawiki.notify', 'jquery.client'] ).done( function () { | |||
/* Begin of mw.loader.using callback */ | |||
if ( | /** | ||
* Main Page layout fixes | |||
* | |||
* Description: Adds an additional link to the complete list of languages available. | |||
}) | * Maintainers: [[User:AzaToth]], [[User:R. Koot]], [[User:Alex Smotrov]] | ||
*/ | |||
if ( mw.config.get( 'wgPageName' ) === 'Main_Page' || mw.config.get( 'wgPageName' ) === 'Talk:Main_Page' ) { | |||
$( function () { | |||
mw.util.addPortletLink( 'p-lang', '//meta.wikimedia.org/wiki/List_of_Wikipedias', | |||
'Complete list', 'interwiki-completelist', 'Complete list of Wikipedias' ); | |||
} ); | |||
} | } | ||
/* | /** | ||
/* | * Redirect User:Name/skin.js and skin.css to the current skin's pages | ||
* (unless the 'skin' page really exists) | |||
* @source: http://www.mediawiki.org/wiki/Snippets/Redirect_skin.js | |||
* @rev: 2 | |||
*/ | |||
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.shift() + '/' + mw.config.get( 'skin' ); | |||
if ( titleParts.slice( -1 ) == 'skin.js' ) { | |||
window.location.href = mw.util.getUrl( userSkinPage + '.js' ); | |||
} else if ( titleParts.slice( -1 ) == 'skin.css' ) { | |||
window.location.href = mw.util.getUrl( userSkinPage + '.css' ); | |||
} | |||
} | |||
} | } | ||
/* | /** | ||
* Map addPortletLink to mw.util | |||
* @deprecated: Use mw.util.addPortletLink instead. | |||
*/ | |||
mw.log.deprecate( window, 'addPortletLink', mw.util.addPortletLink, 'Use mw.util.addPortletLink instead' ); | |||
/ | /** | ||
* | * Extract a URL parameter from the current URL | ||
* @deprecated: Use mw.util.getParamValue with proper escaping | |||
* | |||
*/ | */ | ||
mw.log.deprecate( window, 'getURLParamValue', mw.util.getParamValue, 'Use mw.util.getParamValue instead' ); | |||
/* | /** | ||
* Test if an element has a certain class | |||
* @deprecated: Use $(element).hasClass() instead. | |||
*/ | |||
mw.log.deprecate( window, 'hasClass', function ( element, className ) { | |||
return $( element ).hasClass( className ); | |||
}, 'Use jQuery.hasClass() instead' ); | |||
// | /** | ||
// | * @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL | ||
/ | * @rev 6 | ||
*/ | |||
var extraCSS = mw.util.getParamValue( 'withCSS' ), | |||
extraJS = mw.util.getParamValue( 'withJS' ); | |||
// | if ( extraCSS ) { | ||
if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) { | |||
mw.loader.load( '/w/index.php?title=' + 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 ) { | ||
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) { | |||
mw.loader.load( '/w/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript' ); | |||
} else { | |||
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } ); | |||
} | |||
} | |||
/* | /** | ||
* 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 () { | |||
var require_wikiminiatlas = false; | |||
var coord_filter = /geohack/; | |||
$( function () { | |||
$( 'a.external.text' ).each( function( key, link ) { | |||
if ( link.href && coord_filter.exec( link.href ) ) { | |||
require_wikiminiatlas = true; | |||
// break from loop | |||
return false; | |||
} | |||
} ); | |||
if ( $( 'div.kmldata' ).length ) { | |||
require_wikiminiatlas = true; | |||
} | |||
if ( require_wikiminiatlas ) { | |||
mw.loader.load( '//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript' ); | |||
} | |||
} ); | |||
} )(); | |||
/** | /** | ||
Line 291: | Line 359: | ||
mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton ); | mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton ); | ||
/** | |||
* Uploadwizard_newusers | |||
* Switches in a message for non-autoconfirmed users at [[Wikipedia:Upload]] | |||
* | |||
* Maintainers: [[User:Krimpet]] | |||
*/ | |||
function uploadwizard_newusers() { | |||
if ( mw.config.get( 'wgNamespaceNumber' ) === 4 && mw.config.get( 'wgTitle' ) === 'Upload' && mw.config.get( 'wgAction' ) === 'view' ) { | |||
var oldDiv = document.getElementById( 'autoconfirmedusers' ), | |||
newDiv = document.getElementById( 'newusers' ); | |||
if ( oldDiv && newDiv ) { | |||
var userGroups = mw.config.get( 'wgUserGroups' ); | |||
if ( userGroups ) { | |||
for ( var i = 0; i < userGroups.length; i++ ) { | |||
if ( userGroups[i] === 'autoconfirmed' ) { | |||
oldDiv.style.display = 'block'; | |||
newDiv.style.display = 'none'; | |||
return; | |||
} | |||
} | |||
} | |||
oldDiv.style.display = 'none'; | |||
newDiv.style.display = 'block'; | |||
return; | |||
} | |||
} | |||
} | |||
$(uploadwizard_newusers); | |||
/** | |||
* Magic editintros **************************************************** | |||
* | |||
* Description: Adds editintros on disambiguation pages and BLP pages. | |||
* Maintainers: [[User:RockMFR]] | |||
*/ | |||
function addEditIntro( name ) { | |||
$( '.mw-editsection, #ca-edit' ).find( 'a' ).each( function ( i, el ) { | |||
el.href = $( this ).attr( 'href' ) + '&editintro=' + name; | |||
} ); | |||
} | |||
if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) { | |||
$( function () { | |||
if ( document.getElementById( 'disambigbox' ) ) { | |||
addEditIntro( 'Template:Disambig_editintro' ); | |||
} | |||
} ); | |||
$( function () { | |||
var cats = mw.config.get('wgCategories'); | |||
if ( !cats ) { | |||
return; | |||
} | |||
if ( $.inArray( 'Living people', cats ) !== -1 || $.inArray( 'Possibly living people', cats ) !== -1 ) { | |||
addEditIntro( 'Template:BLP_editintro' ); | |||
} | |||
} ); | |||
} | |||
/* End of mw.loader.using callback */ | |||
} ); | |||
/* DO NOT ADD CODE BELOW THIS LINE */ |