Jump to content

User:Writ Keeper/Scripts/backlinkWarner.js

From Wikipedia, the free encyclopedia
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.
$(document).ready(function()
{
	if(mw.config.get("wgAction") == "delete")
	{
		var backlinkWarning = $(".mw-warning.plainlinks");
		if(backlinkWarning.length > 0)
		{
			backlinkWarning.append("<ul id='backlinkWarnings'></ul>");
			var data = {action:"query",list:"backlinks",format:"json",bltitle:mw.config.get("wgPageName"),blnamespace:"0",blfilterredir:"nonredirects",bllimit:"1"};
			$.post("/w/api.php",data, function(response)
			{
				if(response.query.backlinks.length > 0)
				{
					$("#backlinkWarnings").append("<li style='color:red;'>There are pages in mainspace that link to this article.</li>");
				}
			});
			var data = {action:"query",list:"backlinks",format:"json",bltitle:mw.config.get("wgPageName"),blfilterredir:"redirects",bllimit:"1"};
			$.post("/w/api.php",data, function(response)
			{
				if(response.query.backlinks.length > 0)
				{
					$("#backlinkWarnings").append("<li style='color:red;'>There are pages that redirect to this article.</li>");
				}
			});
			var data = {action:"query",list:"embeddedin",format:"json",eititle:mw.config.get("wgPageName"),eilimit:"2"};
			$.post("/w/api.php",data, function(response)
			{
				if(response.query.embeddedin.length > 1 || (response.query.embeddedin.length == 1 && response.query.embeddedin[0].title.replace(/ /g,"_") != mw.config.get("wgPageName")))
				{
					$("#backlinkWarnings").append("<li style='color:red;'>There are pages that transclude this page.</li>");					
				}
			});
		}
	}
});