Jump to content

User:Gfoley4/RFPP.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// <pre><nowiki> 

  if (document.title.indexOf("Editing Wikipedia:Requests for page protection/Increase (section)") != -1) {

function fullprot_tag()
{
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|p}}. ~~" + "~~";
  f.wpSummary.value += "fully protected ";
}

// Break

function fullprotexp_tag()
{
  var expfull = prompt( "The page protection will expire in..." );
  if( !expfull ) {
  return;
 } else {
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|p|" + expfull + "}} ~~" + "~~";
  f.wpSummary.value += "fully protected for " + expfull + " ";
 }
}

// Break

function semiprot_tag()
{
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|s}}. ~~" + "~~";
  f.wpSummary.value += "semi-protected ";
}

// Break

function semiprotexp_tag()
{
  var expsemi = prompt( "The page protection will expire in..." );
  if( !expsemi ) {
  return;
 } else {
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|s|" + expsemi + "}} ~~" + "~~";
  f.wpSummary.value += "semi-protected for " + expsemi + " ";
 }
}

// Break

function salt_tag()
{
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|t}}. ~~" + "~~";
  f.wpSummary.value += "protected to prevent recreation ";
}

// Break

function pendprot_tag()
{
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|pd}}. ~~" + "~~";
  f.wpSummary.value += "pending-change protected ";
}

// Break

function pendprotexp_tag()
{
  var exppend = prompt( "The page protection will expire in..." );
  if( !exppend ) {
  return;
 } else {
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|pd|" + exppend + "}} ~~" + "~~";
  f.wpSummary.value += "pending-change protected for " + exppend + " ";
 }
}

// Break

function moveprot_tag()
{
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|m}}. ~~" + "~~";
  f.wpSummary.value += "move protected ";
}

// Break

function templprot_tag()
{
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|tp}}. ~~" + "~~";
  f.wpSummary.value += "template protected ";
}

// Break

function approt_tag()
{
  var apreason = prompt( "Admin\'s name? (Optional)" );
  if( !apreason ) {
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|ap}} by another admin. ~~" + "~~";
  f.wpSummary.value += "already protected ";
 } else {
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|ap|" + apreason + "}}. ~~" + "~~"; 
  f.wpSummary.value += "already protected ";
 }
}

// Break

function declinedprot_tag()
{
  var declinereason = prompt( "Reason? (Optional)" );
  if( !declinereason ) {
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|d}} ~~" + "~~";
  f.wpSummary.value += "declined ";
 } else {
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|d}}, " + declinereason + " ~~" + "~~";
  f.wpSummary.value += "declined ";
 }
}

// Break

function neaprot_tag()
{
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|nea}} ~~" + "~~";
  f.wpSummary.value += "declined - not enough recent activity ";
}

// Break

function npprot_tag()
{
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|np}} ~~" + "~~";
  f.wpSummary.value += "declined - pages are not protected pre-emptively ";
}

// Break


function drprot_tag()
{
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|dr}} ~~" + "~~";
  f.wpSummary.value += "declined - consider dispute resolution ";
}

// Break

function userprot_tag()
{
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|b}} ~~" + "~~";
  f.wpSummary.value += "user(s) blocked ";
}

// Break

function userreblock_tag()
{
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|tb}} ~~" + "~~";
  f.wpSummary.value += "user(s) re-blocked with talk page editing disallowed";
}

// Break

function aunprot_tag()
{
  var aureason = prompt( "Admin\'s name? (Optional)" );
  if( !aureason ) {
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|au}} by another admin. ~~" + "~~";
  f.wpSummary.value += "already unprotected ";
 } else {
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|au|" + aureason + "}}. ~~" + "~~"; 
  f.wpSummary.value += "already unprotected ";
 }
}

// Break

function unprot_tag()
{
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|u}} ~~" + "~~";
  f.wpSummary.value += "unprotected ";
}

// Break

function notunprot_tag()
{
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|nu}} ~~" + "~~";
  f.wpSummary.value += "not unprotected ";
}

// Break

function createsourced_tag()
{
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|cr}} ~~" + "~~";
  f.wpSummary.value += "not unprotected - please create a sourced version in your userspace first";
}

// Break

// Break

