User:Derfel/global.js

ShoutWiki — express yourself and be heard!
Jump to: navigation, search
// *****************************************************************
// Splarka's fastdelete.js
// *****************************************************************
if( wgNamespaceNumber != -1 && !window.DeleteButtonsLoaded ) {
	addOnloadHook( addDeleteButtons );
}
var DeleteButtonsLoaded = true; // prevent duplication

// Add delete buttons depending on skin
function addDeleteButtons() {
	if( !window.fdButtons ) {
		return;
	}

	switch( skin ) {
		case 'chick': /* pass to monobook */
		case 'simple': /* pass to monobook */
		case 'myskin': /* pass to monobook */
		case 'monobook':
			if( !document.getElementById( 'ca-delete' ) ) {
				return;
			}
			var url = document.getElementById('ca-delete').firstChild.href;
			for( var i = 0; i < fdButtons.length; i++ ) {
				if( fdButtons[i].hotkey ) {
					addPortletLink(
						'p-cactions',
						wgScriptPath + '/index.php?title=' +
							encodeURIComponent( wgPageName ) +
							'&action=delete&submitdelete=true&wpReason=' +
							encodeURIComponent( fdButtons[i].summary ),
						fdButtons[i].label,
						'ca-delete' + i,
						'one-click delete: ' + fdButtons[i].summary,
						fdButtons[i].hotkey
					);
				} else {
					addPortletLink(
						'p-cactions',
						wgScriptPath + '/index.php?title=' +
							encodeURIComponent( wgPageName ) +
							'&action=delete&submitdelete=true&wpReason=' +
							encodeURIComponent( fdButtons[i].summary ),
						fdButtons[i].label,
						'ca-delete' + i,
						'one-click delete: ' + fdButtons[i].summary
					);
				}
			}
		break;

		case 'classic': break; /* not supported yet */
		case 'standard': break; /* not supported yet */
		case 'cologneblue': break; /* not supported yet */
		case 'nostalgia': break; /* not supported yet */

		case 'monaco':
			if( !document.getElementById( 'ca-delete' ) ) {
				return;
			}
			for( var i = 0; i < fdButtons.length; i++ ) {
				addPageBarlink(
					wgScriptPath + '/index.php?title=' +
						encodeURIComponent( wgPageName ) +
						'&action=delete&submitdelete=true&wpReason=' +
						encodeURIComponent( fdButtons[i].summary ),
					fdButtons[i].label
				);
			}
		break;

		case 'phpbb':
			if( !document.getElementById( 'ca-delete' ) ) {
				return;
			}
			for( var i = 0; i < fdButtons.length; i++ ) {
				addToPhpbbTabs(
					wgScriptPath + '/index.php?title=' +
						encodeURIComponent( wgPageName ) +
						'&action=delete&submitdelete=true&wpReason=' +
						encodeURIComponent( fdButtons[i].summary ),
					fdButtons[i].label
				);
			}
		break;
	}
}

addOnloadHook( checkdelete );
function checkdelete() {
	if( queryString( 'autoclose' ) == 'true' && document.getElementById( 'deleteconfirm' ) ) {
		document.getElementById( 'deleteconfirm' ).action += '&autoclose=now';
		document.getElementById( 'deleteconfirm' ).target = '_top';
	}
	if( queryString( 'submitdelete' ) == 'true' ) {
		if ( document.getElementById( 'mw-filedelete-submit' ) ) {
			var btn = document.getElementById( 'mw-filedelete-submit' );
		} else {
			var btn = document.getElementById( 'wpConfirmB' );
		}
		btn.click();
	}
	if( queryString( 'autoclose' ) == 'now' ) {
		try {
			window.close();
		} catch( e ) {
			// not a JS-created window.
		}
	}
}

function queryString( p ) {
	var re = RegExp('[&?]' + p + '=([^&]*)');
	var matches;
	if( matches = re.exec( document.location ) ) {
		try {
			return decodeURI( matches[1] );
		} catch( e ) {
		}
	}
	return null;
}

// Monaco support
function addPageBarlink( url, text ) {
	var pc = document.getElementById( 'page_controls' );
	if( pc.length < 1 ) {
		return;
	}
	var d = document.createElement( 'div' );
	var link = document.createElement( 'a' );
	link.href = url;
	link.appendChild( document.createTextNode( text ) );
	var nuli = document.createElement( 'li' );
	nuli.id = 'control_delete';
	nuli.appendChild( d );
	nuli.appendChild( link );
	pc.appendChild( nuli );
}

// phpBB support
function addToPhpbbTabs( url, text ) {
	var tabs = document.getElementById( 'tabs' );
	if( tabs.length < 1 ) {
		return;
	}
	var s = document.createElement( 'span' );
	var link = document.createElement( 'a' );
	link.href = url;
	link.appendChild( s );
	s.appendChild( document.createTextNode( text ) );
	var nuli = document.createElement( 'li' );
	nuli.id = 'ca-delete';
	nuli.appendChild( link );
	tabs.appendChild( nuli );
}

