User:Sander Säde/assess.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:Sander Säde/assess. |
//<nowiki>
//<noinclude>
var tForm = "<fieldset style='background-color:#FFFFCC; font-family:Georgia, Times, serif; font-size:small; width:600px; text-align:center'>\n<br/>" +
" <label for='importance'>Importance:</label>\n" +
" <select name='importance' id='importance' onChange='ImportanceChange(this.value)'>\n" +
" <option value='Top'>Top</option>\n" +
" <option value='High'>High</option>\n" +
" <option value='Mid'>Mid</option>\n" +
" <option value='Low' selected='selected'>Low</option>\n" +
" <option value='No'>No</option>\n" +
" </select>\n" +
" \n" +
" <label for='quality '>Quality:</label>\n" +
" <select name='quality' id='quality' onChange='QualityChange(this.value)'>\n" +
" <option value='FA'>FA</option>\n" +
" <option value='A'>A</option>\n" +
" <option value='GA'>GA</option>\n" +
" <option value='B'>B</option>\n" +
" <option value='Start'>Start</option>\n" +
" <option value='Stub' selected='selected'>Stub</option>\n" +
" <option value='No'>No</option>\n" +
" <option value='List'>List</option>\n" +
" <option value='Category'>Category</option>\n" +
" <option value='File'>File</option>\n" +
" <option value='Template'>Template</option>\n" +
" <option value='Disambig'>Disambig</option>\n" +
" </select>\n" +
" \n" +
" <label for='comment'>Comment:</label>\n" +
" <input type='text' name='comment' id='comment' maxlength='128' width='300'>\n" +
" <br/>\n" +
" <span style='font-family:Geneva, Arial, Helvetica, sans-serif; font-size:xx-small; color:#993300' id='assesshelp'></span>\n" +
" <br/>\n" +
" <input name='Assess' type='Button' id='btAssess' style='background-color:#888888; height:18px' value='Assess' onClick='doAssess()'>\n" +
" </fieldset>";
var sub = "";
var nested = false;
$(AssessButton);
function AssessButton() {
if ((document.URL.indexOf(':', 8) != -1) && (document.URL.indexOf('Talk:') == -1) && (document.URL.indexOf('/Category') == -1)) return;
if (document.URL.indexOf('/wiki/') == -1) return;
addPortletLink( "p-cactions", "javascript:assessEst()", "wpe: Assess");
}
function WriteStatus(sText) {
document.getElementById("contentSub").innerHTML += '<br /> <span style="color:Gray">' + sText + "</span>";
}
function assessEst() {
if (document.URL.indexOf('/wiki/Category') != -1) {
WriteStatus('Category: assessing automagically to Cat/NA');
}
WriteStatus('Getting talk page contents...');
if (document.URL.indexOf('/wiki/Category') != -1) {
wgPageName = mw.config.get('wgPageName').replace('Category:', 'Category_talk:');
} else if (mw.config.get('wgPageName').indexOf('Talk:') == -1) wgPageName = 'Talk:' + mw.config.get('wgPageName');
ar=sajax_init_object(null);
ar.open("GET", mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/index.php?title=" + wgPageName + "&action=raw", true);
ar.onreadystatechange = function()
{
if(ar.readyState != 4) return;
textAssessReceived(ar.responseText, wgPageName);
};
ar.send(null);
}
var bTag;
var sPage;
var sPageText;
function textAssessReceived(sText, oPage) {
bTag = false;
sPage = oPage;
sPageText = sText;
WriteStatus('Page contents received: ' + oPage);
if (sText.indexOf('Image:Flag of Estonia.svg|thumb|center')!= -1) {
WriteStatus('Tagged with old template, will replace the template');
}
if (sText.indexOf('{{' + 'WikiProject Estonia') != -1) {
sub = sText.substr(sText.indexOf('{{' + 'WikiProject Estonia'));
sub = sub.substr(0, sub.indexOf('}}') + 2);
if (sub.indexOf('|') != -1) {
if (sub.indexOf('nested=') != -1) {
nested = true;
WriteStatus('Article nested.');
}
WriteStatus('Article probably assessed...');
sub.replace(/= /g,"=");
var srclass = 'unassessed';
if (sub.indexOf('class=') != -1) {
sclass = sub.substr(sub.indexOf('class=') + 6, 3);
if (sclass.substr(0, 2).toLowerCase() == 'fa') srclass = 'FA';
if (sclass.substr(0, 1).toLowerCase() == 'a') srclass = 'A';
if (sclass.substr(0, 2).toLowerCase() == 'ga') srclass = 'GA';
if (sclass.substr(0, 1).toLowerCase() == 'b') srclass = 'B';
if (sclass.toLowerCase() == 'sta') srclass = 'Start';
if (sclass.toLowerCase() == 'stu') srclass = 'Stub';
if (sclass.substr(0, 2).toLowerCase() == 'no') srclass = 'No-class';
}
WriteStatus("Quality: <b>" + srclass + "</b>");
srclass = "unknown";
if (sub.indexOf('importance=') != -1) {
sclass = sub.substr(sub.indexOf('importance=') + 11, 1);
if (sclass.toLowerCase() == 't') srclass = 'Top';
if (sclass.toLowerCase() == 'h') srclass = 'High';
if (sclass.toLowerCase() == 'm') srclass = 'Mid';
if (sclass.toLowerCase() == 'b') srclass = 'B';
if (sclass.toLowerCase() == 'l') srclass = 'Low';
if (sclass.toLowerCase() == 'n') srclass = 'No-importance';
}
WriteStatus("Importance: <b>" + srclass + "</b>");
alreadyAssessed = true;
createAssessForm();
return;
}
}
if (sText == "") {
WriteStatus("Talk page doesn't exist, ready to tag and assess.");
bTag = true;
}
if (sText.indexOf('{{' + 'WikiProject Estonia}}') == -1) {
WriteStatus('Article untagged. Ready to tag and assess.');
bTag = true;
}
else {
WriteStatus('Article tagged and unassessed. Ready to assess.');
sub='{{' + 'WikiProject Estonia}}'
}
if (document.URL.indexOf('/wiki/Category') != -1) {
tagCategory();
return;
}
createAssessForm();
}
function tagCategory() {
tagPage('NA','Cat','');
}
function createAssessForm() {
document.getElementById("contentSub").innerHTML = document.getElementById("contentSub").innerHTML + tForm;
}
function ImportanceChange(s) {
var st = "";
switch(s){
case "Top": st = "Subject is a must-have for a concise print encyclopedia or other reference work on Estonia."
break;
case "High": st = "Subject contributes a depth of knowledge to the encyclopaedia."
break;
case "Mid": st = "Subject fills in more minor details."
break;
case "Low": st = "Subject is peripheral knowledge, possibly trivial."
break;
case "No": st = "Subject is barely worthy of inclusion to Wikipedia."
break;
default: st = "";
}
document.getElementById("assesshelp").innerHTML = st;
}
function QualityChange(s) {
var st = "";
switch(s){
case "FA": st = "Reserved exclusively for articles that have received 'Featured article' status."
break;
case "A": st = "Provides a well-written, reasonably clear and complete description of the topic."
break;
case "GA": st = "The article has passed through the Good article nomination and been granted GA status."
break;
case "B": st = "Several elements described in 'start', usually a majority of the material needed for a completed article."
break;
case "Start": st = "The article has a meaningful amount of good content, but it is still weak in many areas, and may lack a key element."
break;
case "Stub": st = "The article is either a very short article or a rough collection of information that will need much work to bring it to A-Class level."
break;
case "No": st = "Unknown or very low quality."
break;
default: st = "";
}
document.getElementById("assesshelp").innerHTML = st;
}
function doAssess() {
tagPage(document.getElementById("importance").value,document.getElementById("quality").value,document.getElementById("comment").value );
}
function tagPage(sImp, sQuality, sComment) {
var xmlhttp = sajax_init_object(null);
xmlhttp.overrideMimeType('text/xml');
WriteStatus("Grabbing edit form...");
xmlhttp.open( 'GET' , 'http://en.wikipedia.org/w/index.php?title=' + sPage + '&action=submit', true);
xmlhttp.onreadystatechange = function()
{
if(xmlhttp.readyState != 4) return;
assertFormReceived(xmlhttp.responseXML, sImp, sQuality, sComment);
};
xmlhttp.send(null)
}
function assertFormReceived(pg, sImp, sQuality, sComment) {
form = pg.getElementById('editform');
if(!form ) {
WriteStatus( 'Couldn\'t grab element "editform", aborting, this could indicate failed response from the server');
return;
}
else WriteStatus('Got the edit form');
var text;
var tag;
tag = "{{" + "WikiProject Estonia| class=" + sQuality + "|importance=" + sImp + "|comments=" + sComment;
if (bTag) text = tag + "}}\n" + sPageText;
else {
if (nested) tag += "|nested=yes}}";
else tag += "}}"
text = sPageText.replace(sub, tag);
}
var iStart = text.indexOf('{| class="messagebox standard-talk"');
var iEnd = text.indexOf("|}", iStart);
text = text.replace(text.slice(iStart, iEnd + 2), "");
var summary = 'Assessed importance for [[Wikipedia:WikiProject Estonia]]; class: ' + sQuality + "; importance: " + sImp;
if (sComment != "") summary += "; comments: " + sComment;
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
};
WriteStatus( 'Submitting the form...' );
var xmlhttp = sajax_init_object(null);
xmlhttp.overrideMimeType('text/xml');
xmlhttp.open( 'POST' , mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/index.php?title=" + sPage + "&action=submit", true);
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xmlhttp.onload = function() {
WriteStatus('Form submitted');
}
xmlhttp.send( QueryString.create(postData));
}
//</noinclude>
//</nowiki>