انتقل إلى المحتوى

ميدياويكي:Gadget-Direct-link-to-Commons.js: الفرق بين النسختين

من ويكيبيديا، الموسوعة الحرة
تم حذف المحتوى تمت إضافة المحتوى
Maintenance: mw:RL/MGU - Updated deprecated module name
سطر 19: سطر 19:
commonsBaseScript = '//commons.wikimedia.org/w/index.php?title=File:';
commonsBaseScript = '//commons.wikimedia.org/w/index.php?title=File:';


$content.find( 'a.image' ).attr( 'href', function ( i, currVal ) {
$content.find( 'a.image, a.mw-file-description' ).attr( 'href', function ( i, currVal ) {
if ( uploadBaseRe.test( $( this ).find( 'img' ).attr( 'src' ) ) ) {
if ( uploadBaseRe.test( $( this ).find( 'img' ).attr( 'src' ) ) ) {
return currVal
return currVal

نسخة 00:13، 25 فبراير 2023

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

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

			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 );
			}
		} );
	} );
}