User:Voice of All/Protection/monobook.js: Difference between revisions

Content deleted Content added
m Rm spaces.
m Remove legacy globals per phab:T72470 (via WP:JWB)
 
(11 intermediate revisions by 3 users not shown)
Line 1:
//<pre><nowiki>
 
//This function sets the selected values on the Confirm protection page
addOnloadHook(WP_PP_helper);
function WP_PP_helper()
{
if (document.title.indexOf('Wikipedia:List of protected pages') !=0 && document.title.indexOf('Protected pages') !=0 ) return;
if (document.title.indexOf('/') !=-1) return;
if (___location.href.search(/&action=/) !=-1) return;
addTab("javascript:addProtectReasons()", "Show reasons", "ca-reasons", "Show reasons", "");
}
 
//
var li_prot = 0;
function addProtectReasons()
{
if (!document.getElementsByTagName('ul')[0])
{alert('There are no elements in this list.'); return;}
if (!document.getElementsByTagName('ul')[0].getElementsByTagName('li')[0])
{alert('There are no elements in this list.'); return;}
var ls = document.getElementsByTagName('ul')[0].getElementsByTagName('li');
if (document.getElementById('contentSub').innerHTML.indexOf('Inserting log date and reasons for these items.') !=-1)
{alert('Results already shown.'); return;}
document.getElementById('contentSub').innerHTML += '<br>Inserting log date and reasons for these items.<br>';
consec_addReasons();
}
 
function consec_addReasons()
{
if (document.getElementsByTagName('ul')[0].getElementsByTagName('li')[li_prot])
{
var name = document.getElementsByTagName('ul')[0].getElementsByTagName('li')[li_prot].getElementsByTagName('a')[0].innerHTML;
var URL = '/w/index.php?title=Special:Log&limit=1&type=protect&page=' + escape(name) + '&useskin=standard';
xml_http = HTTPClient();
xml_http.open("GET", URL, true);
xml_http.onreadystatechange = fetch_log_contents;
xml_http.send(null);
}
else
{
document.getElementById('bodyContent').innerHTML = '<strong><span style="color:darkblue;">Log comments and dates inserted</span></strong><br>' + document.getElementById('bodyContent').innerHTML;
var l =document.getElementById('bodyContent').getElementsByTagName('li');
for (var i=0; i<l.length; i++)
{
var title = l[i].getElementsByTagName('a')[0].title;
var href = l[i].getElementsByTagName('a')[0].href;
if (title)
{
l[i].innerHTML = '<a href=javascript:WP_PP_unprotect("' + href.split('/wiki/')[1] + '")><strong>(release)</strong></a> ' + l[i].innerHTML;
}
}
}
}
 
function fetch_log_contents()
{
if (xml_http.readyState != 4) return;
var Done=0;
var xmlpage = xml_http.responseText.split("<div id='article'>")[1].split('<!-- end content -->')[0];
//UTC done
if (xmlpage.indexOf('<ul>') == -1)
{
document.getElementsByTagName('li')[li_prot].innerHTML += '<span style="color:red;"><strong> (error)</strong></span>';
}
else
{
//Current time
xmlpage = xmlpage.split('<ul>')[1].split('</ul>')[0];
if (xmlpage.indexOf('<li>') == -1)
{
document.getElementsByTagName('li')[li_prot].innerHTML += '<span style="color:red;"><strong> (error)</strong></span>';
}
else
{
var now = new Date();
var curtime = now.toUTCString().replace(/GMT/, "UTC");
var li_html = xmlpage.split('<li>')[1].split('</li>')[0];
var lasttime = li_html.split(' <a href=')[0].split(' <A href=')[0].split('<a href=')[0].split('<A href=')[0];
var totdays = getElapsedTime(curtime,lasttime);
totdays = Math.round((100)*totdays)/100;
var reason = li_html.split('<span class="comment">(')[1].split(')</span>')[0];
reason = reason.split(' [edit=')[0].split(' [move=')[0].split('[edit=')[0].split('[move=')[0];
if ( reason=='' ) reason = 'none given';
document.getElementsByTagName('li')[li_prot].innerHTML += '<br>[<strong>' + totdays + ' days old</strong>] <i>(' + reason + ')</i>';
}
}
li_prot += 1;
consec_addReasons();
}
 