// *****************************************************************
// Load various external scripts
// *****************************************************************
// Zocky's SearchBox (search 'n' replace utility)
//importScriptURI('http://en.wikipedia.org/w/index.php?title=User:Zocky/SearchBox.js&action=raw&ctype=text/javascript&dontcountme=s');

// *****************************************************************
// Custom automatic delete buttons
// *****************************************************************
// Adds customizable one-click deletion buttons to any deletable page.
// Requires Splarka's fastdelete.js
var fdButtons = [];
if( typeof( wgContentLanguage ) != 'undefined' && wgContentLanguage != 'fi' ) {
	// For non-Finnish wikis
	fdButtons[fdButtons.length] = {
		'summary': '[[s:Help:Spam|spam]]',
		'label': 'S'
	};
	fdButtons[fdButtons.length] = {
		'summary': 'Vandalism',
		'label': 'V'
	};
        fdButtons[fdButtons.length] = {
		'summary': 'Housekeeping',
		'label': 'H'
	};
} 

// *****************************************************************
// Purge tab on every non-special page
// By Splarka
// *****************************************************************
if( wgNamespaceNumber > -1 ) {
	addOnloadHook(
		function() {
			addPortletLink(
				'p-cactions',
				wgServer + wgScript + '?title=' +
					encodeURIComponent( wgPageName ) + '&action=purge',
				'purge'
			);
		}
	);
}


// *****************************************************************
// &bot=1 on contribs pages for Monobook skin.
// *****************************************************************
function hiderollback() {
	var botlink = document.location.href;
	if( botlink.indexOf('?') == -1 ) {
		botlink += '?bot=1';
	} else {
		botlink += '&bot=1';
	}
	addPortletLink( 'p-cactions', botlink, '&bot=1', 'ca-bot' );
}
if( ( skin == 'monobook' ) && ( wgCanonicalSpecialPageName == 'Contributions' ) ) {
	addOnloadHook( hiderollback );
}


// *****************************************************************
// Code courtesy of pcj of WoWWiki.
// This is a modified version of the WoWWiki site version, in that it is designed for global.js use.
 
// Code adds a checkbox at the top of the Special:RecentChanges list, next to the header.
// Ticking it sets a cookie (should be individual to wikis) and starts updating the RC list.
// This occurs silently without a full page reload occurring.
// *****************************************************************
 
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('</div>[\t\s]*?<!-- end content -->[\t\s]*?<div class="visualClear">', "mi");
var rcTimer;
var rcRefresh = 15000;
function preloadAJAXRC() {
if (skin == "monaco") {
s = 1;
} else {
s = 0;
}
ajaxRCCookie = getCookie("ajaxRC")=="on" ? true:false;
document.getElementsByTagName("h1")[0].innerHTML += '&nbsp;<span style="font-size: xx-small; border-bottom: 1px dotted; cursor:help;" title="Enable auto-refreshing recent changes">AJAX auto-refresh:</span><input type="checkbox" id="ajaxRCtoggle" onClick="toggleRC();">';
document.getElementById("ajaxRCtoggle").checked = ajaxRCCookie;
if (getCookie("ajaxRC")=="on") loadRCData();
}
 
function toggleRC() {
if (document.getElementById("ajaxRCtoggle").checked == true) {
setCookie("ajaxRC", "on", 30);
loadRCData();
} else {
setCookie("ajaxRC", "off", 30);
clearTimeout(rcTimer);
}
}
 
function loadRCData() {
if (getRCDataRO.readyState == 4 || getRCDataRO.readyState == 0) {
if (location.href.indexOf("/wiki/")) {
rcURL = "http://" + location.hostname + "/wiki/Special:RecentChanges" + location.search;
} else {
rcURL = "http://" + location.hostname + "/Special:RecentChanges" + location.search;
}
getRCDataRO.open("GET", rcURL, true);
getRCDataRO.onreadystatechange = parseRCdata;
getRCDataRO.send(null);
}
}
 
function parseRCdata() {
if (getRCDataRO.readyState == 4) {
textFilter = new RegExp('<div id="bodyContent">.*?</div>[\t\s]*?<!-- end content -->[\t\s]*?<div class="visualClear">', "i");
rawRCdata = getRCDataRO.responseText.replace(cr, "").replace(lf, "");
filteredRCdata = textFilter.exec(rawRCdata);
updatedText = filteredRCdata[0].replace('<div id="bodyContent">', "").replace(endText, "");
document.getElementById("bodyContent").innerHTML = updatedText;
rcTimer = setTimeout("loadRCData();", rcRefresh);
}
}
 
if (wgPageName == "Special:RecentChanges") addOnloadHook(preloadAJAXRC);