MediaWiki:Gadget-direct-links-to-commons.js: Porovnání verzí
Vzhled
Smazaný obsah Přidaný obsah
Verze 12688320 uživatele Ori Livneh (diskuse) zrušena: IIANM I9e108a3 was not merged to 1.26wmf10 yet…?!? |
Verze 12689165 uživatele Mormegil (diskuse) zrušena: Sync with mw:Snippets/Direct imagelinks to Commons#Code |
||
Řádek 2: | Řádek 2: | ||
* Direct imagelinks to Commons |
* Direct imagelinks to Commons |
||
* |
* |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
*/ |
*/ |
||
if ( mw.config.get( 'wgNamespaceNumber', 0 ) >= 0 ) { |
if ( mw.config.get( 'wgNamespaceNumber', 0 ) >= 0 ) { |
||
Řádek 11: | Řádek 12: | ||
var |
var |
||
uploadBaseRe = /^\/\/upload\.wikimedia\.org\/wikipedia\/commons/, |
uploadBaseRe = /^\/\/upload\.wikimedia\.org\/wikipedia\/commons/, |
||
⚫ | |||
localBasePath = new RegExp( '^' + |
localBasePath = new RegExp( '^' + mw.RegExp.escape( mw.util.getUrl( mw.config.get( 'wgFormattedNamespaces' )['6'] + ':' ) ) ), |
||
localBaseScript = new RegExp( '^' + |
localBaseScript = new RegExp( '^' + mw.RegExp.escape( mw.util.wikiScript() + '?title=' + mw.util.wikiUrlencode( mw.config.get( 'wgFormattedNamespaces' )['6'] + ':' ) ) ), |
||
commonsBasePath = |
commonsBasePath = '//commons.wikimedia.org/wiki/File:', |
||
commonsBaseScript = |
commonsBaseScript = '//commons.wikimedia.org/w/index.php?title=File:'; |
||
$content.find( 'a.image' ).attr( 'href', function ( i, currVal ) { |
$content.find( 'a.image' ).attr( 'href', function ( i, currVal ) { |
||
if ( uploadBaseRe.test( $( this ).find( 'img' ).attr( 'src' ) ) ) { |
if ( uploadBaseRe.test( $( this ).find( 'img' ).attr( 'src' ) ) ) { |
Verze z 10. 7. 2015, 20:57
/**
* Direct imagelinks to Commons
*
* Required modules: mediawiki.RegExp, mediawiki.util
*
* @source https://www.mediawiki.org/wiki/Snippets/Direct_imagelinks_to_Commons
* @author Krinkle
* @version 2015-06-23
*/
if ( mw.config.get( 'wgNamespaceNumber', 0 ) >= 0 ) {
mw.hook( 'wikipage.content' ).add( function ( $content ) {
var
uploadBaseRe = /^\/\/upload\.wikimedia\.org\/wikipedia\/commons/,
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'] + ':' ) ) ),
commonsBasePath = '//commons.wikimedia.org/wiki/File:',
commonsBaseScript = '//commons.wikimedia.org/w/index.php?title=File:';
$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 );
}
} );
} );
}