function WP_PP_unprotect(title)
{
var URL = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=' + escape(title) + '&action=edit&jsaction=release';
window.open(URL,'WP:AUTOunpro:' + title,'___location=no,toolbar=no,status=no,directories=no,scrollbars=yes,fullscreen=yes');
}
Line 97 ⟶ 9:
function jssubmitclose()
{
var form = document.getElementById('editform').submit();
form.submit();
}
 
Line 143 ⟶ 54:
function protection_tabs()
{
if(document.getElementById('ca-protect'))
{document.getElementById('ca-protect').firstChild.innerHTML = '<span style="color:black;">protect</span>';}
if(document.getElementById('ca-unprotect'))
{document.getElementById('ca-unprotect').firstChild.innerHTML = '<strong>unprotect</strong>';}
var non_art = /Talk:| talk:|User:|MediaWiki:|Image:|Wikipedia:|Template:|Portal:|Help:|Main Page|Category:/;
if (document.title.indexOf("Editing ") != -1)
{
if(document.getElementById('ca-watch'))
{document.getElementById('ca-watch').firstChild.innerHTML = '[w]';}
if(document.getElementById('ca-unwatch'))
{document.getElementById('ca-unwatch').firstChild.innerHTML = '[uw]';}
if (document.title.search(non_art) != -1)
{document.getElementById('ca-talk').firstChild.innerHTML = 'Talk';}
if(document.getElementById('ca-protect'))
{document.getElementById('ca-protect').firstChild.innerHTML = '<span style="color:black;">P (off)</span>';}
if(document.getElementById('ca-unprotect'))
{document.getElementById('ca-unprotect').firstChild.innerHTML = '<strong>P (on)</strong>';}
if (document.title.indexOf("Editing User talk:") != -1)
{
Line 328 ⟶ 225:
else if (txtbox.value.search('\\{\\{(tl\\|)[Mm]oveprotect(ed)\\}\\}') != -1)
{var z_check = 'notag';}
else if (txtbox.value.search(/\{\{[Ss]protect|\{\{[Pp]rotect/) != -1)
{var z_check = 'notag';}
else
Line 432 ⟶ 329:
document.editform.wpTextbox1.value = '{{sprotected' + '}}\n' + document.editform.wpTextbox1.value;
document.editform.wpSummary.value += '+{{sprotected' + '}}';
 
window1 = window.open('http://en.wikipedia.org/w/index.php?title=Wikipedia:List_of_protected_pages&action=edit&section=' + type + '&jsaction=' + act + 'plist&jsaction=' + jstarget,
'WP:PP add',
'___location=no,toolbar=no,status=no,directories=no,scrollbars=yes,fullscreen=yes');
window2 = window.open('http://en.wikipedia.org/w/index.php?title=' + target.replace(/&/g,"%26") + '&action=protect&jsaction=sprotect',
'Page protect',
Line 492 ⟶ 387:
document.editform.wpTextbox1.value = '{{Vprotected' + '}}\n' + document.editform.wpTextbox1.value;
document.editform.wpSummary.value += '+{{Vprotected' + '}}';
window1 = window.open('http://en.wikipedia.org/w/index.php?title=Wikipedia:List_of_protected_pages&action=edit&section=' + type + '&jsaction=' + act + 'plist&jsaction=' + jstarget,
'WP:PP add',
'___location=no,toolbar=no,status=no,directories=no,scrollbars=yes,fullscreen=yes');
window2 = window.open('http://en.wikipedia.org/w/index.php?title=' + target.replace(/&/g,"%26") + '&action=protect&jsaction=fprotect',
'Page protect',
Line 538 ⟶ 430:
document.editform.wpTextbox1.value = '{{protected' + '}}\n' + document.editform.wpTextbox1.value;
document.editform.wpSummary.value += '+{{protected' + '}}';
window.open('http://en.wikipedia.org/w/index.php?title=Wikipedia:List_of_protected_pages&action=edit&section=' + otherpro + '&jsaction=oplist&jsaction=' + jstarget,
'WP:PP add',
'___location=no,toolbar=no,status=no,directories=no,scrollbars=yes,fullscreen=yes');
window.open('http://en.wikipedia.org/w/index.php?title=' + target.replace(/&/g,"%26") + '&action=protect&jsaction=fprotect',
'Page protect',
Line 582 ⟶ 471:
document.editform.wpTextbox1.value = '{{sprotected' + '}}\n' + document.editform.wpTextbox1.value;
document.editform.wpSummary.value += '+{{sprotected' + '}}';
window.open('http://en.wikipedia.org/w/index.php?title=Wikipedia:List_of_protected_pages&action=edit&section=' + otherpro + '&jsaction=oplist&jsaction=' + target,
'targetname',
'___location=no,toolbar=no,status=no,directories=no,scrollbars=yes,fullscreen=yes');
window.open('http://en.wikipedia.org/w/index.php?title=' + target.replace(/&/g,"%26") + '&action=protect&jsaction=sprotect',
'targetnameo',
Line 602 ⟶ 488:
{
var original = document.editform.wpTextbox1.value;
jstarget = URLEncoding(mw.config.get('wgTitle'));
if(m = document.editform.wpTextbox1.value.match(/\{\{(\w\w-|)semi-protected(2|)\}\}/) )
{
Line 678 ⟶ 564:
{
alert("Error: There is no recognized protection tag on this page.");
___location.href = 'http://en.wikipedia.org/w/index.php?title=' + mw.config.get('wgTitle').replace(/&/g,"%26") + '&action=protect&jsaction=unprotect';
return;
}
Line 690 ⟶ 576:
document.editform.wpSummary.value += 'Unprotected page -- removing tag';
document.editform.wpTextbox1.value = document.editform.wpTextbox1.value.replace(whattag,'');
window.open('http://en.wikipedia.org/w/index.php?title=' + mw.config.get('wgTitle').replace(/&/g,"%26") + '&action=protect&jsaction=unprotect' + auto,
'WP:unpro:' + mw.config.get('wgTitle'),
'___location=no,toolbar=no,status=no,directories=no,scrollbars=yes,fullscreen=yes');
jssubmitclose();
Line 1,037 ⟶ 923:
{
if (reg == 'a')
{
window.open('http://en.wikipedia.org/w/index.php?title=Wikipedia:List_of_protected_pages&action=edit&section=' + anontalk + '&jsaction=pdelist&jsaction=' + jstarget,
'WP:PP remove',
'___location=no,toolbar=no,status=no,directories=no,scrollbars=yes,fullscreen=yes');
gonotagged = 'yes';
}
else if (reg == 'r')
{
window.open('http://en.wikipedia.org/w/index.php?title=Wikipedia:List_of_protected_pages&action=edit&section=' + regtalk + '&jsaction=pdelist&jsaction=' + jstarget,
'Page unprotect',
'___location=no,toolbar=no,status=no,directories=no,scrollbars=yes,fullscreen=yes');
gonotagged = 'yes';
}
Line 1,059 ⟶ 939:
var level = prompt("Page no longer semi or fully protected (enter *s* or *f*)?");
if (level == 's')
{
window.open('http://en.wikipedia.org/w/index.php?title=Wikipedia:List_of_protected_pages&action=edit&section=' + usersemi + '&jsaction=pdelist&jsaction=' + jstarget,
'WP:PP remove',
'___location=no,toolbar=no,status=no,directories=no,scrollbars=yes,fullscreen=yes');
gonotagged = 'yes';
}
else if (level == 'f')
{
window.open('http://en.wikipedia.org/w/index.php?title=Wikipedia:List_of_protected_pages&action=edit&section=' + userfull + '&jsaction=pdelist&jsaction=' + target,
'Page unprotect',
'___location=no,toolbar=no,status=no,directories=no,scrollbars=yes,fullscreen=yes');
gonotagged = 'yes';
}
Line 1,101 ⟶ 975:
var whattag_upper = tagtype.substring(0,1).toUpperCase() + tagtype.substring(1,whattag.length);
document.editform.wpTextbox1.value = document.editform.wpTextbox1.value.replace('{{' + tagtype + '}}','');
document.editform.wpTextbox1.value = document.editform.wpTextbox1.value.replace('{{' + whattag_upper + '}}','');
var windowpp = window.open('http://en.wikipedia.org/w/index.php?title=Wikipedia:List_of_protected_pages&action=edit&section=' + type + '&jsaction=pdelist&jsaction=' + jstarget,
'WP:PP remove',
'___location=no,toolbar=no,status=no,directories=no,scrollbars=yes,fullscreen=yes');
var windowcp = window.open('http://en.wikipedia.org/w/index.php?title=' + target.replace(/&/g,"%26") + '&action=protect&jsaction=unprotect',
'Page unprotect',
Line 1,130 ⟶ 1,001:
}
}
else if (document___location.titlehref.indexOf('Confirm protection&action=protect') !==0-1)
{
var auto = '0';
Line 1,178 ⟶ 1,049:
edit.getElementsByTagName('option')[2].selected=false;
document.getElementById('mwProtect-reason').value = 'Heavy vandalism from multiple sources.';
document.getElementById('mwProtect-expiryexpires').value = '5 days';
}
if (action == 'fprotect')
Line 1,191 ⟶ 1,062:
edit.getElementsByTagName('option')[2].selected=true;
document.getElementById('mwProtect-reason').value = 'Users engaging in edit warring.';
document.getElementById('mwProtect-expiryexpires').value = 'infinite';
}
if (auto=='1') {document.getElementsByTagName('form')[0].click();}
Line 1,205 ⟶ 1,076:
if (t.value.length > 0)
t.value += '\n';
t.value +=":{{RFPP|p}} '''Fully protected''' due to [[Wikipedia:Edit war|revert warring]]. " + "~" + "~" + "~" + "~";
f.wpSummary.value += "Response: page fully protected";
}
Line 1,214 ⟶ 1,085:
if (t.value.length > 0)
t.value += '\n';
t.value +=":{{RFPP|s}} '''Semi-protected''' due to heavy [[vandalism]]. " + "~" + "~" + "~" + "~";
f.wpSummary.value += "Response: page semi-protected";
}
Line 1,223 ⟶ 1,094:
if (t.value.length > 0)
t.value += '\n';
t.value +=":{{RFPP|m}} '''Move-protected''' due to excessive renaming. " + "~" + "~" + "~" + "~";
f.wpSummary.value += "Response: page move-protected";
}
Line 1,232 ⟶ 1,103:
if (t.value.length > 0)
t.value += '\n';
t.value +=":{{RFPP|u}} '''Un-protected.''' It's been protected for long enough. Hopefully things have calmed down since then. " + "~" + "~" + "~" + "~";
f.wpSummary.value += "Response: page un-protected";
}
Line 1,300 ⟶ 1,171:
if (t.value.length > 0)
t.value += '\n';
t.value +=":{{RFPP|b}} The user has been [[WP:BLOCK|blocked]] from editing. " + "~" + "~" + "~" + "~";
f.wpSummary.value += "Response: user blocked";
}
Line 1,330 ⟶ 1,201:
f.wpSummary.value += "Response: page was not protected";
}
 
function URLEncoding(input)
{
var encodedInputString=escape(input);
encodedInputString=encodedInputString.replace(/\+/g, "%2B");
encodedInputString=encodedInputString.replace(/\//g,"%2F");
encodedInputString=encodedInputString.replace(/&/g,"%26");
var outputurl=encodedInputString;
return outputurl;
}
 
 
//</nowiki></pre>