This module may be used to generate a sorted "plain list", which is a sorted unordered HTML list without visible bullets.
| This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
| This module depends on the following other modules: |
This module may be used to generate a sorted "plain list", which is a sorted unordered HTML list without visible bullets.
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.|propertyID= parameter, which will override any explicitly specified values.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>}}{{#invoke:sorted plain list|asc|apples, oranges, bananas}} → {{#invoke:sorted plain list|desc|apples, oranges, bananas}} → {{#invoke:sorted plain list|asc|Santa Fe, Santa Rosa, Santana}} → {{#invoke:sorted plain list|desc|Santa Fe, Santa Rosa, Santana}} → {{#invoke:sorted plain list|ascd|Santa Fe, Santa Rosa, Santana}} → {{#invoke:sorted plain list|descd|Santa Fe, Santa Rosa, Santana}} → {{#invoke:sorted plain list|asc|apples; oranges; bananas|;}} → {{#invoke:sorted plain list|desc|apples; oranges; bananas|;}} → {{#invoke:sorted plain list|asc|1,500,666; 200; 3,999; 0; -5|;|type=number}} → {{#invoke:sorted plain list|desc|1,500,666; 200; 3,999; 0; -5|;|type=number}} → {{#invoke:sorted plain list|asc|1,500,666; 200; 3,999; 0; -5; apples; oranges; bananas|;}} → {{#invoke:sorted plain list|desc|1,500,666; 200; 3,999; 0; -5; apples; oranges; bananas|;}} → {{#invoke:sorted plain list|asc|1,500,666; 200; 3,999; 0; -5; apples; oranges; bananas|;|type=number}} → {{#invoke:sorted plain list|desc|1,500,666; 200; 3,999; 0; -5; apples; oranges; bananas|;|type=number}} → {{#invoke:sorted plain list|ascd|District 1, District 8, District 10, District 11}} → {{#invoke:sorted plain list|descd|District 1, District 8, District 10, District 11}} →
-- This module generates a sorted plain list
-- It was created as a modification of [[Module:Sort]]
local p = {}
local lang = mw.getContentLanguage()
local ubl = require('Module:List').unbulleted
local function transformstring(s)
local a = mw.text.trim(s)
a = mw.ustring.gsub(a, '%[%[[^%[%]<>|][^%[%]<>|]*|([^%[%]<>|][^%[%]<>|]*)%]%]', '%1')
a = mw.ustring.gsub(a, '%[%[([^%[%]<>|][^%[%]<>|]*)%]%]', '%1')
a = mw.ustring.gsub(a, '[%s%‑]', 'AA' )
a = mw.ustring.gsub(a, '([%D])([%d])$', '%10%2')
return a
end
-- This function was copied/modified from [[Module:Wikidata]]
local function getValue(frame, propertyID)
local entity = mw.wikibase.getEntityObject()
local claims
if entity and entity.claims then
claims = entity.claims[propertyID]
end
if claims then
-- if wiki-linked value output as link if possible
if (claims[1] and claims[1].mainsnak.snaktype == "value" and claims[1].mainsnak.datavalue.type == "wikibase-entityid") then
local out = {}
for k, v in pairs(claims) do
local sitelink = mw.wikibase.sitelink("Q" .. v.mainsnak.datavalue.value["numeric-id"])
local label = mw.wikibase.label("Q" .. v.mainsnak.datavalue.value["numeric-id"])
if label == nil then label = "Q" .. v.mainsnak.datavalue.value["numeric-id"] end
if sitelink then
out[#out + 1] = "[[" .. sitelink .. "|" .. label .. "]]"
else
out[#out + 1] = label
end
end
return out
else
-- just return best values
return { entity:formatPropertyValues(propertyID).value }
end
else
return {""}
end
end
function p.asc(frame)
local items
if frame.args.propertyID then
items = getValue(frame, frame.args.propertyID)
else
items = mw.text.split( frame.args[1] or '', frame.args[2] or ',', true)
end
if (frame.args['type'] or '') == 'number' then
table.sort( items, function (a, b) return ((lang:parseFormattedNumber(a) or math.huge) < (lang:parseFormattedNumber(b) or math.huge)) end )
else
table.sort( items, function (a, b) return mw.text.trim(a) < mw.text.trim(b) end )
end
return ubl(items)
end
function p.desc(frame)
if frame.args.propertyID then
items = getValue(frame, frame.args.propertyID)
else
items = mw.text.split( frame.args[1] or '', frame.args[2] or ',', true)
end
if (frame.args['type'] or '') == 'number' then
table.sort( items, function (a, b) return ((lang:parseFormattedNumber(a) or math.huge) > (lang:parseFormattedNumber(b) or math.huge)) end )
else
table.sort( items, function (a, b) return mw.text.trim(a) > mw.text.trim(b) end )
end
return ubl(items)
end
function p.ascd(frame)
local items
if frame.args.propertyID then
items = getValue(frame, frame.args.propertyID)
else
items = mw.text.split( frame.args[1] or '', frame.args[2] or ',', true)
end
if (frame.args['type'] or '') == 'number' then
table.sort( items, function (a, b) return ((lang:parseFormattedNumber(a) or math.huge) < (lang:parseFormattedNumber(b) or math.huge)) end )
else
table.sort( items, function (a, b) return ( transformstring(a) < transformstring(b) ) end)
end
return ubl(items)
end
function p.descd(frame)
local items
if frame.args.propertyID then
items = getValue(frame, frame.args.propertyID)
else
items = mw.text.split( frame.args[1] or '', frame.args[2] or ',', true)
end
if (frame.args['type'] or '') == 'number' then
table.sort( items, function (a, b) return ((lang:parseFormattedNumber(a) or math.huge) > (lang:parseFormattedNumber(b) or math.huge)) end )
else
table.sort( items, function (a, b) return ( transformstring(a) > transformstring(b) ) end)
end
return ubl(items)
end
return p
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.