function adoneprot_tag()
{
  var adonereason = prompt( "Admin\'s name? (Optional)" );
  if( !adonereason ) {
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|ad}} by another admin. ~~" + "~~";
  f.wpSummary.value += "already done ";
 } else {
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|ad|" + adonereason + "}}. ~~" + "~~"; 
  f.wpSummary.value += "already done";
 }
}

function doneprot_tag()
{
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|do}} ~~" + "~~";
  f.wpSummary.value += "done ";
}

// Break

function note_tag()
{
  var notereason = prompt ("Note:");
  if ( !notereason) {
  return;
 } else {
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|n}} " + notereason + " ~~" + "~~";
  f.wpSummary.value += "note ";
 }
}

// Break

function question_tag()
{
  var question = prompt ("Question:");
  if ( !question) {
  return;
 } else {
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
  t.value +=":{" + "{RFPP|q}} " + question + " ~~" + "~~";
  f.wpSummary.value += "question ";
 }
}

function prot_tagging()
{
  mw.util.addPortletLink('p-navigation', 'javascript:fullprot_tag()', "(Fully protected)");
  mw.util.addPortletLink('p-navigation', 'javascript:fullprotexp_tag()', "(Full) \+ expiry");
  mw.util.addPortletLink('p-navigation', 'javascript:semiprot_tag()', "(Semi-protected)");
  mw.util.addPortletLink('p-navigation', 'javascript:semiprotexp_tag()', "(Semi) \+ expiry");
  mw.util.addPortletLink('p-navigation', 'javascript:salt_tag()', "(Salt)");
  mw.util.addPortletLink('p-navigation', 'javascript:moveprot_tag()', "(Move protected)");
  mw.util.addPortletLink('p-navigation', 'javascript:pendprot_tag()', "(Pending protected)");
  mw.util.addPortletLink('p-navigation', 'javascript:pendprotexp_tag()', "(Pend) \+ expiry");
  mw.util.addPortletLink('p-navigation', 'javascript:templprot_tag()', "(Template protected)");
  mw.util.addPortletLink('p-navigation', 'javascript:approt_tag()', "(Already prot\'d)");
  mw.util.addPortletLink('p-navigation', 'javascript:declinedprot_tag()', "(Declined)");
  mw.util.addPortletLink('p-navigation', 'javascript:neaprot_tag()', "(Declined nea)");
  mw.util.addPortletLink('p-navigation', 'javascript:npprot_tag()', "(Declined np)");
  mw.util.addPortletLink('p-navigation', 'javascript:drprot_tag()', "(Declined dr)");
  mw.util.addPortletLink('p-navigation', 'javascript:userprot_tag()', "(User blocked)");
  mw.util.addPortletLink('p-navigation', 'javascript:userreblock_tag()', "(User talk disabled)");
  mw.util.addPortletLink('p-navigation', 'javascript:aunprot_tag()', "(Already unprot\'d)");
  mw.util.addPortletLink('p-navigation', 'javascript:unprot_tag()', "(Unprotected)");
  mw.util.addPortletLink('p-navigation', 'javascript:notunprot_tag()', "(Not unprotected)");
  mw.util.addPortletLink('p-navigation', 'javascript:createsourced_tag()', "(Create sourced first)");
  mw.util.addPortletLink('p-navigation', 'javascript:adoneprot_tag()', "(Already done)");
  mw.util.addPortletLink('p-navigation', 'javascript:doneprot_tag()', "(Done)");
  mw.util.addPortletLink('p-navigation', 'javascript:note_tag()', "(Note)");
  mw.util.addPortletLink('p-navigation', 'javascript:question_tag()', "(Question)");
}


$(prot_tagging);
importStylesheet('User:Steel359/protection2.css');

// End if
};

// ---------------------------------------------------------------------------------------------------------------
//                                                                                                Protection tags

    function queryString(p) {
        var re = RegExp('[&?]' + p + '=([^&]*)');
        var matches;
        if (matches = re.exec(document.location)) {
            try { 
                return decodeURI(matches[1]);
            } catch (e) {
            }
        }
        return null;
    };

function misc_tagging()
{
  mw.util.addPortletLink('p-tb', mw.config.get('wgServer') + '/wiki/Wikipedia:Requests for page protection', "WP:RFPP");
}

$(misc_tagging);

// ----------------------------------------------------------

