MediaWiki:Common.js

// ============================================================ // BEGIN collapsible tables // This script is from Wikipedia. For author attribution, please see http://en.wikipedia.org/w/index.php?title=MediaWiki:Common.js&action=history // ============================================================

/* Test if an element has a certain class ************************************** * * Description: Uses regular expressions and caching for better performance. * Maintainers: User:Mike Dillon, User:R. Koot, User:SG */ // Start debugging block console.log('L4DWiki_PageName:', wgPageName) // End debugging block

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. * Maintainers: User:R. Koot */ /* customized for Left 4 Dead wiki */

var autoCollapse = 1; 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 collapseIndex = 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"; Button.className = "t_show_hide";

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] );

if ( !hasClass( Tables[i], "nocount" ) ) { collapseIndex++; }           tableIndex++; }   }

for ( var i = 0; i < tableIndex; i++ ) { if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( collapseIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) { collapseTable( i ); }        else if ( hasClass( NavigationBoxes[i], "innercollapse" ) ) { var element = NavigationBoxes[i]; while (element = element.parentNode) { if ( hasClass( element, "outercollapse" ) ) { collapseTable ( i ); break; }           }        }    } }

addOnloadHook( createCollapseButtons );

// ============================================================ // END collapsible tables // This script is from Wikipedia. For author attribution, please see http://en.wikipedia.org/w/index.php?title=MediaWiki:Common.js&action=history // ============================================================

importArticles({   type: "script",    articles: [        "w:c:dev:MediaWiki:Countdown/code.js"    ] });

///////////////////////////////////////////////////////////////////////////////////////////////////////////

// ADVANCED AUTO REFRESHING RECENT CHANGES AND WATCHLIST // Code courtesy of "pcj" of WoWWiki.

// WHAT IT DOES // The code adds a checkbox at the top of Special:RecentChanges and Special:Watchlist, next to the header. // Ticking this sets a cookie (specific to each wiki) and starts updating the list. // This occurs silently every 60 seconds without a full page reload occurring.

///////////////////////////////////////////////////////////////////////////////////////////////////////////

ajaxPages="Special:RecentChanges,Special:Watchlist,";

function setCookie(c_name,value,expiredays) { var exdate=new Date exdate.setDate(exdate.getDate+expiredays) document.cookie=c_name+ "=" +escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString) }

function getCookie(c_name) { if (document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "=") if (c_start!=-1) { c_start=c_start + c_name.length+1 c_end=document.cookie.indexOf(";",c_start) if (c_end==-1) c_end=document.cookie.length return unescape(document.cookie.substring(c_start,c_end)) } } return "" }

