Preskočiť na obsah

MediaWiki:Gadget-Direct-link-to-Commons.js: Rozdiel medzi revíziami

z Wikipédie, slobodnej encyklopédie
Smazaný obsah Přidaný obsah
He7d3r (diskusia | príspevky)
Migration: wikiGetlink → getUrl
 
Riadok 17: Riadok 17:
commonsBaseScript = '//commons.wikimedia.org/w/index.php?title=File:';
commonsBaseScript = '//commons.wikimedia.org/w/index.php?title=File:';
$( 'a.image' ).attr( 'href', function ( i, currVal ) {
$( 'a.image, a.mw-file-description' ).attr( 'href', function ( i, currVal ) {
if ( uploadBaseRe.test( $(this).find( 'img' ).attr( 'src' ) ) ) {
if ( uploadBaseRe.test( $(this).find( 'img' ).attr( 'src' ) ) ) {
return currVal
return currVal

Aktuálna revízia z 21:31, 7. marec 2023

/**
 * Direct imagelinks to Commons
 *
 * @source mediawiki.org/wiki/Snippets/Direct_imagelinks_to_Commons
 * @author [[commons:User:Krinkle]]
 * @version 8
 */
if ( mw.config.get( 'wgNamespaceNumber', 0 ) >= 0 ) {
        $( function () {
                var
                        uploadBaseRe = new RegExp( '^//upload\.wikimedia\.org/wikipedia/commons/' ),
 
                        localBasePath = mw.util.getUrl( mw.config.get( 'wgFormattedNamespaces' )['6'] + ':' ),
                        localBaseScript = 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, a.mw-file-description' ).attr( 'href', function ( i, currVal ) {
                        if ( uploadBaseRe.test( $(this).find( 'img' ).attr( 'src' ) ) ) {
                                return currVal
                                        .replace( localBasePath, commonsBasePath )
                                        .replace( localBaseScript, commonsBaseScript );
                        }
                });
        });
}