User:Trilobite/Tools

From Wikipedia, the free encyclopedia


Note: much of this is outdated.




There are various JavaScript tools you can use to speed up tedious administrative work. I thought it would be worth putting up a page about them to encourage others to use them, because I suspect problems like the VfD backlog wouldn't be so great if more people were able to lend a hand without having to do everything manually.

Most of these are based on those found in ABCD's monobook.js, but I've adapted and extended them in some places.

If you're doing recent changes patrol and you want a really great program to help you, I recommend CryptoDerk's Vandal Fighter.

I've tried to keep my explanations logical in a way that will allow you to pick and choose which tools you want. If any of it's unclear let me know what you're trying to do and I'll see if I can help. Disclaimer: I'm not very good with JavaScript.

I've also put some of my cosmetic changes to the MonoBook skin on this page, as well as browser shortcuts relating to Wikimedia projects. If you're editing, or just reading Wikipedia, I really recommend using a tabbed browser. I don't know how I'd manage without one. Mozilla Firefox is my favourite browser, for this and a whole variety of other reasons.

Contents

[edit] How to use the tools

To use any of these functions, add the code to your monobook.js. You need to be using the MonoBook skin, which can be set in your preferences and is enabled by default. You can edit your monobook.js as a subpage of your user page. In my case it's at User:Trilobite/monobook.js.

Because some of the functions contain four tildes and subst: templates, you'll need to enclose the whole page in commented-out nowiki tags, as follows:

/* <nowiki> */

...
...
...

/* </nowiki> */

You also need to tell your browser to actually execute some of the functions, by adding something like this:

window.onload = Main;
function Main() {
    changelinks();
    addtoolboxlinks();
    addpurge();
    morelinks();
    LivePreviewInstall();
}

Those functions that need to be listed in your function Main() vary according to which tools you want to use. If you're not using function changelinks(), you don't need to list changelinks(); here. Where a line needs to be added to your function Main() list, I've noted this.

[edit] Tools for anyone

These tools don't require the extra technical capabilities given to administrators.

[edit] Add tabs depending on the kind of page you're looking at

This adds extra tools as tabs at the top of pages, next to "history" and "watch", etc. You can extend this in all kinds of ways. The example below gives you a tab to purge the cache, a regexp facility in edit mode, and a tab that tags images without source information as unverified.

function addlilink(tabs, url, name, id) {
    var na = document.createElement('a');
    na.href = url;
    na.id = id;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    li.appendChild(na);
    tabs.appendChild(li);
    return li;
}

function addpurge() {
    ta['ca-purge'] = ['g', 'Purge the internal cache for this page'];
    if(!document.getElementById) return;
    var x = document.getElementById('ca-history');
    var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    if(!x) return;
    if(x.children) x = x.children[0];
    else x = x.childNodes[0];
    addlilink(tabs, x.href.replace(/=history/, "=purge"), 'purge', 'ca-purge');
}

function morelinks() {
    var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    if(document.title.indexOf("Editing ") == 0) addlilink(tabs, 'javascript:replace()', 'replace', '');
    if(document.title.indexOf("Editing Image:") == 0) addlilink(tabs, 'javascript:unverified()', 'tag', '');
}

You need to add addpurge(); and morelinks(); to the list in your function Main() for this to work.

If you don't want the purge tab, leave out the whole of function addpurge() and everything within its curly brackets, and leave addpurge(); out of your function Main(). You need to have function addlilinks(), however, in order for function morelinks() to work, as it's this that actually adds the extra tabs function morelinks() tells it to add.

The if(document.title.indexOf("... lines in function morelinks() are the ones that allow you to customise this facility. The example above includes the two that are useful to non-sysops, both explained below.

Note that when using extra tabs, the spacing between the "watch/unwatch" and "move" tabs can push those furthest to the right off the side of the page. You can get rid of this space by adding the following line to your monobook.css:

li#ca-watch, li#ca-unwatch { margin-left: 0.3em; }

[edit] Regexp in edit mode

This gives you a "replace" tab when you edit a page, and allows you to search and replace in the wikitext with regular expressions. If you wanted to replace every occurrence of "teh" with "the" you'd click the replace tab, put "teh" in the box and click OK, then put "the" in the next box and click OK. Regular expressions allow you to perform more powerful manipulations with this tool.

function replace() {
    var s = prompt("Search regexp?");
    if(s) {
        var r = prompt("Replace regexp?");
        if(!r && r != '') return;
        var txt = document.editform.wpTextbox1;
        txt.value = txt.value.replace(new RegExp(s, "g"), r);
    }
}

You need to have if(document.title.indexOf("Editing ") == 0) addlilink(tabs, 'javascript:replace()', 'replace', ''); in the list in your morelinks(); for this to work. See above for how to install morelinks();.

[edit] Tag images as unverified

When you're editing an image description page, this will give you a "tag" tab. When you click it, {{unverified}} will be added to the page and the edit summary filled in. You just need to save the page.

function unverified() {
    document.editform.wpSummary.value = 'needs a source and copyright tag - see [[Wikipedia:Image copyright tags]]';
    var txt = document.editform.wpTextbox1;
    if(txt.value.length > 0) txt.value += '\n';
    txt.value += '{{unverified}}';
    txt.focus();
}

You need to have if(document.title.indexOf("Editing Image:") == 0) addlilink(tabs, 'javascript:unverified()', 'tag', ''); in the list in your morelinks(); for this to work. See above for how to install morelinks();.

[edit] Warn vandals

When you're editing a user talk page, this gives you a string of tabs that add {{test}} templates to warn users who are vandalising. Add the following to the list in your function morelinks():

    if(document.title.indexOf("Editing User talk:") == 0) {
        addlilink(tabs, 'javascript:vandal("test")', '1', '');
        addlilink(tabs, 'javascript:vandal("test2")', '2', '');
        addlilink(tabs, 'javascript:vandal("test2a")', '2a', '');
        addlilink(tabs, 'javascript:vandal("test3")', '3', '');
        addlilink(tabs, 'javascript:vandal("test4")', '4', '');
        addlilink(tabs, 'javascript:vandal("test5")', '5', '');
        addlilink(tabs, 'javascript:vandal("spam")', 's1', '');
        addlilink(tabs, 'javascript:vandal("spam2")', 's2', '');
        addlilink(tabs, 'javascript:vandal("spam3")', 's3', '');
        addlilink(tabs, 'javascript:vandal("spam4")', 's4', '');
    }

These tabs call function vandal(), which you'll need to add somewhere else:

function vandal(tmplt) {
    var txt = document.editform.wpTextbox1;
    if(txt.value.length > 0) txt.value += '\n';
    txt.value += '{{subst:' + tmplt + '}} ~~~~';
    txt.focus();
    txt = document.editform.wpSummary;
    txt.value = tmplt
    document.editform.wpWatchthis.checked = false;
}

Subst is used to paste the whole text of the templates onto the page, and your signature is automatically added. If you spend a lot of time battling vandalism and your user page gets attacked, adding an extra tilde in the code (which will just leave a timestamp) might help.

The tabs used for different templates are as follows:

  • 1 for {{test}} — initial test
  • 2 for {{test2}} — sterner warning for adding nonsense
  • 2a for {{test2a}} — sterner warning for blanking
  • 3 for {{test3}} — threat to block for vandalism
  • 4 for {{test4}} — final warning for vandalism
  • 5 for {{test5}} — block message for vandalism
  • s1 for {{spam}} — spam warning
  • s2 for {{spam2}} — threat to block for spamming
  • s3 for {{spam3}} — final warning for spamming
  • s4 for {{spam4}} — block message for spamming

It's advisable not to use test4, test5, spam3 and spam4 unless you are a sysop with the ability to carry out threats to block. If you want to save space, selectively removing addlilink lines in function morelinks() will work fine.

[edit] Change the names of links in your personal tools

Your personal tools are the links such as "my talk", "preferences" and "log out" that appear by default as greenish-blue text at the very top of every page. This function changes their names to whatever you specify.

function changelinks() {
    if(!document.getElementById) return;
    document.getElementById('pt-mytalk').firstChild.innerHTML = 'Talk page';
    document.getElementById('pt-preferences').firstChild.innerHTML = 'Preferences';
    document.getElementById('pt-watchlist').firstChild.innerHTML = 'Watchlist';
    document.getElementById('pt-mycontris').firstChild.innerHTML = 'Contributions';
    document.getElementById('pt-logout').firstChild.innerHTML = 'Log out';
    if(document.getElementById('ca-edit'))
        document.getElementById('ca-edit').firstChild.innerHTML = 'edit';
}

You need to add changelinks(); to the list in your function Main() for this to work.

I use this in conjunction with CSS that turns my personal tools into a box in the sidebar, replacing the navbox under the Wikipedia logo which I don't really use. See below for how to do this.

The example above also includes code to change the "edit this page" tab to read "edit". This is achieved by these two optional lines:

    if(document.getElementById('ca-edit'))
        document.getElementById('ca-edit').firstChild.innerHTML = 'edit';

[edit] Add links to your toolbox in the sidebar

The toolbox is the collection of links that appears in the sidebar underneath the search box, and above the interwiki links, if there are any. You can add extra links to it with this function:

function addtoolboxlinks() {
    var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0];
    addlilink(tb, '/wiki/Special:Newpages', 'New pages', '');
    addlilink(tb, '/wiki/Category:Candidates_for_speedy_deletion', 'Speedy deletions', '');
    addlilink(tb, '/wiki/Wikipedia:Votes_for_deletion/Old', 'VfD backlog', '');
    addlilink(tb, '/wiki/Wikipedia:Vandalism_in_progress', 'Vandalism', '');
    addlilink(tb, '/wiki/Special:Blockip', 'Block IP', '');
    addlilink(tb, '/wiki/Wikipedia:Village_pump_%28all%29', 'Village pump', '');
    addlilink(tb, '/wiki/Wikipedia:Administrators%27_noticeboard', 'Noticeboard', '');
    addlilink(tb, '/wiki/Wikipedia:Administrators%27_noticeboard/Incidents', 'Incidents', '');
}

Just change the URLs and the link titles to modify this to suit your needs. The extra links will appear under the "Special pages" link in your toolbox.

You need to add addtoolboxlinks(); to the list in your function Main() for this to work. Note also that this uses function addlilink() to add the extra links to your toolbox. If you haven't already added this code for use with function morelinks();, you'll need to add the following somewhere:

function addlilink(tabs, url, name, id) {
    var na = document.createElement('a');
    na.href = url;
    na.id = id;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    li.appendChild(na);
    tabs.appendChild(li);
    return li;
}

One problem I found was that the addition of these links, after the page had finished loading, somehow pushed the footer down so there was a strange grey gap beneath the page's content box. After various attempts to get round this bug I eventually succeeded by putting this line in monobook.css:

#footer { margin-top: -0.1em; }

I never fully understood what caused the problem, or quite how this solves it, but it seems to work. It's possible that this is a quirk of Firefox.

[edit] Live Preview

I also use Pilaf's Live Preview, which can be installed by adding this:

wpUserName = 'YOURUSERNAMEHERE';
wpShowImages = true;
document.write('<script type="text/javascript" src="http://en.wikipedia.org/w/index.php?title=User:Pilaf/livepreview.js&action=raw&ctype=text/javascript&dontcountme=s"></script>'); 

Change YOURUSERNAMEHERE to your user name, and add LivePreviewInstall(); to the list in your function Main().

To help Pilaf keep track of who is using his creation, add the following at the very end of your monobook.js:

/* [[User:Pilaf/livepreview.js]] */

Note that unlike everything else, this goes after your closing nowiki tag, so you end up with:

/* <nowiki> */

...
...
...

/* </nowiki> */
/* [[User:Pilaf/livepreview.js]] */

[edit] Tools for sysops

These tools are concerned with such things as closing VfD discussions and performing speedy deletions, so you'll probably need to be an administrator to find them useful. Two of them won't work at all unless you're a sysop, because you won't be able to get to the delete and undelete pages.

All of these involve adding extra tabs depending on the kind of page you're looking at, so you'll need function addlilinks() and function morelinks() installed. See above for how to do this.

[edit] Automatically fill in deletion summaries

When on a "confirm delete" page, this adds a string of tabs that fill in a deletion summary and check the confirm box. Add the following to the list in your function morelinks():

    if(document.title.indexOf("Confirm delete - Delete") == 0) {
        addlilink(tabs, 'javascript:speedy("nonsense")', 'no', '');
        addlilink(tabs, 'javascript:speedy("remove redirect for page move")', 're', '');
        addlilink(tabs, 'javascript:speedy("misleading redirect")', 'mr', '');
        addlilink(tabs, 'javascript:speedy("talk page with no useful history")', 'tu', '');
        addlilink(tabs, 'javascript:speedy("talk page of deleted article")', 'td', '');
        addlilink(tabs, 'javascript:vfddelete()', 'vfd', '');
    }

These tabs call function speedy() and function vfddelete(), which you'll need to add somewhere else:

function speedy (criterion) {
    var form = document.forms.deleteconfirm;
    form.wpReason.value = criterion;
}

function vfddelete() {
    var form = document.forms.deleteconfirm;
    form.wpReason.value = '[[Wikipedia:Votes for deletion/' + unescape(window.location.href.replace(/^.*\?title=([^&]+)&action=delete.*$/, '$1').replace(/_/g, ' ')) + ']]';
}

The tabs used for different results are as follows:

  • no for general purpose nonsense (gibberish, testing, vandalism, no content etc.)
  • re for removal of a redirect for a page move
  • mr for a misleading redirect, such as one that points to a redlink
  • tu for talk pages with no useful history, such as those that have been vandalised then blanked
  • td for talk pages of deleted articles
  • vfd for pages condemned to deletion by VfD

Clicking one of the tabs doesn't submit the form, so you can still change the reason you're giving for deletion. The "vfd" tab automatically adds a link to the VfD page in question. You can easily customise these to suit whatever reasons you most commonly give for page deletions.

[edit] Close a VfD discussion

Extra tabs for closing VfD
Extra tabs for closing VfD


When editing a VfD page, this adds a string of tabs that close the discussion by adding the top and bottom templates, and a result. Add the following to the list in your function morelinks():

    if(document.title.indexOf("Editing Wikipedia:Votes for deletion") == 0) {
        addlilink(tabs, 'javascript:closevfd("delete", "")', 'D', '');
        addlilink(tabs, 'javascript:closevfd("keep", "")', 'K', '');
        addlilink(tabs, 'javascript:closevfd("merge and redirect", " to [[" + prompt("Merge and redirect to?") + "]]")', 'M', '');
        addlilink(tabs, 'javascript:closevfd(prompt("Result?"), "")', 'O', '');
        addlilink(tabs, 'javascript:closevfd("redirect", " to [[" + prompt("Redirect to?") + "]]")', 'R', '');
        addlilink(tabs, 'javascript:closevfd("speedy delete", "")', 'S', '');
        addlilink(tabs, 'javascript:closevfd("transwiki", " to " + prompt("Transwiki to?"))', 'T', '');
    }

These tabs call function closevfd(), which you'll need to add somewhere else:

function closevfd(bold, notbold) {
    var txt = document.editform.wpTextbox1;
    txt.value = "{{subst:vt}} '''" + bold + "'''" + notbold + ". ~~~~\n" + txt.value + "\n{{subst:vb}}\n";
    txt = document.editform.wpSummary;
    txt.value = "close discussion: " + bold + notbold;
    document.editform.wpWatchthis.checked = false;
}

The tabs used for different results are as follows:

  • D for "delete"
  • K for "keep"
  • M for "merge and redirect to" (provides a box for you to fill in the name of the article)
  • O for other (provides a box for you to fill in the result)
  • R for "redirect to" (provides a box for you to fill in the name of the article)
  • S for "speedy delete"
  • T for "transwiki to" (provides a box for you to fill in the name of the project)

[edit] Add a "this page was listed on VfD" note to the talk page of a kept article

When editing a talk page, this adds a tab that appends a section linking to a VfD discussion that concluded in favour of keeping. Add the following to the list in your function morelinks():

    if(document.title.indexOf("Editing Talk:") == 0) addlilink(tabs, 'javascript:vfdresult()', 'vfd', '');

This tab calls function vfdresult(), which you'll need to add somewhere else:

function vfdresult() {
    document.editform.wpSummary.value = 'VfD concluded in favour of keeping';
    var txt = document.editform.wpTextbox1;
    if(txt.value.length > 0) txt.value += '\n';
    txt.value += '==Votes for deletion==\nIn June 2005, this article was nominated for deletion. The result was to keep. See [[Wikipedia:Votes for deletion/{{subst:PAGENAME}}]] for a record of the discussion. ~~~~';
    txt.focus();
}

Because VfD discussions are not necessarily closed a set number of days after they were listed, I've left the time element as a month and year instead of trying to come up with some way of calculating an exact date. You'll need to go back and change this one word in the code when the discussions you're closing tick over into the next month.

[edit] Hide closed VfD discussions on backlog pages

When viewing a VfD log page, which transcludes a series of discussions, this adds two tabs which show and hide closed discussions. This makes finding discussions to close easier than scrolling down through those that have already been closed. Add the following to the list in your function morelinks():

    if(document.title.indexOf("Wikipedia:Votes for deletion/Log") == 0) {
        addlilink(tabs, 'javascript:hidevfd()', 'hide', 'ca-hide');
        addlilink(tabs, 'javascript:showvfd()', 'show', 'ca-show');
    }

These tabs call function hidevfd() and function showvfd(), which you'll need to add somewhere else:

function hidevfd() {
    var divs = document.getElementsByTagName("div");
    for(var x = 0; x < divs.length; ++x)
        if(divs[x].className.indexOf("vfd") != -1)
            divs[x].style.display = "none";
    document.getElementById('footer').style.display = 'none';
}

function showvfd() {
    var divs = document.getElementsByTagName("div");
    for(var x = 0; x < divs.length; ++x)
        if(divs[x].className.indexOf("vfd") != -1)
            divs[x].style.display = "";
    document.getElementById('footer').style.display = '';
}

[edit] Link to VfD discussions from Special:Undelete

Extra tab on deleted pages
Extra tab on deleted pages


When viewing a deleted page that went through VfD, the VfD template doesn't link to the discussion for the article itself but to the useless Wikipedia:Votes for deletion/Undelete. This function adds a tab at the top of the page that links to the discussion you were actually looking for. Add the following to the list in your function morelinks():

    if(document.title.indexOf("View and restore deleted pages") == 0) vfdold();

You'll need to add function vfdold() somewhere else:

function vfdold () {
    var x = document.getElementById('ca-article');
    var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    if(!x) return;
    if(x.children) x = x.children[0];
    else x = x.childNodes[0];
    addlilink(tabs, x.href.replace(/Special:Undelete/, "Wikipedia:Votes_for_deletion"), 'vfd', '');
}

Note that this won't work if the VfD subpage has a different title to the deleted article. All it does is create a link which substitutes "Special:Undelete" for "Wikipedia:Votes_for_deletion" in the URL of the page you're on. Also, I think some of the code above is redundant, because this function doesn't need to do the checks that the function it was based on does. It does the job though.

[edit] My CSS changes

While JavaScript is useful for adding tabs and performing functions automatically, CSS allows you to modify the appearance of the site in lots of ways.

To make any of these changes, add the code to your monobook.css. You need to be using the MonoBook skin, which can be set in your preferences and is enabled by default. You can edit your monobook.css as a subpage of your user page. In my case it's at User:Trilobite/monobook.css.

I've only tested these changes in Firefox, but the effects should be almost identical in any standards-compliant browser.

[edit] Replace sidebar navbox with personal tools

Your personal tools are the links such as "my talk", "preferences" and "log out" that appear by default as greenish-blue text at the very top of every page. I've turned them into a box in the sidebar, directly under the Wikipedia logo. I realised that I didn't use the navigation box very much, so I got rid of it and replaced it with this box. It wouldn't take too many changes to the CSS given below to have them both present in the sidebar. It would also be possible to add useful links from the navbox to the toolbox, which is also in the sidebar, using the JavaScript described above.

This is the CSS you need to replace the navbox with your personal tools:

div#p-navigation {
    display: none;
}
#p-personal {
    position: relative;
    z-index: 3;
    width: 11.6em;
    margin: 0 0 0.5em 0;
}
#p-personal .pBody {
    width: 10.8em;
    float: none;
    overflow: hidden;
    border: 1px solid #aaa;
    padding: 0 0.8em 0.3em 0.5em;
    background: #fff;
}
#p-personal ul {
    line-height: 1em;
    list-style-type: square;
    font-size: 95%;
    margin: 0.3em 0 0 1.5em;
    padding: 0;
    text-align: left;
    text-transform: none;
}
#p-personal li {
    display: list-item;
    padding: 0;
    margin: 0.3em 0;
    color: #000 !important;
}
#p-personal li a {
    color: #002bb8;
    text-decoration: none;
}
#p-personal li a:hover {
    text-decoration: underline;
}

