User:Fæ/monobook.js

From Wikimedia UK
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/*
    Commonly used imported scripts
*/
importScript('User:SQL/refcheck.js'); // Reference checker
//importScript('User:Lupin/popups.js'); popupFixDabs = true;
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('User:AzaToth/twinkle.js'); // In preference settings

importScript('Wikipedia:WikiProject Deletion sorting/delsort.js');
// importScript("User:EpochFail/HAPPI.js"); // interesting but slow
importScript('User:Smith609/toolbox.js'); // Citation bot

/*
   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]]";
importScriptURI('http://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
importScriptURI('http://en.wikipedia.org/w/index.php?title=Wikipedia:AutoEd/unicodify.js&action=raw&ctype=text/javascript'); // autoEdUnicodify() converts HTML entities to WikiText
importScriptURI('http://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
importScriptURI('http://en.wikipedia.org/w/index.php?title=Wikipedia:AutoEd/whitespace.js&action=raw&ctype=text/javascript'); // autoEdWhitespace() cleans up whitespace
importScriptURI('http://en.wikipedia.org/w/index.php?title=Wikipedia:AutoEd/wikilinks.js&action=raw&ctype=text/javascript'); // autoEdWikilinks() simplifies and shortens wikilinks where appropriate
importScriptURI('http://en.wikipedia.org/w/index.php?title=Wikipedia:AutoEd/htmltowikitext.js&action=raw&ctype=text/javascript'); // autoEdHTMLtoWikitext() converts HTML to wikitext
importScriptURI('http://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
importScriptURI('http://en.wikipedia.org/w/index.php?title=Wikipedia:AutoEd/unicodecontrolchars.js&action=raw&ctype=text/javascript'); // autoEdUnicodeControlChars() converts HTML to wikitext
importScriptURI('http://en.wikipedia.org/w/index.php?title=Wikipedia:AutoEd/templates.js&action=raw&ctype=text/javascript'); // autoEdTemplates() cleans up templates
importScriptURI('http://en.wikipedia.org/w/index.php?title=Wikipedia:AutoEd/tablestowikitext.js&action=raw&ctype=text/javascript'); // autoEdTablestoWikitext() replaces HTML tables with wikitables
importScriptURI('http://en.wikipedia.org/w/index.php?title=Wikipedia:AutoEd/extrabreaks.js&action=raw&ctype=text/javascript'); // autoEdExtraBreaks() removes extra BR tags
importScriptURI('http://en.wikipedia.org/w/index.php?title=Wikipedia:AutoEd/links.js&action=raw&ctype=text/javascript'); // autoEdLinks() cleans up common link errors

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);
}

/*
    Onload actions
*/
addOnloadHook(function(){
  // Navigation area
  /* Swap Random article link for Commons and other handy links */
  var rpage=document.getElementById("n-Donate"),
    thisUser=wgPageName.search(/User/)>-1?wgPageName.split(":")[1].split("/")[0].replace(/[\s\']/g,"_"):"";
  rpage.innerHTML="<a href=http"+"://commons.wikimedia.org/wiki/Special:Watchlist target=_blank>"+
    (thisUser==''?'c':'c')+'</a> &middot; <a href=http'+
    '://en.wikipedia.org/wiki/Special:Watchlist target=_blank>'+(thisUser==''?'wikipedia':'w')+'</a> &middot; <a href=http'+
    "://uk.wikimedia.org/wiki/Special:Watchlist target=_blank>uk</a>"+(thisUser!=""?" &middot; <a href=http"+
    "://toolserver.org/~soxred93/pcount/index.php?lang=en&wiki=wikipedia&name="+
    thisUser+" target=_blank title='Edit count for "+thisUser+"'>ec</a> &middot; <a href=http"+
    "://toolserver.org/~vvv/sulutil.php?user="+thisUser+" target=_blank title='Global accounts for "+thisUser+"'>sul</a>":"");

  // Highlight Watchlist
  if(wgPageName == "Special:Watchlist" || wgPageName=="Special:RecentChanges" || 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 (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="~";
          myUnwatch.title="Unwatch"+myHref.replace(/.*=(.*)&.*/," $1");
          myUnwatch.href=myHref;
          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(wgPageName=="Special:RecentChanges" || 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";
      } 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;
        }
      }  // End if
    } // End for bodyLinks
  } else if(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 wgPageNam
  // 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
    }
  }
  // Show IP address in sidebar (fails in Firefox)
  /* Works but I'm worried about lag time
  if(BrowserDetect.browser=="Safari"){
  var sidebar = document.getElementById('p-navigation').parentNode;
  var container = document.createElement('div');
  container.setAttribute('class','portlet');
  container.setAttribute('id','p-showip');
  container.style="background-color:#DED";
  sidebar.appendChild(container);
  var myFrame = document.createElement('iframe');
    myFrame.src="http://checkip.dyndns.com/";
    myFrame.width="200";
    myFrame.height="50";
    myFrame.scrolling="no";
    myFrame.frameborder="0";
    myFrame.style="opacity:0;filter:alpha(opacity=0)";
  // Firefox (opacity:x) x can be a value from 0.0 - 1.0, In IE (filter:alpha(opacity=x)) x can be a value from 0 - 100
  container.appendChild(myFrame);
  }

  */
}
);

