Module:Sorted plain list

-- 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').unbulletedlocal 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 aend-- This function was copied/modified from [[Module:Wikidata]]local function getValue(frame, propertyID)local entity = mw.wikibase.getEntityObject()local claimsif entity and entity.claims thenclaims = entity.claims[propertyID]endif claims then-- if wiki-linked value output as link if possibleif (claims[1] and claims[1].mainsnak.snaktype == "value" and claims[1].mainsnak.datavalue.type == "wikibase-entityid") thenlocal out = {}for k, v in pairs(claims) dolocal 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"] endif sitelink thenout[#out + 1] = "[[" .. sitelink .. "|" .. label .. "]]"elseout[#out + 1] = labelendendreturn outelse-- just return best valuesreturn { entity:formatPropertyValues(propertyID).value }endelsereturn {""}endendfunction 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)endfunction 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)endfunction 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)endfunction 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)endreturn p