User:Lyrithya/deathlist.js

From Uncyclopedia, the content-free encyclopedia
Jump to navigation Jump to search

Note: After saving, you have to bypass your browser's cache to see the changes.

  • Internet Explorer: hold down the Ctrl key and click the Refresh or Reload button, or press Ctrl+F5.
  • Firefox: hold down the Shift key while clicking Reload; alternatively press Ctrl+F5 or Ctrl-Shift-R.
  • Opera, Konqueror and Safari users can just click the Reload button.
  • Chrome: press Ctrl+F5 or Shift+F5
// <nowiki>
deathlist = {};

deathlist.addDEATHLIST = function() {
	if (wgCanonicalNamespace == "File"){
		addPortletLink('p-cactions', 'javascript:deathlist.go(0)', 'Deathlist', 'td-deathlist', 'Add file to deathlist');
	} else if (document.getElementById('ca-history')) {
		addPortletLink('p-cactions', 'javascript:deathlist.go(0)', 'Deathlist', 'td-deathlist', 'Add page to deathlist');
		//addPortletLink('p-cactions', 'javascript:deathlist.go(1)', 'deathlist-C', 'td-deathlistc', 'Add page to deathlist, with a comment');
	};
}
deathlist.debugOutput = function(str) {
	deathlist.output += str;
	deathlist.panel.setBody(deathlist.output);
}
deathlist.debugStatus = function(i) {
	var s = (i) ? 'green;"> [OK]' : 'red;"> [FAILED]';
	deathlist.debugOutput('<span style="font-weight: bold;color:' + s + '</span>');
}

deathlist.go = function(page) {
	//deathlist.comment = (com) ? " - " + escape(prompt("Comment:","")) : '';
	//if (com && deathlist.comment == null) return;
	deathlist.page = (page) ? page : wgPageName.replace(/_/g,' ');
	deathlist.panel = new YAHOO.widget.Panel("deathlist", { width:"240px", fixedcenter:true, draggable:true, zindex:10, modal:false, visible:false } ); 
	deathlist.panel.setHeader('deathlisting, please wait...');
	deathlist.panel.setFooter('<br /><hr>Originally by <a href="/wiki/User:Villahj_Ideeut">Villahj Ideeut</a>, modz by <a href="/wiki/User:Spang">Spang</a> and <a href="/wiki/User:Mitch_1_2">Mitch</a>')
	deathlist.output = '';
	deathlist.debugOutput("<br />Loading deathlist page...");
	deathlist.panel.render(document.body); 
	deathlist.panel.show();
	if (wgCanonicalNamespace == "File")
		YAHOO.util.Connect.asyncRequest('GET', '/api.php?action=query&titles=User:Lyrithya/deathlist/images&prop=revisions|info|links&pllimit=500&rvprop=content&rvlimit=1&rvsection=0&format=xml&intoken=edit', deathlist.update, null);
	else YAHOO.util.Connect.asyncRequest('GET', '/api.php?action=query&titles=User:Lyrithya/deathlist/articles&prop=revisions|info|links&pllimit=500&rvprop=content&rvlimit=1&rvsection=0&format=xml&intoken=edit', deathlist.update, null);
}

