User:Lar/moretabs/monobook.js

In today's world, User:Lar/moretabs/monobook.js is a relevant topic that impacts people of all ages, genders, and backgrounds. The importance of addressing this issue lies in its influence on different aspects of daily life, from physical and emotional health to social and economic development. Throughout history, User:Lar/moretabs/monobook.js has been the subject of extensive research and debate, giving rise to a wide range of perspectives and approaches on how to approach it. In this article, we will explore different aspects of User:Lar/moretabs/monobook.js, from its origins to its implications today, in order to provide a comprehensive and up-to-date view on this topic.
// <nowiki>

// must have brought DYK funcs in before calling this module as it depends on some of them

// generate and return date in the form "June 11, 2006"
function cur_date()
{
  var months = new Array('January', 'February', 'March', 'April', 'May', 'June',
                         'July', 'August', 'September', 'October', 'November', 'December');
  var date = new Date();
  var moDayStr = months+" "+date.getUTCDate();
  var t = moDayStr;
  return t;
}

function cur_date_dashes()
{
  var date = new Date();
  var moDayYearStr = date.getUTCDate()+"-"+date.getUTCMonth()+"-"+date.getUTCFullYear();
  var t = moDayYearStr;
  return t;
}

function cur_date_year()
{
  var months2 = new Array('January', 'February', 'March', 'April', 'May', 'June',
                         'July', 'August', 'September', 'October', 'November', 'December');
  var date = new Date();
  var yearStr = date.getUTCFullYear();
  var MoDayStr = months2+" "+date.getUTCDate();
  var t = MoDayStr+", "+yearStr;
  return t;
}

// for article talk page
function afdresult()
{
    var res = prompt("Result?","Keep - No Consensus");
    if(!res) return;
    var afddate = prompt("Nomination date?",cur_date());
    document.editform.wpSummary.value = 'AFD result - ' + res.replace(/'/g, '');
    var txt = document.editform.wpTextbox1;
    if(txt.value.length > 0) txt.value += '\n';
    txt.value += "{{oldafdfull|date=] ]|result='''" + res + "'''|votepage={{subst:PAGENAME}}}}";
    txt.focus();
}

/**** Make old AfD's appear or disappear ****/

function hideafd()
{
    var divs = document.getElementsByTagName("div");
    for(var x = 0; x < divs.length; ++x)
        if(divs.className.indexOf("vfd") != -1)
            divs.style.display = "none";
    // needed to shrink the page - rendering bug
    document.getElementById('footer').style.display = 'none';
}

function showafd()
{
    var divs = document.getElementsByTagName("div");
    for(var x = 0; x < divs.length; ++x)
        if(divs.className.indexOf("vfd") != -1)
            divs.style.display = "";
    // might as well put it back...
    document.getElementById('footer').style.display = '';
}


// appends msg to the currently-editted page, sets the summary to summ,
// and marks or unmarks the Watch this page checkbox according to watch.
function edit_summary_watch(msg, summ, watch)
{
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += msg;
  f.wpSummary.value = summ;
  f.wpWatchthis.checked = watch;
}


// appends msg to the currently-editted page, sets the summary to summ,
// and marks or unmarks the Watch this page checkbox according to watch.

// SAME AS ABOVE?? ... almost, one has optional \n the other is mandatory
function add_del_tag(msg, summ, watch)
{
  var f = document.editform, t = f.wpTextbox1;
    msg += '\n';
    msg += t.value;
    t.value = msg;
  f.wpSummary.value = summ;
  f.wpWatchthis.checked = watch;
}

// do a newsletter delivery
// edit summary should say
//   Delivery of ] newsletter ]
// payload should be
//  
//   == ] Newsletter, ], July 2006 ==
//  {{subst:Wikipedia:WikiProject_The_Beatles/Outreach/Newsletter/Issue_003}}

function newsletterDeliv()
{
  var f = document.editform, t = f.wpTextbox1;
  t.value += "{{-}} \n{{subst:Wikipedia:WikiProject_The_Beatles/Outreach/Newsletter/Issue_008}}";
  f.wpSummary.value = "] Newsletter, "
            +"], December 2006";

}
// cribbed from http://alexking.org/blog/2003/06/02/inserting-at-the-cursor-using-javascript/
function insertAtCursor(myField, myValue) 
{
  //IE support
  if (document.selection) {
    myField.focus();
    sel = document.selection.createRange();
    sel.text = myValue;
  }
    
  //MOZILLA/NETSCAPE support
  else if (myField.selectionStart || myField.selectionStart == '0') {
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos)
          + myValue
          + myField.value.substring(endPos, myField.value.length);
  } else {
    myField.value += myValue;
  }
}

