Modul:URIutil: Unterschied zwischen den Versionen

K 1 Version importiert: Citation Templates
imported>XenonX3
K Änderte den Schutzstatus für „Modul:URIutil“: Häufig eingebundenes Modul: https://de.wikipedia.org/w/index.php?title=Wikipedia:Administratoren/Anfragen&diff=199774253&oldid=199774128 ([Bearbeiten=Nur Administratoren] (unbeschränkt) [Verschieben=Nur Administratoren] (unbeschränkt))
 
Zeile 1: Zeile 1:
local URIutil = { suite  = "URIutil",
local URIutil = { suite  = "URIutil",
                   serial = "2019-02-22",
                   serial = "2020-05-09",
                   item  = 19644443 };
                   item  = 19644443 };
--[=[
--[=[
Zeile 23: Zeile 23:
* linkISSN()
* linkISSN()
* linkLCCN()
* linkLCCN()
* linkPMID()
* linkURN()
* linkURN()
* mayDOI()
* mayDOI()
Zeile 40: Zeile 41:
loadData: URIutil/config URIutil/isbn URIutil/urn
loadData: URIutil/config URIutil/isbn URIutil/urn
]=]
]=]
local Failsafe = URIutil
local CurrentPageName
local CurrentPageName


Zeile 184: Zeile 186:
     end
     end
     if not r then
     if not r then
         local lucky;
         local lucky, storage;
         lucky, r = pcall( mw.loadData,  "Module:URIutil/" .. acquire );
        storage = "Module:URIutil/" .. acquire;
         lucky, r = pcall( mw.loadData, storage );
        if not lucky then
            if not URIutil.suited and
              type( URIutil.item ) == "number" then
                local suited = string.format( "Q%d", URIutil.item );
                URIutil.suited = mw.wikibase.getSitelink( suited )
                                or  true;
            end
            if type( URIutil.suited ) == "string" then
                storage = string.format( "%s/%s",
                                        URIutil.suited, acquire );
                lucky, r = pcall( mw.loadData, storage );
            end
        end
         if type( r ) ~= "table" then
         if type( r ) ~= "table" then
             r = { };
             r = { };
Zeile 203: Zeile 219:
     --    Returns  link, or false
     --    Returns  link, or false
     local r;
     local r;
     if type( alert ) == "string"  and  alert ~= "" then
     if type( alert ) == "string"  and
      alert ~= "-" and
      alert ~= "" then
         r = string.format( "[[Category:%s]]", alert );
         r = string.format( "[[Category:%s]]", alert );
     end
     end
Zeile 750: Zeile 768:
                 s = r;
                 s = r;
             end
             end
             r = string.format( "[//lccn.loc.gov/%s %s]", r, s );
             r = string.format( "[https://lccn.loc.gov/%s %s]", r, s );
         end
         end
     else
     else
