User:Brian New Zealand/monobook.js

Nō Wikipedia Māori

Kia mōhio koe: I muri i te tiaki, whakawātea te keteroki (whakatōpūtanga rorohiko) o tō matapihi ipurangi kia puta ai ngā rerekētanga katoa. Mozilla/Safari/Konqueror: pēhi i te pātuhi Shift i a koe e pāwhiri ana i te Uta anō (pēhi rānei i te Ctrl-Shift-R), IE: pēhi Ctrl-F5, Opera: pēhi F5.

function addForceSummary()
{
    if(!/&action=edit/.test(window.location.href) && !/&action=submit/.test(window.location.href)) return;
    if(/&section=new/.test(window.location.href)) return;
    if(!document.forms.editform) return;
    document.forms.editform.wpSave.onclick = forceSummary;
}

function forceSummary()
{
    if(!document.forms.editform.wpSummary.value.replace(/^(?:\/\\*.*\\*\/)? *(.*) *$/,'$1'))
    {
        var r = prompt('Are you sure you want to submit without adding a summary?\nTo add a summary, type it in the box below:',document.forms.editform.wpSummary.value);
        if(r == null) { return false; }
        document.forms.editform.wpSummary.value = r;
    }
    return true;
}

addOnloadHook(addForceSummary);

// Filter changes live
// [[User:Lupin/recent2.js]] - please include this line

