Jump to content

User:R'n'B/ndr.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by R'n'B (talk | contribs) at 18:02, 14 February 2012 (fix). 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.
/* ndr.js : Wikipedia app to process non-disambiguation redirect lists
 * Copyright (c) 2012 [[en:User:R'n'B]]
 *  Creative Commons Attribution-ShareAlike License applies
 * Requires MediaWiki and jQuery (included with MediaWiki)
 */
// Version 0.1; alpha release
/*global console, mw, jQuery, importScript */
(function ($) {
	// pseudo-global variables
	var app,
		startup;
	importScript("User:R'n'B/wrappi.js");
	mw.util.addCSS(
'ul {\
    line-height: 1.5em;\
    list-style-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAANCAMAAABW4lS6AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRFAFKM////QIUK9QAAAAJ0Uk5T/wDltzBKAAAAGklEQVR42mJgBAEGokgGBjBGBxBxsBqAAAMACHwALd5r8ygAAAAASUVORK5CYII=");\
    list-style-type: square;\
    margin: 0.3em 0 0 1.5em;\
    padding: 0;\
}\
.pagehistory li {\
    border: 1px solid white;\
}\
li {\
    margin-bottom: 0.1em;\
}'
	);
	app = mw.RnB.ndr = {
        $activerow: null,
		setup: function () {
			this.rowindex = 1; // start at 1 because 0 is header row
			this.numrows = $('table tr').length;
			this.dummyform = $('<span id="dummyform"></span').html(
'<input id="delbtn" type="button" value="Delete">\
<input id="skipbtn" type="button" accesskey="i" value="Skip">'
				);
            return app.getnextrow();
		},
        getnextrow: function () {
			var m;
            if (this.$activerow !== null) {
				$('#dummyform').detach();
				this.$activerow.css("font-weight", "normal");
            }
            this.$activerow = $('table tr').eq(this.rowindex);
			this.redirect = $('td', this.$activerow).eq(0).text();
			this.target = $('td', this.$activerow).eq(1).text();
			this.blcount = $('td', this.$activerow).eq(2).text();
			this.ablcount = $('td', this.$activerow).eq(3).text();
			m = this.redirect.match(/^(.*) \(disambiguation\)$/);
			if (!m || this.blcount !== "0" || 
					$('td', this.$activerow).eq(0).children('a').hasClass("new")) {
				this.$activerow = null;
				return app.skipbutton();
			}
			this.originaltarget = m[1];
			$('td', this.$activerow).eq(0).append(this.dummyform);
			$('#delbtn').unbind('click', app.delbutton);
			$('#skipbtn').unbind('click', app.skipbutton);
			$('#delbtn').click(app.delbutton);
			$('#skipbtn').click(app.skipbutton);
			this.$activerow.css("font-weight", "bold");
        },
		// DON'T USE this IN THE FOLLOWING EVENT HANDLERS!
		delbutton: function () {
			var url = mw.config.get("wgServer") + mw.config.get("wgScript")
				+ "?title=" + mw.util.wikiUrlencode(app.redirect)
				+ "&action=delete&wpReason="
				+ mw.util.rawurlencode('[[WP:CSD#G6|G6]]: Housekeeping and routine (non-controversial) cleanup: a "disambiguation" redirect to a target that is not a disambiguation page');
			console.log(url);
			window.open(url, "_blank");
			return app.skipbutton();
		},
		skipbutton: function () {
			// skip this item and go to the next
			app.rowindex += 1;
			if (app.rowindex < app.numrows) {
				return app.getnextrow();
			}
		}
	};
	mw.loader.using(
		['jQuery.makeCollapsible'],
		app.setup
	);
} (jQuery));