User:R'n'B/ndr.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:R'n'B/ndr. |
/* 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 1.17, and jQuery 1.4.2 (included with MediaWiki)
*/
// Version 0.2; 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">'
);
this.cookiename = ("NDR" +
/Non-disambiguation_redirects\/([0-9]{3})/
.exec(mw.config.get("wgPageName"))[1]
);
return app.getnextrow();
},
getnextrow: function () {
var m, firstrow = mw.cookie.get(this.cookiename);
console.log(firstrow, $('table tr').eq(this.rowindex).find('td').eq(0).text());
if (firstrow !== undefined &&
$('table tr').eq(this.rowindex).find('td').eq(0).text()
< firstrow) {
return app.skipbutton();
}
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.originaltarget = $('td', this.$activerow).eq(1).text();
this.target = $('td', this.$activerow).eq(2).text();
this.originaltarget = (this.originaltarget == "-") ? this.target : this.originaltarget;
this.blcount = $('td', this.$activerow).eq(3).text().trim();
this.ablcount = $('td', this.$activerow).eq(4).text().trim();
m = this.redirect.match(/^(.*) \(disambiguation\)$/);
if (!m || this.ablcount !== "0" ||
$('td', this.$activerow).eq(0).children('a').hasClass("new")) {
this.$activerow = null;
return app.skipbutton();
}
$('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");
mw.cookie.set(this.cookiename, this.redirect);
},
// 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#G14|G14]]: Unnecessary disambiguation page');
console.log(url);
window.open(url, "_blank");
$('td', app.$activerow).eq(0).find('a').addClass('new').removeClass('external');
return app.skipbutton();
},
skipbutton: function () {
// skip this item and go to the next
app.rowindex += 1;
if (app.rowindex < app.numrows) {
return app.getnextrow();
} else {
mw.cookie.set(this.cookiename, null);
}
}
};
startup = function () {
if (mw.RnB) {
mw.loader.using('mediawiki.cookie', function() {app.setup();});
} else {
setTimeout(startup, 100);
}
};
$(startup);
} (jQuery));