미디어위키:Gadget-direct-commons.js: 두 판 사이의 차이

위키배움터
내용 삭제됨 내용 추가됨
Krinkle (토론 | 기여)
Maintenance: mw:RL/MGU - Updated deprecated module name
 
20번째 줄: 20번째 줄:
commonsBaseScript = 'https://commons.wikimedia.org/w/index.php?title=File:';
commonsBaseScript = 'https://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

2023년 3월 8일 (수) 05:07 기준 최신판

/**
 * Direct imagelinks to Commons
 *
 * Required modules: mediawiki.util
 *
 * @source https://www.mediawiki.org/wiki/Snippets/Direct_imagelinks_to_Commons
 * @author Krinkle
 * @version 2017-08-30
 */
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.RegExp.escape( mw.util.getUrl( localFileNSString ) ) ),
				localBaseScript = new RegExp( '^' + mw.RegExp.escape(
					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 );
				}
			} );
		} );
	} );
}