Extension:RandomSelection
RandomSelection Release status: stable |
|||
---|---|---|---|
Implementation | Tag | ||
Description | Displays a random option from the given set. | ||
Author(s) | Ross McClure (Algorithmtalk) | ||
Latest version | 2.1.7 (2012-09-02) | ||
MediaWiki | 1.12+ | ||
Database changes | No | ||
License | GPL | ||
Download |
GitHub: Note: Changelog |
||
Example | Example http://wiki.mises.org/wiki/Template:Featured_article |
||
|
|||
|
|||
Translate the RandomSelection extension if it is available at translatewiki.net |
|||
Check usage and version matrix; code metrics |
The RandomSelection extension allows for randomly-generated content inside your wiki; e.g. rotating images, random greetings, etc.
Contents
Usage[edit | edit source]
To choose between one or more options, simply place each option inside an <option> tag, like so:
<choose> <option>This is the first choice.</option> <option>This is the second choice.</option> <option>And so on...</option> </choose>
From each set of <choose> tags, precisely one <option> tag will be selected at random, and its contents shown. Anything can be placed inside of option tags: links, images, even templates. Note, however, that template arguments will not be expanded due to bugzilla:2257.
Parameters to <choose>[edit | edit source]
Parameter | Description |
---|---|
before | Put this text before the chosen option |
after | Put this text after the chosen option |
Parameters to <option>[edit | edit source]
Parameter | Description |
---|---|
weight | Weight of the option |
Weight[edit | edit source]
If you'd like some options to be shown more often than others, you can add weight to the option tags, like so:
<choose> <option weight="2">This option will be shown twice as often as a normal option.</option> <option>By default, options have a weight of 1.</option> <option weight="1.5">This option also has a weight of 1. Fractional portions are ignored.</option> </choose>
You can also have what is placed inside the option tags be sent as an argument to a template, e.g.:
Choice templates[edit | edit source]
<choose> <option>Template:Featured article/Elephant</option> <option>Template:Featured article/Giraffe</option> <option>Template:Featured article/Rhinoceros</option> <choicetemplate>PageWithEditButton</choicetemplate> </choose>
You could then create a Template:PageWithEditButton with these contents:
[{{canonicalurl:{{{1}}}|action=edit}} Edit] {{{{{1}}}}}
This is useful if you want to set up randomly rotating featured articles and have an edit button to allow the user to edit the featured article blurbs.
"before" and "after" parameters[edit | edit source]
If you wanted to display one of three YouTube videos, you could try this (Extension:Widget and Widget:YouTube required):
<choose before="{{#widget: YouTube|id=" after="}}"> <option>eR7-AUmiNcA</option><!--King of Anything--> <option>cSCi7kCXKDA</option><!--Slipping Through My Fingers--> <option>7n2d9XPsmmE</option><!--When Death Note Music Plays in My Car--> </choose>
Installation[edit | edit source]
- Download and extract the file(s) in a directory called
RandomSelection
in yourextensions/
folder. If you're a developer and this extension is in a Git repository, then instead you should clone the repository. - Add the following code at the bottom of your LocalSettings.php:
require_once "$IP/extensions/RandomSelection/RandomSelection.php";
- Done! Navigate to "Special:Version" on your wiki to verify that the extension is successfully installed.
Changelog[edit | edit source]
- 2007-12-10 -- Updated for compatibility with MW 1.12's new parser model
- 2008-02-23 -- Minor bugfix
- 2008-05-08 -- Bugfix
- 2008-07-01 -- Use ParserFirstCallInit hook if it's available
- 2009-09-30 -- Doxygen comments added + minor tweaks
- 2010-01-17 -- dropped backwards compatibility with old MediaWikis as per r55838 and made the extension work under PHP 5.3+
- 2012-09-02 -- Added
<choicetemplate>
functionality - 2013-11-10 -- Added "before" and "after" parameters
Tested[edit | edit source]
- MW 1.22.x -
OK --Leucosticte (talk) 10:32, 10 November 2013 (UTC)
- MW 1.16.x -
OK --[[kgh]] (talk) 22:10, 7 June 2012 (UTC)
- MW 1.18.x -
OK --[[kgh]] (talk) 18:37, 7 June 2012 (UTC)
- MW 1.19.x -
OK --Leucosticte (talk) 21:58, 2 September 2012 (UTC)
- MW 1.20.x -
OK --Arcane21 (talk) 00:14, 30 August 2013 (UTC)Arcane21
- MW 1.21.x -
OK --Arcane21 (talk) 00:14, 30 August 2013 (UTC)Arcane21
See also[edit | edit source]
- Extension:BedellPenDragon#FAQ (has a discussion of the differences between RandomSelection, Blurb and BedellPenDragon)
- Extension:Blurb