Snippets/Point links on file description to Wikimedia Commons
Appearance
< Snippets
Point links on file description to Wikimedia Commons | |
---|---|
Language(s): | JavaScript |
Compatible with: | MediaWiki 1.23+ |
Description
[edit]Redefine view/talk/edit links on file description pages to point directly to Wikimedia Commons, avoiding the creation of description pages for images from Wikimedia Commons.
Code
[edit]/**
* Redefine view/talk/edit links on file description pages
* This avoids the creation of description pages for imagens from Wikimedia Commons
*
* @source: https://www.mediawiki.org/wiki/Snippets/Point_links_on_file_description_to_Wikimedia_Commons
* @author: [[w:sv:User:Daedalus]]
* @author: [[User:Helder.wiki]]
* @rev: 2
*/
if ( 6 === mw.config.get( 'wgNamespaceNumber' ) ) {
$( function () {
var title = mw.config.get( 'wgTitle' ),
filelink = mw.util.getUrl( 'commons:File' + title ),
filetalklink = mw.util.getUrl( 'commons:File_talk' + title );
// If the page has history, do nothing
if ( $( '#ca-history' )[0] ) {
return;
}
// Link to view description page on Commons
$( '#ca-nstab-image > a' )
.addClass( 'extiw' )
.attr( 'href', filelink );
// Link to edit description page on Commons
$( '#ca-edit > a' )
.addClass( 'extiw' )
.attr( 'href', filelink + '?action=edit' )
.find( 'span' ).text( 'Editar no Commons' );
// If there is a (local) talk page, do nothing
if ( !$( '#ca-talk' ).hasClass( 'new' ) ) {
return;
}
// Link to talk about this file on Commons
$( '#ca-talk > a' )
.removeClass( 'new' ).addClass( 'extiw' )
.attr( 'href', filetalklink );
} );
}