Hauptmenü öffnen

Änderungen

MediaWiki:Gadget-Direct-link-to-Commons.js

1.922 Bytes hinzugefügt, 18:05, 25. Jun. 2015
K
fix comment
/**
* Direct imagelinks to Commons
*
* @source https://www.mediawiki.org/wiki/Snippets/Direct_imagelinks_to_Commons
* @author [[commons:User:Krinkle]]
* @version 12, with local modifications
* required modules: mediawiki.RegExp, mediawiki.util
*/
if ( mw.config.get( 'wgNamespaceNumber', 0 ) >= 0 && !mw.user.options.get( 'multimediaviewer-enable' )) {
mw.hook( 'wikipage.content' ).add( function ( $content ) {
var
commonsBasePath = '//commons.wikimedia.org/wiki/File:',
commonsBaseScript = '//commons.wikimedia.org/w/index.php?title=File:',
localBasePath = new RegExp( '^' + mw.RegExp.escape( mw.util.getUrl( mw.config.get( 'wgFormattedNamespaces' )['6'] + ':' ) ) ),
localBaseScript = new RegExp( '^' + mw.RegExp.escape( mw.util.wikiScript() + '?title=' +
mw.util.wikiUrlencode( mw.config.get( 'wgFormattedNamespaces' )['6'] + ':' ) ) ),
uploadBaseRe = new RegExp( '^' + mw.RegExp.escape( '//upload.wikimedia.org/wikipedia/commons/' ) );

$content.find( 'a.image' ).attr( 'href', function ( i, currVal ) {
if ( uploadBaseRe.test( $( this ).find( 'img' ).attr( 'src' ) ) ) {
return currVal
.replace( localBasePath, commonsBasePath )
.replace( localBaseScript, commonsBaseScript )
// prevent false positive XSS detection in NoScript
// https://de.wikipedia.org/?oldid=121733234#Verdacht_auf_XSS_bei_Klammern_im_Dateinamen
.replace( /\(/g, '%28' )
.replace( /\)/g, '%29' );
}
});
});
}