Movatterモバイル変換


[0]ホーム

URL:


Jump to content
MediaWiki
Search

Extension:RandomSelection

From mediawiki.org
Translate this page
Languages:
MediaWiki extensions manual
RandomSelection
Release status: stable
ImplementationTag,Parser function
DescriptionDisplays a random option from the given set
Author(s)
Latest version3.0.0 (2018-09-09)
MediaWiki1.43+
Database changesNo
LicenseGNU General Public License 2.0 or later
Download
Example

  • ‎<choose>
  • ‎<option>
  • ‎<choicetemplate>
Translate the RandomSelection extension if it is available at translatewiki.net

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

Installation

[edit]
  • Download and move the extractedRandomSelection folder to yourextensions/ directory.
    Developers and code contributors should install the extensionfrom Git instead, using:
    cdextensions/gitclonehttps://gerrit.wikimedia.org/r/mediawiki/extensions/RandomSelection
  • Add the following code at the bottom of yourLocalSettings.php file:
    wfLoadExtension('RandomSelection');
  • YesDone – Navigate toSpecial:Version on your wiki to verify that the extension is successfully installed.

Usage

[edit]

Tags

[edit]

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

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

[edit]
ParameterDescription
uncachedDisable caching for the chosen option
beforePut this text before the chosen option
afterPut 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 theuncached parameter.

<chooseuncached><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 andExtension:YouTube required):

<choosebefore="{{#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

[edit]
ParameterDescription
weightWeight 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><optionweight="2">This option will be shown twice as often as a normal option.</option><option>By default, options have a weight of 1.</option><optionweight="1.5">This option also has a weight of 1. Fractional portions are ignored.</option></choose>


Parser function

[edit]

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

{{#choose: |This is the first choice. |This is the second choice. |And so on...}}

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

[edit]
This extension is included in the following wiki farms/hosts and/or packages:This is not an authoritative list. Some wiki farms/hosts and/or packages may contain this extension even if they are not listed here. Always check with your wiki farms/hosts or bundle to confirm.
Retrieved from "https://www.mediawiki.org/w/index.php?title=Extension:RandomSelection&oldid=7887882"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp