Extension:SimpleSort
SimpleSort Release status: experimental |
|
---|---|
Implementation | Parser function |
Description | A simple extension to allow sorting of elements within an input string. |
Author(s) | Clark Verbrugge (clumptalk) |
Latest version | 1.0.0 |
MediaWiki | 1.26+ |
PHP | 5.4+ |
License | Creative Commons Zero v1.0 Universal |
Download | |
Quarterly downloads | 0 |
Translate the SimpleSort extension if it is available at translatewiki.net | |
The SimpleSort extension allows you to sort a list of items, contained in the same string.
Usage
[edit]Once installed you can use the #simplesort
template invocation. It takes 1 or 2 arguments, depending on whether you are happy with the defaults or if you want to customize the sorting. The 1-argument form assumes a comma-separated list of items (ignoring and discarding whitespace around the commas), and sorts them in ascending order, case-insensitive, following php's "natural" sorting order:
- {{#simplesort:a, LIST,of, Things,to , sort, maybe with, num1, num11, num2}}
- This produces output
a,LIST,maybe with,num1,num2,num11,of,sort,Things,to
- This produces output
Optionally, you may specify as a first argument one or more options, each separated by whitespace. Available options are:
desc
Use descending rather than ascending order.alpha
Use regular alphabetic ordering.num
Use regular numeric ordering.case
Use a case-sensitive comparison.insep="X"
UseX
as an item separator to recognize items. Whitespace aroundX
will still be ignored and discarded.outsep="X"
UseX
as an item separator in the sorted output. The default is to use the same string asinsep
stoponblank
Discards all list items after the first blank entry.
For example,
- {{#simplesort:desc case|a, LIST,of, Things,to , sort, maybe with, num1, num11, num2}}
to,sort,of,num11,num2,num1,maybe with,a,Things,LIST
- {{#simplesort:num insep=" "|3 4 2 1 8 9 2 6 5 }}
1 2 2 3 4 5 6 8 9
- {{#simplesort:insep="potato" outsep=", "|rutabaga potato onionpotatorat}}
onion, rat, rutabaga
Keyed Sorting
[edit]The sorting order may also be given by sorting one list, applying the resulting ordering to a second list. For this you need to use the keyed
option as (one of) the first argument(s) to #simplesort
, and to supply two lists. The sort order generated by the first list is then used to reorder the second list, and only the second list is output. For example,
- {{#simplesort:keyed|b, c, a|Veronica, Jughead, Archie}}
Archie,Veronica,Jughead
Other options described above can also be used in conjunction with keyed
. For example,
- {{#simplesort:keyed outsep=" loves "|b, c, a|Veronica, Jughead, Archie}}
Archie loves Veronica loves Jughead
Note, however, that the input separators must be the same for both lists, and (of course) the output separator is only applied to the second list. If the first list is shorted than the second then remaining items in the second list are discarded. If the first list is longer than the second then blank entries will be used to fill out the output.
Installation
[edit]- Download and move the extracted
SimpleSort
folder to yourextensions/
directory.
Developers and code contributors should install the extension from Git instead, using:cd extensions/
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/SimpleSort - Add the following code at the bottom of your LocalSettings.php file:
wfLoadExtension( 'SimpleSort' );
- Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.