MediaWiki:Common.js

/* Test if an element has a certain class ************************************** * * Description: Uses regular expressions and caching for better performance. * Taken from Wikipedia's Common.js. */ var hasClass = (function {     var reCache = {};     return function (element, className) {         return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);    }; });

/** Collapsible tables ********************************************************* * *  Description: Allows tables to be collapsed, showing only the header. See *              NavFrame. * Taken from Wikipedia's Common.js. */ 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  // ============================================================ // displayTimer // ============================================================ var refreshDate; function addDate {    var UTCDate = ((new Date).toUTCString).replace("GMT", "(UTC)");    $('#showdate').empty.append(' ' + UTCDate.substring(5) + ' ');   window.clearTimeout(refreshDate);    refreshDate = window.setTimeout(addDate, 5000); } $(document).ready(function { if (skin == 'oasis') $(' ').appendTo('#GlobalNavigation'); else $('#p-personal ul').prepend(' '); addDate; refreshDate = window.setTimeout(addDate, 5000); $('#displayTimer').css({'font-size': "12px"}); }); // /**/ if (mwCustomEditButtons) {  mwCustomEditButtons[mwCustomEditButtons.length] = {     "imageFile": "http://images.wikia.com/central/images/c/c8/Button_redirect.png",     "speedTip": "Redirect",     "tagOpen": "#REDIRECT ",     "tagClose": "",     "sampleText": "Insert text"}; } var ArchiveToolConfig = {    archiveListTemplate: 'ArchiveList',   archivePageTemplate: 'Archive',   archiveSubpage: 'Archive',   userLang: true }; importScriptPage('ArchiveTool/code.js', 'dev'); importScriptPage('DisableArchiveEdit/code.js', 'dev'); $(function { var m, userName = false; if (-1 != [2,1200,3,500,501].indexOf(wgNamespaceNumber) && (m = wgPageName.match(/(?:\:|%3[aA])([^\/]+)/))) { userName = m[1]; } else if (-1 != 'Following Contributions'.indexOf(wgCanonicalSpecialPageName)) { userName = wgUserName; }   if (userName) { function ISODateNDaysAgo (days) { function pad (n) { return n < 10 ? '0' + n : n; } function ISODateString (d) { return   d.getUTCFullYear + '-' + pad(d.getUTCMonth+1) + '-' + pad(d.getUTCDate)   + 'T'                      + pad(d.getUTCHours)   + ':' + pad(d.getUTCMinutes) + ':' + pad(d.getUTCSeconds) + 'Z'; }           return ISODateString(new Date(Date.now - days * 24 * 60 * 60 * 1000)); }       var apiUrl = '/api.php?action=query&list=usercontribs&uclimit=1&ucprop=title|timestamp&format=json' + '&ucuser=' + userName + '&ucstart=' + ISODateNDaysAgo(0) + '&ucend='  + ISODateNDaysAgo(3 * 30); $.getJSON(apiUrl, function (result) {           if (typeof result.query != 'undefined' && typeof result.query.usercontribs != 'undefined' && !result.query.usercontribs.length) {               $(' inactive ').appendTo('#UserProfileMasthead hgroup').css({ backgroundColor: 'rgb(360,360,360)', color: 'rgb(80,80,80)' });           }        });    } }); function hasGroup(group) {    for (var i in wgUserGroups) {        if (wgUserGroups[i] == group) return true;    }    return false; } /* Shows messages for Admins */ function showAdmMessage {    if (hasGroup('sysop')) {        $('.adminmessage').css({'display': 'block !important'});    } }

addOnloadHook(showAdmMessage); importScriptPage('AutoEditDropdown/code.js', 'dev'); importScriptPage('FixWantedFiles/code.js', 'dev');

// http://dev.wikia.com/wiki/RevealAnonIP importScriptPage('RevealAnonIP/code.js', 'dev'); ajaxCallAgain = [RevealAnonIP];

/* Histats Counter */ var _Hasync= _Hasync|| []; _Hasync.push(['Histats.start', '1,2031268,4,0,0,0,00010000']); _Hasync.push(['Histats.fasi', '1']); _Hasync.push(['Histats.track_hits', '']); (function { var hs = document.createElement('script'); hs.type = 'text/javascript'; hs.async = true; hs.src = ('http://s10.histats.com/js15_as.js'); (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(hs); }); /* End */