Extension:RandomInclude

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

Release status: stable

Implementation Tag
Description Includes a random text.
Author(s) Fernando Correia, John Erling Blad
Last version 1.3.5 (2007-02-08)
MediaWiki 1.8.2, 1.9.1
License GPL
Download RandomInclude.php

Check usage (experimental)

Contents

[edit] Introduction

RandomInclude is an extension to MediaWiki that includes in the page a text selected at random from a list.

It is based on the RandomText extension.

[edit] Features

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

[edit] Installation

  1. Download RandomInclude.php and save it in the extensions directory of your wiki.
  2. Insert this line in the LocalSettings.php file:
    include_once('extensions/RandomInclude.php');
    

[edit] Configuration

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 formating of output

These vars 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

[edit] Usage

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.

[edit] Inline

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

Random quote of the day:

<random>
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.
</random>

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'] = '----';

[edit] Through transclusion

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:

{{#random:{{Tips}}}}

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}}}}

[edit] Alternatives

[edit] Feedback

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

Personal tools
Namespaces

Variants
Actions
Navigation
Support
Download
Development
Communication
Print/export
Toolbox