User:The Editor's Apprentice/randomlink
This is the documentation page for The Editor's Apprentice's random link tool which, by default, adds a option in the left sidebar to follow a random link on whatever page your currently viewing. This is useful if you want to view a random article that is related to the current article. It is also useful for impartially selecting an article to work on from a specified category or list of articles.
The tool can also be set up to follow a random link on a given page or set of pages. This can be useful for quickly viewing an article from a consistent group, such a to-do list. Additional details on the ways this tool can be customized can be viewed in the customization section below.
Installation
[edit]To enable this tool, add importScript("User:The Editor's Apprentice/randomlink.js")
to your general purpose JavaScript page and then reload the page.
Customization
[edit]Explanation of variables
[edit]Several variables can be changed in order to customize the tool. The following is list of changes that can be made to the tools variables and an explanation of their effects.
- randomlink_open = true;
- Causes the new page to be opened in a new window or tab, leaving the current window/tab unchanged.
- randomlink_start = "Wikipedia:Featured articles";
- randomlink_start = [ "Wikipedia:Featured articles", "Wikipedia:Featured pictures" ];
- Use this variable to start from a specified page rather than from the current page. If you list multiple start pages (either as an array or as a pipe-delimited string), the tool will select randomly among them. To weight a starting page more strongly (because it has more links under it), list it multiple times.
- randomlink_hops = 2;
- Normally, only one link is followed, but if your start page is a category that lists other categories, it will take several hops to reach an actual article. Use this variable to increase the number of links followed before settling on a page. The variable is limited to maximum of 4.
- randomlink_paged = true;
- Some special pages are paged, with the first page listing only the first hundred or so links. To get around this limitation, set this variable to true, and the tool will attempt to select a random section of the full result set for its start page. For example, if your start page is a category that usually has over 200 articles in it or what links here with over 500 links, you should probably set this. Also use it on special pages like uncategorized pages.
- randomlink_exclude = /^List of|\(series\)/;
- If certain titles are being selected that you wish to exclude, you can use this variable to filter them out based on a regular expression. The above example excludes titles beginning with "List of" or containing "(series)".
- randomlink_maxfrom = 24000000;
- If you're the kind of person who likes to consume something to the last drop, then this is the option for you. This parameter sets the maximum page id allowed when doing a paged what links here. The default value is about 15% less than the maximum page id, to ensure that at least 100 articles are always found past it even for smallish WikiProjects. But you can tune it for larger cases to ensure that the most recent articles make it into the pool. As of this writing, the value above is tuned to reach the end of the baseball articles. It might return nothing for smaller WikiProjects, where a value of 22000000 might be more appropriate.
Multiple menu options
[edit]To configure the tool for several different purposes, you can add your own menu options that call the randomLink()
function. The randomlink_start
and randomlink_hops
settings can be specified as parameters for randomLink()
in this case. The following code adds five menu options in addition to basic "Random link". There are are as follows:
- Random link – default behavior, follows a random link on current page
- Random back-link – goes backwards, to a random page that links here
- Random page – loads a random article the slow way, by drilling down randomly through Special:AllPages
- Featured article – goes to a random featured article listed on WP:FA
- Video game article – goes to a random article in WikiProject Video games, via categories
- Baseball article – goes to a random article in WikiProject Baseball, via What links here
importScript("User:The Editor's Apprentice/randomlink.js");
addOnloadHook( function()
{
// Other special cases are "Special:RecentChangesLinked" and "Special:Contributions"
mw.util.addPortletLink('p-navigation', 'javascript:randomLink("Special:WhatLinksHere")',
'Random back-link', 'n-randomback', 'Random page that links here');
mw.util.addPortletLink('p-navigation', 'javascript:randomLink("Special:AllPages",4)',
'Random page', 'n-randompage2', 'Load a random article, the slow way');
// Ignore most of the top and bottom meta links on WP:FA
randomlink_exclude = /^Wikipedia:|^Portal:|^(Lists?|Outline|Library) of|^(Deaths in )?20\d\d$/;
mw.util.addPortletLink('p-navigation', 'javascript:randomLink("Wikipedia:Featured articles")',
'Featured article', 'n-randomfa', 'Pick a random featured article');
vgcats = "Top|High|Mid|Low|Low|Low|Low|Low|Low|Low|NA|Unknown";
vgcats = vgcats.replace(/\w+/g, "Category:$&-importance video game articles");
mw.util.addPortletLink('p-navigation', 'javascript:randomlink_paged=1;randomLink(vgcats)',
'Video game article', 'n-randomvg', 'Random article in WikiProject Video games');
// WhatLinksHere is probably a better way to find all articles in a WikiProject
bblist = "Special:WhatLinksHere/Template:WikiProject_Baseball?namespace=1&hidelinks=1&limit=250";
mw.util.addPortletLink('p-navigation', 'javascript:randomlink_paged=1;randomlink_maxfrom=24000000;randomLink(bblist)',
'Baseball article', 'n-randombb', 'Random article in WikiProject Baseball');
});
This code block relies on the function mw.util.addPortletLink()
which adds custom links to places like the left sidebar and the toolbar at the top right. You can view more information about the function and how it works on the MediaWiki core documentation website
Some helpful information, "content actions" here refers to the links under the "More" dropdown located next to the search box. "Personal tools" refers to the links that appear on the left under the "Tools" heading. "Navigation" refers to the links that appear on the left and above the "Tools" heading. "Toolbar" refers to the links that appear in the top right next to one's username.
How links are chosen
[edit]The tool tries to only consider "normal" links in an article.
It is also designed to do the right thing on special pages, considering only the "main" links. For example, on recent changes or user contributions (among many others), it will choose a title from the list, excluding user links and other links.
But on history pages, it will only follow user page links, as they are the main thing there.
In categories, it will choose only items if there are any pages or files in the category. Otherwise, it will select from content links, subcategories, and parent categories. This change be changed by setting the randomlink_hops
variable to a number great than 1, for example for including
randomlink_hops = 2;
in your general purpose JavaScript page.
If you do that, the tool will always descend into available subcategories.
Bookmarks
[edit]To access this tool from brow ser bookmarks, see this discussion.
Credit
[edit]This tool was originally maintained by GregU, who is no longer active on Wikipedia and so The Editor's Apprentice has taken the responsibility of carrying the tool into the future