MediaWiki:Common.js
Jump to navigation
Jump to search
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */ //<source lang="javascript"><br><br>/*<br> * Description: Redirects from /User:UserName/skin.js or .css to the user's actual skin page<br> * Maintainer: Cacycle<br> */<br>if (wgArticleId == 0 && wgUserName) {<br> var slash = wgPageName.indexOf('/');<br> var norm = wgPageName.substr(0, slash) + wgPageName.substr(slash).toLowerCase();<br> var test = 'User:' + wgUserName.replace(/ /g, '_') + '/skin.';<br> var ext = null;<br> if (norm == test + 'js') ext = 'js';<br> else if (norm == test + 'css') ext = 'css';<br> if (ext != null) window.location.href = window.location.href.replace(/\/skin.(css|js)/i, '/' + skin + '.' + ext);<br>}<br><br>/** extract a URL parameter from the current URL **********<br> * From [[En:User:Lupin/autoedit.js]]<br> *<br> * paramName : the name of the parameter to extract<br> */<br>function getURLParamValue( paramName, url) <br>{<br> if (typeof (url) == 'undefined' || url === null) url = document.location.href;<br> var cmdRe=RegExp( '[&?]' + paramName + '=([^&#]*)' ); // Stop at hash<br> var m=cmdRe.exec(url);<br> if (m && m.length > 1) return decodeURIComponent(m[1]);<br> return null;<br>}<br><br>/** &withJS= URL parameter *******<br> * Allow to try custom scripts from MediaWiki space <br> * without editing [[Special:Mypage/monobook.js]]<br> */<br>var extraJS = getURLParamValue("withJS");<br>if ( extraJS && extraJS.match("^MediaWiki:[^&<>=%]*\.js$") ) {<br> importScript(extraJS);<br>}<br><br>/* Import more specific scripts if necessary */<br><br>if (wgAction == "edit" || wgAction == "submit" || wgPageName == "Special:Upload") //scripts specific to editing pages<br>{<br> importScript("MediaWiki:Common.js/edit.js")<br>}<br>else if (wgPageName == "Special:Watchlist") //watchlist scripts<br>{<br> importScript("MediaWiki:Common.js/watchlist.js")<br>}<br>if( wgNamespaceNumber == 6 ) {<br> importScript('MediaWiki:Common.js/file.js');<br>}<br><br>/** For sysops and accountcreators *****************************************<br> *<br> * Description: Allows for sysop-specific Javascript at [[MediaWiki:Sysop.js]],<br> * and accountcreator-specific CSS at [[MediaWiki:Accountcreator.css]].<br> */<br>if ( wgUserGroups ) {<br> for ( var g = 0; g < wgUserGroups.length; ++g ) {<br> if ( wgUserGroups[g] == "sysop" ) {<br> importStylesheet("MediaWiki:Sysop.css");<br> addOnloadHook( function() {<br> if ( !window.disableSysopJS ) {<br> importScript("MediaWiki:Sysop.js");<br> }<br> } );<br> } <br> else if ( wgUserGroups[g] == "accountcreator" ) {<br> importStylesheet("MediaWiki:Accountcreator.css");<br> }<br> }<br>}<br><br><br>/** WikiMiniAtlas *******************************************************<br> *<br> * Description: WikiMiniAtlas is a popup click and drag world map.<br> * This script causes all of our coordinate links to display the WikiMiniAtlas popup button.<br> * The script itself is located on meta because it is used by many projects.<br> * See [[Meta:WikiMiniAtlas]] for more information. <br> * Maintainers: [[User:Dschwen]]<br> */<br><br>if (wgServer == "https://secure.wikimedia.org") {<br> var metaBase = "https://secure.wikimedia.org/wikipedia/meta";<br>} else {<br> var metaBase = "http://meta.wikimedia.org";<br>}<br>importScriptURI(metaBase+"/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400")<br><br>/* Scripts specific to Internet Explorer */<br><br>if (navigator.appName == "Microsoft Internet Explorer")<br>{<br> /** Internet Explorer bug fix **************************************************<br> *<br> * Description: Fixes IE horizontal scrollbar bug<br> * Maintainers: [[User:Tom-]]?<br> */<br> <br> var oldWidth;<br> var docEl = document.documentElement;<br> <br> function fixIEScroll()<br> {<br> if (!oldWidth || docEl.clientWidth > oldWidth)<br> doFixIEScroll();<br> else<br> setTimeout(doFixIEScroll, 1);<br> <br> oldWidth = docEl.clientWidth;<br> }<br> <br> function doFixIEScroll() {<br> docEl.style.overflowX = (docEl.scrollWidth - docEl.clientWidth < 4) ? "hidden" : "";<br> }<br> <br> document.attachEvent("onreadystatechange", fixIEScroll);<br> document.attachEvent("onresize", fixIEScroll);<br> <br> <br> /**<br> * Remove need for CSS hacks regarding MSIE and IPA.<br> */<br> if (document.createStyleSheet) {<br> document.createStyleSheet().addRule('.IPA', 'font-family: "Doulos SIL", "Charis SIL", Gentium, "DejaVu Sans", Code2000, "TITUS Cyberbit Basic", "Arial Unicode MS", "Lucida Sans Unicode", "Chrysanthi Unicode";');<br> }<br><br> // In print IE (7?) does not like line-height<br> appendCSS( '@media print { sup, sub, p, .documentDescription { line-height: normal; }}');<br><br> // IE overflow bug<br> appendCSS('div.overflowbugx { overflow-x: scroll !important; overflow-y: hidden !important; } div.overflowbugy { overflow-y: scroll !important; overflow-x: hidden !important; }');<br><br> // IE zoomfix<br> //Use to fix right floating div/table inside tables.<br> appendCSS('.iezoomfix div, .iezoomfix table { zoom: 1;}' );<br> <br> //Import scripts specific to Internet Explorer 6<br> if (navigator.appVersion.substr(22, 1) == "6") {<br> importScript("MediaWiki:Common.js/IE60Fixes.js")<br> }<br>}<br><br><br>/* Test if an element has a certain class **************************************<br> *<br> * Description: Uses regular expressions and caching for better performance.<br> * Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]<br> */<br><br>var hasClass = (function () {<br> var reCache = {};<br> return function (element, className) {<br> return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);<br> };<br>})();<br><br><br>/** Interwiki links to good articles ***************************************<br> *<br> * Description: Highlights interwiki links to good articles (or<br> * equivalents) by changing the bullet before the interwiki link<br> * into a good article symbol.<br> * Maintainers: [[User:R. Koot]]<br> */<br> <br>function LinkGA() <br>{<br> if ( document.getElementById( "p-lang" ) ) {<br> var InterwikiLinks = document.getElementById( "p-lang" ).getElementsByTagName( "li" );<br> <br> for ( var i = 0; i < InterwikiLinks.length; i++ ) {<br> if ( document.getElementById( InterwikiLinks[i].className + "-ga" ) ) {<br> InterwikiLinks[i].className += " GA"<br> InterwikiLinks[i].title = "This is a good article in another language.";<br> }<br> }<br> }<br>}<br> <br>addOnloadHook( LinkGA );<br><br>/** Interwiki links to featured articles ***************************************<br> *<br> * Description: Highlights interwiki links to featured articles (or<br> * equivalents) by changing the bullet before the interwiki link<br> * into a star.<br> * Maintainers: [[User:R. Koot]]<br> */<br><br>function LinkFA() <br>{<br> if ( document.getElementById( "p-lang" ) ) {<br> var InterwikiLinks = document.getElementById( "p-lang" ).getElementsByTagName( "li" );<br><br> for ( var i = 0; i < InterwikiLinks.length; i++ ) {<br> if ( document.getElementById( InterwikiLinks[i].className + "-fa" ) ) {<br> InterwikiLinks[i].className += " FA"<br> InterwikiLinks[i].title = "This is a featured article in another language.";<br> }<br> }<br> }<br>}<br><br>addOnloadHook( LinkFA );<br><br><br>/** Collapsible tables *********************************************************<br> *<br> * Description: Allows tables to be collapsed, showing only the header. See<br> * [[wikipedia:NavFrame|RTENOTITLE]].<br> * Maintainers: [[User:R. Koot]]<br> */<br><br>var autoCollapse = 2;<br>var collapseCaption = "hide";<br>var expandCaption = "show";<br><br>function collapseTable( tableIndex )<br>{<br> var Button = document.getElementById( "collapseButton" + tableIndex );<br> var Table = document.getElementById( "collapsibleTable" + tableIndex );<br><br> if ( !Table || !Button ) {<br> return false;<br> }<br><br> var Rows = Table.rows;<br><br> if ( Button.firstChild.data == collapseCaption ) {<br> for ( var i = 1; i < Rows.length; i++ ) {<br> Rows[i].style.display = "none";<br> }<br> Button.firstChild.data = expandCaption;<br> } else {<br> for ( var i = 1; i < Rows.length; i++ ) {<br> Rows[i].style.display = Rows[0].style.display;<br> }<br> Button.firstChild.data = collapseCaption;<br> }<br>}<br><br>function createCollapseButtons()<br>{<br> var tableIndex = 0;<br> var NavigationBoxes = new Object();<br> var Tables = document.getElementsByTagName( "table" );<br><br> for ( var i = 0; i < Tables.length; i++ ) {<br> if ( hasClass( Tables[i], "collapsible" ) ) {<br><br> /* only add button and increment count if there is a header row to work with */<br> var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0];<br> if (!HeaderRow) continue;<br> var Header = HeaderRow.getElementsByTagName( "th" )[0];<br> if (!Header) continue;<br><br> NavigationBoxes[ tableIndex ] = Tables[i];<br> Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );<br><br> var Button = document.createElement( "span" );<br> var ButtonLink = document.createElement( "a" );<br> var ButtonText = document.createTextNode( collapseCaption );<br><br> Button.className = "collapseButton"; //Styles are declared in Common.css<br><br> ButtonLink.style.color = Header.style.color;<br> ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );<br> ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );<br> ButtonLink.appendChild( ButtonText );<br><br> Button.appendChild( document.createTextNode( "[" ) );<br> Button.appendChild( ButtonLink );<br> Button.appendChild( document.createTextNode( "]" ) );<br><br> Header.insertBefore( Button, Header.childNodes[0] );<br> tableIndex++;<br> }<br> }<br><br> for ( var i = 0; i < tableIndex; i++ ) {<br> if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {<br> collapseTable( i );<br> } <br> else if ( hasClass( NavigationBoxes[i], "innercollapse" ) ) {<br> var element = NavigationBoxes[i];<br> while (element = element.parentNode) {<br> if ( hasClass( element, "outercollapse" ) ) {<br> collapseTable ( i );<br> break;<br> }<br> }<br> }<br> }<br>}<br><br>addOnloadHook( createCollapseButtons );<br><br><br>/** Dynamic Navigation Bars (experimental) *************************************<br> *<br> * Description: See [[wikipedia:NavFrame|RTENOTITLE]].<br> * Maintainers: UNMAINTAINED<br> */<br><br>// set up the words in your language<br>var NavigationBarHide = '[' + collapseCaption + ']';<br>var NavigationBarShow = '[' + expandCaption + ']';<br><br>// shows and hides content and picture (if available) of navigation bars<br>// Parameters:<br>// indexNavigationBar: the index of navigation bar to be toggled<br>function toggleNavigationBar(indexNavigationBar)<br>{<br> var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);<br> var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);<br><br> if (!NavFrame || !NavToggle) {<br> return false;<br> }<br><br> // if shown now<br> if (NavToggle.firstChild.data == NavigationBarHide) {<br> for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {<br> if (hasClass(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic')) {<br> NavChild.style.display = 'none';<br> }<br> }<br> NavToggle.firstChild.data = NavigationBarShow;<br><br> // if hidden now<br> } else if (NavToggle.firstChild.data == NavigationBarShow) {<br> for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {<br> if (hasClass(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic')) {<br> NavChild.style.display = 'block';<br> }<br> }<br> NavToggle.firstChild.data = NavigationBarHide;<br> }<br>}<br><br>// adds show/hide-button to navigation bars<br>function createNavigationBarToggleButton()<br>{<br> var indexNavigationBar = 0;<br> // iterate over all < div >-elements <br> var divs = document.getElementsByTagName("div");<br> for (var i = 0; NavFrame = divs[i]; i++) {<br> // if found a navigation bar<br> if (hasClass(NavFrame, "NavFrame")) {<br><br> indexNavigationBar++;<br> var NavToggle = document.createElement("a");<br> NavToggle.className = 'NavToggle';<br> NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);<br> NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');<br><br> var isCollapsed = hasClass( NavFrame, "collapsed" );<br> /*<br> * Check if any children are already hidden. This loop is here for backwards compatibility:<br> * the old way of making NavFrames start out collapsed was to manually add style="display:none"<br> * to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make<br> * the content visible without JavaScript support), the new recommended way is to add the class<br> * "collapsed" to the NavFrame itself, just like with collapsible tables.<br> */<br> for (var NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling) {<br> if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {<br> if ( NavChild.style.display == 'none' ) {<br> isCollapsed = true;<br> }<br> }<br> }<br> if (isCollapsed) {<br> for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {<br> if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {<br> NavChild.style.display = 'none';<br> }<br> }<br> }<br> var NavToggleText = document.createTextNode(isCollapsed ? NavigationBarShow : NavigationBarHide);<br> NavToggle.appendChild(NavToggleText);<br><br> // Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)<br> for(var j=0; j < NavFrame.childNodes.length; j++) {<br> if (hasClass(NavFrame.childNodes[j], "NavHead")) {<br> NavFrame.childNodes[j].appendChild(NavToggle);<br> }<br> }<br> NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);<br> }<br> }<br>}<br><br>addOnloadHook( createNavigationBarToggleButton );<br><br><br>/** Main Page layout fixes *********************************************************<br> *<br> * Description: Adds an additional link to the complete list of languages available.<br> * Maintainers: [[User:AzaToth]], [[User:R. Koot]], [[User:Alex Smotrov]]<br> */<br><br>if (wgPageName == 'Main_Page' || wgPageName == 'Talk:Main_Page') <br> addOnloadHook(function () {<br> addPortletLink('p-lang', 'http://meta.wikimedia.org/wiki/List_of_Wikipedias',<br> 'Complete list', 'interwiki-completelist', 'Complete list of Wikipedias')<br> var nstab = document.getElementById('ca-nstab-main')<br> if (nstab && wgUserLanguage=='en') {<br> while (nstab.firstChild) nstab = nstab.firstChild<br> nstab.nodeValue = 'Main Page'<br> }<br> }<br>)<br><br><br>/** Table sorting fixes ************************************************<br> *<br> * Description: Disables code in table sorting routine to set classes on even/odd rows<br> * Maintainers: [[User:Random832]]<br> */<br><br>ts_alternate_row_colors = false;<br><br><br>/***** uploadwizard_newusers ********<br> * Switches in a message for non-autoconfirmed users at [[wikipedia:Upload|RTENOTITLE]]<br> *<br> * Maintainers: [[User:Krimpet]]<br> ****/<br>function uploadwizard_newusers() {<br> if (wgNamespaceNumber == 4 && wgTitle == "Upload" && wgAction == "view") {<br> var oldDiv = document.getElementById("autoconfirmedusers"),<br> newDiv = document.getElementById("newusers");<br> if (oldDiv && newDiv) {<br> if (typeof wgUserGroups == "object" && wgUserGroups) {<br> for (i = 0; i < wgUserGroups.length; i++) {<br> if (wgUserGroups[i] == "autoconfirmed") {<br> oldDiv.style.display = "block";<br> newDiv.style.display = "none";<br> return;<br> }<br> }<br> }<br> oldDiv.style.display = "none";<br> newDiv.style.display = "block";<br> return;<br> }<br> }<br>}<br>addOnloadHook(uploadwizard_newusers);<br><br><br>/** IPv6 AAAA connectivity testing **/<br><br>var __ipv6wwwtest_factor = 100;<br>var __ipv6wwwtest_done = 0;<br>if ((wgServer != "https://secure.wikimedia.org") && (Math.floor(Math.random()*__ipv6wwwtest_factor)==42)) {<br> importScript("MediaWiki:Common.js/IPv6.js");<br>}<br><br>/** Magic editintros ****************************************************<br> *<br> * Description: Adds editintros on disambiguation pages and BLP pages.<br> * Maintainers: [[User:RockMFR]]<br> */<br><br>function addEditIntro(name)<br>{<br> var el = document.getElementById('ca-edit');<br> if (!el)<br> return;<br> el = el.getElementsByTagName('a')[0];<br> if (el)<br> el.href += '&editintro=' + name;<br>}<br><br><br>if (wgNamespaceNumber == 0) {<br> addOnloadHook(function(){<br> if (document.getElementById('disambigbox'))<br> addEditIntro('Template:Disambig_editintro');<br> });<br><br> addOnloadHook(function(){<br> var cats = document.getElementById('mw-normal-catlinks');<br> if (!cats)<br> return;<br> cats = cats.getElementsByTagName('a');<br> for (var i = 0; i < cats.length; i++) {<br> if (cats[i].title == 'Category:Living people' || cats[i].title == 'Category:Possibly living people') {<br> addEditIntro('Template:BLP_editintro');<br> break;<br> }<br> }<br> });<br>}<br><br>/*<br> * Description: Stay on the secure server as much as possible<br> * Maintainers: [[User:TheDJ]]<br> */<br>if(wgServer == 'https://secure.wikimedia.org') {<br> importScript( 'MediaWiki:Common.js/secure.js');<br>}<br><br>// Define ta for now. Bugzilla 23175<br>window.ta = [];<br><br>//</source><br>