document.write('<script type="text/javascript" src="' 
             + 'http://en.wikipedia.org/w/index.php?title=User:Lupin/recent2.js' 
             + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

// [[User:Lupin/popups.js]] - please include this line 

document.write('<script type="text/javascript" src="' 
             + 'http://en.wikipedia.org/w/index.php?title=User:Lupin/popups.js' 
             + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
popupFixRedirs=true;
popupRedirAutoClick='wpPreview';
popupFixDabs=true;

function addlilink(tabs, url, name, id, title, key){
    var na = document.createElement('a');
    na.href = url;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    if(id) li.id = id;
    li.appendChild(na);
    tabs.appendChild(li);
    if(id)
    {
        if(key && title)
        {
            ta[id] = [key, title];
        }
        else if(key)
        {
            ta[id] = [key, ''];
        }
        else if(title)
        {
            ta[id] = ['', title];
        }
    }
    // re-render the title and accesskeys from existing code in wikibits.js
    akeytt();
    return li;
}

//

//From http://en.wikipedia.org/w/index.php?title=User:JesseW/monobook.js&oldid=20755510
function addSinceTab() {
    var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    if (window.location.href.indexOf("&action=history&gotosince=true")!=-1) {
       do_since_I_last_edited()
    }
    else if (!/wiki\/Special:|w\/index.php?title=Special:/.test(window.location.href)) {
       var thetitle=document.title.slice(0, String(document.title).indexOf(" - "));
       var l=addlilink(tabs, "/w/index.php?title="+thetitle+"&action=history&gotosince=true", 'since', '');
       l.lastChild.title="Changes since I last edited";
    }
}
function do_since_I_last_edited() {
        var csub=document.getElementById("contentSub");
        var msg=document.createElement("p");
        msg.appendChild(document.createTextNode
                        ("Parsing history... please wait..."));
        msg.className="error";
        csub.insertBefore(msg, csub.firstChild)

        var username=document.getElementById("pt-userpage").textContent;
        var hists=document.getElementById("pagehistory").childNodes;
        for (n=0;n<hists.length;n++) {
            if (hists[n].getElementsByTagName("span")[0].textContent==username) {
                document.location=hists[n].childNodes[1].href; 
                return;
            }
        }

        msg.replaceChild(document.createTextNode
                         ("You have not edited this page! (recently)"),
                         msg.firstChild);
}


if (window.addEventListener) window.addEventListener("load", addSinceTab, false);
else if (window.attachEvent) window.attachEvent("onload", addSinceTab);

//
// Returns <li><a href="url">name</a></li>
function addlilink(url, name)
{
  var na = document.createElement('a');
  na.setAttribute('href', url);

  var txt = document.createTextNode(name);
  na.appendChild(txt);

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

// Adds a "blocklog" tab and fills in the username field on Special:Blockip, if a "&faketarget=username" is present.
function do_blockip_stuff()
{
  // Look for a &faketarget= for the username/ip
  var l = location.search.substring(1).split('&');
  var target = '';
  for (var i = 0; i < l.length; ++i)
    {
      var n = l[i].indexOf('=');
      if (l[i].substring(0, n) == 'faketarget')
	{
	  target = l[i].substring(n + 1);
	  break;
	}
    }

  if (target == '')
    return;

  // put account name in "IP Address/username" field
  var addr = document.getElementsByName('wpBlockAddress')[0];
  addr.value = unescape(target);

  // add "blocklog" tab
  var c1 = document.getElementById('column-one');
  var tabs = c1.getElementsByTagName('div')[0].getElementsByTagName('ul')[0];
  tabs.appendChild(addlilink('/w/index.php?title=Special%3ALog&type=block&user=&page=User%3A' + target, 'blocklog'));
}

// Gets the URL version of the page title.
function get_tidy_title()
{
  var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
  // cut everything up to "title=" from the start and everything past "&action=edit" from the end
  editlk = editlk.substring(editlk.indexOf('title=') + 6, editlk.lastIndexOf('&action=edit'));

  return editlk;
}

// Adds "block" and "blocklog" tabs to User: and User talk: pages.
function add_user_tabs(tabs, title)
{
  username = title.substring(title.indexOf(':') + 1);
  var slloc = username.indexOf('/');
  if (slloc > 0)
    username = username.substring(0, slloc);

  tabs.appendChild(addlilink('/w/index.php?title=Special%3ALog&user=' + username, 'log'));

  tabs.appendChild(addlilink('/w/index.php?title=Special%3ABlockip&wpBlockAddress=' + username, 'block'));
  tabs.appendChild(addlilink('/w/index.php?title=Special%3ALog&type=block&page=User%3A' + username, 'blocklog'));
  tabs.appendChild(addlilink('http://en.wikipedia.org/wiki/' + title, 'en'));
}

function add_log_tab(tabs, title)
{
  tabs.appendChild(addlilink('/w/index.php?title=Special%3ALog&page=' + title, 'log'));
  tabs.appendChild(addlilink('http://en.wikipedia.org/wiki/' + title, 'en'));
}

function add_image_tabs(tabs, imagetitle)
{
  tabs.appendChild(addlilink('http://en.wikipedia.org/wiki/' + imagetitle, 'en'));
  tabs.appendChild(addlilink('http://tools.wikimedia.de/~daniel/WikiPlay/CheckUsage.php?w=_100000&i=' + imagetitle, 'check-usage'));

  add_log_tab(tabs, imagetitle);

  imagetitle = imagetitle.substring(6);

  var i = 0;
  while (i < imagetitle.length && imagetitle.substring(i, i+1) >= '0' && imagetitle.substring(i, i+1) <= '9')
    i++;
  imagetitle = imagetitle.substring(i);

  if (i > 0 && imagetitle.substring(0, 3) == 'px-') {
    imagetitle = imagetitle.substring(3);
    tabs.appendChild(addlilink('/wiki/Image:' + imagetitle, 'unthumb'));
  }
}

function do_onload()
{
  var title = get_tidy_title();
  var tabs = document.getElementById('column-one').getElementsByTagName('div')[0].getElementsByTagName('ul')[0];

  if (title.indexOf('Image:') == 0)
    add_image_tabs(tabs, title);
  else if (title.indexOf('User:') == 0
      || title.indexOf('User_talk:') == 0)
    add_user_tabs(tabs, title);
  else if (title.indexOf('Block_user') == 0) // could stand to be more robust
    do_blockip_stuff();
  else
    add_log_tab(tabs, title);
}

if (window.addEventListener) 
  window.addEventListener("load", do_onload, false);
else if (window.attachEvent) 
  window.attachEvent("onload", do_onload);