User:Evad37/XfdUnlink.js

// This script requires Twinkle < https://en.wikipedia.org/wiki/Wikipedia:Twinkle > to be installed. It is derived from the twinkle unlink module < https://en.wikipedia.org/wiki/MediaWiki:Gadget-twinkleunlink.js >, available under CC BY-SA 3.0 License < https://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License > and the GFDL < https://en.wikipedia.org/wiki/Wikipedia:Text_of_the_GNU_Free_Documentation_License > ////////////////////////

XfdUnlink = function(_presetReason, _targetPage) { console.log("XfdUnlink running..."); var Twinkle_available; if (typeof Twinkle !== 'undefined') { Twinkle_available = true; } else { Twinkle_available = false; //don't attempt to run if twinkle isn't available alert("Error: Twinkle not available. Check that is is enabled in Preferences → Gadgets"); return; } console.log("Twinkle_available = " + Twinkle_available);

presetReason = decodeURIComponent(_presetReason); targetPage = decodeURIComponent(_targetPage);

// $.getScript('https://en.wikipedia.org/w/index.php?title=MediaWiki:Gadget-twinkleunlink.js&action=raw&ctype=text/javascript', function { //	console.log("MediaWiki:Gadget-twinkleunlink.js loaded..."); //  $.getScript('https://en.wikipedia.org/w/index.php?title=Mediawiki:Gadget-morebits.js&action=raw&ctype=text/javascript', function  { //	console.log("Mediawiki:Gadget-morebits.js loaded..."); // $.getScript('https://en.wikipedia.org/w/index.php?title=Mediawiki:Gadget-morebits.css&action=raw&ctype=text/css', function {  // console.log("Mediawiki:Gadget-morebits.css loaded...");

var targetPageEncoded = mw.util.wikiUrlencode(targetPage); var targetPageTitleObj = new mw.Title( targetPageEncoded ); var targetPageNsNumber = targetPageTitleObj.getNamespaceId; var Window = new Morebits.simpleWindow( 600, 440 ); Window.setTitle( "Unlink backlinks" ); Window.setScriptName( "XfdUnlink (via Twinkle)" ); Window.addFooterLink( "Twinkle help", "WP:TW/DOC#unlink" );

var form = new Morebits.quickForm( Twinkle.unlink.callback.evaluate );

// prepend some basic documentation var node1 = Morebits.htmlNode("code", "link text"); var node2 = Morebits.htmlNode("code", "link text"); node1.style.fontFamily = node2.style.fontFamily = "monospace"; node1.style.fontStyle = node2.style.fontStyle = "normal"; form.append( {		type: 'div',		style: 'margin-bottom: 0.5em',		label: [			'This tool allows you to unlink all incoming links ("backlinks") that point to this page' +				(targetPageNsNumber === 6 ? ", and/or hide all inclusions of this file by wrapping them in comment markup" : "") +				". For instance, ",			node1,			" would become ",			node2,			". Use it with caution."		]	} );

form.append( {		type: 'input',		name: 'reason',		label: 'Reason: ',		value: presetReason,		size: 60	} );

var query; if(targetPageNsNumber === 6) { // File: query = { 'action': 'query', 'list': [ 'backlinks', 'imageusage' ], 'bltitle': targetPageEncoded, 'iutitle': targetPageEncoded, 'bllimit': Morebits.userIsInGroup( 'sysop' ) ? 5000 : 500, // 500 is max for normal users, 5000 for bots and sysops 'iulimit': Morebits.userIsInGroup( 'sysop' ) ? 5000 : 500, // 500 is max for normal users, 5000 for bots and sysops 'blnamespace': Twinkle.getPref('unlinkNamespaces'), 'iunamespace': Twinkle.getPref('unlinkNamespaces'), 'rawcontinue': true };	} else { query = { 'action': 'query', 'list': 'backlinks', 'bltitle': targetPageEncoded, 'blfilterredir': 'nonredirects', 'bllimit': Morebits.userIsInGroup( 'sysop' ) ? 5000 : 500, // 500 is max for normal users, 5000 for bots and sysops 'blnamespace': Twinkle.getPref('unlinkNamespaces'), 'rawcontinue': true };	}	var wikipedia_api = new Morebits.wiki.api( 'Grabbing backlinks', query, Twinkle.unlink.callbacks.display.backlinks ); wikipedia_api.params = { form: form, Window: Window, image: mw.config.get('wgNamespaceNumber') === 6 }; wikipedia_api.post;

var root = document.createElement( 'div' ); root.style.padding = '15px'; // just so it doesn't look broken Morebits.status.init( root ); wikipedia_api.statelem.status( "loading..." ); Window.setContent( root ); Window.display;

// }); // }); // });

};