Modul:Sort: Unterschied zwischen den Versionen

1.796 Bytes hinzugefügt ,  vor 7 Jahren
2018-03-16
w>PerfektesChaos
(2016-11-24)
w>PerfektesChaos
(2018-03-16)
Zeile 1: Zeile 1:
local Serial = "2016-11-24"
local Sort = { suite  = "Sort",
              serial = "2018-03-16",
              item  = 24205172 }
--[=[
--[=[
Sort
Sort
]=]
]=]


local Sort = { }




Zeile 29: Zeile 28:
         lucky, collate = pcall( mw.loadData,  storage .. collate )
         lucky, collate = pcall( mw.loadData,  storage .. collate )
         if adapt  and  type( collate ) == "table" then
         if adapt  and  type( collate ) == "table" then
             local variants = mw.text.split( adapt, "%s+" )
             local variants = type( adapt )
             local n = #variants
            local n
            if variants == "string" then
                variants = mw.text.split( adapt, "%s+" )
             elseif variants == "table" then
                variants = adapt
            else
                variants = { }
            end
            n = #variants
             if n == 1  and  variants[ 1 ] == "" then
             if n == 1  and  variants[ 1 ] == "" then
                 n = 0
                 n = 0
Zeile 264: Zeile 271:
     return r
     return r
end -- Sort.num()
end -- Sort.num()
Sort.failsafe = function ( assert )
    -- Retrieve versioning and check for compliance
    -- Precondition:
    --    assert  -- string, with required version or "wikidata",
    --                or false
    -- Postcondition:
    --    Returns  string with appropriate version, or false
    local since = assert
    local r
    if since == "wikidata" then
        local item = Sort.item
        since = false
        if type( item ) == "number"  and  item > 0 then
            local entity = mw.wikibase.getEntity( string.format( "Q%d",
                                                                item ) )
            if type( entity ) == "table" then
                local vsn = entity:formatPropertyValues( "P348" )
                if type( vsn ) == "table"  and
                  type( vsn.value) == "string" and
                  vsn.value ~= "" then
                    r = vsn.value
                end
            end
        end
    end
    if not r then
        if not since  or  since <= Sort.serial then
            r = Sort.serial
        else
            r = false
        end
    end
    return r
end -- Sort.failsafe()




Zeile 307: Zeile 351:




function p.failsafe()
p.failsafe = function ( frame )
     return Serial
    -- Versioning interface
    local s = type( frame )
    local since
    if s == "table" then
        since = frame.args[ 1 ]
    elseif s == "string" then
        since = frame
    end
    if since then
        since = mw.text.trim( since )
        if since == "" then
            since = false
        end
    end
     return Sort.failsafe( since )  or  ""
end -- p.failsafe()
end -- p.failsafe()


Anonymer Benutzer