User:Fæ/monobook.js

/* Commonly used imported scripts */ // importScript('User:SQL/refcheck.js'); // Reference checker // importScript('User:RRuk/autocopyvio.js'

/*
    Commonly used imported scripts
*/
// importScript('User:SQL/refcheck.js'); // Reference checker
// importScript('User:RRuk/autocopyvio.js'); // Copyvio menu
// importScript('User:Quarl/util.js'); importScript('User:Quarl/wikipage.js');

// importScript('Wikipedia:WikiProject User scripts/Scripts/Add LI menu'); 
// importStylesheet('Wikipedia:WikiProject User scripts/Scripts/Add LI menu/css'); 

// importScript('Wikipedia:WikiProject Deletion sorting/delsort.js');
// importScript("User:EpochFail/HAPPI.js"); // interesting but slow
// importScript('User:Smith609/toolbox.js'); // Citation bot
// importScript('User:Mr.Z-man/closeAFD.js');
// importScript('User:Ale_jrb/Scripts/igloo.js');
// importScript('User:Ale_jrb/Scripts/userhist.js');  //[[User:Ale_jrb/Scripts]]
// importScript('User:ProveIt GT/ProveIt.js'); // proveit.cc.gatech.edu

importScript('User:Fæ/QRcode.js'); //QRcode on toolbar
importScript('Wikipedia:WikiProject Deletion sorting/delsort.js'); // Appears in menu but does nothing at the moment

/*
   Local imports
*/
// importScript('User:Fæ/catWatch.js'); // Add category items to watchlist

/*
  Detect browser (use BrowserDetect.browser=="Firefox" or "Safari")

var BrowserDetect = {
  init: function () {
    this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
    this.version = this.searchVersion(navigator.userAgent)
      || this.searchVersion(navigator.appVersion)
      || "an unknown version";
    this.OS = this.searchString(this.dataOS) || "an unknown OS";
  },
  searchString: function (data) {
    for (var i=0;i<data.length;i++)  {
      var dataString = data[i].string;
      var dataProp = data[i].prop;
      this.versionSearchString = data[i].versionSearch || data[i].identity;
      if (dataString) {
        if (dataString.indexOf(data[i].subString) != -1)
          return data[i].identity;
      }
      else if (dataProp)
        return data[i].identity;
    }
  },
  searchVersion: function (dataString) {
    var index = dataString.indexOf(this.versionSearchString);
    if (index == -1) return;
    return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
  },
  dataBrowser: [
    {
      string: navigator.userAgent,
      subString: "Chrome",
      identity: "Chrome"
    },
    {   string: navigator.userAgent,
      subString: "OmniWeb",
      versionSearch: "OmniWeb/",
      identity: "OmniWeb"
    },
    {
      string: navigator.vendor,
      subString: "Apple",
      identity: "Safari",
      versionSearch: "Version"
    },
    {
      prop: window.opera,
      identity: "Opera"
    },
    {
      string: navigator.vendor,
      subString: "iCab",
      identity: "iCab"
    },
    {
      string: navigator.vendor,
      subString: "KDE",
      identity: "Konqueror"
    },
    {
      string: navigator.userAgent,
      subString: "Firefox",
      identity: "Firefox"
    },
    {
      string: navigator.vendor,
      subString: "Camino",
      identity: "Camino"
    },
    {    // for newer Netscapes (6+)
      string: navigator.userAgent,
      subString: "Netscape",
      identity: "Netscape"
    },
    {
      string: navigator.userAgent,
      subString: "MSIE",
      identity: "Explorer",
      versionSearch: "MSIE"
    },
    {
      string: navigator.userAgent,
      subString: "Gecko",
      identity: "Mozilla",
      versionSearch: "rv"
    },
    {     // for older Netscapes (4-)
      string: navigator.userAgent,
      subString: "Mozilla",
      identity: "Netscape",
      versionSearch: "Mozilla"
    }
  ],
  dataOS : [
    {
      string: navigator.platform,
      subString: "Win",
      identity: "Windows"
    },
    {
      string: navigator.platform,
      subString: "Mac",
      identity: "Mac"
    },
    {
         string: navigator.userAgent,
         subString: "iPhone",
         identity: "iPhone/iPod"
      },
    {
      string: navigator.platform,
      subString: "Linux",
      identity: "Linux"
    }
  ]

};
BrowserDetect.init();
*/
/*
    wikEd settings
*/
var wikEdComboPresetOptions = {};
wikEdComboPresetOptions['summary'] = ['copyedit', 'reply', 'article created', 'linkfix', 'typo fix', 'linkspam removal', 'vandalism revert', 'formatting', 'scripting', 'code tweak'];
// Browser specific
if(BrowserDetect.browser=="Safari"){
  window.wikEdTextSizeAdjust = 175;
}; // For some reason Safari appears to render the textbox in a teeny font by default

