„MediaWiki:Gadget-Direct-link-to-Commons.js“ – Versionsunterschied
Erscheinungsbild
Inhalt gelöscht Inhalt hinzugefügt
K wieder zurück auf Version vom 23. Juni 2015, 00:27 Uhr (Spezial:PermaLink/143450268#mw.RegExp.escape) |
K fix comment |
||
Zeile 5: | Zeile 5: | ||
* @author [[commons:User:Krinkle]] |
* @author [[commons:User:Krinkle]] |
||
* @version 12, with local modifications |
* @version 12, with local modifications |
||
* required modules: jquery, |
* required modules: jquery, mw.RegExp, mediawiki, mediawiki.util |
||
*/ |
*/ |
||
if ( mw.config.get( 'wgNamespaceNumber', 0 ) >= 0 && !mw.user.options.get( 'multimediaviewer-enable' )) { |
if ( mw.config.get( 'wgNamespaceNumber', 0 ) >= 0 && !mw.user.options.get( 'multimediaviewer-enable' )) { |
Version vom 25. Juni 2015, 17:21 Uhr
/**
* 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: jquery, mw.RegExp, mediawiki, 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( '/media/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' );
}
});
});
}