Module:Sorted plain list
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module depends on the following other modules: |
Overview
This module may be used to generate a sorted "plain list", which is a sorted unordered HTML list without visible bullets.
- There are six possible sort modes
asc
is ascending as defined by the default LUA string comparison operator.desc
is descending as defined by the default LUA string comparison operator.asc
with|type=number
is ascending using numeric comparison instead of string comparison.desc
with|type=number
is descending using numeric comparison instead of string comparison.ascd
is ascending dictionary order, so spaces are sorted before other characters.descd
is descending dictionary order, so spaces are sorted before other characters.
- By default, the list is assumed to be delimited by commas, this can be changed to semicolons or any other choice.
- The list may be implicitly loaded from a wikidata property using the
|propertyID=
parameter, which will override any explicitly specified values.
Usage
To convert a comma separated list to a sorted plainlist, use
{{#invoke:sorted plain list|asc|<comma separated entries>}}
{{#invoke:sorted plain list|desc|<comma separated entries>}}
{{#invoke:sorted plain list|ascd|<comma separated entries>}}
{{#invoke:sorted plain list|descd|<comma separated entries>}}
To convert a semicolon separated list to a sorted plainlist, use
{{#invoke:sorted plain list|asc|<semicolon separated entries>|;}}
{{#invoke:sorted plain list|desc|<semicolon separated entries>|;}}
{{#invoke:sorted plain list|ascd|<semicolon separated entries>|;}}
{{#invoke:sorted plain list|descd|<semicolon separated entries>|;}}
To convert a semicolon separated list of numbers to a sorted plainlist, use
{{#invoke:sorted plain list|asc|<semicolon separated entries>|;|type=number}}
{{#invoke:sorted plain list|desc|<semicolon separated entries>|;|type=number}}
To convert a wikidata property list to a sorted plainlist, use
{{#invoke:sorted plain list|asc|propertyID=<PNUMBER>}}
{{#invoke:sorted plain list|desc|propertyID=<PNUMBER>}}
{{#invoke:sorted plain list|ascd|propertyID=<PNUMBER>}}
{{#invoke:sorted plain list|descd|propertyID=<PNUMBER>}}
Examples
{{#invoke:sorted plain list|asc|apples, oranges, bananas}}
→ - bananas
- oranges
- apples
{{#invoke:sorted plain list|desc|apples, oranges, bananas}}
→ - apples
- oranges
- bananas
{{#invoke:sorted plain list|asc|Santa Fe, Santa Rosa, Santana}}
→ - Santa Rosa
- Santana
- Santa Fe
{{#invoke:sorted plain list|desc|Santa Fe, Santa Rosa, Santana}}
→ - Santa Fe
- Santana
- Santa Rosa
{{#invoke:sorted plain list|ascd|Santa Fe, Santa Rosa, Santana}}
→ Script error: The function "ascd" does not exist.
{{#invoke:sorted plain list|descd|Santa Fe, Santa Rosa, Santana}}
→ Script error: The function "descd" does not exist.
{{#invoke:sorted plain list|asc|apples; oranges; bananas|;}}
→ - bananas
- oranges
- apples
{{#invoke:sorted plain list|desc|apples; oranges; bananas|;}}
→ - apples
- oranges
- bananas
{{#invoke:sorted plain list|asc|1,500,666; 200; 3,999; 0; -5|;|type=number}}
→ - -5
- 0
- 200
- 3,999
- 1,500,666
{{#invoke:sorted plain list|desc|1,500,666; 200; 3,999; 0; -5|;|type=number}}
→ - 1,500,666
- 3,999
- 200
- 0
- -5
{{#invoke:sorted plain list|asc|1,500,666; 200; 3,999; 0; -5; apples; oranges; bananas|;}}
→ - -5
- 0
- 200
- 3,999
- apples
- bananas
- oranges
- 1,500,666
{{#invoke:sorted plain list|desc|1,500,666; 200; 3,999; 0; -5; apples; oranges; bananas|;}}
→ - 1,500,666
- oranges
- bananas
- apples
- 3,999
- 200
- 0
- -5
{{#invoke:sorted plain list|asc|1,500,666; 200; 3,999; 0; -5; apples; oranges; bananas|;|type=number}}
→ Lua error at line 10: attempt to compare nil with number.
{{#invoke:sorted plain list|desc|1,500,666; 200; 3,999; 0; -5; apples; oranges; bananas|;|type=number}}
→ Lua error at line 20: attempt to compare number with nil.
{{#invoke:sorted plain list|ascd|District 1, District 8, District 10, District 11}}
→ Script error: The function "ascd" does not exist.
{{#invoke:sorted plain list|descd|District 1, District 8, District 10, District 11}}
→ Script error: The function "descd" does not exist.
See also
-- This module generates a sorted plain list
-- It was created as a modification of [[Module:Sort]]
local p = {}
local lang = mw.getContentLanguage()
function p.asc(frame)
items = mw.text.split( frame.args[1] or '', frame.args[2] or ',', true)
if (frame.args['type'] or '') == 'number' then
table.sort( items, function (a, b) return (lang:parseFormattedNumber(a)) < (lang:parseFormattedNumber(b)) end )
else
table.sort( items )
end
return '<div class="plainlist"><ul><li>' .. table.concat( items, "</li><li>" ) .. '</li></ul></div>'
end
function p.desc(frame)
items = mw.text.split( frame.args[1] or '', frame.args[2] or ',', true)
if (frame.args['type'] or '') == 'number' then
table.sort( items, function (a, b) return (lang:parseFormattedNumber(a)) > (lang:parseFormattedNumber(b)) end )
else
table.sort( items, function (a, b) return a > b end )
end
return '<div class="plainlist"><ul><li>' .. table.concat( items, "</li><li>" ) .. '</li></ul></div>'
end
return p