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 | Lua error in Module:Extension at line 172: bad argument #1 to 'inNamespace' (unrecognized namespace name 'skin'). |
Public wikis using | Lua error in Module:Extension at line 172: bad argument #1 to 'inNamespace' (unrecognized namespace name 'skin'). |
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
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
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
- <translate> [[<tvar name=2>Special:ExtensionDistributor/SimpleSort</tvar>|Download]] and move the extracted <tvar name=name>
SimpleSort
</tvar> folder to your <tvar name=ext>extensions/
</tvar> directory.</translate>
<translate> Developers and code contributors should install the extension [[<tvar name=git>Special:MyLanguage/Download from Git</tvar>|from Git]] instead, using:</translate>cd extensions/
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/SimpleSort - <translate> Add the following code at the bottom of your <tvar name=1>LocalSettings.php </tvar> file:</translate>
wfLoadExtension( 'SimpleSort' );
- File:OOjs UI icon check-constructive.svg <translate> Done</translate> – <translate> Navigate to <tvar name=special>Special:Version</tvar> on your wiki to verify that the extension is successfully installed.</translate>
- Pages with script errors
- Pages with broken file links
- Experimental extensions
- Extensions without an image
- Parser function extensions
- Extensions without a compatibility policy
- Extensions with manual MediaWiki version
- Public domain licensed extensions
- Extensions in Wikimedia version control
- ParserFirstCallInit extensions
- All extensions