//refactored notices

//var idString = prompt("ID string?");
//(Refactored to ] per ]) ~~~~

function refactorTo()
{
  var f = document.editform, t = f.wpTextbox1;
  var toUser = prompt("user that we are refactoring to?");
  //check for empty string
  if ( toUser=='') {
      toUser+='Fred'; 
  }

  var myValue="(Refactored to ] per ]) ~~~~";

  // insert at cursor
  insertAtCursor(t, myValue);
  f.wpSummary.value = "refactor to ]";
}

function refactorFrom()
{
  var f = document.editform, t = f.wpTextbox1;
  var fromUser = prompt("user that we are refactoring from (blank for Lar)?");
  //check for empty string
  if ( fromUser=='') {
      fromUser+='Lar'; 
  }

  var myValue="(Refactored from ] per ]) ";

  // insert at cursor
  insertAtCursor(t, myValue);
  f.wpSummary.value = "refactor from ] and reply";
}

// add a <ref> {{cite web|url=(parm) |title= |work= |author= |accessmonthday= |accessyear=}} </ref> 
// at the end of the current edit contents.

function addCiteWeb()
{
  var urlString=prompt("URL string?");           // prompt for URL
  var date = new Date();
  var f = document.editform, t = f.wpTextbox1;   // t points to the edit box

  //check for empty string
  if (urlString=='') {
     urlString+=' ';           
  }

  var myValue="<ref> {{cite web|url="+urlString+" |title= |work= |author= |accessdate="+cur_date_dashes()+"}} </ref>";

  // insert at end
  // t.value += myValue;

  // insert at cursor
  insertAtCursor(t, myValue);
}


// add a {{subst:unsigned2|00:49, 27 May 2006|Joe Random User}} 
// at the end of the current edit contents. 
// will have problems at the change in years since it depends on date.getUTCFullYear()
function addUnsigned2()
{
  // sample string to paste in is "18:32, 18 June 2006 FredUser" or "00:49, 27 May 2006 Timothy Usher "
  var date = new Date();
  var idString = prompt("ID string?");
  var f = document.editform, t = f.wpTextbox1;

  // a regexp for the date part of the string would be a better way to do this... 
  //... but slicing on year should almost always work

  var pipeLoc= idString.indexOf(date.getUTCFullYear()); // assume 4 digit year, breaks after 9999
  var idStringPiped= idString.substr(0,pipeLoc+4)+'|'+idString.substr(pipeLoc+5,idString.length);

  t.value += "{{subst:unsigned2|" + idStringPiped + "}}";
  f.wpSummary.value = "add {{tl|Unsigned2}} using string:" + idString;
}

//Add test-n templates to user talk pages
function testn(number)
{
  var page = prompt("Vandalism to which article?")
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += "{{subst:test" + number + "-n|" + page + "}} ~~~~";
  f.wpSummary.value = "Your edits to ]" 
  document.editform.wpWatchthis.checked = false;
}