I use this in conjunction with JavaScript to change the names of some of the links in the personal tools. See above for how to do this.

The following code stops visited links in the sidebar from turning purple:

div.pBody a:visited { color: #002bb8; }

I override this for the "what links here" and "related changes" links, as these are specific to each page and it's useful to have them colour-coded. The following code does this:

#t-whatlinkshere a:visited, #t-recentchangeslinked a:visited { color: #5a3696 !important; }

The "printable version" link in the toolbox is redundant, as a printable version is produced autmoatically by CSS. You can get rid of it with this:

li#t-print { display: none; }

After the upgrade to MediaWiki 1.5, something strange happened to the bullet images and they didn't display next to my extra toolbox links. It seems a bit ugly to have these anyway, so I got rid of them:

ul, #p-personal ul, #p-tb ul {
    list-style-image: none !important;
    list-style-type: disc;
}

Moving the personal tools from the top of the page leaves a gap there, so you can shift the main content of the page up like this:

#p-cactions { top: 0.3em; }
#content { margin-top: 1.8em; }

One thing that annoyed me about the personal tools before I turned them into a box in the sidebar was the silly man icon that appears next to your username. You can get rid of this by adding:

li#pt-userpage { background: none; }

[edit] Minor changes

Selected tabs have a slightly odd yellow border, as does the page footer. You can get rid of these as follows:

