From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual
Crystal Clear action run.png

Release status: unmaintained

Implementation Tag
Description Allows to include random text.
Author(s) Fernando Correia, John Erling Blad
Latest version 1.3.5 (2007-02-08)
MediaWiki 1.8+
Database changes No
License GPL
Download RandomInclude.php

Translate the RandomInclude extension if it is available at translatewiki.net

Check usage and version matrix; code metrics

The RandomInclude extension includes in the page a text selected at random from a list. It is based on the RandomText extension.

Note that it is possible to do this without an extension like this, using magic words and ParserFunctions - see w:Template:Random number for an example random number generator.


  • Can be used inline or through transclusion.
  • Supports wikitext.


  • Copy the code into a file and place the file(s) in a directory called RandomInclude in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
require_once "$IP/extensions/RandomInclude/RandomInclude.php";
  • Configure as required
  • YesY Done - Navigate to Special:Version on your wiki to verify that the extension is successfully installed.


There are several variables to be used for general configuration and as default values.

$wgRandomInclude['pattern'] = '*';    // default pattern to use as boundary between items (use '----' to get previous behaviour)
$wgRandomInclude['separator'] = '';   // default separator rendered between items
$wgRandomInclude['count'] = 1;        // default number of items
$wgRandomInclude['limit'] = 20;       // default limit on runaway loop
$wgRandomInclude['seed'] = none;      // default seed value
$wgRandomInclude['hash'] = none;      // default hash value
$wgRandomInclude['period'] = none;    // default period as minute, hour, day, week or seconds (integer)
$wgRandomInclude['mode'] = ?;         // default mode is none or ordered depending on count
$wgRandomInclude['cache'] = 'enabled';// default cache strategy, set to 'disable' to do no caching
$wgRandomInclude['format'] = 'none';  // default format string, set to 'none' to do no formatting of output

These variables can be tailored on individual basis in each call to the tag function, or the parser function, named accordingly.

The format string is a four element string; start list, start item, end item and end list. The string accepts aliases for common wikiconstructs like ²{ and }² for {{ and }}, ²[ and ]² for [[ and ]], broken pipe (¦) for pipe (|) and '\n' for linebreaks. In addition there are keywords %ITEM% for each included item and %COUNT% for the position in the output list.

Parser cache is automatically disabled for pages that use the RandomInclude extension. If for any reason the random text on the page only changes when you edit or purge the page, you can try disabling the cache for the whole wiki. Notice that doing this will affect the performance of the wiki.

  • To disable the page cache insert these lines on LocalSettings.php:
# Disable cache
$wgEnableParserCache = false;
$wgCachePages = false;
  • To give the page cache an expiration time insert these lines on LocalSettings.php:
# Set cache expiration time
$wgCacheEpoch = wfTimestamp( TS_MW, time() - 86400 ); # 60*60*24 = 1 day


The seed attribute can interfere with other functions and should generally be avoided.

The hash attribute is typically used to take some textual value and turn this into a numeric index. By generating this from date and time information, together with page specific information very specialized schemes for random updates can be created.


You can list the alternative random texts directly on the page in which they should appear:

Random quote of the day:

Absence makes the heart grow fonder.
Actions speak louder than words.
An ounce of prevention is worth a pound of cure.
[[Wikitext]] '''can''' be used here.

Note that this example uses the previous default pattern to separate entries; to use this with the current version, use the following configuration line instead:

$wgRandomInclude['pattern'] = '----';

Through transclusion[edit]

For larger lists of random texts, it will be better to create a template with the random texts and to include it on a separate page. This way, you can read and verify all random texts. This is especially useful if the random texts can have several lines and use wiki markup.

For instance, create a template called {{Tips}} with this content:

Absence makes the heart grow fonder.
Actions speak louder than words.
An ounce of prevention is worth a pound of cure.
==== Tip ====
Titles and [[wikitext]] '''can''' be used here.

On the page that will show the random text, use this:

Random quote of the day:


You can even create several separate random text templates and include a random text from one of them like this:

Random quote of the day:

{{#random:{{Template one}}----{{Template two}}----{{Template three}}}}



Use the discussion page for feedback, questions, feature requests and bug reports.