function getXmlHttpRequestObject { if (window.XMLHttpRequest) { return new XMLHttpRequest; //Not Internet Explorer } else if(window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); //Internet Explorer } else { //fail silently } } getRCDataRO = getXmlHttpRequestObject; var cr = new RegExp("\r", "gm"); var lf = new RegExp("\n", "gm"); var endText = new RegExp(' [\t\s]*?[\t\s]*? ', "mi"); var rcTimer; var rcRefresh = 60000; function preloadAJAXRC { if (skin == "monaco") { s = 1; } else { s = 0; } ajaxRCCookie = (getCookie("ajaxload-"+wgPageName)=="on") ? true:false; document.getElementsByTagName("h1")[0].innerHTML += ' AJAX: '; document.getElementById("ajaxRCtoggle").checked = ajaxRCCookie; if (getCookie("ajaxload-"+wgPageName)=="on") loadRCData; }

function toggleRC { if (document.getElementById("ajaxRCtoggle").checked == true) { setCookie("ajaxload-"+wgPageName, "on", 30); loadRCData; } else { setCookie("ajaxload-"+wgPageName, "off", 30); clearTimeout(rcTimer); } }

function loadRCData { if (getRCDataRO.readyState == 4 || getRCDataRO.readyState == 0) { if (location.href.indexOf("/wiki/")) { rcURL = "http://" + location.hostname + "/wiki/" + wgPageName + location.search; } else { rcURL = "http://" + location.hostname + "/" + wgPageName + location.search; }

//rcURL = 'http://disneyparks.wikia.com/index.php?title=Special:RecentChanges&from=20080930151557&days=30&limit=500&hideminor=0';

getRCDataRO.open("GET", rcURL, true); getRCDataRO.onreadystatechange = parseRCdata; getRCDataRO.send(null); } }

function parseRCdata { if (getRCDataRO.readyState == 4) { textFilter = new RegExp(' .*? [\t\s]*?[\t\s]*? ', "i"); rawRCdata = getRCDataRO.responseText.replace(cr, "").replace(lf, ""); filteredRCdata = textFilter.exec(rawRCdata); updatedText = filteredRCdata[0].replace(' ', "").replace(endText, ""); document.getElementById("bodyContent").innerHTML = updatedText + document.getElementById("bodyContent").innerHTML; rcTimer = setTimeout("loadRCData;", rcRefresh); } }

if (ajaxPages.indexOf(wgPageName)!=-1) { addOnloadHook(preloadAJAXRC); }

// ============================================================ // BEGIN username display // ============================================================

function displayUsername { const Elements = document.getElementsByTagName( "span" ); for ( var i = 0; i < Elements.length; i++ ) { if ( hasClass( Elements[i], "current-user" ) ) { Elements[i].innerHTML = "Username"; } } }

addOnloadHook( displayUsername );

// ============================================================ // END collapsible tables // This script is from Wikipedia. For author attribution, please see http://en.wikipedia.org/w/index.php?title=MediaWiki:Common.js&action=history // ============================================================

///////////////////////////////////////////////////////////////////////////////////////////////////////////

// END OF CODE

///////////////////////////////////////////////////////////////////////////////////////////////////////////

var SA = window.SA || {}; SA.widget = SA.widget || {}; SA.widget.info = {}; SA.widget.info.data = {}; SA.widget.info.fn = {}; SA.widget.info.fn.ui = {}; SA.widget.info.fn.ui.loader = {}; SA.widget.info.fn.ui.table = {}; SA.widget.info.fn.data = {}; SA.widget.info.fn.ui.loader.updateLoadingIcon = function( m ) { document.getElementById( 'sa-user-info' ).textContent = m; }; SA.widget.info.fn.ui.loader.loggedIn = function { var message; if ( typeof SA.widget.info.data.userName === 'string' ) { message = 'Loading your data ' + SA.widget.info.data.userName + '! One moment...'; SA.widget.info.fn.ui.loader.updateLoadingIcon( message ); SA.widget.info.data.status = true; } else { message = 'Please login to use this widget!'; SA.widget.info.fn.ui.loader.updateLoadingIcon( message ); SA.widget.info.data.status = false; } }; SA.widget.info.fn.ui.table.init = function { SA.widget.info.data.table = document.createElement( 'table' ); SA.widget.info.data.tableHeading = document.createElement( 'tr' ); SA.widget.info.data.tableBody = document.createElement( 'tr' ); SA.widget.info.data.table.setAttribute( 'class', 'wikitable' ); }; SA.widget.info.fn.ui.table.addEntry = function( k, v ) { var col, row; if ( k === 'registration' ) { v = SA.widget.info.fn.data.parseTimeStamp( v ); } row = document.createElement( 'td' ); row.textContent = k; col = document.createElement( 'td' ); col.textContent = v; SA.widget.info.data.tableHeading.appendChild( row ); SA.widget.info.data.tableBody.appendChild( col ); }; SA.widget.info.fn.ui.table.print = function { SA.widget.info.data.table.appendChild( SA.widget.info.data.tableHeading ); SA.widget.info.data.table.appendChild( SA.widget.info.data.tableBody ); document.getElementById( 'sa-user-info' ).textContent = ''; document.getElementById( 'sa-user-info' ).appendChild( SA.widget.info.data.table ); }; SA.widget.info.fn.data.parseTimeStamp = function( ts ) { var endings = [ 'st', 'nd', 'rd', 'th' ]; var months = { '01': 'January', '02': 'February', '03': 'March', '04': 'April', '05': 'May', '06': 'June', '07': 'July', '08': 'August', '09': 'September', '10': 'October', '11': 'November', '12': 'December' }; var stamps = ts.split( 'T' ); stamps[1] = stamps[1].replace( 'Z', '' ); stamps[0] = stamps[0].split( '-' ); if ( parseInt( stamps[0][2] ) < 10 ) { stamps[0][2] = stamps[0][2].replace( '0', '' ); } if ( stamps[0][2] === '1' ) { stamps[0][2] += endings[0]; } else if ( stamps[0][2] === '2' ) { stamps[0][2] += endings[1]; } else if ( stamps[0][2] === '3' ) { stamps[0][2] += endings[2]; } else { stamps[0][2] += endings[3]; } return months[stamps[0][1]] + ' ' + stamps[0][2] + ', ' + stamps[0][0] + ' at ' + stamps[1] + ' (UTC)'; }; SA.widget.info.fn.data.fetchUserInfo = function { $.ajax({   crossDomain: true,    url: 'https://community.wikia.com/api.php',    type: 'POST',    data: {      action: 'query',      list: 'users',      ususers: SA.widget.info.data.userName,      usprop: 'registration|gender',      format: 'json'    },    dataType: 'JSONP',    success: function( data ) {      data = $(data['query']['users']);      data = data[0];      console.log( data );      SA.widget.info.fn.ui.table.init;      for (var key in data) {        SA.widget.info.fn.ui.table.addEntry( key, data[key] );      }      SA.widget.info.fn.ui.table.print;    },    error: function {      var message = 'An error occured while fetching your information!';      SA.widget.info.fn.ui.loader.updateLoadingIcon( message );    },  }); }; SA.widget.info.fn.init = function { SA.widget.info.data.userName = mw.config.get( 'wgUserName' ); SA.widget.info.fn.ui.loader.loggedIn; if ( SA.widget.info.data.status === false ) return; SA.widget.info.fn.data.fetchUserInfo; }; if (document.getElementById("sa-user-info") != null) { SA.widget.info.fn.init; }