Module:Property sortkey

From Wikidata
Jump to navigation Jump to search
Lua
CodeDiscussionLinksLink count SubpagesDocumentationTestsResultsSandboxLive code All modules

Documentation for this module may be created at Module:Property sortkey/doc

Code

local p = {}

function p.sortkey(args)
    local key=mw.title.getCurrentTitle().text
    if type(args)=="string" then
        key=args
	elseif mw.getCurrentFrame().args[1] then
        key=mw.getCurrentFrame().args[1]
    elseif mw.getCurrentFrame():getParent() and mw.getCurrentFrame():getParent().args[1] then
        key=mw.getCurrentFrame():getParent().args[1]
    end
    if string.sub(key,1,1)=='P' then
        key=string.sub(key,2)
    end
    if string.len(key)<4 then
        key=string.rep('0',4-string.len(key))..key
    elseif string.len(key)>4 then
        ind=math.floor((tonumber(key) or 0)/1000)-9
        key=mw.ustring.sub("ABCDEFGHIJKLMNOPQRSTUVWXYZΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ",ind,ind) .. key
    end
    return key
end

return p