deathlist.update = {
	success: function(o) {
		deathlist.debugStatus(1);
		deathlist.debugOutput("<br />Checking deathlist for selected page...");
		var titles = o.responseXML.getElementsByTagName('pl');
		for (lk in titles) {
			try {
				if (titles[lk].getAttribute('title') == deathlist.page) {
					deathlist.debugStatus(0);
					deathlist.debugOutput('<br />Page already on deathlist!<br /><a href="javascript:deathlist.panel.hide()">Close</a>');
					return;
				}
			} catch(e) {};
		}
		deathlist.debugStatus(1);
		deathlist.debugOutput('<br />Page not listed, adding it now...');
		try {
			var sectionText = o.responseXML.getElementsByTagName('rev')[0].firstChild.nodeValue;
			var lines = sectionText.split('\n');
			var redirect = (document.getElementById('contentSub').innerHTML.indexOf('Redirect page') == -1) ? 0 : 1;
			if (redirect == 0) {
				if (wgCanonicalNamespace == "File")
					lines.splice(1,0,'*[[' + deathlist.page + '|12x12px]] [[:' + deathlist.page + ']]');
				else lines.splice(1,0,'*[[:' + deathlist.page + ']]');
			} else {
				lines.splice(1,0,'*{{redirect|' + deathlist.page + '}}');
			};
			sectionText = lines.join('\n');
		} catch(e) {
			deathlist.debugStatus(0);
			deathlist.debugOutput('<br />Could not add text to the page!<br /><a href="javascript:deathlist.panel.hide()">Close</a>');
			return;
		}
		deathlist.debugStatus(1);
		deathlist.debugOutput('<br />Saving page...');
		
		var token = o.responseXML.getElementsByTagName('page')[0].getAttribute('edittoken');
		if (wgCanonicalNamespace == "File")
			var post = 'title=User:Lyrithya/deathlist/images&section=0&token=' + encodeURIComponent(token) + '&summary=Vigilance[[' + encodeURIComponent(deathlist.page) + '|.]]&text=' + encodeURIComponent(unescape(sectionText));
		else var post = 'title=User:Lyrithya/deathlist/articles&section=0&token=' + encodeURIComponent(token) + '&summary=Vigilance[[' + encodeURIComponent(deathlist.page) + '|.]]&text=' + encodeURIComponent(unescape(sectionText));
		YAHOO.util.Connect.asyncRequest('POST', '/api.php?action=edit&format=xml', deathlist.saved, post);
	},
	failure: function() {
		deathlist.debugStatus(0);
		deathlist.debugOutput('<br />Couldn\'t connect to deathlist page!<br /><a href="javascript:deathlist.panel.hide()">Close</a>');
	}
}

deathlist.saved = {
	success: function(o) {
		try {
			result = (o.responseXML.getElementsByTagName('edit')[0].getAttribute('result') == 'Success') ? 1 : 0;
		} catch(e) {
			result = 0;
		}
		if (result) {
			deathlist.debugStatus(1);
			deathlist.debugOutput('<br /><b>Saved!</b><br /><a href="/wiki/User:Lyrithya/deathlist/articles">Go to deathlist</a> or <br /><a href="javascript:deathlist.panel.hide()">close</a>');
		} else {
			with(o.responseXML.getElementsByTagName('error')[0]) {
				deathlist.debugStatus(0);
				if (wgCanonicalNamespace == "File")
					deathlist.debugOutput('<br /><b>Saving failed :(</b><br />Error: ' + getAttribute('code') + ' - ' + getAttribute('info') + '<br /><a href="/wiki/User:Lyrithya/deathlist/images">Add manually</a> or <br /><a href="javascript:deathlist.panel.hide()">close</a>');
				else deathlist.debugOutput('<br /><b>Saving failed :(</b><br />Error: ' + getAttribute('code') + ' - ' + getAttribute('info') + '<br /><a href="/wiki/User:Lyrithya/deathlist/articles">Add manually</a> or <br /><a href="javascript:deathlist.panel.hide()">close</a>');
			}
		}
	},
	failure: function(o) {
		deathlist.debugStatus(0);
		if (wgCanonicalNamespace == "File")
			deathlist.debugOutput('<br /><b>Connection failed :(</b><br /><a href="/wiki/User:Lyrithya/deathlist/images">Go to deathlist</a> or <br /><a href="javascript:deathlist.panel.hide()">close</a>');
		else deathlist.debugOutput('<br /><b>Connection failed :(</b><br /><a href="/wiki/User:Lyrithya/deathlist/articles">Go to deathlist</a> or <br /><a href="javascript:deathlist.panel.hide()">close</a>');
	}
}

// <nowiki>
gallery = {};
 
gallery.addGALLERY = function() {
	if (wgCanonicalNamespace == "File"){
		addPortletLink('p-cactions', 'javascript:gallery.go(0)', 'Gallery', 'td-gallery', 'Add file to gallery');
	};
}
gallery.debugOutput = function(str) {
	gallery.output += str;
	gallery.panel.setBody(gallery.output);
}
gallery.debugStatus = function(i) {
	var s = (i) ? 'green;"> [OK]' : 'red;"> [FAILED]';
	gallery.debugOutput('<span style="font-weight: bold;color:' + s + '</span>');
}
 