/*
  AutoEd
*/
var autoEdTag="Cleaned up using [[WP:AutoEd|AutoEd]]";
mw.loader.load('//en.wikipedia.org/w/index.php?title=Wikipedia:AutoEd/core.js&action=raw&ctype=text/javascript'); //Imports the "framework" script needed to make this function 
//Import individual modules for use
mw.loader.load('//en.wikipedia.org/w/index.php?title=Wikipedia:AutoEd/unicodify.js&action=raw&ctype=text/javascript'); // autoEdUnicodify() converts HTML entities to WikiText
mw.loader.load('//en.wikipedia.org/w/index.php?title=Wikipedia:AutoEd/isbn.js&action=raw&ctype=text/javascript'); // autoEdISBN() fixes ISBN syntax so that WikiMagic can work
mw.loader.load('//en.wikipedia.org/w/index.php?title=Wikipedia:AutoEd/whitespace.js&action=raw&ctype=text/javascript'); // autoEdWhitespace() cleans up whitespace
mw.loader.load('//en.wikipedia.org/w/index.php?title=Wikipedia:AutoEd/wikilinks.js&action=raw&ctype=text/javascript'); // autoEdWikilinks() simplifies and shortens wikilinks where appropriate
mw.loader.load('//en.wikipedia.org/w/index.php?title=Wikipedia:AutoEd/htmltowikitext.js&action=raw&ctype=text/javascript'); // autoEdHTMLtoWikitext() converts HTML to wikitext
mw.loader.load('//en.wikipedia.org/w/index.php?title=Wikipedia:AutoEd/headlines.js&action=raw&ctype=text/javascript'); // autoEdHeadlines() fixes common headline errors and renames some headers
mw.loader.load('//en.wikipedia.org/w/index.php?title=Wikipedia:AutoEd/unicodecontrolchars.js&action=raw&ctype=text/javascript'); // autoEdUnicodeControlChars() converts HTML to wikitext
mw.loader.load('//en.wikipedia.org/w/index.php?title=Wikipedia:AutoEd/templates.js&action=raw&ctype=text/javascript'); // autoEdTemplates() cleans up templates
mw.loader.load('//en.wikipedia.org/w/index.php?title=Wikipedia:AutoEd/tablestowikitext.js&action=raw&ctype=text/javascript'); // autoEdTablestoWikitext() replaces HTML tables with wikitables
mw.loader.load('//en.wikipedia.org/w/index.php?title=Wikipedia:AutoEd/extrabreaks.js&action=raw&ctype=text/javascript'); // autoEdExtraBreaks() removes extra BR tags
mw.loader.load('//en.wikipedia.org/w/index.php?title=Wikipedia:AutoEd/links.js&action=raw&ctype=text/javascript'); // autoEdLinks() cleans up common link errors
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Fæ/ae fixes.js&action=raw&ctype=text/javascript'); // FaeFixes() local options

function autoEdFunctions() { //Activates individual modules when "auto ed" tab is clicked
var txt = document.editform.wpTextbox1;
txt.value = autoEdUnicodify(txt.value);
txt.value = autoEdISBN(txt.value);
txt.value = autoEdWhitespace(txt.value);
txt.value = autoEdWikilinks(txt.value);
txt.value = autoEdHTMLtoWikitext(txt.value);
txt.value = autoEdHeadlines(txt.value);
txt.value = autoEdUnicodeControlChars(txt.value);
txt.value = autoEdTemplates(txt.value);
txt.value = autoEdTablestoWikitext(txt.value);
txt.value = autoEdExtraBreaks(txt.value);
txt.value = autoEdLinks(txt.value);
txt.value = FaeFixes(txt.value);
}

/* Add new url to toolbox */
function tbLink(tid,ttxt,thref) {
  var tul=document.getElementById("t-whatlinkshere"),ta=document.createElement("a"),tli=document.createElement("li");
  ta.appendChild(document.createTextNode(ttxt));
  ta.href=thref;
  tli.appendChild(ta);
  tli.id=tid;
  tul.parentNode.appendChild(tli);
}

