„MediaWiki:Gadget-Direct-link-to-Commons.js“ – Versionsunterschied
Erscheinungsbild
Inhalt gelöscht Inhalt hinzugefügt
ATDT (Diskussion | Beiträge) K Replacing usage of $.escapeRE with mw.RegExp.escape |
MBq (Diskussion | Beiträge) Änderung 143336520 von Ori Livneh rückgängig gemacht; WP:AAF |
||
Zeile 12: | Zeile 12: | ||
commonsBasePath = '//commons.wikimedia.org/wiki/File:', |
commonsBasePath = '//commons.wikimedia.org/wiki/File:', |
||
commonsBaseScript = '//commons.wikimedia.org/w/index.php?title=File:', |
commonsBaseScript = '//commons.wikimedia.org/w/index.php?title=File:', |
||
localBasePath = new RegExp( '^' + |
localBasePath = new RegExp( '^' + $.escapeRE( mw.util.getUrl( mw.config.get( 'wgFormattedNamespaces' )['6'] + ':' ) ) ), |
||
localBaseScript = new RegExp( '^' + |
localBaseScript = new RegExp( '^' + $.escapeRE( mw.util.wikiScript() + '?title=' + |
||
mw.util.wikiUrlencode( mw.config.get( 'wgFormattedNamespaces' )['6'] + ':' ) ) ), |
mw.util.wikiUrlencode( mw.config.get( 'wgFormattedNamespaces' )['6'] + ':' ) ) ), |
||
uploadBaseRe = new RegExp( '^' + |
uploadBaseRe = new RegExp( '^' + $.escapeRE( '/media/wikipedia/commons/' ) ); |
||
$content.find( 'a.image' ).attr( 'href', function ( i, currVal ) { |
$content.find( 'a.image' ).attr( 'href', function ( i, currVal ) { |
Version vom 23. Juni 2015, 07:29 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, jquery.mwExtension, 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( '^' + $.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'] + ':' ) ) ),
uploadBaseRe = new RegExp( '^' + $.escapeRE( '/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' );
}
});
});
}