Zum Inhalt springen

Modul:Sort: Unterschied zwischen den Versionen

4.234 Bytes hinzugefügt ,  vor 2 Jahren
K
14 Versionen von wikivoyage:Modul:Sort importiert
w>PerfektesChaos
(2016-11-24)
K (14 Versionen von wikivoyage:Modul:Sort importiert)
 
(5 dazwischenliegende Versionen von 3 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
local Serial = "2016-11-24"
local Sort = { suite  = "Sort",
              serial = "2019-10-29",
              item  = 24205172 }
--[=[
--[=[
Sort
Sort
]=]
]=]
local Failsafe  = Sort
local GlobalMod = Sort






local Sort = { }
local foreignModule = function ( access, advanced, append, alt, alert )
    -- Fetch global module
    -- Precondition:
    --    access    -- string, with name of base module
    --    advanced  -- true, for require(); else mw.loadData()
    --    append    -- string, with subpage part, if any; or false
    --    alt      -- number, of wikidata item of root; or false
    --    alert    -- true, for throwing error on data problem
    -- Postcondition:
    --    Returns whatever, probably table
    -- 2019-10-29
    local storage = access
    local finer = function ()
                      if append then
                          storage = string.format( "%s/%s",
                                                  storage,
                                                  append )
                      end
                  end
    local fun, lucky, r, suited
    if advanced then
        fun = require
    else
        fun = mw.loadData
    end
    GlobalMod.globalModules = GlobalMod.globalModules or { }
    suited = GlobalMod.globalModules[ access ]
    if not suited then
        finer()
        lucky, r = pcall( fun,  "Module:" .. storage )
    end
    if not lucky then
        if not suited  and
          type( alt ) == "number"  and
          alt > 0 then
            suited = string.format( "Q%d", alt )
            suited = mw.wikibase.getSitelink( suited )
            GlobalMod.globalModules[ access ] = suited or true
        end
        if type( suited ) == "string" then
            storage = suited
            finer()
            lucky, r = pcall( fun, storage )
        end
        if not lucky and alert then
            error( "Missing or invalid page: " .. storage, 0 )
        end
    end
    return r
end -- foreignModule()




Zeile 14: Zeile 67:
     -- Precondition:
     -- Precondition:
     --    adjust  -- string to be aligned
     --    adjust  -- string to be aligned
     --    apply  -- string with base
     --    apply  -- string or table, with base
     --                "latin"
     --                "latin"
     --    adapt  -- variation, or false
     --    adapt  -- string or table, with variation, or false
     --                "DIN5007m2"  -- DIN 5007 mode "2"
     --                "DIN5007m2"  -- DIN 5007 mode "2"
     local r = adjust
     local r = adjust
     if adapt  or  not r:match( "^[ -~]*$" ) then
     if adapt  or  not r:match( "^[ -~]*$" ) then
        local storage = "Module:Sort/"
         local collate, post, pre
         local collate, lucky, post, pre
         if apply then
         if apply then
             collate = apply
             collate = apply
Zeile 27: Zeile 79:
             collate = "uni"
             collate = "uni"
         end
         end
         lucky, collate = pcall( mw.loadData, storage .. collate )
         if type( collate ) == "string" then
            collate = foreignModule( Sort.suite,
                                    false,
                                    collate,
                                    Sort.item )
        end
         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 42: Zeile 107:
                 collate = tmp
                 collate = tmp
                 for i = 1, n do
                 for i = 1, n do
                     lucky, tmp = pcall( mw.loadData,
                     tmp = foreignModule( Sort.suite,
                                        storage .. variants[ i ] )
                                        false,
                                        variants[ i ],
                                        Sort.item )
                     if type( tmp ) == "table" then
                     if type( tmp ) == "table" then
                         var = tmp.single
                         var = tmp.single
Zeile 73: Zeile 140:
                             end    -- for k, v
                             end    -- for k, v
                         end
                         end
                     elseif lucky then
                     elseif type( tmp ) == "string" then
                         collate = "Invalid table " .. variants[ i ]
                         collate = tmp
                         break    -- for i
                         break    -- for i
                     else
                     else
                         collate = tmp
                         collate = "Invalid table " .. variants[ i ]
                         break    -- for i
                         break    -- for i
                     end
                     end
Zeile 98: Zeile 165:
                         s = " "
                         s = " "
                     end
                     end
                 elseif (k >=   768 and  k <=   866)  or
                 elseif ( k >= 0x0300 and  k <= 0x0362 )  or
                       (k >= 6832 and  k <= 6911)  or
                       ( k >= 0x1AB0 and  k <= 0x1AFF )  or
                       (k >= 7616 and  k <= 7679)  or
                       ( k >= 0x1DC0 and  k <= 0x1DFF )  or
                       (k >= 65056 and  k <= 65071) then
                       ( k >= 0xFE20 and  k <= 0xFE2F ) then
                     -- COMBINING ...
                     -- COMBINING ...
                     s = ""
                     s = ""
Zeile 121: Zeile 188:
         else
         else
             r = "**ERROR** Sort.lex ** Submodule unavailable " .. collate
             r = "**ERROR** Sort.lex ** Submodule unavailable " .. collate
        end
        if type( post ) == "table" then
         end
         end
     end
     end
Zeile 264: Zeile 329:
     return r
     return r
end -- Sort.num()
end -- Sort.num()
Failsafe.failsafe = function ( atleast )
    -- Retrieve versioning and check for compliance
    -- Precondition:
    --    atleast  -- string, with required version or "wikidata" or "~"
    --                or false
    -- Postcondition:
    --    Returns  string  -- with queried version, also if problem
    --              false  -- if appropriate
    -- 2019-10-15
    local last  = ( atleast == "~" )
    local since = atleast
    local r
    if last  or  since == "wikidata" then
        local item = Failsafe.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 seek = Failsafe.serialProperty or "P348"
                local vsn  = entity:formatPropertyValues( seek )
                if type( vsn ) == "table"  and
                  type( vsn.value ) == "string"  and
                  vsn.value ~= "" then
                    if last  and  vsn.value == Failsafe.serial then
                        r = false
                    else
                        r = vsn.value
                    end
                end
            end
        end
    end
    if type( r ) == "nil" then
        if not since  or  since <= Failsafe.serial then
            r = Failsafe.serial
        else
            r = false
        end
    end
    return r
end -- Failsafe.failsafe()




Zeile 307: Zeile 417:




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 Failsafe.failsafe( since )  or  ""
end -- p.failsafe()
end -- p.failsafe()