/*
    Onload actions
*/
addOnloadHook(function(){

  // Navigation area
  /* Swap Random article link for Commons and other handy links */
  var rpage=document.getElementById("n-randompage"), vpage=document.getElementById("n-variablepage"),
    thisUser=mw.config.get('wgPageName').search(/User/)>-1?wgPageName.split(":")[1].split("/")[0].replace(/[\s\']/g,"_"):"Fæ";
  rpage.innerHTML="<a href=http"+"://commons.wikimedia.org/w/index.php?title=Special:Watchlist&days=31 target=wtab >"+
    (thisUser==""?"Commons":"c")+
    "</a> &middot; <a href=http"+
    "://uk.wikimedia.org/w/index.php?title=Special:Watchlist&days=60 target=wtab >uk</a>"+(thisUser!=""?" &middot; <a href=http"+
    "://toolserver.org/~soxred93/pcount/index.php?lang=en&wiki=wikipedia&name="+
    thisUser+" target=wtab title='Edit count for "+thisUser+"'>ec</a> &middot; "+"<a href=http"+
    "://toolserver.org/~vvv/sulutil.php?user="+thisUser+" target=wtab title='Global accounts for "+thisUser+"'>sul</a>":"");
  vpage.innerHTML="<a href=https"+
    "://ticket.wikimedia.org/otrs/index.pl?Action=AgentTicketQueue&QueueID=34&View="+
    " target=otrs title='OTRS database'>OTRS</a>";

  // Highlight Watchlist
  if(mw.config.get('wgPageName') == "Special:Watchlist" || mw.config.get('wgPageName')=="Special:RecentChanges" || mw.config.get('wgPageName')=="Special:RecentChangesLinked"){
    var myBody=document.getElementById('bodyContent'),
      bodyLinks=myBody.getElementsByTagName('a'),
      spans=myBody.getElementsByTagName('span');
    for(var i=0;i<spans.length;i++){ // Rollbacks
      if(spans[i].className=="mw-rollback-link"){
        if (mw.config.get('wgPageName') == "Special:Watchlist") { // Add unwatch link and shorten rollback link
          var myHref=spans[i].childNodes[1].href.replace(/action.rollback.*/,'action=unwatch'),
            myUnwatch=document.createElement('a');
          myUnwatch.innerHTML="&nbsp;~";
          myUnwatch.title="Unwatch"+myHref.replace(/.*=(.*)&.*/," $1");
          myUnwatch.href=myHref;
          myUnwatch.target="unwatch";
          spans[i].parentNode.appendChild(myUnwatch);
          spans[i].childNodes[1].innerHTML=spans[i].childNodes[1].innerHTML.replace(/rollback/g,"-");
          spans[i].innerHTML=spans[i].innerHTML.replace(/\]|\[/g,"");
        }else if(mw.config.get('wgPageName')=="Special:RecentChanges" || mw.config.get('wgPageName')=="Special:RecentChangesLinked"){
          var myArrow=document.createTextNode('--');
          spans[i].parentNode.insertBefore(myArrow,spans[i].parentNode.firstChild);
          //"<font style='color:red;font-weight:bold'>&rarr;</font>"+spans[i].parentNode.innerHTML+"<font style='color:red;font-weight:bold'>&larr;</font>";
        }
      }  // end if className
    } // end for i
    for (var i in bodyLinks){
      if(bodyLinks[i].innerHTML.search(/Fæ/)>-1){ // Green
        bodyLinks[i].parentNode.style.backgroundColor="#BFB";
        bodyLinks[i].parentNode.style.color="black";
        var theseLinks=bodyLinks[i].parentNode.getElementsByTagName('a');
        for (var e=0; e<theseLinks.length && e<3; e++){
          theseLinks[e].style.color="darkgreen";
          theseLinks[e].style.backgroundColor="#BFB";
        }
      } else if(bodyLinks[i].innerHTML.search(/^\d{1,3}\.\d{1,3}\./)>-1){ // Red
        with(bodyLinks[i].parentNode){
          style.backgroundColor="#FBB";
          //innerHTML="<font style='color:red;'>&rarr;</font>"+innerHTML;
        }
      } else if(bodyLinks[i].innerHTML.search(/Bot$|WOSlinker$|^MiszaBot/i)>-1){
        with(bodyLinks[i].parentNode){
          style.backgroundColor="#BBB"; // Grey
          parentNode.style.fontSize="80%";
          parentNode.style.lineHeight="80%";
          parentNode.parentNode.parentNode.style.paddingLeft="1.42em"; // Indent at table level
        }
        var theseLinks=bodyLinks[i].parentNode.getElementsByTagName('a');
        for (var e=0; e<theseLinks.length; e++){
          theseLinks[e].style.color="#303030";
          theseLinks[e].style.backgroundColor="#BBB";
        }
      } else if(bodyLinks[i].innerHTML.search(/^AWB$/)>-1){
        with(bodyLinks[i].parentNode.parentNode){
          style.backgroundColor="#BBB"; // Grey
          parentNode.style.fontSize="80%";
          parentNode.style.lineHeight="80%";
          parentNode.parentNode.parentNode.style.marginLeft="1.42em"; // Indent at table level
        }
      }  // End if
    } // End for bodyLinks
  } else if(mw.config.get('wgPageName')=="Special:Log"){ // Delete non-contributing lines for logs of new users
    var myBody=document.getElementById('bodyContent'),
      lineitems=myBody.getElementsByTagName('li');
    for(var i=lineitems.length-1;i>-1;i--){
      if(lineitems[i].className=="mw-logline-newusers"){
        if(lineitems[i].innerHTML.search(/class="new">contribs</)>-1){
          lineitems[i].parentNode.removeChild(lineitems[i]); //lineitems[i].innerHTML="";
        }
      }
    }
  } // End if wgPageName
  // Map to underworld
  for (var i in document.links){
    if(document.links[i].innerHTML=="Fæ"){
      document.links[i].href="http://en.wikipedia.org/wiki/User:Fæ/Underworld";
      document.links[i].innerHTML="<font style='color:green;'>Fæ</font>";
      break; // Only change the first indexed link that matches
    }
  }

  // Additions to toolbox
  // Dab
  var myPage=mw.config.get('wgPageName').search(/User|Talk|Wikipedia/i)<0?wgPageName.split(":")[0].replace(/[\s\']/g,"_"):'';
  if(mw.config.get('wgPageName').search(/User|Talk|Wikipedia/i)<0){
    tbLink("t-dab","Dab check","http:"+"//toolserver.org/~dispenser/cgi-bin/dab_solver.py?page="+myPage+"&commonfixes=on");
    }
  // Re-skin
  if(location.href.search(/useskin/)<0){
    tbLink("t-vskin","Vector skin","http://en.wikipedia.org/wiki/"+mw.config.get('wgPageName')+"?&useskin=vector");
  }
}
);

/*
    Regex menu framework
*/
function rmflinks() {
  var mypage=mw.config.get('wgPageName').split(':')[0];
  var txt=document.editform.wpTextbox1, txtv=txt.value;
  regexTool('{\{linktext\|}\}','linky("linktext")');
  if(mypage.search(/talk|wikipedia|user/ig)>-1){
    /* regexTool('~\~\~\~','sig()'); */
    regexTool('[\[wp:]\]','linky("wp")');
    if(txt.value.length>20 || location.href.search(/section=new/)>-1){
      regexTool('[\[user:]\]','linky("user")');
      regexTool('\<'+'nowiki>','linky("nowiki")');
      regexTool('hide blue','hideText()');
      regexTool('hide green','hideText("lightgreen")');
      regexTool('hide yellow','hideText("lightyellow")');
    }
    if(mypage == "User_talk"){ // User talk page
      if(txt.value.length<200){
        var twcheck=location.href.search(/vanarticle=/)>-1 ? "*" : "";
        if(location.href.search(/\d{1,3}\.\d{1,3}\.\d{1,3}/)>-1){      // New anon IP?
          regexTool('Welcome anon IP','myWelcome("anon")');
          regexTool('- vandal'+twcheck,'myWelcome("anonvandal")');
          regexTool('- non-neutral'+twcheck,'myWelcome("pov-anon")');
          regexTool('- blanking'+twcheck,'myWelcome("blank-anon")');
          regexTool('- photo help'+twcheck,'myWelcome("photo-anon")');
          regexTool('- unsourced'+twcheck,'myWelcome("unsourced-anon")');
        } else { // New and not anon?
          regexTool('Welcome default','myWelcome("graphical")');
          regexTool('- pink','myWelcome("pink")');
          // regexTool('- red','myWelcome("red")');
          regexTool('- cookies','myWelcome("cookies")');
          regexTool('- laws','myWelcome("laws")');
          regexTool('- test or blanking'+twcheck,'myWelcome("testedit")');
          regexTool('- userspace only','myWelcome("0")');
          regexTool('- vandal'+twcheck,'myWelcome("vandal")');
          regexTool('- spam'+twcheck,'myWelcome("spam")');
          regexTool('- non-neutral'+twcheck,'myWelcome("pov")');
          regexTool('- photo help'+twcheck,'myWelcome("photo")');
          regexTool('- unsourced'+twcheck,'myWelcome("unsourced")');
        }
        if(twcheck.length>0){regexTool('- ELNO'+twcheck,'myWelcome("elno")')};
      } else {
      regexTool('Tidy warnings','tidyWarnings()');
      }
    } else if(mypage == "Talk"|| mypage == "Wikipedia_talk"){ // Article or WP talk page
      if(txtv.search(/MiszaBot/)==-1){regexTool('Auto archive','archiving()')};
      if(txtv.search(/\{BM-related/)==-1){regexTool('BM-related','talkHead("BM-related\n\|class=Stub\n\|importance=\n")')};
      if(txtv.search(/\{WPBS/i)==-1){regexTool('Banner shell','wpbs()')};
      if(location.href.search(/section=0/)>-1&&txtv.search(/\}\}$/)==-1){regexTool('Add initial title','initTitle()')};
      if(txtv.search(/\{hidemessages/)==-1){regexTool('Hide messages','talkHead("Hidemessages\|\n")')};
      if(txtv.search(/\{find/i)==-1){regexTool('Find notice','find()')};
    }
  regexTool('icon smiley','smiley("1")');
  regexTool('icon shades','smiley("9")');
  regexTool('Char codes','tidyChar()');
  }else{ // Appears to be an Article page
    var txt=document.editform.wpTextbox1;
    regexTool('{\{cn}\}','cn()');
    regexTool('{\{weasel}\}','weasel()');
    if(location.href.search(/section=/)==-1){ // Editing the whole page
      if(txt.value.search(/== ?(References|Notes|Footnotes)/)==-1){regexTool('§ references','refs()')};
      if(txt.value.search(/== ?See also/)==-1){regexTool('§ see also','seeAlso()')};
    } else { // Editing section
    if(txt.value.search(/<ref/)==-1){regexTool('{\{ref\|sec}\}','refSec()')}
    }
    if(txt.value.search(/DEFAULTSORT/)==-1){regexTool('default sort','defaultsort()')};
    if(txt.value.search(/==.*ultur[ae]/)>-1){regexTool('popular culture','ipc()')};
    regexTool('strip footnotes','stripFN()');
    if(mypage.search(/Category/ig)>-1){regexTool('catWatch','catWatch()')};
    if(txt.value.search(/\{\{(adv|notab|pov|blp unsourced|blp sources|refimprove|nofootnotes|original|coi|news release)/i)>-1){regexTool('Multiple tag','multiple()')};
    if(txtv.search(/alumn(i|ae)\w*==/i)>-1){
      regexTool('{\{Alumni}\}',
        'insertTags("\\n{\{Alumni}\}","","");setreason("Alumni list citations needed")');
    }
  }
}

/* Regex: helpful supporting functions */
function wedClassic(tog){ // Check whether wikEd is in classic view or not
  if (typeof(wikEdUseWikEd) == 'undefined') {return}; // If not enabled then give up
  if (wikEdUseWikEd == true){ // Using wikEd
    if(tog=="on"){document.getElementById('wikEdUseWikEd').click()};
    if(tog==null){return false}; // Return false if not classic view
  } else {
    if(tog=="off"){document.getElementById('wikEdUseWikEd').click()};
    if(tog==null){return true}; // Return true if in classic view
  }
}

/* Regex: signature */
function sig(){
  insertTags("Fæ (\[\[User talk:Fæ"+(mw.config.get('wgPageName')=="User_talk:Fæ"?"#top":"")+"|talk\]\]) ~\~\~\~\~","","");
}
/* Regex: cn tag */
function cn(){
  insertTags("{\{Citation needed}\}","","");
  setreason("Citation needed");
}
/* Regex: weasel tag */
function weasel(){
  insertTags("{\{weasel-inline}\}","","");
  setreason("Copyedit needed");
}
/* Regex: references section */
function refs(){ insertTags("\n== References ==\n{\{reflist}\}\n","","") };
/* Regex: see also section */
function seeAlso(){ insertTags("\n== See also ==\n","","") };

function myWelcome(mytype){
  var welBox='\<div style="padding:0.5em;border:orange solid 1px;{\{subst:border-radius|6px}\};width:98%;">',
    // Emphasises warning
    va=location.href.search(/vanarticle=/)>-1 ? "|"+location.href.split(/vanarticle=/)[1].split(/\&/)[0].replace(/%2C/g,",").replace(/_/g," ") : "",
    tdy=new Date(),  arrM='January,February,March,April,May,June,July,August,September,October,November,December'.split(','), mhead="=\= "+arrM[tdy.getMonth()]+" 2010 =\=\n",
    uw1="\<!-- Template:uw-vandalism1 -->",
    whead="=\= Welcome =\=\n";
    uwBox=welBox+"[\[File:Information.svg\|25px\|alt=Info|right]\]";
    anonTxt="\n\nYou are welcome to continue editing articles without [[Special:Userlogin|logging in]], but many editors recommend that you '''<span class='plainlinks'>[{\{fullurl:Special:Userlogin|type=signup}\} create an account]</span>'''. Doing so is free, requires no personal information, and provides several benefits such as the ability to create articles. For a full outline and explanation of the benefits that come with creating an account, please see [[Wikipedia:Why create an account?|this page]]. If you edit without a username, your [[IP address]] ({\{ subst:ROOTPAGENAME}\}) is used to identify you instead."
  switch(mytype){
    default:
      insertTags(whead+'\{\{divbox\|fawn\|\|\{'+'{subst:w-basic\|subst=subst:\|cookies=true}'+'}\n\}\}','','');break;
    case "graphical":
      insertTags(whead+'{\{subst:User:Fæ/Welcome}\}','','');break;
    case "laws":
      insertTags(mhead+'{\{subst:User:Fæ/Welcomelaws}\}','','');break;
    case "pink":
      insertTags(whead+'{\{subst:User:Fæ/Welcome|color=pink}'+'}','','');break;
    case "red":
      insertTags(whead+'{\{subst:User:Fæ/Welcome|color=red}'+'}','','');break;
    case "anon":
      insertTags(whead+welBox+'{'+'{subst:welcome-anon}'+'} ~\~\~\~\</div\>','','');break;
    case "0":
      insertTags(whead+'\{\{divbox\|fawn\|\|{\{subst:Welcome0}\}\n\}\}','','');break; // for new users who have created their user page, but have not yet contributed elsewhere
    case "testedit":
      insertTags(mhead+'{\{subst:Template:Welcome-test'+va+'}\}','','');break; // test edits or blanking
    case "photo":
      insertTags(whead+'{\{subst:User:Fæ/Welcome}\}\n{\{subst:User:Fæ/help/photo}\}','','');break;
    /* Anonymous contributors */
    case "pov-anon":
      insertTags(mhead+uwBox+'{\{subst:welcomenpov'+va+'}\}'+anonTxt+' ~~\~~\</div>'+uw1,'','');break;
    case "pov":
      insertTags(mhead+uwBox+'{\{subst:welcomenpov'+va+'}\} ~~\~~\</div>'+uw1,'','');break; // for someone whose initial efforts do not adhere to the NPOV policy
    case "unsourced-anon":
      insertTags(mhead+uwBox+'{\{subst:welcomeunsourced'+va+'}\}'+anonTxt+' ~~\~~\</div>'+uw1,'','');break;
    case "blank-anon":
      insertTags(mhead+uwBox+'{\{subst:Uw-delete1'+va+'}\}'+anonTxt+' ~~\~~\</div>'+uw1,'','');break;
    case "unsourced":
      insertTags(mhead+uwBox+'{\{subst:welcomeunsourced'+va+'}\} ~~\~~\</div>'+uw1,'','');break;
    case "spam":
      insertTags(mhead+uwBox+'{\{subst:Welcomespam'+va+'}\} ~~\~~\</div>'+uw1,'','');break;
    case "elno":
      insertTags(mhead+'{\{subst:User:Fæ/Welcome|1=As you have just started editing, I hope you find the following selection of links helpful and that they provide you with some ideas for how to get the best out of Wikipedia. The external link you added to \[\['+va+'\]\] has been removed as it appeared to fail the guidance of \[\[WP:ELNO|External links to be avoided\]\], please take some time to review the guidance and discuss on the article talk page (\[\[Talk:'+va.replace(/\|/g,'')+'\]\]) if you disagree.}\}','','');break;
    case "vandal":
      insertTags(mhead+uwBox+'{\{subst:Welcomevandal'+va+'}\}\</div>'+uw1,'','');break;
    case "anonvandal":
      insertTags(mhead+'{'+'{subst:Welcome-anon-vandal'+va+'\|notitle=yes}\}'+uw1,'','');break;
    case "photo-anon":
      insertTags(whead+welBox+'{'+'{subst:welcome-anon}'+'} ~\~\~\~\</div\>\n{\{subst:User:Fæ/help/photo}\}','','');break;
  }
  setreason('Welcome');
  doaction('save');
}

/* Regex: anonymous IP vandal welcome */
function stubPage(){
  insertTags('.','','');
  setreason('Stub');
  doaction('save');
}
/* Regex: tidy user warnings */
function tidyWarnings(){
  if(regsearch(/==/)!=null){ // if no titles then give up
    var count=0;
    var txt = document.editform.wpTextbox1;
    // Delete duplicate headings
    var arrT=txt.value.match(/==.*==/g); // do a .match to create array
    while (count<arrT.length-1){
      // compare next two titles
      if(arrT[count]==arrT[count+1]){
        var t1=new RegExp(arrT[count]);
        regex(t1,"-!-PARK-!-"); // park first match
        regex(t1,"-!-DEL-!-"); // delete second match
        regex(/-!-DEL-!-\n*/gm,"");
        regex(/-!-PARK-!-/,arrT[count]); // unpark
      }
      count++;
    }
    txt.value=txt.value.replace(/(\}\}\n)\n+/gm,"$1").replace(/\n+(\n\{\{)/gm,"$1"); // drop surplus lines around templates
    txt.value=txt.value.replace(/(==\n)\n+/gm,"$1").replace(/\n+(\n==)/gm,"$1"); // drop surplus lines around headers
    txt.value=txt.value.replace(/^\n+/g,"").replace(/\n+$/g,""); // drop trailing lines
    // Find current month
    var strYear='2010', lastMonth='January';
    var arrMonth='January,February,March,April,May,June,July,August,September,October,November,December'.split(',');
    var dteNow= new Date();
    var intMonth = dteNow.getMonth();
    var strMonth = arrMonth[intMonth];
    if(intMonth>1){lastMonth=arrMonth[intMonth-1]};
    var regexLastMonth=new RegExp("(==( ?)"+lastMonth+" "+strYear+"( ?)==)");
    var regexMonth=new RegExp("(==( ?)"+strMonth+" "+strYear+"( ?)==)");
    regex(/\n{3,}/gm,'\n\n'); // Strip blank lines
    regex(/\n?\{\{old IP warnings [^\}]+\}\}/gim,''); // Strip previous warnings
    regex(/(==|.*[Ww]elcome)/,'{'+'{old IP warnings top}}\n$1'); // Start hiding from top of page
    if(regsearch(regexLastMonth)!=null){
      regex(regexLastMonth,'{'+'{old IP warnings bottom}}\n$1');
    } else if(regsearch(regexMonth)!=null){
      regex(regexMonth,'{'+'{old IP warnings bottom}}\n$1');
    } else { // No match to last or current month so match earliest entry for this year
      var myRegex=new RegExp("(==[^=]*"+strYear+"[^=]*==)$");
      if(regsearch(myRegex)!=null){
        regex(myRegex,'{'+'{old IP warnings bottom}}\n$1');
      }else{
        txt.value=txt.value+'\n{'+'{old IP warnings bottom}}';
      }
    }
    var myPat=":'"+"'If this is a shared ["+"[IP address"; // Replace all but the last match for this note
    while (txt.value.indexOf(myPat)<txt.value.lastIndexOf(myPat)) {
      txt.value=txt.value.replace(/\n.{2,5}If this is a shared.{1,5}IP address.*/,'');
    }
    txt.value=txt.value.replace(/..old IP warnings top..\n..old IP warnings bottom..\n/,""); // ignore null case
    txt.value=txt.value.replace(/\n Fæ/g," Fæ"); // Odd correction?
    setreason('Tidy');
  }
   // doaction('diff');
}
/* Regex: default sort */
function defaultsort(){
  var pn=mw.config.get('wgPageName').split('_(')[0].replace(/_/g," "); // Name
  if(pn.search(' ')>-1){
    var arrPn=pn.split(' ');
    pn=arrPn.pop()+', '+arrPn.join(' ');
  }
  var txt = document.editform.wpTextbox1;
  if(txt.value.search(/\[\[Category/i)>-1){
    txt.value=txt.value.replace(/(\[\[Category)/i,"{\{DEFAULTSORT:"+pn+"}}\n$1");
  }else{ // No categories?
    txt.value=txt.value+"\n{\{DEFAULTSORT:"+pn+"}}\n";
  }
  setreason("default sort");
  document.editform.wpMinoredit.checked = true; // Make this a minor edit
  doaction('diff');
}
/* Regex: in popular culture */
function ipc(){
  var ppattern=/(===*[\w ]*(popular|human|general)* ?cultur[ael]*[\w ]*===*)/gi;
  if(regsearch(ppattern)!=null){
    regex(ppattern,'$1\n{\{In popular culture}}');
    setreason('Popular culture list seems trivial');
  } else {
    setreason('No popular culture section found!');
  }
  doaction('diff');
}
/* Regex: References needed in section */
function refSec(){
  regex(/(==\n)/,'$1{\{Unreferenced section}\}\n');
  setreason('Unreferenced section');
}
/* Regex: linking while writing */
function linky(t){
  switch(t){
  case "wp":insertTags('[[wp:','\|]\]');break;
  case "user":insertTags('[[user:','\|]\]');break;
  case "linktext":insertTags('{\{linktext|','}\}');break;
  case "nowiki":insertTags('<'+'code style="background:#DFD"><'+'nowiki>','<'+'/nowiki><'+'/code>');break;
  default: insertTags('[[',']\]');break;
  }
}

/* Regex: Bare footnotes */
function stripFN(){
  var txt = document.editform.wpTextbox1;
  txt.value=txt.value.replace(/(>)\[(http[^]]+)\](<)/g,"$1$2$3");
  document.editform.wpMinoredit.checked = true; // Minor edit
  setreason("Strip links");
  doaction('diff');
}

/* Regex: Archive in talk header */
function archiving(){
  var pName=mw.config.get('wgPageName').replace(/_/g," ");
  var temp="<!-- archive must stay multi-line -->\n"+
    "{\{User:MiszaBot/config\n|archiveheader = {\{aan}}"+
    "\n|maxarchivesize = 200K"+
    "\n|counter = 1"+
    "\n|minthreadsleft = 5"+
    "\n|minthreadstoarchive = 1"+
    "\n|algo = old(60d)"+
    "\n|archive = "+pName+"/Archive %(counter)d"+
    "\n}}\n"+
    "{\{archives|auto=|search=yes|bot=MiszaBot|age=60}}";
  insertTags(temp,'','');
  setreason("Archiving");
}
/* Regex: Project in talk header */
function talkHead(h){
  insertTags('{\{'+h,'}\}','');
  var txt=document.editform.wpTextbox1;
  txt.value=txt.value.replace(/\{\{4}([^\{])/g,"{\{\n{\{$1").replace(/([^\}])\}{4}/g,"$1\}\}\n\}\}").replace(/\|\{\{/g,"\|\n\{\{");
  setreason("Header");
}
/* Regex: WikiProjectBannerShell */
function wpbs(){
  var txt = document.editform.wpTextbox1;
  txt.value=txt.value.replace(/WikiProjectBannerShell\|1/,"WikiProjectBannerShell\|blp=yes\|1");
  if(txt.value.search(/\{\{(shell|WikiProjectBanners)\|/)>-1){
    txt.value=txt.value.replace(/\{\{shell|\{\{WikiProjectBanners/,"{\{WikiProjectBannerShell")
      .replace(/WikiProjectBannerShell\|1/,"WikiProjectBannerShell\|blp=yes\|1");
  } else if(txt.value.search(/\{\{WikiProjectBannerShell/i)==-1){
    var banner="{\{WikiProjectBannerShell|blp=yes|1=\n";
    insertTags(banner,'}}');
  } else { // Banner exists so toggle BLP between 3 states
    if(txt.value.search(/Shell.blp=yes/i)>-1){
      txt.value=txt.value.replace(/blp=yes/,"blpo=yes");
    }else if(txt.value.search(/Shell.blp=no/i)>-1){
      txt.value=txt.value.replace(/blp=no/,"blp=yes");
    }else if(txt.value.search(/Shell.blpo=yes/i)>-1){
      txt.value=txt.value.replace(/blpo=yes/,"blp=no");
    }
  }
  document.editform.wpMinoredit.checked = true; // Make this a minor edit
  setreason("Header");
}
/* Regex: initial talk page title */
function initTitle(){
  var txt = document.editform.wpTextbox1;
  txt.value=txt.value.replace(/(\}\})\n*([^\}]+)$/,"$1\n\n== Initial ==\n$2");
  setreason("Layout");
}
/* Regex: Collapse text on a talk page */
function hideText(c){
  if(c!=null){}else{c="lightblue"};
  insertTags("{\{cot\|bg="+c+"}\}\n","\n{\{cob}\}");
}

/* Regex: ASCII codes */
function tidyChar() {
  // External links
  for(var i=0;i<20;i++){ // keep underscores in web addresses
    regex(/(http:\/\/[\S]*?)_/g,"$1xunderscorex")
    regex(/(http:\/\/[\S]*?)\%22/g,"$1xquotex")
  };
  regex(/_/g,' ');
  regex(/[\.%]22/g,'"'); // Quotes
  regex(/xunderscorex/g,'_'); // unpark underscore
  regex(/xquotex/g,'%22'); // unpark quotes
  // Changes that don't break external links
  regex(/[\.%]3F/g,'?'); // Question mark
  regex(/[\.%]26/g,'&'); // Amp
  regex(/[\.%]28/g,'(');
  regex(/[\.%]29/g,')'); // Brackets
  regex(/[\.%]27/g,'\''); // apostrophe
  regex(/[\.%]2F/g,'/'); // slashes
  regex(/[\.](7B|7D)/g,'%$1'); // curly brackets (will display link correctly but cannot use actual character)
  //setreason('ASCII format');
  doaction('diff');
}
/* Regex: Multiple issues */
function multiple(){
  var txt = document.editform.wpTextbox1,
    myTags=new Array("advertisement","advert","autobiography","biased","blpdispute","citations missing","citations missing:nofootnotes",
"citation style","citecheck","cleanup","COI","colloquial",
"confusing","context","contradict","copyedit","criticism-section:criticisms",
"crystal","deadend","disputed","essay-entry","examplefarm","expand",
"expert","external links","fancruft","fansite","fiction",
"globalize","copyedit","histinfo","hoax","howto",
"inappropriate person","incomplete","lead missing","lead rewrite","lead too long",
"lead too short","in-universe","cleanup-jargon","cleanup-laundry","likeresume",
"verylong","newsrelease:news release","notability","onesource","onesource:one source","original research",
"orphan","Out of date","peacock","plot","POV",
"POV-check","primarysources:primary sources","primarysources","prose","proseline","quotefarm",
"recentism","refimprove","refimprove:morefootnotes","refimproveBLP","refimproveBLP:BLP sources","cleanup-restructure:cleanup","review",
"rewrite","sections","self-published","cleanup-spam","story",
"synthesis","inappropriate tone","travel guide","trivia","unbalanced",
"unencyclopedic","unreferenced","unreferencedBLP:unreferenced BLP", "unreferencedBLP:BLP unsourced","update","weasel",
"wikify"),
    myTagsSearch='', mulTag="{"+"{Multiple issues\n";
  for(var i=0;i<myTags.length;i++){
    myTagsSearch=myTagsSearch+"\|\\{\\{"+(myTags[i].search(':')>-1?myTags[i].split(":")[1]:myTags[i]);
  }
  myTagsSearch=myTagsSearch.substring(1); // Drop first character
  var myTagsPattern=new RegExp("("+myTagsSearch+")","mi");
  if(txt.value.search(/\{Multiple issues/i)==-1){
    txt.value=txt.value.replace(myTagsPattern, mulTag+"\}\}\n$1"); //Insert multiple at first tag occurrence if does not already exist
  }
  //Create rest of tag
  for(var i=0;i<myTags.length;i++){
    var thisTag=myTags[i];
    if(thisTag.search(/\:/)>-1){thisTag=thisTag.split(":")[1]};
    var thisTagPattern=new RegExp("\\{\\{"+thisTag,"i");
    if(txt.value.search(thisTagPattern)>-1){
      thisTag=txt.value.match(thisTagPattern)[0];
      var tDate=(txt.value.split(thisTag)[1]).split('}')[0].replace(/\n/g," ").replace(/\|/,"").replace(/date ?= ?/,"");
      if(tDate.search(/inline|\|/)==-1){
        mulTag=mulTag+"\|"+myTags[i].split(':')[0]+(tDate.length>2? "="+tDate : "")+"\n";
        var pattern=new RegExp("\\{\\{"+thisTag.replace(/\{/g,"")+"[^\\}]*"+"\\}\\}\\n?","i");
        txt.value=txt.value.replace(pattern,"");
      }
    }
  }
  //Insert
  txt.value=txt.value.replace(/\{\{Multiple issues\n/,mulTag);
  setreason("Merge multiple issues");
}
/* Regex: Find notice */
function find(){
  var pName=mw.config.get('wgPageName').split(':')[1].split('_(')[0].replace(/_/g," ");
  insertTags('{\{tmbox\|image=[[File:Gnome-searchtool.svg\|40px]]|text={\{find\|','}\}\}\}',pName);
  document.editform.wpMinoredit.checked = true; // Make this a minor edit
  setreason("Header");
}
/* Regex: Smiley */
function smiley(p){
  insertTags('{\{=)'+(p=='1'?'':'|'+p)+'}}','','');
}

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.