Modul:Vorlage:LuaModuleDoc: Unterschied zwischen den Versionen

K
36 Versionen von wikipedia:Modul:Vorlage:LuaModuleDoc importiert
(2018-08-01)
K (36 Versionen von wikipedia:Modul:Vorlage:LuaModuleDoc importiert)
 
(5 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
local LuaModuleDoc = { suite  = "LuaModuleDoc",
local LuaModuleDoc = { suite  = "LuaModuleDoc",
                       serial = "2018-08-01",
                       serial = "2022-04-22",
                       item  = 12981914,
                       item  = 12981914,
                       frame  = false,
                       frame  = false,
Zeile 15: Zeile 15:
* failsafe()
* failsafe()
]=]
]=]
local Failsafe = LuaModuleDoc




Zeile 144: Zeile 145:
         local mode = 0
         local mode = 0
         local repo = entity:formatPropertyValues( "P1324" )
         local repo = entity:formatPropertyValues( "P1324" )
         local params, s, t
         local params, s
         if type( repo ) == "table"  and
         if type( repo ) == "table"  and
           type( repo.value) == "string"  and
           type( repo.value ) == "string"  and
           repo.value:find( "//" ) then
           repo.value:find( "//" ) then
             repo = mw.uri.new( repo.value )
            local t = mw.text.split( repo.value, ",%s+" )
            if #t > 1 then
                for i = 1, #t do
                    if t[ i ]:find( mw.site.server, 1, true ) then
                        s = t[ i ]
                        break -- for i
                    end
                end -- for i
                if not s then
                    s = t[ 1 ]
                end
            else
                s = repo.value
            end
             repo = mw.uri.new( s )
             if type( repo.path ) == "string"  and
             if type( repo.path ) == "string"  and
               repo.path:match( "^/wiki/" ) then
               repo.path:match( "^/wiki/" ) then
                 local space
                 local space
                 space, s = repo.path:sub( 7 ):match( "^([^:]+):(.+)$" )
                 space, s = repo.path:sub( 7 ):match( "^([^:]+):(.+)$" )
                 if space and s then
                 if space and
                  mw.site.namespaces[ space ] then
                     t = mw.title.makeTitle( space, s )
                     t = mw.title.makeTitle( space, s )
                     s = "//" .. repo.host
                     s = "//" .. repo.host
Zeile 180: 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
                 if fetch( "forkedGlobal", "0" ) ~= "1"  and
                 if fetch( "forkedGlobal", "0" ) ~= "1"  and
                   params.version  and  params.here  and
                   params.version  and  params.here  and
                   params.version ~= params.here then
                   params.version ~= params.here then
                     params.update = "1"
                     params.update = "1"
                 end
                 end
Zeile 273: 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 650: 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 false
     --                         or wikidata|item|~|@ or false
     -- Postcondition:
     -- Postcondition:
     --    Returns  string with appropriate version, or false
     --    Returns  string -- with queried version/item, also if problem
    --              false   -- if appropriate
    -- 2020-08-17
    local since  = atleast
    local last  = ( since == "~" )
    local linked = ( since == "@" )
    local link  = ( since == "item" )
     local r
     local r
     if since == "wikidata" then
     if last  or  link  or  linked  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 suited = string.format( "Q%d", item )
                                                              item ) )
            if link then
            if type( ent ) == "table" then
                r = suited
                local vsn = ent:formatPropertyValues( "P348" )
            else
                if type( vsn ) == "table"  and
                local entity = mw.wikibase.getEntity( suited )
                  type( vsn.value) == "string"  and
                if type( entity ) == "table" then
                  vsn.value ~= "" then
                    local seek = Failsafe.serialProperty or "P348"
                    r = vsn.value
                    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
                        elseif linked then
                            if mw.title.getCurrentTitle().prefixedText
                              ==  mw.wikibase.getSitelink( suited ) then
                                r = false
                            else
                                r = suited
                            end
                        else
                            r = vsn.value
                        end
                    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 682: Zeile 723:
     end
     end
     return r
     return r
end -- LuaModuleDoc.failsafe()
end -- Failsafe.failsafe()




Zeile 728: Zeile 769:
         end
         end
     end
     end
     return LuaModuleDoc.failsafe( since )  or  ""
     return Failsafe.failsafe( since )  or  ""
end -- p.failsafe()
end -- p.failsafe()


return p
return p