Nicht angemeldeter Benutzer - Bearbeiten von Seiten ist nur als angemeldeter Benutzer möglich.

Änderungen

Zur Navigation springen Zur Suche springen
2.982 Bytes hinzugefügt ,  18:06, 14. Jul. 2019
2019-07-14
Zeile 1: Zeile 1: −
local Serial = "2018-01-10"
+
local Handle = { suite  = "Handle",
 +
                serial = "2019-07-14",
 +
                item  = 19644424 }
 
--[=[
 
--[=[
 
Template:Handle  {{DOI}} {{HDL}}
 
Template:Handle  {{DOI}} {{HDL}}
 
require: URIutil
 
require: URIutil
 
]=]
 
]=]
 +
local Failsafe = Handle
      Zeile 21: Zeile 24:  
   errHide    = false,
 
   errHide    = false,
 
   errNS      = false,
 
   errNS      = false,
 +
  errDate    = { en = "Bad ISO year (month)",
 +
                  de = "ISO-Jahr (ggf. Monat) fehlerhaft" },
 
   errInvalid  = { en = "Invalid:",
 
   errInvalid  = { en = "Invalid:",
 
                   de = "Ungültig:" },
 
                   de = "Ungültig:" },
Zeile 171: Zeile 176:  
     end
 
     end
 
     if unknown then
 
     if unknown then
         r = string.format( "'<code>%s</code>' in Template:%s",
+
        local e = mw.html.create( "code" )
                           table.concat( unknown, " " ),
+
        e:wikitext( table.concat( unknown, " " ) )
                          Config.scheme )
+
         r = string.format( "'%s' in Template:%s",
 +
                           tostring( e ), Config.scheme )
 
         r = failed( "errUnkown", r )
 
         r = failed( "errUnkown", r )
 
     else
 
     else
Zeile 188: Zeile 194:  
         end
 
         end
 
         if URIutil[ "is" .. Config.showName ]( access )  then
 
         if URIutil[ "is" .. Config.showName ]( access )  then
 +
            local suffer = args[ Config.parProblem ]
 
             r = URIutil[ "link" .. Config.showName ]( access )
 
             r = URIutil[ "link" .. Config.showName ]( access )
 
             if Config.showArticle then
 
             if Config.showArticle then
Zeile 195: Zeile 202:  
                 r = string.format( "%s:%s", Config.scheme, r )
 
                 r = string.format( "%s:%s", Config.scheme, r )
 
             end
 
             end
             if args[ Config.parProblem ] then
+
             if suffer  and  suffer ~= "" then
                 r = string.format( "%s <small>%s</small>",
+
                local scan = "^(2[01]%d%d)(%-?[01]?%d?)$"
                                  r,  factory( "problemNote" ) )
+
                local s, sm = suffer:match( scan )
 +
                local e
 +
                if sm  and  sm ~= "" then
 +
                    s = sm:match( "^%-([01]%d)$" )
 +
                    if s then
 +
                        local m = tonumber( s )
 +
                        if m < 1  or  m > 12 then
 +
                            s = false
 +
                        end
 +
                    end
 +
                 end
 +
                if s then
 +
                    e = mw.html.create( "small" )
 +
                              :wikitext( factory( "problemNote" ) )
 +
                    r = string.format( "%s %s", r, tostring( e ) )
 +
                else
 +
                    e = mw.html.create( "code" )
 +
                              :wikitext( Config.parProblem .. "=" )
 +
                    r = failed( "errDate", tostring( e ) )
 +
                end
 
             end
 
             end
 
         else
 
         else
Zeile 211: Zeile 237:       −
-- Export
+
Handle.main = function ( argsF, argsT )
local p = { }
  −
 
  −
p.main = function ( argsF, argsT )
   
     -- Invocation; decide between first and secondary processing
 
     -- Invocation; decide between first and secondary processing
 
     --    argsF  -- table, with #invoke parameters
 
     --    argsF  -- table, with #invoke parameters
Zeile 264: Zeile 287:  
     end
 
     end
 
     return r
 
     return r
end -- p.main()
+
end -- Handle.main()
 +
 
 +
 
 +
 
 +
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
 +
    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 vsn = entity:formatPropertyValues( "P348" )
 +
                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()
       +
 +
-- Export
 +
local p = { }
    
p.f = function ( frame )
 
p.f = function ( frame )
 
     local lucky, r
 
     local lucky, r
 
     Config.frame = frame
 
     Config.frame = frame
     lucky, r = pcall( p.main, frame.args, frame:getParent().args )
+
     lucky, r = pcall( Handle.main, frame.args, frame:getParent().args )
 
     if not lucky then
 
     if not lucky then
 
         r = Config.fault( string.format( "%s * %s",
 
         r = Config.fault( string.format( "%s * %s",
Zeile 279: Zeile 348:  
end -- p.f()
 
end -- p.f()
    +
p.failsafe = function ( frame )
 +
    -- 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()
   −
 
+
p.Handle = function ()
function p.failsafe()
+
    -- Module interface
     return Serial
+
     return Handle
end -- p.failsafe()
+
end -- p.Handle()
    
return p
 
return p
Cookies helfen uns bei der Bereitstellung von imedwiki. Durch die Nutzung von imedwiki erklärst du dich damit einverstanden, dass wir Cookies speichern.

Navigationsmenü