User:Digwuren/tagwpe.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:Digwuren/tagwpe. |
// <nowiki>
// Script for rapid tagging of articles, originally by [[User:DLX|DLX]].
$(WPEButton);
function WPEButton() {
if ((document.URL.indexOf(':', 8) != -1) && (document.URL.indexOf('Talk:') == -1)) return;
if (document.URL.indexOf('/wiki/') == -1) return;
mw.util.addPortletLink(chooseBox('tWP:E', TwinkleConfig.toolboxButtons), "javascript:wpetag()", "Tag WP:E", "", "", "");
}
function wpetag() {
Status.init(document.getElementById('bodyContent'));
Status.status('Checking for redirect: ' + wgPageName);
b=sajax_init_object();
b.open("GET", "http://en.wikipedia.org/w/api.php?action=query&titles=" + wgPageName + "&format=json", false);
b.onreadystatechange = function() {
if(b.readyState != 4) return;
w = b.responseText.slice(b.responseText.indexOf('"title":"') + 9, b.responseText.length - 5);
if (w.indexOf("\u") == -1) wgPageName = w;
Status.status('Page evaluated to: ' + wgPageName);
};
b.send("");
if (wgPageName.indexOf('Talk:') == -1) wgPageName = 'Talk:' + wgPageName;
a=sajax_init_object();
a.open("GET", mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/index.php?title=" + wgPageName + "&action=raw", true);
a.onreadystatechange = function() {
if (a.readyState != 4) return;
textReceived(a.statusText, a.responseText, wgPageName);
};
a.send("");
}
function textReceived(sStatus, sText, oPage) {
Status.status('Page contents received: ' + oPage);
if (sText.indexOf('Image:Flag of Estonia.svg|thumb|center')!= -1) {
Status.status('Already tagged, but with the old template. Consider replacing it manually.');
if (TagWPEConfig.OpenAfter == true) {
window.location = mw.config.get('wgServer') + mw.config.get('wgArticlePath').replace('$1', oPage.replace('_', ' '));
}
return;
}
if (sText.indexOf("{{"+"WikiProject Estonia") != -1) {
Status.status('Already tagged!');
if (TagWPEConfig.OpenAfter == true) window.location = mw.config.get('wgServer') + mw.config.get('wgArticlePath').replace('$1', oPage.replace('_', ' '));
return;
}
if (sText == "") {
Status.status("Talk page doesn't exist, ready to tag.");
}
var xmlhttp = sajax_init_object();
xmlhttp.overrideMimeType('text/xml');
Status.status("Grabbing edit form...");
xmlhttp.open('GET' , 'http://en.wikipedia.org/w/index.php?title=' + oPage + '&action=submit', true);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState != 4) return;
formReceived(xmlhttp.responseXML, sText, oPage);
};
xmlhttp.send("")
}
function formReceived(pg, sText, oPage) {
form = pg.getElementById('editform');
if (!form) {
Status.error("Couldn't grab element 'editform' -- aborting, this could indicate failed response from the server");
return;
} else {
Status.status('Got the edit form');
}
text = "{{"+"WikiProject Estonia}}\n" + sText;
var summary = 'Added to [[Wikipedia:WikiProject Estonia]]';
var postData = {
'wpMinoredit': form.wpMinoredit.checked,
'wpWatchthis': form.wpWatchthis.checked,
'wpStarttime': form.wpStarttime.value,
'wpEdittime': form.wpEdittime.value,
'wpAutoSummary': form.wpAutoSummary.value,
'wpEditToken': form.wpEditToken.value,
'wpSummary': summary,
'wpTextbox1': text
};
Status.status('Submitting the form...');
var xmlhttp = sajax_init_object();
xmlhttp.overrideMimeType('text/xml');
xmlhttp.open('POST' , mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/index.php?title=" + oPage + "&action=submit", true);
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xmlhttp.onload = function() {
Status.status('Form submitted');
if (TagWPEConfig.OpenAfter == true) {
window.location = mw.config.get('wgServer') + mw.config.get('wgArticlePath').replace('$1', oPage.replace('_', ' '));
Status.status('Loading the talk page...');
}
}
xmlhttp.send(QueryString.create(postData));
}
// </nowiki>