Extension:MadLib

The MMadlib extension allows you to easily generate madlib-style text, giving you a magic word in which you can use tags to specify replaceable text, with the replacements randomly chosen from separate mediawiki pages corresponding to the tag each time the page is loaded.

Usage
Mmadlib usage requires you first create a word list for each tag. Then you can construct madlib sentences by referring to your tags within the "#mmadlib" magic word (template) construction.

Word Lists
Each tag requires a line-separated list of possible replacements stored in a page named to correspond to a specific tag. You have two ways you can format lines in these word list pages:

Each entire line defines a distinct bit of text that might be selected as a tag replacement.
 * Simple
 * The first character should not be a "#" (if you really want a "#" used the escaped form, &amp;#35;).

The line consists of chunks of text separated by hashtags that identify distinct sub-forms of your replacement text. When you want a specific form you can then specify the desired hashtag, and instead of the whole line you get just that portion. For this to work the line should be constructed as a sequence of pairs of hashtags and the corresponding replacement, separated by whitespace. For example,  is a line defining two hashtags.
 * Hashtagged
 * The first non-whitespace character of each line should be a "#".
 * The empty string is a valid hashtag; this is useful when you want a default, non-hashtagged replacement string as well as specific, hashtagged replacements.

Magic Word Use
The mmadlib itself is constructed within a template invocation, as

There are 2 necessary parameters, and one optional. The first parameter specifies the text, including the tags you want to replace, where each tag is contained in angle brackets (like " "). The second parameter consists of a comma-separated list of the tags your text uses (like "animal"); note that these are the names of the wordlist pages. The third parameter, if present, gives a common prefix to the names of the word list pages. This is useful if you put your word lists into sub-pages or a different namespace, so if your word lists are "Words/Mammals", "Words/Fish", you can specify a third parameter of "Words/" and then just use "", "", instead of writing "", "".
 * Tag names and the prefixes are case-sensitive and should match the wiki page name.

If you used a hashtagged word list, a tag should have a hashtag to specify which variation it wants. You can also force the randomization of repeated uses of the same tag to be the same or not. Thus there are actually 4 formats to describe how a tag is replaced:
 * Each use of " " is (separately) replaced by randomly selected text. If your word list doesn't use hashtags these are full lines, or if you word list does use hashtags these are the parts of the line identified by the empty hashtag ("#").
 * Each use of " " is (separately) replaced by randomly selected text. If your word list doesn't use hashtags these are full lines, or if you word list does use hashtags these are the parts of the line identified by the empty hashtag ("#").


 * 
 * Each use of "" is (separately) replaced by randomly selected text, corresponding to that hashtag. If your word list doesn't use hashtags, or the hashtag isn't found, it'll be an empty string.


 * 
 * Each use of "" is replaced by the same randomly selected text.


 * 
 * Each use of "" is replaced by the same randomly selected text, corresponding to that hashtag.


 * You can use different numbers ("", "" etc), defining distinct sets of replacements that use the same random choice. The number sequence you use to indicate such sets must start at 1 and be contiguous.  By default you can only use 1 through 9, but that upper limit is configurable.
 * These 4 use-cases are processed separately, so sets do not constrain simple uses with hashtags uses. That is, "" and " may not be selected from the same replacement line.  To make them correspond you'd need to explicitly state the default hashtag, "" and " will correspond.

A Simple Example
Suppose the page "animal" contains cat badger wallaby with a limp and the page "location" contains hat shoe closet full of toys Then  will render as one of the 9 possibilities:
 * I read a book about a cat in a hat.
 * I read a book about a wallaby with a limp in a shoe.
 * I read a book about a badger in a closet full of toys.
 * etc.

A Hashtagged Example
Suppose the page "animal" instead contains and the page "location" is as above. Then  will render as one of the 9 possibilities:
 * 1) cat                  #types felines
 * 2) badger               #types mustelids
 * 3) wallaby with a limp  #types macropods that limp
 * I read a book about a cat in a hat. I like felines.
 * I read a book about a wallaby with a limp in a shoe. I like macropods that limp.
 * I read a book about a badger in a closet full of toys. I like mustelids.
 * etc.

Installation

 * Create a folder in the extensions folder named MMadlib
 * Create the the two files shown below and place them in your <tt>extensions/MMadlib/</tt> folder
 * Edit <tt>LocalSettings.php</tt> in the root of your MediaWiki installation, and add the following line near the bottom:

Configuration parameters

 * $wgMmadlibMaxSets: Changes the maximum number of sets of identical random choices. The default is 9.