Extension:RandomText

Random Text is an extension written for MediaWiki that allows to display a random text from a list (such as a list of quotes) on a page.

Note: I know this is a fairly trivial extension but I couldn't find a hint on solving this anywhere else so I deemed it important to document it here ;)

Semi-random numbers can be generated without an extension like this, using magic words and ParserFunctions - see w:Template:Random number for an example.

Installation
The extension is short and sweet, copy the following to extensions/random.php: 

Now we have to load the extension in LocalSettings.php as follows:

Usage
Basic usage is very easy, simply insert the lines you want to be randomized seperated by '@@@' and enclosed in &lt;random&gt;...&lt;/random&gt; tags, for example: Text 1 @@@ Text 2 @@@ Text 3

At this stage it gets a bit tricky though due to the automatic caching of pages in MediaWiki. If you save a page with the source code above, the page will be created and placed in the cache with one of the lines in it. This will only change once the source code is changed again. To get around this, I invalidate every page that is older than one day (= 86400 seconds), this can be achieved by placing the following in LocalSettings.php:

Of course it is possible to set this value to a lower number but keep in mind that this will have an impact on server load as pages are regenerated more often rather than pulled from cache.

To help testing the extension without modifying the Cache Epoch, a refresh of a cached page can be forced by appending &action=purge to the URL.

Development
This extension was written by Martin Rohrbach (Martin dot Rohrbach at gmail dot com). Thanks to Hans Kramer for the suggestion to use recursiveTagParse.

Demo

 * http://www.clogamp.com/wiki – The extension is used for the quote of the day on the first page
 * http://www.wikihumor.home.pl/wiki/Template:Stub (pl) – Random text for stub template.

Alternatives

 * Random
 * RandomArea
 * RandomInclude
 * Bashfr -- displays random lines of text stored within a file (originally "quotations"), similar to the Fortune module.