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.
/** * PJR has not included all Wikipedia:Common.js in this file. * Using a program such as Winmerge will reveal the differences. * * Keep code in MediaWiki:Common.js to a minimum as it is unconditionally * loaded for all users on every wiki page. If possible create a gadget that is * enabled by default instead of adding it here (since gadgets are fully * optimized ResourceLoader modules with possibility to add dependencies etc.) * */ if ( /^MediaWiki(\/.+)?$/.test( wgPageName ) && wgAction == 'view' ) { addOnloadHook(function(){ document.body.className+=" mainpage"; }) } /* Any JavaScript here will be loaded for all users on every page load. */ function includePage( name ) { document.write('<script type="text/javascript" src="' + wgScript + '?title=' + name + '&action=raw&ctype=text/javascript"><\/script>' ); } /* End of includePage */ /** * Main Page layout fixes * * Description: Adds an additional link to the complete list of languages available. * Maintainers: [[User:AzaToth]], [[User:R. Koot]], [[User:Alex Smotrov]] */ /** * 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 */ /** * Map addPortletLink to mw.util * * @deprecated: Use mw.util.addPortletLink instead. */ /** * Extract a URL parameter from the current URL * * @deprecated: Use mw.util.getParamValue with proper escaping */ /** * Test if an element has a certain class * * From English Wikipedia, 2008-09-15 * * Description: Uses regular expressions and caching for better performance. * Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]] */ var hasClass = (function() { var reCache = {}; return function ( element, className ) { return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className); }; })(); /** * @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL * @rev 5 */ // CSS // JS /** * Import more specific scripts if necessary */ // switches for scripts // TODO: migrate to JSConfig // var load_extratabs = true; var load_edittools = true; // extra drop down menu on editing for adding special characters includePage( 'MediaWiki:Edittools.js' ); // provides Harvard Referencing importScript('HarvardReferences.js'); // Editpage scripts if( wgAction == 'edit' || wgAction == 'submit' ) importScript('MediaWiki:Editpage.js') /* End of extra pages */ /** * Load scripts specific to Internet Explorer */ /** * Fix for Windows XP Unicode font rendering */ /** * WikiMiniAtlas * * Description: WikiMiniAtlas is a popup click and drag world map. * This script causes all of our coordinate links to display the WikiMiniAtlas popup button. * The script itself is located on meta because it is used by many projects. * See [[Meta:WikiMiniAtlas]] for more information. * Maintainers: [[User:Dschwen]] */ ( function () { var require_wikiminiatlas = false; var coord_filter = /geohack/; $( document ).ready( function() { $( 'a.external.text' ).each( function( key, link ) { if ( link.href && coord_filter.exec( link.href ) ) { require_wikiminiatlas = true; // break from loop return false; } } ); if ( $( 'div.kmldata' ).length ) { require_wikiminiatlas = true; } if ( require_wikiminiatlas ) { mw.loader.load( '//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript' ); } } ); } )(); /** * Interwiki links to featured articles *************************************** * * Description: Highlights interwiki links to featured articles (or * equivalents) by changing the bullet before the interwiki link * into a star. * Maintainers: [[User:R. Koot]] */ /** * Collapsible tables ********************************************************* * * From English Wikipedia, 2008-09-15 * * Description: Allows tables to be collapsed, showing only the header. See * [[Wikipedia:NavFrame]]. * Maintainers: [[User:R. Koot]] */ var autoCollapse = 2; var collapseCaption = 'hide'; var expandCaption = 'show'; function collapseTable( tableIndex ){ var Button = document.getElementById( 'collapseButton' + tableIndex ); var Table = document.getElementById( 'collapsibleTable' + tableIndex ); if ( !Table || !Button ) { return false; } var Rows = Table.rows; if ( Button.firstChild.data == collapseCaption ) { for ( var i = 1; i < Rows.length; i++ ) { Rows[i].style.display = 'none'; } Button.firstChild.data = expandCaption; } else { for ( var i = 1; i < Rows.length; i++ ) { Rows[i].style.display = Rows[0].style.display; } Button.firstChild.data = collapseCaption; } } function createCollapseButtons(){ var tableIndex = 0; var NavigationBoxes = new Object(); var Tables = document.getElementsByTagName( 'table' ); for ( var i = 0; i < Tables.length; i++ ) { if ( hasClass( Tables[i], 'collapsible' ) ) { /* only add button and increment count if there is a header row to work with */ var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0]; if( !HeaderRow ) continue; var Header = HeaderRow.getElementsByTagName( 'th' )[0]; if( !Header ) continue; NavigationBoxes[tableIndex] = Tables[i]; Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex ); var Button = document.createElement( 'span' ); var ButtonLink = document.createElement( 'a' ); var ButtonText = document.createTextNode( collapseCaption ); Button.style.styleFloat = 'right'; Button.style.cssFloat = 'right'; Button.style.fontWeight = 'normal'; Button.style.textAlign = 'right'; Button.style.width = '6em'; ButtonLink.style.color = Header.style.color; ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex ); ButtonLink.setAttribute( 'href', "javascript:collapseTable(" + tableIndex + ");" ); ButtonLink.appendChild( ButtonText ); Button.appendChild( document.createTextNode( "[" ) ); Button.appendChild( ButtonLink ); Button.appendChild( document.createTextNode( "]" ) ); Header.insertBefore( Button, Header.childNodes[0] ); tableIndex++; } } for ( var i = 0; i < tableIndex; i++ ) { if ( hasClass( NavigationBoxes[i], 'collapsed' ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], 'autocollapse' ) ) ) { collapseTable( i ); } } } addOnloadHook( createCollapseButtons ); /** * Dynamic Navigation Bars (experimental) * * From English Wikipedia, 2008-09-15 * * Description: See [[Wikipedia:NavFrame]]. * Maintainers: UNMAINTAINED */ /* set up the words in your language */ var NavigationBarHide = '[' + collapseCaption + ']'; var NavigationBarShow = '[' + expandCaption + ']'; /** * Shows and hides content and picture (if available) of navigation bars * Parameters: * indexNavigationBar: the index of navigation bar to be toggled **/ function toggleNavigationBar( indexNavigationBar ){ var NavToggle = document.getElementById('NavToggle' + indexNavigationBar); var NavFrame = document.getElementById('NavFrame' + indexNavigationBar); if( !NavFrame || !NavToggle ) { return false; } /* if shown now */ if( NavToggle.firstChild.data == NavigationBarHide ) { for( var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) { if ( hasClass( NavChild, 'NavPic' ) ) { NavChild.style.display = 'none'; } if ( hasClass( NavChild, 'NavContent') ) { NavChild.style.display = 'none'; } } NavToggle.firstChild.data = NavigationBarShow; /* if hidden now */ } else if( NavToggle.firstChild.data == NavigationBarShow) { for( var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) { if( hasClass( NavChild, 'NavPic' ) ) { NavChild.style.display = 'block'; } if( hasClass( NavChild, 'NavContent' ) ) { NavChild.style.display = 'block'; } } NavToggle.firstChild.data = NavigationBarHide; } } /* adds show/hide-button to navigation bars */ function createNavigationBarToggleButton() { var indexNavigationBar = 0; /* iterate over all < div >-elements */ var divs = document.getElementsByTagName('div'); for( var i = 0; NavFrame = divs[i]; i++ ) { /* if found a navigation bar */ if( hasClass( NavFrame, 'NavFrame' ) ) { indexNavigationBar++; var NavToggle = document.createElement("a"); NavToggle.className = 'NavToggle'; NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar); NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');'); var NavToggleText = document.createTextNode(NavigationBarHide); /** * 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( var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) { if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) { if( NavChild.style.display == 'none' ) { NavToggleText = document.createTextNode(NavigationBarShow); break; } } } NavToggle.appendChild( NavToggleText ); /* Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) */ for( var j=0; j < NavFrame.childNodes.length; j++) { if( hasClass( NavFrame.childNodes[j], 'NavHead' ) ) { NavFrame.childNodes[j].appendChild(NavToggle); } } NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar); } } } addOnloadHook( createNavigationBarToggleButton ); /** * Uploadwizard_newusers * Switches in a message for non-autoconfirmed users at [[Wikipedia:Upload]] * * Maintainers: [[User:Krimpet]] */ /** * Magic editintros **************************************************** * * Description: Adds editintros on disambiguation pages and BLP pages. * Maintainers: [[User:RockMFR]] */ /** * Description: Stay on the secure server as much as possible * Maintainers: [[User:TheDJ]] */ /* DO NOT ADD CODE BELOW THIS LINE */