// adds various tabs and menu tabs
function add_more_tabs()
{
  var tabs = document.getElementById('p-cactions').getElementsByTagName('ul');
  var username=document.getElementById("pt-userpage").textContent;

  // Only add for pages with "Editing User talk:" somewhere in the title
  if (document.title.indexOf("Editing User talk:") != -1)
    {
      addlimenu(tabs, 'Talk messages', 'talkm');
      var talkm = document.getElementById('talkm').getElementsByTagName('ul');
      addlilink(talkm,'javascript:updated_dyk()','DYK-Auth');
      addlilink(talkm,'javascript:updated_dyk_nom()','DYK-Nom');
      addlilink(talkm,'javascript:addUnsigned2()','Unsigned2');
      addlilink(talkm,'javascript:refactorTo()','refactor TO');
      addlilink(talkm,'javascript:refactorTo()','refactor FROM');
      addlilink(talkm,'javascript:newsletterDeliv()','Newsletter');
      addlilink(talkm,'javascript:edit_summary_watch("{{subst:Welcome}} -- ~~~~", "Welcome to Wikipedia!", true, 1)','Welcome', '');
      addlilink(talkm,'javascript:edit_summary_watch("{{subst:Anon}} -- ~~~~", "Welcome to Wikipedia!", true, 1)','Anon', '');
      addlilink(talkm, 'javascript:testn(1)', 'Test1', '');
      addlilink(talkm,'javascript:testn(2)','Test2', '');
      addlilink(talkm,'javascript:testn("2a")','Test2a', '');
      addlilink(talkm,'javascript:testn(3)','Test3', '');
      addlilink(talkm,'javascript:edit_summary_watch("{{subst:Test4}} -- ~~~~", "Last warning", false, 1)','Test4', '');
      addlilink(talkm,'javascript:edit_summary_watch("{{subst:Test5-n|24 hours|~~~~}}", "You have been blocked", false, 1)','Test5', '');
      addlilink(talkm,'javascript:edit_summary_watch("{{subst:s/block1||24 hours|reason=vandalism|signature=~~~~}}", "You have been blocked", false, 1)','S/block', '');
      addlilink(talkm,'javascript:edit_summary_watch("{{subst:bv}} -- ~~~~", "Vandalism", false, 1)','BV', '');
      addlilink(talkm,'javascript:edit_summary_watch("{{subst:Vanity|}} -- ~~~~", "About the page you created", false, 1)','Vanity', '');
      addlilink(talkm,'javascript:edit_summary_watch("{{subst:spam1}} -- ~~~~", "Adding links to Wikipedia", false, 1)','Spam1', '');
      addlilink(talkm,'javascript:edit_summary_watch("{{subst:spam2}} -- ~~~~", "Spamming", false, 1)','Spam2', '');
      addlilink(talkm,'javascript:edit_summary_watch("{{subst:spam3}} -- ~~~~", "Last warning for spamming", false, 1)','Spam3', '');
      addlilink(talkm,'javascript:edit_summary_watch("{{subst:spam4}} -- ~~~~", "You have been blocked for spamming", false, 1)','Spam4', '');
      addlilink(talkm,'javascript:edit_summary_watch("{{subst:rvfd|}} -- ~~~~", "{{rvfd}}", false, 1)','rvfd', '');
      addlilink(talkm,'javascript:edit_summary_watch("{{subst:blanking}} -- ~~~~", "Blanking pages", false, 1)','blanking', '');
      addlilink(talkm,'javascript:edit_summary_watch("{{subst:nothanks|}} -- ~~~~", "About your edits", false, 1)','nothanks', '');
      addlilink(talkm,'javascript:edit_summary_watch("{{nothanks-sd|pg=page name|url=url of source}} -- ~~~~", "{{nothanks-sd}}", false, 1)','nothanks-sd', '');
    }

  // Only add for pages with "Editing Talk:" somewhere in the title
  if (document.title.indexOf("Editing Talk:") != -1) {
      addlimenu(tabs, 'artTalk msgs', 'talkm');
      var talkm = document.getElementById('talkm').getElementsByTagName('ul');
      addlilink(talkm,'javascript:dyk_talk()','DYK');
      addlilink(talkm,'javascript:afdresult()','AfDres');
      addlilink(talkm,'javascript:addUnsigned2()','Unsigned2');
      addlilink(talkm,'javascript:refactorTo()','refactor TO');
      addlilink(talkm,'javascript:refactorTo()','refactor FROM');
   }
   

   // AfD tabs
   if(document.title.indexOf("Editing Wikipedia:Articles for deletion") != -1){   
        addlimenu(tabs, 'AfD actions', 'afda');
        var afda = document.getElementById('afda').getElementsByTagName('ul');
        addlilink(afda,'javascript:addUnsigned2()','Unsigned2');
        addlilink(afda, 'javascript:closevfd("Delete", "")', 'Delete', '');
        addlilink(afda, 'javascript:closevfd("Speedy Delete", "")', 'SD', '');
        addlilink(afda, 'javascript:closevfd("Keep", "")', 'Keep', '');
        addlilink(afda, 'javascript:closevfd("Keep (No consensus)", "")', 'Keep, NC', '');
        addlilink(afda, 'javascript:closevfd("Merge and Redirect", " to ]")', 'M&R', '');
        addlilink(afda, 'javascript:closevfd("Redirect", " to ]")', 'Redirect', '');
        addlilink(afda, 'javascript:closevfd("Ttranswiki", " to " + prompt("Transwiki to?"))', 'Transwiki', '');
        addlilink(afda, 'javascript:closevfd("Transwiki", " to Wiktionary")', 'WIKT', '');
        addlilink(afda, 'javascript:closevfd(prompt("Result?"), "")', 'Other', '');

    }
   if(document.title.indexOf("Wikipedia:Articles for deletion") ==0 ){     //Add show/hide closed AfDs
        addlilink(tabs, 'javascript:hideafd()', 'hide closed', 'ca-hide');
        ta = ;
        addlilink(tabs, 'javascript:showafd()', 'show closed', 'ca-show');
        ta = ;
    }

   if (document.title.indexOf("Editing User:" + username + "/Status") == 0){
        addlimenu(tabs, 'Change my status', 'mystatus');
        var mystatus = document.getElementById('mystatus').getElementsByTagName('ul');
        addlilink(mystatus, 'javascript:edit_status("in")', 'In', '');
        addlilink(mystatus, 'javascript:edit_status("out")', 'Out', '');
        addlilink(mystatus, 'javascript:edit_status("around")', 'Around', '');
   }

  if (document.title.indexOf("Block user") == 0) {
        addlilink(tabs, 'javascript:blockuser("{{username}}", "indefinite")', "username");
        addlilink(tabs, 'javascript:blockuser("imposter", "indefinite")', "imposter");
        addlilink(tabs, 'javascript:blockuser("please contact an administrator for verification purposes, as described on this page", "indefinite")', "verification");
        addlilink(tabs, 'javascript:blockuser("vandalism only account", "indefinite")', "vandalism only");
        addlilink(tabs, 'javascript:blockuser("{{wow}}", "indefinite")', "willy");
        addlilink(tabs, 'javascript:blockuser("{{wic}}", "indefinite")', "communism");
        addlilink(tabs, 'javascript:blockuser("{{3RR3}}", "24 hours")', "revert");
        addlilink(tabs, 'javascript:blockuser("vandalism - AOL", "15 minutes")', "AOL")
        addlilink(tabs, 'javascript:blockuser("vandalism - shared IP", "3 hours")', "shared")
        addlilink(tabs, 'javascript:blockuser("vandalism - returning", "1 week")', "returning");
        addlilink(tabs, 'javascript:blockuser("vandalism", "24 hours")', "vandalism");
   }

   // if we are editing  and it's SOME kind of talk page...
//   if ( (document.title.indexOf("Editing") ==0) && (document.title.indexOf("Talk") != -1) )
//   {
//      addlimenu(tabs, 'any Talk', 'anytalkm');
//      var anytalkm = document.getElementById('anytalkm').getElementsByTagName('ul');
//      addlilink(anytalkm,'javascript:addUnsigned2()','Unsigned2');
//   }

   if (document.title.indexOf("Editing") != -1)
   {
     addlimenu(tabs, 'refsL', 'refsL');
     var refsL = document.getElementById('refsL').getElementsByTagName('ul');
     addlilink(refsL,'javascript:addCiteWeb()','CiteWeb');
   }

}