/*
    Regex menu framework
*/
function rmflinks() {
  var mypage=wgPageName.split(':')[0];
  var txt=document.editform.wpTextbox1, txtv=txt.value;
  if(mypage.search(/talk|wikipedia|user/ig)>-1){
    regexTool('~\~\~\~','sig()');
    regexTool('[\[wp:]\]','linky("wp")');
    if(txt.value.length>20){
      regexTool('[\[user:]\]','linky("user")');
      regexTool('{\{linktext\|}\}','linky("linktext")');
      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<2){
        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 vandal'+twcheck,'myWelcome("anonvandal")');
          regexTool('Welcome','myWelcome("anon")');
        } else { // New?
          regexTool('Welcome default','myWelcome("graphical")');
          regexTool('- pink','myWelcome("pink")');
          // regexTool('- red','myWelcome("red")');
        }
        regexTool('- cookies','myWelcome("cookies")');
        regexTool('- laws','myWelcome("laws")');
        regexTool('- userspace only','myWelcome("0")');
        regexTool('- vandal'+twcheck,'myWelcome("vandal")');
        regexTool('- spammer'+twcheck,'myWelcome("spam")');
        regexTool('- POV edits'+twcheck,'myWelcome("pov")');
        regexTool('- unsourced'+twcheck,'myWelcome("unsourced")');
        // regexTool('Stub out','stubPage()');
      } else {
      regexTool('Tidy warnings','tidyWarnings()');
      }
    } else if(mypage == "Talk"){ // Article 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(/\{shell|\{WikiProjectBannerShell|\{WPBS/i)==-1){regexTool('Banner shell','talkHead("shell\|\n")')};
      if(location.href.search(/section=0/)>-1&&txtv.search(/\}\}$/)==-1){regexTool('Add initial title','initTitle()')};
    }
  }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()')};
    }
    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()')};
  }
}

/* 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æ"+(wgPageName=="User_talk:Fæ"?"#top":"")+"|talk\]\]) ~\~\~\~\~","","");
}
/* Regex: cn tag */
function cn(){
  insertTags("{\{cn}\}","","");
  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 mbxClass='\<div class="messagebox standard-talk" style="padding:0.5em;border:silver solid 2px;-moz-border-radius:6px;-webkit-border-radius:6px;margin-left:0;width:98%;">'; // Emphasises warning
var 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";
  switch(mytype){
    default:
      insertTags('\{\{divbox\|fawn\|\|\{'+'{subst:w-basic\|subst=subst:\|cookies=true}'+'}\n\}\}','','');break;
    case "graphical":
      insertTags('{\{subst:User:Fæ/Welcome}\}','','');break;
    case "laws":
      insertTags('{\{subst:User:Fæ/Welcomelaws}\}','','');break;
    case "pink":
      insertTags('{\{subst:User:Fæ/Welcome|color=pink}'+'}','','');break;
    case "red":
      insertTags('{\{subst:User:Fæ/Welcome|color=red}'+'}','','');break;
    case "anon":
      insertTags(mbxClass+'{'+'{subst:welcome-anon}'+'} ~\~\~\~\</div\>','','');
      break;
    case "0":
      insertTags('\{\{divbox\|fawn\|\|{\{subst:Welcome0}\}\n\}\}','','');break; // for new users who have created their user page, but have not yet contributed elsewhere
    case "pov":
      insertTags(mhead+mbxClass+'{\{subst:welcomenpov'+va+'}\} ~~\~~\</div>','','');break; // for someone whose initial efforts do not adhere to the neutral point of view policy
    case "unsourced":
      insertTags(mhead+mbxClass+'{\{subst:welcomeunsourced'+va+'}\} ~~\~~\</div>','','');break;
    case "spam":
      insertTags(mhead+mbxClass+'{\{subst:Welcomespam'+va+'}\} ~~\~~\</div>','','');break;
    case "vandal":
      insertTags(mhead+mbxClass+'{\{subst:Welcomevandal'+va+'}\}\</div>','','');break;
    case "anonvandal":
      insertTags(mhead+'{'+'{subst:Welcome-anon-vandal'+va+'\|notitle=yes}\}','','');
  }
  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=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: 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=wgPageName.replace(/_/g," ");
  var temp="<!-- archive must stay multi-line -->\n"+
    "{{User:MiszaBot/config\n|archiveheader = {{aan}}"+
    "\n|archive = "+pName+"/Archive %(counter)d"+
    "\n|maxarchivesize = 200K"+
    "\n|counter = 1"+
    "\n|algo = old(60d)"+
    "\n|minthreadsleft = 3"+
    "\n|minthreadstoarchive = 1\n}}\n"+
    "{{autoarchivingnotice|bot=MiszaBot|age=2|days=months}}\n{{archivebox|auto=yes|search=yes}}";
  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: 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}\}");
}