gallery.go = function(page) {
	gallery.page = (page) ? page : wgPageName.replace(/_/g,' ');
	gallery.panel = new YAHOO.widget.Panel("gallery", { width:"240px", fixedcenter:true, draggable:true, zindex:10, modal:false, visible:false } ); 
	gallery.panel.setHeader('adding to gallery, please wait...');
	gallery.panel.setFooter('<br /><hr>Originally by <a href="/wiki/User:Villahj_Ideeut">Villahj Ideeut</a>, modz by <a href="/wiki/User:Spang">Spang</a> and <a href="/wiki/User:Mitch_1_2">Mitch</a>')
	gallery.output = '';
	gallery.debugOutput("<br />Loading gallery page...");
	gallery.panel.render(document.body); 
	gallery.panel.show();
	YAHOO.util.Connect.asyncRequest('GET', '/api.php?action=query&titles=User:Lyrithya/deathlist/gallery&prop=revisions|info|links&pllimit=5000&rvprop=content&rvlimit=1&rvsection=0&format=xml&intoken=edit', gallery.update, null);
}
 
gallery.update = {
	success: function(o) {
		gallery.debugStatus(1);
		gallery.debugOutput("<br />Checking gallery for selected page...");
		var titles = o.responseXML.getElementsByTagName('pl');
		for (lk in titles) {
			try {
				if (titles[lk].getAttribute('title') == gallery.page) {
					gallery.debugStatus(0);
					gallery.debugOutput('<br />Page already on gallery!<br /><a href="javascript:gallery.panel.hide()">Close</a>');
					return;
				}
			} catch(e) {};
		}
		gallery.debugStatus(1);
		gallery.debugOutput('<br />Page not listed, adding it now...');
		try {
			var sectionText = o.responseXML.getElementsByTagName('rev')[0].firstChild.nodeValue;
			var lines = sectionText.split('\n');
			lines.splice(1,0,gallery.page);
			sectionText = lines.join('\n');
		} catch(e) {
			gallery.debugStatus(0);
			gallery.debugOutput('<br />Could not add text to the page!<br /><a href="javascript:gallery.panel.hide()">Close</a>');
			return;
		}
		gallery.debugStatus(1);
		gallery.debugOutput('<br />Saving page...');
 
		var token = o.responseXML.getElementsByTagName('page')[0].getAttribute('edittoken');
		var post = 'title=User:Lyrithya/deathlist/gallery&section=0&token=' + encodeURIComponent(token) + '&summary=Vigilance[[' + encodeURIComponent(gallery.page) + '|.]]&text=' + encodeURIComponent(unescape(sectionText));
		YAHOO.util.Connect.asyncRequest('POST', '/api.php?action=edit&format=xml', gallery.saved, post);
	},
	failure: function() {
		gallery.debugStatus(0);
		gallery.debugOutput('<br />Couldn\'t connect to gallery page!<br /><a href="javascript:gallery.panel.hide()">Close</a>');
	}
}
 
gallery.saved = {
	success: function(o) {
		try {
			result = (o.responseXML.getElementsByTagName('edit')[0].getAttribute('result') == 'Success') ? 1 : 0;
		} catch(e) {
			result = 0;
		}
		if (result) {
			gallery.debugStatus(1);
			gallery.debugOutput('<br /><b>Saved!</b><br /><a href="/wiki/User:Lyrithya/deathlist/gallery">Go to gallery</a> or <br /><a href="javascript:gallery.panel.hide()">close</a>');
		} else {
			with(o.responseXML.getElementsByTagName('error')[0]) {
				gallery.debugStatus(0);
				gallery.debugOutput('<br /><b>Saving failed :(</b><br />Error: ' + getAttribute('code') + ' - ' + getAttribute('info') + '<br /><a href="/wiki/User:Lyrithya/deathlist/gallery">Add manually</a> or <br /><a href="javascript:gallery.panel.hide()">close</a>');
			}
		}
	},
	failure: function(o) {
		gallery.debugStatus(0);
		gallery.debugOutput('<br /><b>Connection failed :(</b><br /><a href="/wiki/User:Lyrithya/deathlist/gallery">Go to gallery</a> or <br /><a href="javascript:gallery.panel.hide()">close</a>');
	}
}

YAHOO.util.Event.onContentReady('p-cactions', gallery.addGALLERY);
YAHOO.util.Event.onContentReady('p-cactions', deathlist.addDEATHLIST);

// </nowiki>