function closevfd(bold, notbold){
    var form = document.editform;
    var txt = form.wpTextbox1;
    txt.value = "{{subst:at}} '''" + bold + "'''" + notbold + ". --~~~~\n" + txt.value + "\n{{subst:ab}}\n";
    form.wpSummary.value = "Close discussion: " + bold + notbold;
    form.wpWatchthis.checked = false;
}

///////////////////////////////////////////////////////////////////
// AutoVFD by Korath
// This needs to change depending on skin used.
//////////////////////////////////////////////////////////////////
function add_link2(url, name)
{
  var na = document.createElement('a');
  na.setAttribute('href', url);
  na.appendChild(document.createTextNode(name));

  var li = document.createElement('li');
  li.appendChild(na);

  var tabs = document.getElementById('p-cactions').getElementsByTagName('ul');
  tabs.appendChild(li);
}

function strip_namespace(target)
{
  var colon = target.indexOf(':');
  if (colon != -1)
    {
      var spaces = new Array('User', 'Wikipedia', 'Image', 'MediaWiki', 'Template', 'Help', 'Category');
      var ns = target.substring(0, colon);
      if (ns == '' || ns == 'Talk')
        return target.substring(colon + 1);
      else
        for (var i = 0; i < spaces.length; ++i)
          {
            if (ns == spaces
                || ns == spaces + '_talk')
              return target.substring(colon + 1);
          }
    }

  return target;
}

