Diferencia entre revisiones de «MediaWiki:Gadget-a-commons-directo.js»
Apariencia
Contenido eliminado Contenido añadido
mod. mw.RegExp obsoleto |
Ver PD |
||
Línea 25: | Línea 25: | ||
commonsBaseScript = '//commons.wikimedia.org/w/index.php?title=File:'; |
commonsBaseScript = '//commons.wikimedia.org/w/index.php?title=File:'; |
||
$content.find( 'a.image, a.mw-file-description' ).attr( 'href', function ( i, currVal ) { |
|||
if ( uploadBaseRe.test( $( this ).find( 'img' ).attr( 'src' ) ) ) { |
|||
return currVal |
return currVal |
||
.replace( localBasePath, commonsBasePath ) |
.replace( localBasePath, commonsBasePath ) |
Revisión del 19:07 26 nov 2022
/**
* Direct imagelinks to Commons
*
* @fuente: //www.mediawiki.org/wiki/Snippets/Direct_imagelinks_to_Commons
* @autor: [[commons:User:Krinkle]]
* @versión: 9
*/
if ( mw.config.get( 'wgNamespaceNumber', 0 ) >= 0 ) {
mw.loader.using( [ 'mediawiki.util' ] ).done( function () {
mw.hook( 'wikipage.content' ).add( function ( $content ) {
var
uploadBaseRe = /^\/\/upload\.wikimedia\.org\/wikipedia\/commons/,
localFileNSString = mw.config.get( 'wgFormattedNamespaces' )['6'] + ':',
localBasePath = new RegExp(
'^' + mw.util.escapeRegExp( mw.util.getUrl( localFileNSString ) )
),
localBaseScript = new RegExp(
'^' + mw.util.escapeRegExp(
mw.util.wikiScript() + '?title=' + mw.util.wikiUrlencode( localFileNSString )
)
),
commonsBasePath = '//commons.wikimedia.org/wiki/File:',
commonsBaseScript = '//commons.wikimedia.org/w/index.php?title=File:';
$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 );
}
} );
} );
} );
}