// pp-dispute

$(function (){
  if(queryString("jsaction")=="pp-dispute") {
  var fulldisputeexp = prompt( "Expiry time? (Optional)" );
  if ( fulldisputeexp == null ) {
  return;
 } else if ( fulldisputeexp == '' ) {
  var f = document.editform, t = f.wpTextbox1;
  t.value = "{" + "{pp-dispute}}" + '\n' + t.value;
  f.wpSummary.value = "{" + "{pp-dispute}}";
 } else {
  var f = document.editform, t = f.wpTextbox1;
  t.value = "{" + "{pp-dispute|expiry={" + "{subst:#time:F j, Y|\+" + fulldisputeexp + "}}}}" + '\n' + t.value;
  f.wpSummary.value = "{" + "{pp-dispute}}";
 }
  document.forms[0].wpSave.click();
 }
});

// pp-vandalism

$(function (){
  if(queryString("jsaction")=="pp-vandalism") {
  var fullvandalexp = prompt ("Expiry time? (Optional)");
  if ( fullvandalexp == null ) {
  return;
 } else if ( fullvandalexp == '' ) {
  var f = document.editform, t = f.wpTextbox1;
  t.value = "{" + "{pp-vandalism}}" + '\n' + t.value;
  f.wpSummary.value = "{" + "{pp-vandalism}}";
 } else {
  var f = document.editform, t = f.wpTextbox1;
  t.value = "{" + "{pp-vandalism|expiry={" + "{subst:#time:F j, Y|\+" + fullvandalexp + "}}}}" + '\n' + t.value;
  f.wpSummary.value = "{" + "{pp-vandalism}}";
 }
  document.forms[0].wpSave.click();
 }
});

// pp-usertalk

$(function (){
  if(queryString("jsaction")=="pp-usertalk") {
  var fulltalkexp = prompt ("Expiry time? (Optional)");
  if ( fulltalkexp == null ) {
  return;
 } else if ( fulltalkexp == '' ) {
  var f = document.editform, t = f.wpTextbox1;
  t.value = "{" + "{pp-usertalk}}" + '\n' + t.value;
  f.wpSummary.value = "{" + "{pp-usertalk}}";
 } else {
  var f = document.editform, t = f.wpTextbox1;
  t.value = "{" + "{pp-usertalk|expiry={" + "{subst:#time:F j, Y|\+" + fulltalkexp + "}}}}" + '\n' + t.value;
  f.wpSummary.value = "{" + "{pp-usertalk}}";
 }
  document.forms[0].wpSave.click();
 }
});

// pp-protected (other)

$(function (){
  if(queryString("jsaction")=="pp-protected") {
  var fullreason = prompt ( "This page is currently protected from editing because... (Optional)" );
  if ( fullreason == null ) {
  return;
 } else if ( fullreason == '' ) {
  var f = document.editform, t = f.wpTextbox1;
  t.value = "{" + "{pp-protected}}" + '\n' + t.value;
  f.wpSummary.value = "{" + "{pp-protected}}";
 } else {
  var f = document.editform, t = f.wpTextbox1;
  t.value = "{" + "{pp-protected|reason=" + fullreason + "}}" + '\n' + t.value;
  f.wpSummary.value = "{" + "{pp-protected}}";
 }

  var fullotherexp = prompt ( "Expiry time? (Optional)");
  if ( fullotherexp == null ) {
  return;
 } else if ( fullotherexp == '' ) {
  document.forms[0].wpSave.click();
 } else {
  var f = document.editform, t = f.wpTextbox1;
  t.value = t.value.split('{'+'{pp-protected').join('{'+'{pp-protected|expiry={{subst:#time:F j, Y|\+' + fullotherexp + "}}" );
  document.forms[0].wpSave.click();
 }
}
});

// pp-small=yes

$(function (){
  if(queryString("jsaction")=="pp-small") {
  var f = document.editform, t = f.wpTextbox1;
  t.value = "{" + "{pp-protected|small=yes}}" + '\n' + t.value;
  f.wpSummary.value = "{" + "{pp-protected|small=yes}}";
  document.forms[0].wpSave.click();
 }
});

// pp-semi-vandalism

