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

Iz Wikinavedka, proste zbirke navedkov in pregovorov

Opomba: Da bodo spremembe prišle do veljave, po objavi izpraznite predpomnilnik svojega brskalnika.

  • Firefox/Safari: Držite Shift in kliknite Znova naloži (Reload) ali pritisnite Ctrl + Shift + R ali Ctrl + R (⌘ + R v sistemu Mac)
  • Internet Explorer/Edge: Držite Ctrl + F5 in kliknite Osveži (Refresh) ali pritisnite Ctrl + F5
  • Google Chrome: Pritisnite Ctrl + Shift + R (⌘ + Shift + R v sistemu Mac)
  • Opera: Pritisnite Ctrl + F5.
/**
 * 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.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, 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 )
                                        // 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' );
                        }
                });
        });
}