Extension:RandomSelection

Category:Extensions without an imageCategory:Extensions without a compatibility policyCategory:GPL licensed extensions
MediaWiki extensions manual
RandomSelection
Release status: stableCategory:Stable extensions
Implementation Tag Category:Tag extensions, Parser function Category:Parser function extensions
Description Displays a random option from the given set
Author(s)
Latest version 3.0.0 (2018-09-09)
MediaWiki 1.43+Category:Extensions with manual MediaWiki version
Database changes No
License GNU General Public License 2.0 or later
Download Category:Extensions in Wikimedia version control
Example
  • <choose>
  • <option>
  • <choicetemplate>
Quarterly downloads 25 (Ranked 91st)
Public wikis using 7,190 (Ranked 23rd)
Translate the RandomSelection extension if it is available at translatewiki.net
Category:All extensions

The RandomSelection extension allows for randomly-generated content inside your wiki; e.g. rotating images, random greetings, etc.

Installation

  • Download and move the extracted RandomSelection folder to your extensions/ directory.
    Developers and code contributors should install the extension from Git instead, using:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/RandomSelection
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'RandomSelection' );
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Usage

Tags

To choose between one or more options, simply place each option inside an <option> tag which are themselves placed inside <choose> tags, 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.

However, template arguments will not be expanded due to T4257.

You can also have what is placed inside the option tags be sent as an argument to a template with the <choicetemplate> tag, e.g.:

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

Parameters to <choose>

Parameter Description
uncached Disable caching for the chosen option
before Put this text before the chosen option
after Put this text after the chosen option
Since version 2.2.2 caching in the <choose> tag is disabled only if the user specifies <choose uncached>. Previously caching was disabled by default.

If you wanted to disable caching for the options, you should add the uncached parameter.

<choose uncached>
<option>This is the first choice.</option>
<option>This is the second choice.</option>
<option>And so on...</option>
</choose>

If you wanted to display one of three YouTube videos, you could try this (Extension:Widgets and Extension: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>

Parameters to <option>

Parameter Description
weight Weight of the option

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>

Parser function

To choose between one or more options, simply place each option inside the #choose: parser function, like so:

{{#choose:
 |<translate nowrap><!--T:45--> This is the first choice.</translate>
 |<translate nowrap><!--T:46--> This is the second choice.</translate>
 |<translate nowrap><!--T:47--> And so on...</translate>
}}

From each choice divided by a pipe, precisely one choice will be selected at random, and its contents shown. Anything can be placed inside: links, images, even templates.

See also

Category:Random content extensions
Category:All extensions Category:Extensions in Wikimedia version control Category:Extensions included in Fandom Category:Extensions included in Miraheze Category:Extensions included in MyWikis Category:Extensions included in ShoutWiki Category:Extensions included in WikiForge Category:Extensions with manual MediaWiki version Category:Extensions without a compatibility policy Category:Extensions without an image Category:GPL licensed extensions Category:MagicWordwgVariableIDs extensions Category:ParserFirstCallInit extensions Category:Parser function extensions Category:Random content extensions Category:Stable extensions Category:Tag extensions