function vfd()
{
  document.editform.wpTextbox1.value = '{' + '{' + 'subst:afd}}\n' + document.editform.wpTextbox1.value;
  document.editform.wpSummary.value = 'afd';

  var target = document.editform.action;
  target = target.substring(target.indexOf('title=') + 6,
                            target.lastIndexOf('&action=submit'));

  var months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
  var date = new Date();
  date = date.getUTCFullYear() + '_' + months + '_' + date.getUTCDate();

  var pagename = strip_namespace(target);

  window.open('/w/index.php?title=Wikipedia:Articles_for_deletion/' + pagename + '&action=edit&fakeaction=vfdsub&faketarget=' + target,
              'Afd ' + unescape(target),
              'status,toolbar,location,menubar,directories,resizeable,scrollbars');
  window.open('/w/index.php?title=Wikipedia:Articles_for_deletion/Log/' + date + '&action=edit&fakeaction=vfdlist&faketarget=' + pagename,
              'VfdLog ' + unescape(target),
              'status,toolbar,location,menubar,directories,resizeable,scrollbars');
}

function autovfd()
{
  if (document.title.indexOf('Editing ') == 0)
    {
      var action = '';
      var target = '';
      if (location.search)
        {
          var l = location.search.substring(1).split('&');
          for (var i = 0; i < l.length; ++i)
            {
              var eq = l.indexOf('=');
              var name = l.substring(0, eq);
              if (name == 'fakeaction')
                action = l.substring(eq + 1);
              else if (name == 'faketarget')
                target = unescape(l.substring(eq + 1)).replace(/_/g, ' ');
            }
        }

      if (action == 'vfdlist')
        {
          document.editform.wpTextbox1.value += '{{' + 'subst:afd3|pg=' + target + '}}\n';
          document.editform.wpSummary.value = ']';
        }
      else if (action == 'vfdsub')
        {
          if (document.editform.wpTextbox1.value.length > 0)
            {
              target = document.editform.action;
              target = unescape(target.substring(target.indexOf('title=') + 6, target.lastIndexOf('&action=submit'))).replace(/_/g, ' ');
              window.alert("There's an old vfd at the default location already.\n\n" +
                           'Please either move it out of the way (and update existing links to it), or file the Vfd by hand in another location (such as ]).');
            }
          else
            document.editform.wpTextbox1.value += '{' + '{' + 'subst:afd2|pg=' + target + '|text=' + '}' + '}' +
  '-- ~' + '~' + '~' + '~\n' +
              '\n*\'\'\' \'\'\'\n*\'\'\' \'\'\'\n*\'\'\' \'\'\'\n';
        }
      else
        add_link2('javascript:vfd()', 'Afd');
    }
}

///////////////////////////////////////////////////////////////////
// AutoCopyvio - Created by bmicomp from modified autovfd
//////////////////////////////////////////////////////////////////

function copyvio()
{
  document.editform.wpTextbox1.value = '{' + '{' + 'copyvio|url=}}';
  document.editform.wpSummary.value = 'copyvio';

  var target = document.editform.action;
  target = target.substring(target.indexOf('title=') + 6,
                            target.lastIndexOf('&action=submit'));

  var months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
  var date = new Date();
//  date = months + '_' + date.getUTCDate();
  var datestring = date.getUTCFullYear() + '_' + months + '_' + date.getUTCDate();

  var pagename = strip_namespace(target);

  window.open('/w/index.php?title=Wikipedia:Copyright_problems/' + datestring + '&action=edit&fakeaction=copyviolist&faketarget=' + pagename,
              'status,toolbar,location,menubar,directories,resizeable,scrollbars');
}

function autocopyvio()
{
  if (document.title.indexOf('Editing ') == 0)
    {
      var action = '';
      var target = '';
      if (location.search)
        {
          var l = location.search.substring(1).split('&');
          for (var i = 0; i < l.length; ++i)
            {
              var eq = l.indexOf('=');
              var name = l.substring(0, eq);
              if (name == 'fakeaction')
                action = l.substring(eq + 1);
              else if (name == 'faketarget')
                target = unescape(l.substring(eq + 1)).replace(/_/g, ' ');
                
            }
        }

      if (action == 'copyviolist')
        {
//          var index = document.editform.wpTextbox1.value.lastIndexOf("\n==Footer==");
/*            if (index == -1) 
          {
            window.alert("Couldn't find footer\n\n");
          } 
          else
          { */
//            var firsthalf = document.editform.wpTextbox1.value.substr(0,index);
//            var secondhalf = document.editform.wpTextbox1.value.substr(index);
            document.editform.wpTextbox1.value += '*] <span class="plainlinks">( &middot; )</span>' + ' from  ~' + '~~' + '~';
            document.editform.wpSummary.value = 'Copyvio ' + ']';
          }
//        }
      else
        add_link2('javascript:copyvio()', 'copyvio');
    }
}

//</nowiki>