User:Jorgecarleitao/common.js
/* _____________________________________________________________________________
* | |
* | === WARNING: GLOBAL GADGET FILE === |
* | Changes to this page affect many users. |
* | Please discuss changes on the talk page or on WT:Gadget before editing. |
* |_____________________________________________________________________________|
*
* Imported from version 4.1.15.501952101 as of July 12, 2012 from User:mabdul/afc push.js
* A helper script for Wikipedia:WikiProject Articles for creation; see Wikipedia:WikiProject Articles for creation/Helper script
*/
////////////////////////////////////////////
// Yet another AfC helper script
// v.4.1.15
////////////////////////////////////////////
// Changelog is posted at
// Wikipedia:WikiProject Articles for creation/Helper script/Changelog
////////////////////////////////////////////
importScript('User:Timotheus Canens/displaymessage.js');
function afcHelper_escapeHtmlChars(original){
return original
.replace(/&/g, "&")
.replace(/
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
if (wgPageName.indexOf('Wikipedia:Articles_for_creation/') != -1 || wgPageName.indexOf('Wikipedia_talk:Articles_for_creation/') != -1) {
if(typeof(afcHelper_advert) == 'undefined')
afcHelper_advert = ' (AFCH)';
var afcHelper = new Object()
afcHelper.PageName = wgPageName.replace(/_/g, ' ');
afcHelper.AJAXnumber = 0;
afcHelper.submissionTitle = wgTitle.replace(/Articles for creation\//g, '');
afcHelper.reasonhash = {
'v': 'submission is unsourced or contains only unreliable sources',
'blank': 'submission is blank',
'lang': 'submission is not in English',
'cv': 'submission is a copyright violation',
'exists': 'submission already exists in main space',
'dup': 'submission is a duplicate of another submission',
'redirect': 'submission is a redirect request',
'test': 'submission is a test edit',
'news': 'submission appears to be a news report of a single event',
'dict': 'submission is a dictionary definition',
'joke': 'submission appears to be a joke',
'blp': 'submission does not conform to BLP',
'neo': 'submission is a neologism',
'npov': 'submission is not written from a neutral point of view',
'adv': 'submission is written like an advertisement',
'context': 'submission provides insufficient context',
'mergeto': 'submission is too short but can be merged',
'plot': 'submission is a plot summary',
'essay': 'submission reads like an essay',
'not': 'submission is covered by WP:NOT',
'nn': 'subject appears to be non-notable',
'web': 'subject appears to be non-notable web content',
'prof': 'subject appears to be a non-notable academic',
'athlete': 'subject appears to be a non-notable athlete',
'music': 'subject appears to be a non-notable musical performer or work',
'film': 'subject appears to be a non-notable film',
'corp': 'subject appears to be a non-notable company or organization',
'bio': 'subject appears to be a non-notable person',
'reason': ''
};
function afcHelper_init() {
if (!wfSupportsAjax()) {
displayMessage('Your browser does not seem to support AJAX, which is required for the afcHelper script v3.');
return;
}
form = '
form += afcHelper_blanking();
form +='
Reviewing '+afcHelper.PageName+'
'+''+
''+
''+
''+
''+
'
';displayMessage(form);
}
function afcHelper_prompt(type) {
if(type == 'accept'){
var text = '
Accepting '+afcHelper.PageName+'
'+''+
'
';
var assessmentSelect = afcHelper_generateSelect("afcHelper_assessment",
[{ label: 'B-class', value: 'B' },
{ label: 'C-class', value: 'C' },
{ label: 'Start-class', value: 'start' },
{ label: 'Stub-class', value: 'stub' },
{ label: 'List-class', value: 'list' },
{ label: 'Disambig-class', value: 'disambig' },
{ label: 'Redirect-class', value: 'redirect' },
{ label: 'Portal-class', value: 'portal' },
{ label: 'Disambig-class', value: 'disambig' },
{ label: 'Project-class', value: 'project' },
{ label: 'Template-class', value: 'template' },
{ label: 'NA-class', value: 'na' },
{ label: 'None', selected : true, value: '' }
], null);
text += assessmentSelect;
text += '
'+
'
'+
'
';
document.getElementById('afcHelper_extra').innerHTML = text;
}
else if(type == 'decline'){
var text = '
Declining '+afcHelper.PageName+'
'+'';
var reasonSelect = afcHelper_generateSelect("afcHelper_reason",
[{ label: 'v - submission is unsourced or contain only unreliable sources', value: 'v' },
{ label: 'blank - submission is blank', value: 'blank' },
{ label: 'lang - submission is not in English', value: 'lang' },
{ label: 'cv - submission is a copyright violation', value: 'cv' },
{ label: 'exists - submission already exists in main space', value: 'exists' },
{ label: 'dup - submission is a duplicate of another submission', value: 'dup' },
{ label: 'redirect - submission is a redirect request', value: 'redirect' },
{ label: 'test - submission is a test edit', value: 'test' },
{ label: 'news - submission appears to be a news report of a single event', value: 'news' },
{ label: 'dict - submission is a dictionary definition', value: 'dict' },
{ label: 'joke - submission appears to be a joke', value: 'joke' },
{ label: 'blp - submission does not conform to BLP', value: 'blp' },
{ label: 'neo - submission is a neologism', value: 'neo' },
{ label: 'npov - submission is not written from a neutral point of view', value: 'npov' },
{ label: 'adv - submission is written like an advertisement', value: 'adv' },
{ label: 'context - submission provides insufficient context', value: 'context' },
{ label: 'mergeto - submission is too short but can be merged', value: 'mergeto' },
{ label: 'plot - submission is a plot summary', value: 'plot' },
{ label: 'essay - submission reads like an essay', value: 'essay' },
{ label: 'not - submission is covered by WP:NOT', value: 'not' },
{ label: 'nn - subject appears to be non-notable - consider using a more specialized decline reason', value: 'nn' },
{ label: 'web - subject appears to be non-notable web content', value: 'web' },
{ label: 'prof - subject appears to be a non-notable academic', value: 'prof' },
{ label: 'athlete - subject appears to be a non-notable athlete', value: 'athlete' },
{ label: 'music - subject appears to be a non-notable musical performer or work', value: 'music' },
{ label: 'film - subject appears to be a non-notable film', value: 'film' },
{ label: 'corp - subject appears to be a non-notable company or organization', value: 'corp' },
{ label: 'bio - subject appears to be a non-notable person', value: 'bio' },
{ label: 'Custom - reason below', selected : true, value: 'reason' }
], "afcHelper_onChange(this)");
text += reasonSelect;
text += '
'+
'
'
' +
'
document.getElementById('afcHelper_extra').innerHTML = text;
}
else if(type == 'misc'){
var text = '
Other options for '+afcHelper.PageName+'
'+''+
''+
'';
'
';document.getElementById('afcHelper_extra').innerHTML = text;
}
else if(type == 'resubmit'){
var text = '
Place a submission template on '+afcHelper.PageName+'
'+
'
' +
'
' +
''+
'';
document.getElementById('afcHelper_extra').innerHTML += text;
}
else if(type == 'mark'){
var text = '
Marking submission ' +afcHelper.PageName+'for reviewing
'+'
';
document.getElementById('afcHelper_extra').innerHTML = text;
}
else if(type == 'comment'){
var text = '
Commenting on ' +afcHelper.PageName+'
'+'
';
document.getElementById('afcHelper_extra').innerHTML = text;
}
}
function afcHelper_act(action) {
if(action == 'accept'){
var newtitle = document.getElementById("afcHelper_movetarget").value;
var assessment = document.getElementById("afcHelper_assessment").value;
var pagePrepend = document.getElementById("afcHelper_pagePrepend").value;
var pageAppend = document.getElementById("afcHelper_pageAppend").value;
var talkAppend = document.getElementById("afcHelper_talkAppend").value;
displayMessage('
document.getElementById('afcHelper_finish').innerHTML += '';
var token = afcHelper_getToken(true);
var callback = function(){
var text = afcHelper_getPageText(newtitle, true);
var username ='';
// clean up page
var afc_re = /\{\{\s*afc submission\s*\|(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
if( afc_re.test( text ) ) {
var afctemplate = afc_re.exec(text)[0];
var author_re = /\|\s*u=\s*[^\|]*\|/i;
if(author_re.test(afctemplate)){
var user = author_re.exec(afctemplate)[0];
username = user.split(/=/)[1];
username = username.replace(/\|/g,'');
var usertext = afcHelper_getPageText("User talk:"+username, true);
usertext += "\n== Your submission at \[\[WP:AFC|Articles for creation\]\] ==";
usertext += "\n\{\{subst:afc talk|1=" + newtitle + "|class=" + assessment + "|sig=yes\}\}";
afcHelper_editPage("User talk:"+username, usertext, token, 'Your submission at \[\[WP:AFC|Articles for creation\]\]');
}
}
var recenttext = afcHelper_getPageText("Wikipedia:Articles for creation/recent", true);
var newentry = "\{\{afc contrib|" + assessment + "|" + newtitle + "|" + username +"\}\}\n";
var lastentry = recenttext.toLowerCase().lastIndexOf("\{\{afc contrib");
var firstentry = recenttext.toLowerCase().indexOf("\{\{afc contrib");
recenttext = recenttext.substring(0, lastentry);
recenttext = recenttext.substring(0, firstentry) + newentry + recenttext.substring(firstentry);
afcHelper_editPage("Wikipedia:Articles for creation/recent", recenttext, token, 'Updating recent AFC creations');
var talktext = "\{\{talkheader\}\}\n\{\{subst:WPAFC/article|class=" + assessment + "\}\}";
talktext += "\n";
talktext += talkAppend;
var testtemplate = /Template:/i;
var testcat = /Category:/i;
var testwp = /Wikipedia:/i;
var testportal = /Portal:/i;
var newtalktitle;
if(testtemplate.test(newtitle)){
newtalktitle = newtitle.replace(/Template:/i, '');
newtalktitle = 'Template talk:'+newtalktitle;}
else if(testcat.test(newtitle)){
newtalktitle = newtitle.replace(/Category:/i, '');
newtalktitle = 'Category talk:'+newtalktitle;}
else if(testwp.test(newtitle)){
newtalktitle = newtitle.replace(/Wikipedia:/i, '');
newtalktitle = 'Wikipedia talk:'+newtalktitle;}
else if(testportal.test(newtitle)){
newtalktitle = newtitle.replace(/Portal:/i, '');
newtalktitle = 'Portal talk:'+newtalktitle;}
else
newtalktitle = 'Talk:'+newtitle;
afcHelper_editPage(newtalktitle, talktext, token, 'Placing WPAFC project banner');
while(afc_re.test(text)){
var startindex = text.search(afc_re);
var template = afc_re.exec(text)[0];
var endindex = startindex + template.length;
text = text.substring(0, startindex) + text.substring(endindex);
}
var cmt_re = /\{\{\s*afc comment\s*\|(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
while(cmt_re.test(text)){
var startindex = text.search(cmt_re);
var template = cmt_re.exec(text)[0];
var endindex = startindex + template.length;
text = text.substring(0, startindex) + text.substring(endindex);
}
var afcindex = text.search(/\{\{afc/i);
while (afcindex != -1){
var endindex = text.indexOf("\}\}", afcindex + 2);
text = text.substring(0,afcindex) + text.substring(endindex+2);
afcindex = text.search(/\{\{afc/i);
}
if(text.indexOf("\<\!--- Important, do not remove this line before article has been created. ---\>") != -1){
var startindex = text.indexOf("\<\!--- Important, do not remove this line before article has been created. ---\>");
var endindex = text.indexOf(">", startindex);
text = text.substring(0, startindex) + text.substring(endindex+1);
}
//Cleaning up the submission
text = afcHelper_cleanup(text);
// Uncomment cats (after the cleanup commented them)
text = text.replace(/\[\[:Category/gi, "\[\[Category");
text = pagePrepend + '\n' + text + '\n'+ pageAppend;
afcHelper_editPage(newtitle, text, token, "Cleanup following AFC creation");
};
afcHelper_movePage(afcHelper.PageName, newtitle, token, 'Created via \[\[WP:AFC|Articles for Creation\]\] (\[\[WP:WPAFC|you can help!\]\])' , callback);
}
else if(action == 'decline'){
var code = document.getElementById("afcHelper_reason").value;
var reasontext = afcHelper.reasonhash[code];
var customreason = document.getElementById("afcHelper_comments").value;
var append = false;
var keep = false;
var blank = document.getElementById("afcHelper_blank").checked;
var blank_csd = document.getElementById("afcHelper_blank_csd").checked;
var notify = document.getElementById("afcHelper_notify").checked;
var teahouse = document.getElementById("afcHelper_notify_Teahouse").checked;
var extra = '';
if(code == 'cv' || code == 'dup' || code == 'mergeto' || code == 'exists' || code == 'lang' || code == 'plot'){
extra = document.getElementById("afcHelper_extra_inlinebox").value;
}
if(extra == null){
return;
}
displayMessage('
document.getElementById('afcHelper_finish').innerHTML += '';
var token = afcHelper_getToken(true);
var text = afcHelper_getPageText(afcHelper.PageName, true);
// Find the first pending submission or marked as review on the page.
var afc_re = /\{\{\s*afc submission\s*\|\s*[||h|r](?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
if( !afc_re.test( text ) ) {
alert( "Unable to locate AFC submission template, aborting..." );
return;
}
//TEMP: removing after cleanup works
var afctemplate = afc_re.exec(text)[0];
//moving the first hit to the top
text=text.replace(afctemplate, '');
text=afctemplate+text;
//TEMP END: removing after cleanup works
var notifytemplate = "afc decline";
if(code == 'reason' && customreason == ''){
alert("You must enter a reason!");
return;
}
var startindex = text.indexOf(afctemplate);
var endindex = startindex + afctemplate.length;
//data is always between the first pipe and the one before the timestamp.
var firstpipe = afctemplate.indexOf('|');
var endpipe = afctemplate.indexOf('|ts');
var newtemplate = afctemplate.substring(0, firstpipe);
var summary = '';
var newcomment = '';
// overwrite any reason that was there.
newtemplate += '|d|'+code;
if(code == 'reason'){
newtemplate += '|3=' + customreason;
}
else if(extra != ''){
newtemplate += '|3=' + extra;
}
newtemplate += '|declinets=\{\{subst:CURRENTTIMESTAMP\}\}|decliner=\{\{subst:REVISIONUSER\}\}'+afctemplate.substring(endpipe);
if(code != 'reason' && customreason != ''){
newcomment = "*\{\{afc comment|1=" + customreason + " \~\~\~\~\}\}";
}
summary = "Declining submission";
if(code == 'reason')
summary += ': see comment therein';
else
summary += ': ' + reasontext;
if(notify){
var author_re = /\|\s*u=\s*[^\|]*\|/i;
if(author_re.test(afctemplate)){
var user = author_re.exec(afctemplate)[0];
var username = user.split(/=/)[1];
username = username.replace(/[\|]/g,'');
var usertext = afcHelper_getPageText("User talk:"+username, true);
var reason = 'Your submission at \[\[Wikipedia:Articles for creation|Articles for creation\]\]';
usertext += "\n== Your submission at \[\[Wikipedia:Articles for creation|Articles for creation\]\] ==";
usertext += "\n\{\{subst:" + notifytemplate + "|1=" + afcHelper.submissionTitle;
if(code == 'cv')
usertext += "| cv = yes";
usertext += "|sig=yes\}\}";
if(teahouse){
document.getElementById('afcHelper_status').innerHTML += '
// stolen from function afcHelper_getPageText(title)
var req = sajax_init_object();
var params = "action=query&prop=categories&format=json&indexpageids=1&titles=User_talk:" + encodeURIComponent(username);
req.open("POST", wgScriptPath + "/api.php", false);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", params.length);
req.setRequestHeader("Connection", "close");
req.send(params);
var response = eval('(' + req.responseText + ')');
var pageid = response['query']['pageids'][0];
var foundTH=0;
if (pageid!="-1"){
var pagecats = new Array ();
pagecats = response['query']['pages'][pageid]['categories'];
if(typeof pagecats != 'undefined'){
for(var i = 0; i < pagecats.length; i++){
if (pagecats[i].title == ("Category:Wikipedia users who received a Teahouse invitation")){
foundTH=1;
break;
}
}
}
}
if(foundTH==0){
document.getElementById('afcHelper_get'+escape(teahouse)).innerHTML = '
usertext += "\n\n\n\{\{subst:Wikipedia:Teahouse/AFC_invitation\}\}";
reason += '; adding invitation for the \[\[Wikipedia:Teahouse|Teahouse\]\]!'
}
else{
document.getElementById('afcHelper_get'+escape(teahouse)).innerHTML = ''+username+' already has an invitation.';
}
delete req;
}
}//end TH stuff
afcHelper_editPage("User talk:"+username, usertext, token, reason);
}
if(!blank){
var containComment = (text.indexOf('----') != -1);
if(newcomment != ''){
if(!containComment)
text = text.substring(0, startindex) + newtemplate + '\n' + newcomment + '\n----\n'+ text.substring(endindex);
else{
text = text.substring(0, startindex) + newtemplate + text.substring(endindex);
var idx = text.indexOf('----');
text = text.substring(0, idx) + newcomment +'\n' + text.substring(idx);
}
}
else
text = text.substring(0, startindex) + newtemplate + text.substring(endindex);
}
else{
text = newtemplate + '\n' + newcomment + '\n\{\{afc cleared';
if(blank_csd)
text+="\|csd\}\}";
else
text+="\}\}";
}
//first remove the multiple pending templates, otherwise one isn't recognized
text = text.replace(/\{\{\s*afc submission\s*\|\s*[||h|r](?:\{\{[^{}]*\}\}|[^}{])*\}\}/i, "");
text = afcHelper_cleanup(text);
afcHelper_editPage(afcHelper.PageName, text, token, summary);
}
else if(action == 'comment'){
var comment = document.getElementById("afcHelper_comments").value;
displayMessage('
document.getElementById('afcHelper_finish').innerHTML += '';
var token = afcHelper_getToken(true);
var text = afcHelper_getPageText(afcHelper.PageName, true);
var containComment = (text.indexOf('----') != -1);
var newComment = "\{\{afc comment|1=" + comment + "\~\~\~\~\}\}";
if(comment != ''){
if(!containComment){
var afc_re = /\{\{\s*afc submission\s*\|\s*[||h|r|d](?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
if( !afc_re.test( text ) ) {
alert( "Unable to locate AFC submission template, aborting..." );
return;
}
var afctemplate = afc_re.exec(text)[0];
var endindex = text.indexOf(afctemplate) + afctemplate.length;
text = text.substring(0, endindex) + '\n' + newComment + '\n----\n'+ text.substring(endindex);
}
else{
var idx = text.indexOf('----');
text = text.substring(0, idx) + newComment +'\n' + text.substring(idx);
}
text = afcHelper_cleanup(text);
afcHelper_editPage(afcHelper.PageName, text, token, "Commenting on submission");
}
}
else if(action == 'mark'){
var comment = document.getElementById("afcHelper_comments").value;
displayMessage('
document.getElementById('afcHelper_finish').innerHTML += '';
var token = afcHelper_getToken(true);
var text = afcHelper_getPageText(afcHelper.PageName, true);
var containComment = (text.indexOf('----') != -1);
var newComment = "\{\{afc comment|1=" + comment + "\~\~\~\~\}\}";
if(comment != ''){
if(!containComment){
var afc_re = /\{\{\s*afc submission\s*\|\s*[||h|r|d](?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
if( !afc_re.test( text ) ) {
alert( "Unable to locate AFC submission template, aborting..." );
return;
}
var afctemplate = afc_re.exec(text)[0];
var endindex = text.indexOf(afctemplate) + afctemplate.length;
text = text.substring(0, endindex) + '\n' + newComment + '\n----\n'+ text.substring(endindex);
}
else{
var idx = text.indexOf('----');
text = text.substring(0, idx) + newComment +'\n' + text.substring(idx);
}
}
var afc_re = /\{\{\s*afc submission\s*\|\s*[||h](?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
if( !afc_re.test( text ) ) {
alert( "Unable to locate AFC submission template, aborting..." );
return;
}
var afctemplate = afc_re.exec(text)[0];
var firstpipe = afctemplate.indexOf('|');
var endpipe = afctemplate.indexOf('|ts');
var newTemplate = afctemplate.substring(0, firstpipe);
newTemplate += '|r||';
newTemplate += afctemplate.substring(endpipe);
var startindex = text.indexOf(afctemplate);
var endindex = text.indexOf(afctemplate) + afctemplate.length;
text = text.substring(0, startindex) + newTemplate + text.substring(endindex);
text = afcHelper_cleanup(text);
afcHelper_editPage(afcHelper.PageName, text, token, "Marking submission as being reviewed");
}
else if(action == 'cleanup'){
displayMessage('
document.getElementById('afcHelper_finish').innerHTML += '';
var token = afcHelper_getToken(true);
var text = afcHelper_getPageText(afcHelper.PageName, true);
var text2 = afcHelper_cleanup(text);
if(text==text2)
document.getElementById('afcHelper_finish').innerHTML += 'This submission is already cleaned. Nothing changed. (Reload page)';
else
afcHelper_editPage(afcHelper.PageName, text2, token, "Cleaning the submission.");
}
document.getElementById('afcHelper_finished_main').style.display = '';
}
function afcHelper_getPageText(title, status) {
if (status == 'true')
document.getElementById('afcHelper_status').innerHTML += '
var req = sajax_init_object();
var params = "action=query&prop=revisions&rvprop=content&format=json&indexpageids=1&titles=" + encodeURIComponent(title);
req.open("POST", wgScriptPath + "/api.php", false);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", params.length);
req.setRequestHeader("Connection", "close");
req.send(params);
var response = eval('(' + req.responseText + ')');
pageid = response['query']['pageids'][0];
if (pageid == "-1") {
if(status == 'true')
document.getElementById('afcHelper_get'+escape(title)).innerHTML = ''+title+' does not exist';
delete req;
return '';
}
pagetext = response['query']['pages'][pageid]['revisions'][0]['*'];
delete req;
if(status == 'true')
document.getElementById('afcHelper_get'+escape(title)).innerHTML = 'Got '+title+'';
return pagetext;
}
function afcHelper_getToken(show) {
if (show) {
document.getElementById('afcHelper_status').innerHTML += '
}
var req = sajax_init_object();
req.open("GET", wgScriptPath + "/api.php?action=query&prop=info&indexpageids=1&intoken=edit&format=json&titles="+encodeURIComponent(afcHelper.PageName), false);
req.send(null);
var response = eval('(' + req.responseText + ')');
pageid = response['query']['pageids'][0];
token = response['query']['pages'][pageid]['edittoken'];
delete req;
if (show) {
document.getElementById('afcHelper_gettoken').innerHTML = 'Got token';
}
return token;
}
function afcHelper_movePage(oldtitle, newtitle, token, summary, callback) {
summary += afcHelper_advert;
document.getElementById('afcHelper_finished_wrapper').innerHTML = '
';var func_id = afcHelper.AJAXnumber;
afcHelper.AJAXnumber++;
document.getElementById('afcHelper_status').innerHTML += '
var req = sajax_init_object();
var params = "action=move&format=json&token="+encodeURIComponent(token)+"&from="+encodeURIComponent(oldtitle) +"&to="+encodeURIComponent(newtitle)+"&reason="+encodeURIComponent(summary);
url = wgScriptPath + "/api.php";
req.open("POST", url, true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", params.length);
req.setRequestHeader("Connection", "close");
req.onreadystatechange = function() {
if(req.readyState == 4 && req.status == 200) {
var error = true;
response = eval('(' + req.responseText + ')');
try {
if (typeof(response['move']) != "undefined") {
document.getElementById('afcHelper_move'+escape(oldtitle)).innerHTML = 'Moved '+oldtitle+'';
error = false;
} else {
document.getElementById('afcHelper_move'+escape(oldtitle)).innerHTML = '
}
}
catch(err) {
document.getElementById('afcHelper_move'+escape(oldtitle)).innerHTML = '
}
if(!error){
if(callback != null)
callback();
}
document.getElementById('afcHelper_AJAX_finished_'+func_id).style.display = '';
delete req;
}
};
req.send(params);
}
function afcHelper_editPage(title, newtext, token, summary) {
summary += afcHelper_advert;
document.getElementById('afcHelper_finished_wrapper').innerHTML = '
';var func_id = afcHelper.AJAXnumber;
afcHelper.AJAXnumber++;
document.getElementById('afcHelper_status').innerHTML += '
var req = sajax_init_object();
var params = "action=edit&format=json&token="+encodeURIComponent(token)+"&title="+encodeURIComponent(title)+"&text="+encodeURIComponent(newtext)+"¬minor=1&summary="+encodeURIComponent(summary);
url = wgScriptPath + "/api.php";
req.open("POST", url, true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", params.length);
req.setRequestHeader("Connection", "close");
req.onreadystatechange = function() {
if(req.readyState == 4 && req.status == 200) {
response = eval('(' + req.responseText + ')');
try {
if (response['edit']['result'] == "Success") {
document.getElementById('afcHelper_edit'+escape(title)).innerHTML = 'Saved '+title+'';
} else {
document.getElementById('afcHelper_edit'+escape(title)).innerHTML = '
}
}
catch(err) {
document.getElementById('afcHelper_edit'+escape(title)).innerHTML = '
}
document.getElementById('afcHelper_AJAX_finished_'+func_id).style.display = '';
delete req;
}
};
req.send(params);
}
function afcHelper_addLink() {
mw.util.addPortletLink("p-cactions", "javascript:afcHelper_init()", "Review", "ca-afcHelper", "Review");
}
function afcHelper_onChange(select) {
var value = select.options[select.selectedIndex].value;
if(value=='cv')
document.getElementById("afcHelper_extra_inline").innerHTML='';
else if(value=='dup')
document.getElementById("afcHelper_extra_inline").innerHTML='';
else if(value=='mergeto')
document.getElementById("afcHelper_extra_inline").innerHTML='';
else if(value=='lang')
document.getElementById("afcHelper_extra_inline").innerHTML='';
else if(value=='exists')
document.getElementById("afcHelper_extra_inline").innerHTML='';
else if(value=='plot')
document.getElementById("afcHelper_extra_inline").innerHTML='';
else
document.getElementById("afcHelper_extra_inline").innerHTML='';
if(value == 'blp' || value == 'cv'){
document.getElementById("afcHelper_blank").setAttribute("checked", "checked");
}
else
document.getElementById("afcHelper_blank").removeAttribute("checked");
}
function afcHelper_cleanup(text) {
//Commenting out cats
text = text.replace(/\[\[Category:/gi, "\[\[:Category:");
//Wikilink correction
var wikiURL=/\[\[(http[s]?\:\/\/en.wikipedia.org\/wiki\/|https\:\/\/secure.wikimedia.org\/wikipedia\/en\/wiki\/)[\|\s]*.*\]\]/i;
var wikiURL2=/\[(http[s]?\:\/\/en.wikipedia.org\/wiki\/|https\:\/\/secure.wikimedia.org\/wikipedia\/en\/wiki\/)[\|\s]*.*\]/i;
while(wikiURL.test(text)){
var firsthit=wikiURL.exec(text);
var firsthit2=firsthit[0].toString();
var firsthit_copy=firsthit[0].toString();
var wikiURL3=/\[\[(http[s]?\:\/\/en.wikipedia.org\/wiki\/|https\:\/\/secure.wikimedia.org\/wikipedia\/en\/wiki\/)/i;
firsthit2=firsthit2.replace(wikiURL3, "\[\[");
firsthit2=firsthit2.replace(/[\s\|]+/i, "\|");
firsthit2=firsthit2.replace(/\]\]/i, "\]\]");
text=text.replace(firsthit_copy, firsthit2);
}
while(wikiURL2.test(text)){
var firsthit=wikiURL2.exec(text);
var firsthit2=firsthit[0].toString();
var firsthit_copy=firsthit[0].toString();
var wikiURL3=/\[(http[s]?\:\/\/en.wikipedia.org\/wiki\/|https\:\/\/secure.wikimedia.org\/wikipedia\/en\/wiki\/)/i;
firsthit2=firsthit2.replace(wikiURL3, "\[\[");
firsthit2=firsthit2.replace(/[\s\|]+/i, "\|");
firsthit2=firsthit2.replace(/\]/i, "\]\]");
text=text.replace(firsthit_copy, firsthit2);
}
// Remove all unneeded HTML comments and wizards stuff
text = text.replace("* \[http\:\/\/www.example.com\/ example.com\]", "");
text = text.replace(/Subject of my article is.../ig, "");
text = text.replace(/\<\!--- Carry on from here, and delete this comment. ---\>/ig, "");
text = text.replace(/\<\!-- This will add a notice to the bottom of the page and won't blank it! The new template which says that your draft is waiting for a review will appear at the bottom; simply ignore the old (grey) drafted templates and the old (red) decline templates. A bot will update your article submission. Until then, please don't change anything in this text box and press "Save page". --\>/ig, "");
text = text.replace(/\<\!-- EDIT BELOW THIS LINE --\>/ig, "");
text = text.replace(/\<\!--- Categories ---\>/gi, '');
text = text.replace(/\<\!--- After listing your sources please cite them using inline citations and place them after the information they cite. Please see http:\/\/en.wikipedia.org\/wiki\/Wikipedia:REFB for instructions on how to add citations. ---\>/ig, "");
text = text.replace(/\<\!--Please don't change anything and press save --\>/ig, "");
text = text.replace(/\<\!-- Please leave this line alone! --\>/ig, "");
text = text.replace(/\<\!--- Important, do not remove this line before article has been created. ---\>/ig, "");
text = text.replace(/== Request review at \[\[WP:AFC\]\] ==\n/ig, "");
//
text = text.replace(/\{\{(userspacedraft|userspace draft|user sandbox)(?:\{\{[^{}]*\}\}|[^}{])*\}\}/ig, "");
text = text.replace(/---[-]+/ig, "");
var afc_re = /\{\{\s*afc submission\s*\|\s*[||h|r](?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
var afc_alt = /\{\{\s*afc submission\s*\|\s*[^t](?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
var afc_all = /\{\{\s*afc submission\s*\|\s*(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
var afc_comment = /\{\{\s*afc comment(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
// Remove all draft templates
if(afc_alt.test(text))
text = text.replace(/\{\{\s*afc submission\s*\|\s*t(?:\{\{[^{}]*\}\}|[^}{])*\}\}/ig, "");
// Find the first pending submission or marked as review on the page.
var temp = text;
//Remove any duplicate open review requests before saving the page (only affects open requests)
//find the first pending template and remove it, if one was removed too much, revert the last removal
while(afc_re.test(text)){
temp = text;
text = text.replace(/\{\{\s*afc submission\s*\|\s*[||h|r](?:\{\{[^{}]*\}\}|[^}{])*\}\}/i, "");
if(!afc_re.test(text)){
text=temp;
break;
}
}
//create an array, strip the submission templates, then AFC comments and then add them back to the page, add then ----
var submissiontemplates=new Array();
var commentstemplates=new Array();
while(afc_all.test(text)){
submissiontemplates.push(afc_all.exec(text));
text=text.replace(afc_all.exec(text), "");
}
while(afc_comment.test(text)){
commentstemplates.push(afc_comment.exec(text));
text=text.replace(afc_comment.exec(text), "");
}
//removal of unnecessary new lines, stars, "-", and whitespaces at the top of the page
text = text.replace(/[*\n\s-]*/m, "");
//adding back the submission templates and comment templates
if(commentstemplates.length>0){
text = '----\n'+text;
for((i=commentstemplates.length-1);i>=0;i--)
text=commentstemplates[i]+'\n\n'+text;
}
if(submissiontemplates.length>0){
for((i=submissiontemplates.length-1);i>=0;i--){
if(i==(submissiontemplates.length-1))
text=submissiontemplates[i]+'\n'+text;
else if(i>=0){
var find_shrinked=/\|\s*small\s*=\s*yes/gi;
if(find_shrinked.test(submissiontemplates[i])){
text=submissiontemplates[i]+text;
}
else{
var temp=submissiontemplates[i].toString();
var templength=temp.length - 2;
temp=temp.slice(0, templength);
text=temp+'\|small=yes\}\}'+text;
}
}
}
}
return text;
}
function afcHelper_generateSelect(title, options, onchange){
var text = '";
return text;
}
addOnloadHook(afcHelper_addLink);
}
function afcHelper_blanking(){
var text = afcHelper_getPageText(afcHelper.PageName, false);
var text = afcHelper_cleanup(text);
//test for AFC submission templates with not enough parameter
//Nmespaces WP (4) and WT (5)
//var afc_alltemplates= /\{\{\s*afc submission(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
//afc_all=text.match(afc_alltemplates);
//longer than 20 characters, but commonly added to the source code
texttest = text.replace(/\<\!-- Bot generated title --\>/gi, "");
texttest = texttest.replace(/\<\!-- See Wikipedia\:WikiProject Musicians --\>/gi, "");
texttest = texttest.replace(/\<\!-- Only for images narrower than 220 pixels --\>/gi, "");
texttest = texttest.replace(/\<\!-- Metadata\: see \[\[Wikipedia\:Persondata\]\]. --\>/gi, "");
var recomment = /\<\!--.{20}.*/gi;
var errormsg ='';
// test if too long (20+ characters) HTML comments are still in the page text
if(recomment.test(texttest))
errormsg = '
Please check the source code! This page contains a really long HTML comment!
';
// count and and check if it fits
// Special thanks to User:Betacommand for KISS
var rerefbegin = /\<\s*ref\s*(name\s*=|group\s*=)*\s*[^\/]*>/ig;
var rerefend = /\<\/\s*ref\s*\>/ig;
refbegin=texttest.match(rerefbegin);
refend=texttest.match(rerefend);
if(refbegin){//Firefox workaround!
if(refend){//Firefox workaround!
if(refbegin.length!=refend.length){
errormsg += '
Please check the source code! This page contains unclosed <ref> tags!
';
}
}
else{
errormsg += '
Please check the source code! This page contains not the same amount of <ref> and </ref> tags!
';
}
}
// test if foo on the page and place the markup on the box
var rerefdouble = /\<\s*ref\s*(name\s*=|group\s*=)*\s*[^\/]*\>?(\<\s*[^\/]*\s*ref\s*(name\s*=|group\s*=)*)/ig;
var refdouble=text.match(rerefdouble);
if(refdouble){
errormsg +='The script found following bad lines:
';
for(i=0;i errormsg +=afcHelper_escapeHtmlChars(refdouble[i].toString())+'> errormsg+=''; } return errormsg; } //function to add afc cleared (csd) checkbox if afc cleared is checked function afcHelper_trigger(type){ var e = document.getElementById(type); e.style.display = ((e.style.display!='none') ? 'none' : 'block'); } //function to disable checkboxes or textfields; not used at the moment, will be used maybe later //function afcHelper_trigger(){ // if(afcHelper_optional_replace.checked){ // afcHelper_reason.disabled=false; // }else{ // afcHelper_reason.disabled=true; // } //}
';