Zum Inhalt springen

Modul:Vorlage:LuaModuleDoc: Unterschied zwischen den Versionen

2019-10-29
(2018-09-24)
(2019-10-29)
Zeile 1: Zeile 1:
local LuaModuleDoc = { suite  = "LuaModuleDoc",
local LuaModuleDoc = { suite  = "LuaModuleDoc",
                       serial = "2018-09-24",
                       serial = "2019-10-29",
                       item  = 12981914,
                       item  = 12981914,
                       frame  = false,
                       frame  = false,
Zeile 15: Zeile 15:
* failsafe()
* failsafe()
]=]
]=]
local Failsafe = LuaModuleDoc




Zeile 149: Zeile 150:
           repo.value:find( "//" ) then
           repo.value:find( "//" ) then
             local t = mw.text.split( repo.value, ",%s+" )
             local t = mw.text.split( repo.value, ",%s+" )
            local params
             if #t > 1 then
             if #t > 1 then
                 for i = 1, #t do
                 for i = 1, #t do
Zeile 183: Zeile 185:
                                       LuaModuleDoc.title.prefixedText )
                                       LuaModuleDoc.title.prefixedText )
                 local vsn = entity:formatPropertyValues( "P348" )
                 local vsn = entity:formatPropertyValues( "P348" )
                 local params = { }
                 params = { }
                 if mode < 2 then
                 if mode < 2 then
                     params[ 1 ] = string.format( "[%s %s]",
                     params[ 1 ] = string.format( "[%s %s]",
Zeile 194: Zeile 196:
                     params.version = vsn.value
                     params.version = vsn.value
                 end
                 end
                 if type( bib ) == "table" and  bib.failsafe then
                 if type( bib ) == "table" then
                    t = type( bib.failsafe )
                    local serial
                    if t == "function" then
                    if bib.failsafe then
                        bib = bib.failsafe( { args = { } } )
                        if type( bib.failsafe ) == "function" then
                         t    = type( bib )
                            serial = bib.failsafe( { args = { } } )
                     else
                         else
                         bib = bib.failsafe
                            serial = bib.failsafe
                        end
                     elseif bib[ "#serial"] then
                         serial = bib[ "#serial"]
                     end
                     end
                     if t == "number" then
                     if type( serial ) == "number" then
                         bib = string.format( "%d", bib )
                         serial = string.format( "%d", serial )
                        t    = "string"
                     end
                     end
                     if t == "string" then
                     if type( serial ) == "string" then
                         params.here = bib
                         params.here = serial
                     end
                     end
                 end
                 end
Zeile 287: Zeile 291:
     end
     end
     if t then
     if t then
         r = mw.site.namespaces[ n ].name .. ":" .. s
         r = string.format( "%s:%s",
                          mw.site.namespaces[ n ].name, s )
     end
     end
     return r
     return r
Zeile 664: Zeile 669:




LuaModuleDoc.failsafe = function ( assert )
Failsafe.failsafe = function ( atleast )
     -- Retrieve versioning and check for compliance
     -- Retrieve versioning and check for compliance
     -- Precondition:
     -- Precondition:
     --    assert -- string, with required version or "wikidata",
     --    atleast -- string, with required version or "wikidata" or "~"
     --               or false
     --                 or false
     -- Postcondition:
     -- Postcondition:
     --    Returns  string with appropriate version, or false
     --    Returns  string -- with queried version, also if problem
    --              false   -- if appropriate
    -- 2019-10-15
    local last  = ( atleast == "~" )
    local since = atleast
     local r
     local r
     if since == "wikidata" then
     if last  or  since == "wikidata" then
         local item = LuaModuleDoc.item
         local item = Failsafe.item
         since = false
         since = false
         if type( item ) == "number"  and  item > 0 then
         if type( item ) == "number"  and  item > 0 then
             local ent = mw.wikibase.getEntity( string.format( "Q%d",
             local entity = mw.wikibase.getEntity( string.format( "Q%d",
                                                              item ) )
                                                                item ) )
             if type( ent ) == "table" then
             if type( entity ) == "table" then
                 local vsn = ent:formatPropertyValues( "P348" )
                local seek = Failsafe.serialProperty or "P348"
                 local vsn = entity:formatPropertyValues( seek )
                 if type( vsn ) == "table"  and
                 if type( vsn ) == "table"  and
                   type( vsn.value ) == "string"  and
                   type( vsn.value ) == "string"  and
                   vsn.value ~= "" then
                   vsn.value ~= "" then
                     r = vsn.value
                     if last  and  vsn.value == Failsafe.serial then
                        r = false
                    else
                        r = vsn.value
                    end
                 end
                 end
             end
             end
         end
         end
     end
     end
     if not r then
     if type( r ) == "nil" then
         if not since  or  since <= LuaModuleDoc.serial then
         if not since  or  since <= Failsafe.serial then
             r = LuaModuleDoc.serial
             r = Failsafe.serial
         else
         else
             r = false
             r = false
Zeile 696: Zeile 710:
     end
     end
     return r
     return r
end -- LuaModuleDoc.failsafe()
end -- Failsafe.failsafe()




Zeile 742: Zeile 756:
         end
         end
     end
     end
     return LuaModuleDoc.failsafe( since )  or  ""
     return Failsafe.failsafe( since )  or  ""
end -- p.failsafe()
end -- p.failsafe()


return p
return p
Anonymer Benutzer