https://wiki.tripwireinteractive.com/index.php?title=MediaWiki:Common.js&feed=atom&action=history
MediaWiki:Common.js - Revision history
2024-03-29T08:05:37Z
Revision history for this page on the wiki
MediaWiki 1.40.0
https://wiki.tripwireinteractive.com/index.php?title=MediaWiki:Common.js&diff=2955&oldid=prev
Yoshiro: Created page with "/** * 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 def..."
2012-10-20T19:50:05Z
<p>Created page with "/** * 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 def..."</p>
<p><b>New page</b></p><div>/**<br />
* Keep code in MediaWiki:Common.js to a minimum as it is unconditionally<br />
* loaded for all users on every wiki page. If possible create a gadget that is<br />
* enabled by default instead of adding it here (since gadgets are fully<br />
* optimized ResourceLoader modules with possibility to add dependencies etc.)<br />
*<br />
* Since common.js isn't a gadget, there is no place to declare its<br />
* dependencies, so we have to lazy load them with mw.loader.using on demand and<br />
* then execute the rest in the callback. In most cases these dependencies will<br />
* be loaded (or loading) already and the callback will not be delayed. In case a<br />
* dependency hasn't arrived yet it'll make sure those are loaded before this.<br />
*/<br />
mw.loader.using( 'mediawiki.util', function() {<br />
/* Begin of mw.loader.using callback */<br />
<br />
/**<br />
* Redirect User:Name/skin.js and skin.css to the current skin's pages<br />
* (unless the 'skin' page really exists)<br />
* @source: http://www.mediawiki.org/wiki/Snippets/Redirect_skin.js<br />
* @rev: 2<br />
*/<br />
if ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgNamespaceNumber' ) == 2 ) {<br />
var titleParts = mw.config.get( 'wgPageName' ).split( '/' );<br />
// Make sure there was a part before and after the slash<br />
// And that the latter is 'skin.js' or 'skin.css'<br />
if ( titleParts.length == 2 ) {<br />
var userSkinPage = titleParts.shift() + '/' + mw.config.get( 'skin' );<br />
if ( titleParts.slice(-1) == 'skin.js' ) {<br />
window.location.href = mw.util.wikiGetlink( userSkinPage + '.js' );<br />
} else if ( titleParts.slice(-1) == 'skin.css' ) {<br />
window.location.href = mw.util.wikiGetlink( userSkinPage + '.css' );<br />
}<br />
}<br />
}<br />
<br />
/** Map addPortletLink to mw.util <br />
*/<br />
window.addPortletLink = function() {<br />
return mw.util.addPortletLink.apply( mw.util, arguments );<br />
};<br />
<br />
/** extract a URL parameter from the current URL **********<br />
*<br />
* @deprecated: Use mw.util.getParamValue with proper escaping<br />
*/<br />
window.getURLParamValue = function() {<br />
return mw.util.getParamValue.apply( mw.util, arguments );<br />
};<br />
<br />
/** &withCSS= and &withJS= URL parameters *******<br />
* Allow to try custom scripts from MediaWiki space <br />
* without editing personal .css or .js files<br />
*/<br />
var extraCSS = mw.util.getParamValue("withCSS");<br />
if ( extraCSS && extraCSS.match(/^MediaWiki:[^&<>=%]*\.css$/) ) {<br />
importStylesheet(extraCSS);<br />
}<br />
var extraJS = mw.util.getParamValue("withJS");<br />
if ( extraJS && extraJS.match(/^MediaWiki:[^&<>=%]*\.js$/) ) {<br />
importScript(extraJS);<br />
}<br />
<br />
<br />
/* Import more specific scripts if necessary */<br />
if (wgAction == 'edit' || wgAction == 'submit' || wgPageName == 'Special:Upload') { //scripts specific to editing pages<br />
importScript('MediaWiki:Common.js/edit.js');<br />
}<br />
else if (mw.config.get('wgPageName') == 'Special:Watchlist') { //watchlist scripts<br />
importScript('MediaWiki:Common.js/watchlist.js');<br />
}<br />
if ( wgNamespaceNumber == 6 ) {<br />
importScript('MediaWiki:Common.js/file.js');<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 />
mw.loader.load('//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400');<br />
<br />
<br />
/**<br />
* Load scripts specific to Internet Explorer<br />
*/<br />
if ($.client.profile().name == 'msie') {<br />
importScript('MediaWiki:Common.js/IEFixes.js');<br />
// Import scripts specific to Internet Explorer 6<br />
if ($.client.profile().versionBase == '6') {<br />
importScript('MediaWiki:Common.js/IE60Fixes.js');<br />
}<br />
}<br />
<br />
<br />
/* Test if an element has a certain class<br />
* Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]<br />
*<br />
* @deprecated: Use $(element).hasClass() instead.<br />
*/<br />
window.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 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 />
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 />
} else 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 />
$( LinkFA );<br />
<br />
<br />
/** Collapsible tables *********************************************************<br />
*<br />
* Description: Allows tables to be collapsed, showing only the header. See<br />
* [[Wikipedia:NavFrame]].<br />
* Maintainers: [[User:R. Koot]]<br />
*/<br />
<br />
var autoCollapse = 2;<br />
var collapseCaption = "hide";<br />
var expandCaption = "show";<br />
<br />
window.collapseTable = function( tableIndex ){<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 />
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", "#" );<br />
addHandler( ButtonLink, "click", new Function( "evt", "collapseTable(" + tableIndex + " ); return killEvt( evt );") );<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.firstChild );<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 />
$( createCollapseButtons );<br />
<br />
<br />
/** Dynamic Navigation Bars (experimental) *************************************<br />
*<br />
* Description: See [[Wikipedia:NavFrame]].<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 />
window.toggleNavigationBar = function(indexNavigationBar){<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 />
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 />
NavToggle.style.color = NavFrame.childNodes[j].style.color;<br />
NavFrame.childNodes[j].appendChild(NavToggle);<br />
}<br />
}<br />
NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);<br />
}<br />
}<br />
}<br />
<br />
$( 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 />
$(function () {<br />
mw.util.addPortletLink('p-lang', '//meta.wikimedia.org/wiki/List_of_Wikipedias',<br />
'Complete list', 'interwiki-completelist', 'Complete list of Wikipedias');<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 />
ts_alternate_row_colors = false;<br />
<br />
<br />
/***** uploadwizard_newusers ********<br />
* Switches in a message for non-autoconfirmed users at [[Wikipedia:Upload]]<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 />
$(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 />
<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 />
$( '.editsection, #ca-edit' ).find( 'a' ).each( function( i, el ) {<br />
el.href = $(this).attr("href") + '&editintro=' + name;<br />
});<br />
}<br />
<br />
if (wgNamespaceNumber === 0) {<br />
$(function(){<br />
if (document.getElementById('disambigbox')) {<br />
addEditIntro('Template:Disambig_editintro');<br />
}<br />
});<br />
<br />
$(function(){<br />
var cats = document.getElementById('mw-normal-catlinks');<br />
if (!cats) {<br />
return;<br />
}<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 ( mw.config.get('wgServer') == 'https://secure.wikimedia.org' ) {<br />
/* Old secure server */<br />
importScript( 'MediaWiki:Common.js/secure.js');<br />
} else if( document.location && document.location.protocol && document.location.protocol == "https:" ) {<br />
/* New secure servers */<br />
importScript('MediaWiki:Common.js/secure new.js');<br />
}<br />
<br />
/* End of mw.loader.using callback */<br />
} );<br />
/* DO NOT ADD CODE BELOW THIS LINE */</div>
Yoshiro