MediaWiki:Gadget-Direct-link-to-Commons.js: diferència entre les revisions

Contingut suprimit Contingut afegit
 
Importació des de en.wiki, això ha de solucionar els problemes amb el giny.
 
Línia 1:
mw.loader.load('//en.wikipedia.org/w/index.php?title=MediaWiki:Gadget-imagelinks.js&action=raw&ctype=text/javascript');
/**
* Direct imagelinks to Commons
*
* @source mediawiki.org/wiki/Snippets/Direct_imagelinks_to_Commons
* @author [[commons:User:Krinkle]]
* @version 11
*/
if ( mw.config.get( 'wgNamespaceNumber', 0 ) >= 0 ) {
mw.hook( 'wikipage.content' ).add( function () {
var
uploadBaseRe = /^\/\/upload\.wikimedia\.org\/wikipedia\/commons/,
 
localBasePath = new RegExp( '^' + $.escapeRE( mw.util.getUrl( mw.config.get( 'wgFormattedNamespaces' )['6'] + ':' ) ) ),
localBaseScript = new RegExp( '^' + $.escapeRE( mw.util.wikiScript() + '?title=' + mw.util.wikiUrlencode( mw.config.get( 'wgFormattedNamespaces' )['6'] + ':' ) ) ),
 
commonsBasePath = '//commons.wikimedia.org/wiki/File:',
commonsBaseScript = '//commons.wikimedia.org/w/index.php?title=File:';
 
$( 'a.image' ).attr( 'href', function ( i, currVal ) {
if ( uploadBaseRe.test( $(this).find( 'img' ).attr( 'src' ) ) ) {
return currVal
.replace( localBasePath, commonsBasePath )
.replace( localBaseScript, commonsBaseScript );
}
} );
} );
}