#p-cactions li.selected { border-color: #aaa; }
#footer { border-color: #aaa; }

The boxes in the sidebar have a thin grey border on the far left, right up against the edge of the page. There isn't one on the right, where the page content box ends, and there probably shouldn't be one on the left either. You can get rid of it with this line:

div.pBody { border-left: none !important; }

By default, the "edit this page" tab and the "Go" button in the search box are bolded. I prefer not to have this:

li#ca-edit a { font-weight: normal !important; }
#searchGoButton { font-weight: normal; }

You can also use JavaScript, as described above, to change the names of these tabs. I turn "edit this page" into "edit".

By default, pages not in the main namespace have a blue background. You can turn it white:

#content { background: #fff; }
#mytabs li { background: #fff; }
#mytabs li a { background-color: #fff; }
#p-cactions li a { background-color: #fff; }
#content div.thumb { border-color: #fff; }

That bit of code also takes care of the colour of the tabs at the top of the page, and the background of thumbnail images.

You may have noticed that the form on the edit screen is quite bunched up. The edit summary field is right under the edit box, with no space between them at all. If you use Live Preview its button is also right under the "save page" button. You can fix these things:

textarea { margin-bottom: 3px; }
input#wpSave, input#wpPreview, input#wpDiff { margin-bottom: 3px; }
input#wpPreview { margin-right: 0.33em; }

If you're an established contributor, you probably won't need the big warnings telling you not to submit copyvios or test in the article space:

div#editpage-specialchars + div { display: none; }

One of the worst features of MonoBook is the annoying box icon that accompanies external links. This was the first thing I changed:

#bodyContent a[href ^="http://"] {
    background: inherit;
    padding: 0 !important;
}

Printing is all taken care of by MonoBook, but one problem is the supposedly helpful expansion of external links with their full URLs so that you don't end up with hyperlinks on paper that can't be followed. This isn't too bad in external link sections at the end of articles, but causes a severe mess with inline links. You can stop links from being expanded in this way:

span.urlexpansion { display: none !important; }

(I never quite understood the logic behind this feature, anyway. It seems more trouble than it's worth. If you have access to the internet so you can look up the external links on your printout, it will probably be possible to find the article on Wikipedia and just follow them from there....)

[edit] See also