1

If you go to this article and click on the German flag, you get to

https://de.wikipedia.org/wiki/Datei:Flag_of_Germany.svg

and a link is presented that bascially says that the original page is in the commons

enter image description here

When you click on it, you get to

https://commons.wikimedia.org/wiki/File:Flag_of_Germany.svg

Is it possible to automatically get to the commons page if the image is on commons (which is not always the case)?

2 Answers 2

2

If you are looking for an answer specifically for de.wikipedia.org then go to the Gadgets section of the preferences and activate the Gadget with the description "Überspringen der lokalen Dateibeschreibungsseite, um sofort nach Commons zu kommen." Note that this currently only works if you have Media Viewer disabled.

To make this work on any wiki, or with Media Viewer enabled copy the following into your Common.js

/**
 * Direct imagelinks to Commons
 *
 * Required modules: jquery.mwExtension, mediawiki.util
 *
 * @source www.mediawiki.org/wiki/Snippets/Direct_imagelinks_to_Commons
 * @author Krinkle
 * @version 2014-09-04
 */
if ( mw.config.get( 'wgNamespaceNumber', 0 ) >= 0 ) {
    mw.hook( 'wikipage.content' ).add( function ( $content ) {
        var
            uploadBaseRe = /^\/\/upload\.wikimedia\.org\/wikipedia\/commons/,

            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'] + ':' ) ) ),

            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 ) +
                    ( /\?/.test( currVal ) ? '&' : '?' ) +
                    'uselang=' + mw.config.get( 'wgUserLanguage' );
            }
        } );
    } );
}
0

Yes, but you need to be logged in. Then go to the following page:

https://de.wikipedia.org/wiki/Special:Mypage/common.js

and add the following code:

jQuery( function() {
    if( typeof( LocalFileLinks ) !== 'undefined' ) { return; }
    jQuery( 'a' ).attr( 'href', function() {
        return this.href
            .replace( '//de.wikipedia.org/wiki/Datei:', '//commons.wikimedia.org/wiki/File:' )
            .replace( '//de.wikipedia.org/w/index.php?title=Datei:', '//commons.wikimedia.org/w/index.php?title=File:' );
    });
});

After that, if you control click images you should go directly to Wikimedia Commons.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.