$(function (){
  if(queryString("jsaction")=="pp-semi-vandalism") {
  var semivandalexp = prompt( "Expiry time? (Optional)" );
  if ( semivandalexp == null ) {
  return;
 } else if ( semivandalexp == '' ) {
  var f = document.editform, t = f.wpTextbox1;
  t.value = "{" + "{pp-semi-vandalism}}" + '\n' + t.value;
  f.wpSummary.value = "{" + "{pp-semi-vandalism}}";
 } else {
  var f = document.editform, t = f.wpTextbox1;
  t.value = "{" + "{pp-semi-vandalism|expiry={" + "{subst:#time:F j, Y|\+" + semivandalexp + "}}}}" + '\n' + t.value;
  f.wpSummary.value = "{" + "{pp-semi-vandalism}}";
 }
  document.forms[0].wpSave.click();
 }
});

// pp-semi-usertalk

$(function (){
  if(queryString("jsaction")=="pp-semi-usertalk") {
  var semitalkexp = prompt ("Expiry time? (Optional)");
  if ( semitalkexp == null ) {
  return;
 } else if ( semitalkexp == '' ) {
  var f = document.editform, t = f.wpTextbox1;
  t.value = "{" + "{pp-semi-usertalk}}" + '\n' + t.value;
  f.wpSummary.value = "{" + "{pp-semi-usertalk}}";
 } else {
  var f = document.editform, t = f.wpTextbox1;
  t.value = "{" + "{pp-semi-usertalk|expiry={" + "{subst:#time:F j, Y|\+" + semitalkexp + "}}}}" + '\n' + t.value;
  f.wpSummary.value = "{" + "{pp-semi-usertalk}}";
 }
  document.forms[0].wpSave.click();
 }
});

// pp-semi-socks

$(function (){
  if(queryString("jsaction")=="pp-semi-sock") {
  var semisockexp = prompt( "Expiry time? (Optional)" );
  if ( semisockexp == null ) {
  return;
 } else if ( semisockexp == '' ) {
  var f = document.editform, t = f.wpTextbox1;
  t.value = "{" + "{pp-semi-sock}}" + '\n' + t.value;
  f.wpSummary.value = "{" + "{pp-semi-sock}}";
 } else {
  var f = document.editform, t = f.wpTextbox1;
  t.value = "{" + "{pp-semi-sock|expiry={" + "{subst:#time:F j, Y|\+" + semisockexp + "}}}}" + '\n' + t.value;
  f.wpSummary.value = "{" + "{pp-semi-sock}}";
 }
  document.forms[0].wpSave.click();
 }
});

// pp-semi-protected (other)

$(function (){
  if(queryString("jsaction")=="pp-semi-protected") {
  var semireason = prompt ( "Editing of this article by unregistered or newly registered users is currently disabled because... (Optional)" );
  if ( semireason == null ) {
  return;
 } else if ( semireason == '' ) {
  var f = document.editform, t = f.wpTextbox1;
  t.value = "{" + "{pp-semi-protected}}" + '\n' + t.value;
  f.wpSummary.value = "{" + "{pp-semi-protected}}";
 } else {
  var f = document.editform, t = f.wpTextbox1;
  t.value = "{" + "{pp-semi-protected|reason=" + semireason + "}}" + '\n' + t.value;
  f.wpSummary.value = "{" + "{pp-semi-protected}}";
 }

  var semiotherexp = prompt ( "Expiry time? (Optional)");
  if ( semiotherexp == null ) {
  return;
 } else if ( semiotherexp == '' ) {
  document.forms[0].wpSave.click();
 } else {
  var f = document.editform, t = f.wpTextbox1;
  t.value = t.value.split('{'+'{pp-semi-protected').join('{'+'{pp-semi-protected|expiry={{subst:#time:F j, Y|\+' + semiotherexp + "}}" );
  document.forms[0].wpSave.click();
 }
}
});

// pp-semi-small=yes

$(function (){
  if(queryString("jsaction")=="pp-semi-small") {
  var f = document.editform, t = f.wpTextbox1;
  t.value = "{" + "{pp-semi-protected|small=yes}}" + '\n' + t.value;
  f.wpSummary.value = "{" + "{pp-semi-protected|small=yes}}";
  document.forms[0].wpSave.click();
 }
});

// Unprotection

