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
To enable this tool, add  to your general purpose JavaScript page and then reload the page.

Explanation of variables
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
To configure the tool for several different purposes, you can add your own menu options that call the  function. The  and   settings can be specified as parameters for   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

This code block relies on the function  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
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  variable to a number great than 1, for example for including in your general purpose JavaScript page.

If you do that, the tool will always descend into available subcategories.

Bookmarks
To access this tool from brow ser bookmarks, see this discussion.

Credit
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