Jump to content

User:Technical 13/Scripts/OrphanStatus.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Technical 13 (talk | contribs) at 02:27, 3 December 2014 (ce (eventually I have to get it all right, right?)). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
if(mw.config.get('wgNamespaceNumber') === 0 && $.inArray("All orphaned articles", mw.config.get('wgCategories')) >= 0){
	function deOrphan(backLinks){
		var deOrphanerRequest = {
			action:"query",
			titles: mw.config.get( 'wgPageName' ),
			prop: "revisions",
			intoken: "edit",
			rvprop: "content",
			indexpageids: 1,
			dataType: "xml",
			format: "xml"
		};
		$.get(mw.config.get( 'wgScriptPath' )+"/api.php", deOrphanerRequest, function(deOrphanerResponse){
			var deOrphanerContent = $(deOrphanerResponse).find('rev').text();
			var deOrphanerSubmit = {
				action: "edit",
				titles: mw.config.get( 'wgPageName' ),
				text: deOrphanerContent.replace(/\{\{Orphan(.*?)\}\}\n/gi, ""),
				summary: "Article [[User:Technical_13/Scripts/OrphanStatus|deOrphaned]]!",
				token: mw.user.tokens.get( 'editToken' )
			};
			console.log("Replacement wikitext:\n%s", deOrphanerContent.replace(/\{\{Orphan(.*?)\}\}\n/gi, ""));
			$.when(
				$.post(mw.config.get( 'wgScriptPath' )+"/api.php", deOrphanerSubmit, function(deOrphanerSesponse){
					$(".loadinganimation").html("Article deOrphanin in progress..."); })
            ).done(function() {
				$(".loadinganimation").html("Article deOrphaned!");
			});
		});
	}
	$('#firstHeading').append('&nbsp; <span class="loadinganimation" style="font-size: medium !important; color: #000 !important; font-family: sans-serif !important;">•   •&nbsp;&nbsp;•&nbsp;&nbsp;</span> ');
	var loadingAnimation = window.setInterval( function() { ($(".loadinganimation").html() == "•   •&nbsp;&nbsp;•&nbsp;&nbsp;" ? $(".loadinganimation").html("&nbsp;•   •&nbsp;&nbsp;•&nbsp;") :  ($(".loadinganimation").html() == "&nbsp;•   •&nbsp;&nbsp;•&nbsp;" ? $(".loadinganimation").html("&nbsp;&nbsp;•   •&nbsp;&nbsp;•") :  ($(".loadinganimation").html() == "&nbsp;&nbsp;•   •&nbsp;&nbsp;•" ? $(".loadinganimation").html("&nbsp;•&nbsp;&nbsp;•   •&nbsp;") :  $(".loadinganimation").html("•   •&nbsp;&nbsp;•&nbsp;&nbsp;")))) }, 250);
	var requestBacklinks = {
		action: "query",
		list: "backlinks",
		format: "json",
		blfilterredir: "nonredirects",
		bllimit: 3,
		blnamespace: 0,
		bltitle: mw.config.get('wgTitle')
	};
	$.get(mw.config.get( 'wgScriptPath' )+"/api.php", requestBacklinks, function(responseBacklinks){
		var backLinks = responseBacklinks.query.backlinks.length;
		switch (backLinks){
			case 0:
				var blStatement = 'This page is an <a href="/wiki/Wikipedia:Orphan" style="font-weight: bold;">orphan</a> as no <a href="/w/index.php?title=Special:WhatLinksHere/' + mw.config.get('wgTitle') + '&namespace=0&hideredirs=1&hidetrans=1" style="font-weight: bold;">other articles</a> link to it.';
				break;
			case 1:
				var blStatement = 'There is <b>1 link to this page</b> from an <a href="/w/index.php?title=Special:WhatLinksHere/' + mw.config.get('wgTitle') + '&namespace=0&hideredirs=1&hidetrans=1" style="font-weight: bold;">other article</a>. <small>(<a href="#deOrphan" onClick="deOrphan(' + backLinks + ');" style="font-weight: bold;">deOrphan</a>)</small>';
				break;
			case 2:
				var blStatement = 'There are <b>2 links to this page</b> from <a href="/w/index.php?title=Special:WhatLinksHere/' + mw.config.get('wgTitle') + '&namespace=0&hideredirs=1&hidetrans=1" style="font-weight: bold;">other articles</a>. <small>(<a href="#deOrphan" onClick="deOrphan(' + backLinks + ');" style="font-weight: bold;">deOrphan</a>)</small>';
				break;
			default:
				var blStatement = 'This page is not an <a href="/wiki/Wikipedia:Orphan" style="font-weight: bold;">orphan</a> as it meets the "Rule of Three" by having three or more links from <a href="/w/index.php?title=Special:WhatLinksHere/' + mw.config.get('wgTitle') + '&namespace=0&hideredirs=1&hidetrans=1" style="font-weight: bold;">other articles</a>.';
				deOrphan(backLinks);
				break;
		}
		clearInterval(loadingAnimation);
		$(".loadinganimation").html(blStatement);
	});
}