מדיה ויקי:Gadget-directlink-to-commons.js: הבדלים בין גרסאות בדף

מתוך צפונות ויקי
(depracation)
(update to latest upstream)
שורה 2: שורה 2:
  * Direct imagelinks to Commons
  * Direct imagelinks to Commons
  *
  *
  * @source mediawiki.org/wiki/Snippets/Direct_imagelinks_to_Commons
* Required modules: mediawiki.util
  * @author [[commons:User:Krinkle]]
*
  * @version 9
  * @source https://www.mediawiki.org/wiki/Snippets/Direct_imagelinks_to_Commons
  * @author Krinkle
  * @version 2022-09-06
  */
  */
if ( mw.config.get( 'wgNamespaceNumber', 0 ) >= 0 ) {
if ( mw.config.get( 'wgNamespaceNumber', 0 ) >= 0 ) {
$( function () {
mw.loader.using( [ 'mediawiki.util' ] ).then( function () {
var
mw.hook( 'wikipage.content' ).add( function ( $content ) {
uploadBaseRe = /^\/\/upload\.wikimedia\.org\/wikipedia\/commons/,
var uploadBaseRe = /^(https:)?\/\/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 = 'https://commons.wikimedia.org/wiki/File:',
commonsBaseScript = 'https://commons.wikimedia.org/w/index.php?title=File:';


localBasePath = mw.util.getUrl( mw.config.get( 'wgFormattedNamespaces' )['6'] + ':' ),
$content.find( 'a.image, a.mw-file-description' ).attr( 'href', function ( i, currVal ) {
localBaseScript = mw.util.wikiScript() + '?title=' + mw.util.wikiUrlencode( mw.config.get( 'wgFormattedNamespaces' )['6'] + ':' ),
if ( uploadBaseRe.test( $( this ).find( 'img' ).attr( 'src' ) ) ) {
 
return currVal
commonsBasePath =  '//commons.wikimedia.org/wiki/File:',
.replace( localBasePath, commonsBasePath )
commonsBaseScript =  '//commons.wikimedia.org/w/index.php?title=File:';
.replace( localBaseScript, commonsBaseScript );
}
$( 'a.image' ).attr( 'href', function ( i, currVal ) {
} );
if ( uploadBaseRe.test( $(this).find( 'img' ).attr( 'src' ) ) ) {
} );
return currVal
} );
.replace( localBasePath, commonsBasePath )
.replace( localBaseScript, commonsBaseScript );
}
});
});
}
}

גרסה מ־17:54, 28 בנובמבר 2022

/**
 * Direct imagelinks to Commons
 *
 * Required modules: mediawiki.util
 *
 * @source https://www.mediawiki.org/wiki/Snippets/Direct_imagelinks_to_Commons
 * @author Krinkle
 * @version 2022-09-06
 */
if ( mw.config.get( 'wgNamespaceNumber', 0 ) >= 0 ) {
	mw.loader.using( [ 'mediawiki.util' ] ).then( function () {
		mw.hook( 'wikipage.content' ).add( function ( $content ) {
			var uploadBaseRe = /^(https:)?\/\/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 = 'https://commons.wikimedia.org/wiki/File:',
				commonsBaseScript = 'https://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 );
				}
			} );
		} );
	} );
}