Zeile 1.266: Zeile 1.284:
         r = mw.text.decode( r, "PATH" );
         r = mw.text.decode( r, "PATH" );
         r = string.format( "[%s/%s%s %s%s]",
         r = string.format( "[%s/%s%s %s%s]",
                           "//doi.org",
                           "https://doi.org",
                           s,
                           s,
                           mw.uri.encode( r ),
                           mw.uri.encode( r ),
Zeile 1.296: Zeile 1.314:
         r = mw.text.decode( mw.text.trim( attempt ),  "PATH" );
         r = mw.text.decode( mw.text.trim( attempt ),  "PATH" );
         r = string.format( "[%s%s %s]",
         r = string.format( "[%s%s %s]",
                           "//hdl.handle.net/",
                           "https://hdl.handle.net/",
                           mw.uri.encode( r ),
                           mw.uri.encode( r ),
                           mw.text.encode( r, "<>&%]" ) );
                           mw.text.encode( r, "<>&%]" ) );
Zeile 1.359: Zeile 1.377:
         if s then
         if s then
             if type( s ) ~= "string"
             if type( s ) ~= "string"
              or  s == "-"
               or  s == "" then
               or  s == "" then
                 s = false;
                 s = false;
Zeile 1.400: Zeile 1.419:
         if s then
         if s then
             if type( s ) ~= "string"
             if type( s ) ~= "string"
              or  s == "-"
               or  s == "" then
               or  s == "" then
                 s = false;
                 s = false;
Zeile 1.407: Zeile 1.427:
         end
         end
         if s  and  s ~= fullPageName() then
         if s  and  s ~= fullPageName() then
             s = string.format( "[[%s|ISSN]]", s );
             if s == "ISSN" then
                s = "[[ISSN]]";
            else
                s = string.format( "[[%s|ISSN]]", s );
            end
         else
         else
             s = "ISSN";
             s = "ISSN";
Zeile 1.436: Zeile 1.460:
     return r;
     return r;
end -- URIutil.linkLCCN()
end -- URIutil.linkLCCN()
function URIutil.linkPMID( attempt, any, abbr, adhere, alert )
    -- Retrieve external PMID link with "PMID"
    -- Precondition:
    --    attempt  -- string or number with presumable PMID
    --    any      -- intentionally dummy parameter
    --    abbr    -- true: link PMID abbreviation
    --    adhere  -- true: use &nbsp;  else: use simple space;
    --    alert    -- string with title of maintenance category, or nil
    -- Postcondition:
    --    Returns  link
    local s = type( attempt );
    local legal, r;
    if s == "string" then
        r = mw.text.trim( attempt );
        if r == "" then
            r = "PMID";
            s = "empty";
        end
    elseif s == "number" then
        r = tostring( attempt );
        s = "string";
    else
        r = "PMID";
    end
    if s == "string" then
        legal = r:match( "^[1-9]%d*$" );
        if legal then
            local cnf = fetch( "config" );
            if cnf then
                s = cnf.pmid;
                if type( s ) == "string"  and
                  s ~= "-"  and
                  s ~= "" then
                    local sep;
                    if s:find( "$1", 5, true ) then
                        s = s:gsub( "%$1", r );
                    else
                        s = s .. r;
                    end
                    r = string.format( "[%s %s]", s, r );
                    if adhere then
                        sep = "&#160;";
                    else
                        sep = " ";
                    end
                    if abbr then
                        s = cnf.supportPMID;
                        if type( s ) == "string" and
                          s ~= "-"  and
                          s ~= ""  and
                          s ~= fullPageName() then
                            if s == "PMID" then
                                s = "[[PMID]]";
                            else
                                s = string.format( "[[%s|PMID]]", s );
                            end
                        else
                            s = "PMID";
                        end
                    else
                        s = "PMID";
                    end
                    r = string.format( "%s%s%s", s, sep, r );
                else
                    cnf = false;
                end
            end
            if not cnf then
                r = string.format( "PMID %s", r );
            end
        else
            r = string.format( "PMID %s", r );
        end
    end
    if not legal then
        local e = mw.html.create( "span" )
                        :addClass( "invalid-PMID" )
                        :wikitext( r );
        r = tostring( e ) .. fault( "(?!?!)" );
        if alert then
            r = r .. flop( alert );
        end
    end
    return r;
end -- URIutil.linkPMID()




Zeile 1.457: Zeile 1.569:
     if URIutil.mayURN( attempt ) then
     if URIutil.mayURN( attempt ) then
         local e = mw.html.create( "span" )
         local e = mw.html.create( "span" )
                         :addClass( "invalid-URN" )
                         :addClass( "invalid-URN" );
                        :wikitext( attempt );
        local serial  = attempt;
         local s = flop( alert );
         local suffix  = flop( alert );
        if serial:sub( 1, 4 ):lower() == "urn:" then
            serial = serial:sub( 5 );
        end
        e:wikitext( serial );
         r = tostring( e ) .. fault( "(?!?!)" );
         r = tostring( e ) .. fault( "(?!?!)" );
         if s then
         if suffix then
             r = r .. s;
             r = r .. suffix;
         end
         end
     else
     else
Zeile 1.768: Zeile 1.884:
         r = ISSNformat( issn, issn.type );
         r = ISSNformat( issn, issn.type );
         if type( cnf.issn ) == "string" then
         if type( cnf.issn ) == "string" then
             r = string.format( "[%s %s]",
             local s = cnf.issn
                              cnf.issn:gsub( "%$1", r ),
            if s:find( "$1", 5, true ) then
                              r );
                s = s:gsub( "%$1", r );
            else
                s = s .. r;
            end
            r = string.format( "[%s %s]", s, r );
         end
         end
     else
     else
Zeile 1.805: Zeile 1.925:
                 s = "Digital Object Identifier";
                 s = "Digital Object Identifier";
             end
             end
             r = string.format( "[[%s|doi]]:%s", s, r );
             if s ~= fullPageName() then
                r = string.format( "[[%s|doi]]:%s", s, r );
            else
                r = "doi:" .. r;
            end
         else
         else
             r = "doi:" .. r;
             r = "doi:" .. r;
Zeile 1.821: Zeile 1.945:
     --    anything  -- intentionally dummy parameter
     --    anything  -- intentionally dummy parameter
     --    abbr      -- true or string: link hdl: abbreviation
     --    abbr      -- true or string: link hdl: abbreviation
    -- Postcondition:
    --    Returns  combined linked URI, or false
     local r = URIutil.linkHandle( attempt );
     local r = URIutil.linkHandle( attempt );
     if r then
     if r then
Zeile 1.826: Zeile 1.952:
         if type( abbr ) == "string" then
         if type( abbr ) == "string" then
             s = abbr;
             s = abbr;
        else
            local cnf = fetch( "config" );
            if cnf then
                s = cnf.supportHandle;
                if type( s ) ~= "string"  or
                  s == "-"  or
                  s == ""  or
                  s == fullPageName() then
                    s = false;
                end
            end
         end
         end
         if s then
         if s then
Zeile 1.854: Zeile 1.991:
         if s then
         if s then
             if type( s ) ~= "string"
             if type( s ) ~= "string"
              or  s == "-"
               or  s == "" then
               or  s == "" then
                 s = false;
                 s = false;
Zeile 1.860: Zeile 1.998:
             s = "Uniform Resource Name";
             s = "Uniform Resource Name";
         end
         end
         if s then
         if s and  s ~= fullPageName() then
             r = string.format( "[[%s|urn]]:%s", s, r );
             r = string.format( "[[%s|urn]]:%s", s, r );
         else
         else
Zeile 1.871: Zeile 2.009:




URIutil.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
     local since = assert;
    --              false   -- if appropriate
     local r;
    local last  = ( atleast == "~" )
     if since == "wikidata" then
     local since = atleast
         local item = URIutil.item;
     local r
         since = false;
     if last  or  since == "wikidata" then
         local item = Failsafe.item
         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 vsn = entity:formatPropertyValues( "P348" )
                 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 <= URIutil.serial then
         if not since  or  since <= Failsafe.serial then
             r = URIutil.serial;
             r = Failsafe.serial
         else
         else
             r = false;
             r = false
         end
         end
     end
     end
     return r;
     return r
end -- URIutil.failsafe()
end -- Failsafe.failsafe()




Zeile 1.999: Zeile 2.143:
function p.linkLCCN( frame )
function p.linkLCCN( frame )
     return Template( frame, "linkLCCN" );
     return Template( frame, "linkLCCN" );
end
function p.linkPMID( frame )
    return Template( frame, "linkPMID" );
end
end
function p.linkURN( frame )
function p.linkURN( frame )
Zeile 2.053: Zeile 2.200:
         end
         end
     end
     end
     return URIutil.failsafe( since )  or  "";
     return Failsafe.failsafe( since )  or  "";
end -- p.failsafe()
end -- p.failsafe()
function p.URIutil( arg )
function p.URIutil( arg )