미디어위키:Common.js

L위키, 시민들이 참여하여 가꾸는 리버럴 위키

참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다.

  • 파이어폭스 / 사파리: Shift 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5 또는 Ctrl-R을 입력 (Mac에서는 ⌘-R)
  • 구글 크롬: Ctrl-Shift-R키를 입력 (Mac에서는 ⌘-Shift-R)
  • 인터넷 익스플로러 / 엣지: Ctrl 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5를 입력.
  • 오페라: Ctrl-F5를 입력.
/**
 * 이 스크립트는 L위키 전체에 적용됩니다. 고칠 때는 주의해주세요.
 * 한국어 위키백과의 동명의 문서(https://ko.wikipedia.org/w/index.php?title=%EB%AF%B8%EB%94%94%EC%96%B4%EC%9C%84%ED%82%A4:Common.js&oldid=27874143)에서 파생되었습니다.
 *
 * 스크립트를 넣을 때는 충분한 설명, 출처를 넣어주세요! 이후 관리가 어려워집니다.
 **/

/* global mw, $ */
/* jshint strict:false, browser:true */

mw.loader.using( ['mediawiki.user', 'mediawiki.util'] ).done( function () {
	/* Begin of mw.loader.using callback */
	
	/**
	 * Redirect User:Name/skin.js and skin.css to the current skin's pages
	 * (unless the 'skin' page really exists)
	 * @source: http://www.mediawiki.org/wiki/Snippets/Redirect_skin.js
	 * @rev: 2
	 */
	if ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgNamespaceNumber' ) === 2 ) {
		var titleParts = mw.config.get( 'wgPageName' ).split( '/' );
		/* Make sure there was a part before and after the slash
		   and that the latter is 'skin.js' or 'skin.css' */
		if ( titleParts.length == 2 ) {
			var userSkinPage = titleParts.shift() + '/' + mw.config.get( 'skin' );
			if ( titleParts.slice( -1 ) == 'skin.js' ) {
				window.location.href = mw.util.getUrl( userSkinPage + '.js' );
			} else if ( titleParts.slice( -1 ) == 'skin.css' ) {
				window.location.href = mw.util.getUrl( userSkinPage + '.css' );
			}
		}
	}
	
	/**
	 * Map addPortletLink to mw.util
	 * @deprecated: Use mw.util.addPortletLink instead.
	 */
	mw.log.deprecate( window, 'addPortletLink', mw.util.addPortletLink, 'Use mw.util.addPortletLink instead' );
	 
	/**
	 * @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
	 * @rev 6
	 */
	var extraCSS = mw.util.getParamValue( 'withCSS' ),
		extraJS = mw.util.getParamValue( 'withJS' );
	
	if ( extraCSS ) {
		if ( extraCSS.match( /^(MediaWiki|미디어위키):[^&<>=%#]*\.css$/ ) ) {
			mw.loader.load( '/w/index.php?title=' + extraCSS + '&action=raw&ctype=text/css', 'text/css' );
		} else {
			mw.notify( '미디어위키 이름공간의 문서만 허용됩니다.', { title: '유효하지 않은 withCSS 값' } );
		}
	}
	 
	if ( extraJS ) {
		if ( extraJS.match( /^(MediaWiki|미디어위키):[^&<>=%#]*\.js$/ ) ) {
			mw.loader.load( '/w/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript' );
		} else {
			mw.notify( '미디어위키 이름공간의 문서만 허용됩니다.', { title: '유효하지 않은 withJS 값' } );
		}
	}
	
	/**
	 * Collapsible tables; reimplemented with mw-collapsible
	 * Styling is also in place to avoid FOUC
	 * 
	 * Allows tables to be collapsed, showing only the header. See [[Help:Collapsing]].
	 * @version 3.0.0 (2018-05-20)
	 * @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js
	 * @author [[User:R. Koot]]
	 * @author [[User:Krinkle]]
	 * @author [[User:TheDJ]]
	 * @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which
	 * is supported in MediaWiki core. Shimmable since MediaWiki 1.32
	 */
	function makeCollapsibleMwCollapsible( $content ) {
		var $tables = $content
			.find( 'table.collapsible:not(.mw-collapsible)' )
			.addClass( 'mw-collapsible' );
	
		$.each( $tables, function( index, table ) {
			// mw.log.warn( '이 문서는 구식 클래스 collapsible을 사용하고 있습니다. mw-collapsible로 변경해 주십시오.');
			if( $( table ).hasClass( 'collapsed') ) {
				$( table ).addClass( 'mw-collapsed' );
				// mw.log.warn( '이 문서는 구식 클래스 collapsed를 사용하고 있습니다. mw-collapsed로 변경해 주십시오.');
			}
		} );
		if( $tables.length > 0 ) {
			mw.loader.using( 'jquery.makeCollapsible' ).then( function() {
				$tables.makeCollapsible();
			} );
		}
	}
	mw.hook( 'wikipage.content' ).add( makeCollapsibleMwCollapsible );
	
	/**
	 * Add support to mw-collapsible for autocollapse, innercollapse and outercollapse
	 *
	 * Maintainers: TheDJ
	 */
	function mwCollapsibleSetup( $collapsibleContent ) {
		var $element,
			$toggle,
			autoCollapseThreshold = 2;
		$.each( $collapsibleContent, function (index, element) {
			$element = $( element );
			if ( $element.hasClass( 'collapsible' ) ) {
				$element.find('tr:first > th:first').prepend( $element.find('tr:first > * > .mw-collapsible-toggle'));
			}
			if ( $collapsibleContent.length >= autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) {
				$element.data( 'mw-collapsible' ).collapse();
			} else if ( $element.hasClass( 'innercollapse' ) ) {
				if ( $element.parents( '.outercollapse' ).length > 0 ) {
					$element.data( 'mw-collapsible' ).collapse();
				}
			}
			// because of colored backgrounds, style the link in the text color
			// to ensure accessible contrast
			$toggle = $element.find( '.mw-collapsible-toggle' );
			if ( $toggle.length ) {
				// Make the toggle inherit text color
				if( $toggle.parent()[0].style.color ) {
					$toggle.find( 'a' ).css( 'color', 'inherit' );
				}
			}
		} );
	}
	
	mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );
	
	/**
	 * Dynamic Navigation Bars (experimental)
	 *
	 * Description: See [[Wikipedia:NavFrame]].
	 * Maintainers: UNMAINTAINED
	 */
	 
	var collapseCaption = '숨기기';
	var expandCaption = '보이기';
	
	// Set up the words in your language
	var navigationBarHide = '[' + collapseCaption + ']';
	var navigationBarShow = '[' + expandCaption + ']';
	
	/**
	 * Shows and hides content and picture (if available) of navigation bars.
	 *
	 * @param {number} indexNavigationBar The index of navigation bar to be toggled
	 * @param {jQuery.Event} event Event object
	 */
	function toggleNavigationBar( indexNavigationBar, event ) {
		var navToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
		var navFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
		var navChild;
	
		if ( !navFrame || !navToggle ) {
			return false;
		}
	
		// If shown now
		if ( navToggle.firstChild.data === navigationBarHide ) {
			for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
				if ( $( navChild ).hasClass( 'NavContent' ) ) {
					navChild.style.display = 'none';
				}
			}
			navToggle.firstChild.data = navigationBarShow;
		
		// If hidden now
		} else if ( navToggle.firstChild.data === navigationBarShow ) {
			for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
				if ( $( navChild ).hasClass( 'NavContent' ) ) {
					navChild.style.display = 'block';
				}
			}
			navToggle.firstChild.data = navigationBarHide;
		}
	
		event.preventDefault();
	}
	
	/**
	 * Adds show/hide-button to navigation bars.
	 *
	 * @param {jQuery} $content
	 */
	function createNavigationBarToggleButton( $content ) {
		var i, j, navChild, navToggle, navToggleText, isCollapsed,
			indexNavigationBar = 0;
		// Iterate over all < div >-elements
		var $divs = $content.find( 'div.NavFrame:not(.mw-collapsible)' );
		$divs.each( function ( i, navFrame ) {
			indexNavigationBar++;
			navToggle = document.createElement( 'a' );
			navToggle.className = 'NavToggle';
			navToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
			navToggle.setAttribute( 'href', '#' );
			$( navToggle ).on( 'click', $.proxy( toggleNavigationBar, null, indexNavigationBar ) );
	
			isCollapsed = $( navFrame ).hasClass( 'collapsed' );
			/**
			 * Check if any children are already hidden.  This loop is here for backwards compatibility:
			 * the old way of making NavFrames start out collapsed was to manually add style="display:none"
			 * to all the NavPic/NavContent elements.  Since this was bad for accessibility (no way to make
			 * the content visible without JavaScript support), the new recommended way is to add the class
			 * "collapsed" to the NavFrame itself, just like with collapsible tables.
			 */
			for ( navChild = navFrame.firstChild; navChild !== null && !isCollapsed; navChild = navChild.nextSibling ) {
				if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) {
					if ( navChild.style.display === 'none' ) {
						isCollapsed = true;
					}
				}
			}
			if ( isCollapsed ) {
				for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
					if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) {
						navChild.style.display = 'none';
					}
				}
			}
			navToggleText = document.createTextNode( isCollapsed ? navigationBarShow : navigationBarHide );
			navToggle.appendChild( navToggleText );
	
			// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
			for ( j = 0; j < navFrame.childNodes.length; j++ ) {
				if ( $( navFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
					navToggle.style.color = navFrame.childNodes[j].style.color;
					navFrame.childNodes[j].appendChild( navToggle );
				}
			}
			navFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
		} );
	}
	
	mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );
	
	/**
	 * 편집 안내 ****************************************************
	 *
	 * 생존 인물에 대한 편집 안내. 영어 위키백과에서 가져옴 - ChongDae
	 * Description: Adds editintros on disambiguation pages and BLP pages.
	 * Maintainers: [[User:RockMFR]]
	 */
	function addEditIntro( name ) {
	    $( '.mw-editsection, #ca-edit, #ca-ve-edit' ).find( 'a' ).each( function ( i, el ) {
	        el.href = $( this ).attr( 'href' ) + '&editintro=' + name;
	    } );
	}
	
	if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) {
	    $( function () {
	        var cats = mw.config.get('wgCategories');
	        if ( !cats ) {
	            return;
	        }
	        if ( $.inArray( '살아있는 사람', cats ) !== -1 || $.inArray( '생사 불명', cats ) !== -1 ) {
	            addEditIntro( '틀:BLP_편집_안내' );
	        }
	    } );
	}
	
	/* Actions specific to the edit page */
	if ( mw.config.get( 'wgAction' ) === 'edit' || mw.config.get( 'wgAction' ) === 'submit' ) {
		/**
		 * Fix edit summary prompt for undo
		 *
		 *  Fixes the fact that the undo function combined with the "no edit summary prompter"
		 *  complains about missing editsummary, if leaving the edit summary unchanged.
		 *  Added by [[User:Deskana]], code by [[User:Tra]].
		 *  See also [[phab:T10912]].
		 */
		$(function () {
			if (document.location.search.indexOf('undo=') !== -1 && document.getElementsByName('wpAutoSummary')[0]) {
				document.getElementsByName('wpAutoSummary')[0].value = '1';
			}
		});
	}
	
	/***** 그림 정보 틀을 자동으로 불러옴 ********
	 * Adds a link to subpages of current page
	 * from commons.wikimedia.org
	 *  Maintainers: [[User:Yonidebest]], [[User:Dschwen]]
	 *  [[사용자:Kwj2772]]가 수정
	 *  JSconfig items: bool 'loadAutoInformationTemplate'
	 *                       (true=enabled (default), false=disabled)
	 * JSConfig를 사용하지 않도록 수정함. --[[사용자:Klutzy|klutzy]] ([[사용자토론:Klutzy|토론]]) 2009년 9월 27일 (일) 20:33 (KST)
	 ****/
	if (mw.config.get('wgCanonicalSpecialPageName') == 'Upload') {
	  mw.loader.load( 'https://www.lwiki.net/w/index.php?title=MediaWiki:Upload.js&action=raw&ctype=text/javascript' );
	}
	
	/* 틀 부제목 구현 및 메타 부제목을 메타에 맞게 */
	if(typeof disablerewriteSitesub === 'undefined' && $('#replacesitesub').length > 0) {
		document.getElementById('siteSub').innerHTML = document.getElementById('replacesitesub').innerHTML;
	}
	
	//파라미터 검출 함수 출처: https://fellowtuts.com/jquery/get-query-string-values-url-parameters-javascript/
	function getUrlParameter(name) {
	    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
	    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
	    results = regex.exec(location.search);
	    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
	}
	
	//메타 여부 검출
	window.metans = false;
	
	if ( mw.config.get( 'wgCanonicalNamespace' ) === '메타' || mw.config.get( 'wgCanonicalNamespace' ) === '메타토론' || ( mw.util.getParamValue('namespace') === '0;1;4;5;12;13' && mw.util.getParamValue('invert') === '1' && mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Recentchanges')) {
		window.metans = true;
	}
	
	/* 메타에서 사이드바 파트 조정 */
	if ( metans === true ) {
		$('#n-projectchat').html('<a href = "'+ mw.util.getUrl( '메타:광장' ) +'">광장</a>');
		$('#n-mainpage-description').html('<a href = "'+ mw.util.getUrl( '메타:대문' ) +'">대문</a>');
		$('#n-recentchanges').html('<a href="'+ mw.util.getUrl( 'Special:RecentChanges' ) + '?namespace=0%3B1%3B4%3B5%3B12%3B13&invert=1">최근 바뀜</a>');
		$('#n-randompage').html('<a href = "'+ mw.util.getUrl( 'Special:Randompage/메타' ) +'">임의의 문서로</a>');
		$('#n-portal').remove();
		$('#n-request').remove();
		$('#n-lw-otherproject-meta').remove();
		$('#n-policy').remove();
	} else {
		$('#n-lw-otherproject-lwiki').remove();
	}

	/* End of mw.loader.using callback */
} );

window.addEventListener('DOMContentLoaded', function() {
	/* 틀 부제목 구현 및 메타 부제목을 메타에 맞게 */
	if(typeof disablerewriteSitesub === 'undefined' && !!document.getElementById('replacesitesub')) {
		document.getElementById('siteSub').innerHTML = document.getElementById('replacesitesub').innerHTML;
	}
});
// Can be removed when no results for ko.wikipedia in https://global-search.toolforge.org/?q=appendCSS%5C%28&regex=1&namespaces=&title=
window.appendCSS = function (css) {
	mw.util.addCSS(css);
};
/* DO NOT ADD CODE BELOW THIS LINE */