$(function (){
  if(queryString("jsaction")=="unprotected") {
  var f = document.editform, t = f.wpTextbox1;
  var pp = RegExp("\{\{pp-.*?\}\}.*?\n");
  t.value = t.value.split(pp).join('');
  f.wpSummary.value = "Unprotected";
  var unprotconfirm = confirm( "This script removes new style protection templates (eg, {"+"{pp-whatever}}), but not the older versions." + "\n" + "If an old style protection template is still present (eg, {"+"{sprotect}}), hit cancel to remove it manually, otherwise hit OK to save the page." );
  if( !unprotconfirm ) {
  return;
 } else {
  document.forms[0].wpSave.click();
 }
}
});

// ---------------------------------------------------------------------------------------------------------

  if ( mw.config.get('wgNamespaceNumber') > -1 ) {

function portalClone(headername, id) {
 var boxclone = document.createElement("div");
 if( mw.config.get('skin') == "vector" ) {
  boxclone.className = 'portal collapsed';
  boxclone.setAttribute('id', id );
  var heading = document.createElement('h3');
  heading.appendChild(document.createTextNode( headername) );
  boxclone.appendChild(heading);
  var link_div = document.createElement('div');
  link_div.className = 'body';
  link_div.appendChild (document.createElement("ul"));
  boxclone.appendChild(link_div);

  } else {
  boxclone.id = id;
  boxclone.setAttribute("class","portlet");
  boxclone.style.marginTop = "7px";
  boxclone.style.marginBottom = "1px";

  var titolo = document.createElement("h3");
  titolo.innerHTML = headername;
  boxclone.appendChild(titolo);

  var corpo = document.createElement("div");
  corpo.setAttribute("class","pBody");
  var list_ul = document.createElement("ul");
  corpo.appendChild(list_ul);
  boxclone.appendChild(corpo);
 }
 var tb =  document.getElementById("p-tb");
 if( tb.nextSibling )
  tb.parentNode.insertBefore(boxclone, tb.nextSibling );
 else
  tb.parentNode.appendChild( boxclone );

 return boxclone;
}

function mylinks() {
 var boxclone = portalClone( "Protection tags", "p-navclone" );
 var baseuri = mw.config.get('wgScript') + '?title=' + encodeURIComponent( mw.config.get('wgPageName') ) + '&action=edit&jsaction=';

 mw.util.addPortletLink( 'p-navclone', baseuri + "pp-dispute", 'Full (dispute)', 'v-dispute' );
 mw.util.addPortletLink( 'p-navclone', baseuri + "pp-vandalism", 'Full (vandalism)', 'v-vandalism' );
 mw.util.addPortletLink( 'p-navclone', baseuri + "pp-usertalk", 'Full (unblockabuse)', 'v-usertalk' );
 mw.util.addPortletLink( 'p-navclone', baseuri + "pp-protected", 'Full (other)', 'v-protected' );
 mw.util.addPortletLink( 'p-navclone', baseuri + "pp-small", 'Full (small=yes)', 'v-small' );
 mw.util.addPortletLink( 'p-navclone', baseuri + "pp-semi-vandalism", 'Semi (vandalism)', 'v-s-vandalism' );
 mw.util.addPortletLink( 'p-navclone', baseuri + "pp-semi-usertalk", 'Semi (unblockabuse)', 'v-s-usertalk' );
 mw.util.addPortletLink( 'p-navclone', baseuri + "pp-semi-sock", 'Semi (sock problems)', 'v-s-socks' );
 mw.util.addPortletLink( 'p-navclone', baseuri + "pp-semi-protected", 'Semi (other)', 'v-s-protected' );
 mw.util.addPortletLink( 'p-navclone', baseuri + "pp-semi-small", 'Semi (small=yes)', 'v-small' );
 mw.util.addPortletLink( 'p-navclone', baseuri + "unprotected", 'Unprotected', 'v-uprot' );
}

function steel_toggle( $element ) {
 $.cookie( 'vector-nav-' + $element.parent().attr( 'id' ), $element.parent().is( '.collapsed' ) );
 $element
  .parent()
  .toggleClass( 'expanded' )
  .toggleClass( 'collapsed' )
  .find( 'div.body' )
  .slideToggle( 'fast' );
}

$( mylinks );

};

// </nowiki></pre>