Zum Inhalt springen

„Modul:JSTOR“ – Versionsunterschied

aus Wikipedia, der freien Enzyklopädie
[gesichtete Version][gesichtete Version]
Inhalt gelöscht Inhalt hinzugefügt
2016-08-30
2016-09-28
Zeile 1: Zeile 1:
local Export = { serial = "2016-08-30",
local Export = { serial = "2016-09-28",
suite = "JSTOR" }
suite = "JSTOR" }
--[=[
--[=[
Zeile 5: Zeile 5:
and other issues dealing with JSTOR ID.
and other issues dealing with JSTOR ID.
]=]
]=]
local Externals




Zeile 131: Zeile 132:
-- auxilary -- URIutil library, or false
-- auxilary -- URIutil library, or false
-- Returns table of library, or string with error message
-- Returns table of library, or string with error message
local r = auxilary
local r
if type( r ) ~= "table" then
if Externals then
r = Externals.URIutil
else
Externals = { }
if type( auxilary ) == "table" then
Externals.URIutil = auxilary
r = Externals.URIutil
end
end
if not r then
local lucky
local lucky
lucky, r = pcall( require, "Module:URIutil" )
lucky, r = pcall( require, "Module:URIutil" )
if type( r ) == "table" then
if type( r ) == "table" then
r = r.URIutil()
Externals.URIutil = r.URIutil()
r = Externals.URIutil
else
else
r = string.format( "<span class=\"error\">%s</span>", r )
r = string.format( "<span class=\"error\">%s</span>", r )
Zeile 142: Zeile 153:
end
end
return r
return r
end -- fault()
end -- fetch()




Zeile 158: Zeile 169:




Export.format = function ( article, area, appear, auxilary )
Export.feasible = function ( article, area, auxilary )
-- Analyze code, create URL, format
-- Check code, normalize
-- article -- string, with JSTOR ID
-- article -- string, with JSTOR ID
-- area -- string, with "stable", "journals", or false
-- area -- string, with "stable", "journals", or false
-- appear -- string, with link title, or false
-- auxilary -- URIutil library, or false
-- auxilary -- URIutil library, or false
-- Returns string, with external link or error message
-- Returns string, with improved ID, or false
local serial = article
local r = article
local suite = area
local suite = area or "stable"
local legal, r
local legal, URIutil
if not suite then
suite = "stable"
end
if suite == "stable" then
if suite == "stable" then
if serial:find( "/", 1, true ) then
if r:find( "/", 1, true ) then
local URIutil = fetch( auxilary )
URIutil = fetch( auxilary )
if type( URIutil ) == "table" then
if type( URIutil ) == "table" then
legal = URIutil.isDOI( serial )
legal = URIutil.isDOI( r )
else
return URIutil
end
end
else
else
legal = serial:match( "^i?[1-9][0-9]*$" ) or
legal = r:match( "^i?[1-9][0-9]*$" ) or
serial:match( "^j%.%w+$" )
r:match( "^j%.%w+%.?[0-9]*$" )
end
end
elseif suite == "journals" then
elseif suite == "journals" then
local URIutil = fetch( auxilary )
URIutil = fetch( auxilary )
if type( URIutil ) == "table" then
if type( URIutil ) == "table" then
legal = URIutil.isISSNvalid( serial )
legal = URIutil.isISSNvalid( r )
if legal then
r = r:gsub( "-", "" )
serial = serial:gsub( "-", "" )
:gsub( "x", "X" )
:gsub( "x", "X" )
end
else
return URIutil
end
end
end
end
if legal then
if not legal then
r = false
end
return r
end -- Export.feasible()



Export.format = function ( article, area, appear, auxilary )
-- Analyze code, create URL, format
-- article -- string, with JSTOR ID
-- area -- string, with "stable", "journals", or false
-- appear -- string, with link title, or false
-- auxilary -- URIutil library, or false
-- Returns string, with external link or error message
local r = Export.feasible( article, area, auxilary )
local suite = area or "stable"
if r then
local show = appear
local show = appear
if show then
if show then
Zeile 204: Zeile 222:
end
end
if not show then
if not show then
show = serial
show = article
end
end
r = string.format( "[http://www.jstor.org/%s/%s %s]",
r = string.format( "[http://www.jstor.org/%s/%s %s]",
suite, serial, show )
suite, r, show )
if not appear then
if not appear then
if Config.showArticle then
if Config.showArticle then
Zeile 218: Zeile 236:
else
else
r = string.format( "%s %s/''%s''",
r = string.format( "%s %s/''%s''",
fault( "errInvalid" ), suite, serial )
fault( "errInvalid" ), suite, article )
end
end
return r
return r
Zeile 336: Zeile 354:




p.jstor = function ()
p.JSTOR = function ()
return Export
return Export
end -- p.jstor()
end -- p.JSTOR()


return p
return p

Version vom 29. September 2016, 01:08 Uhr

Vorlagenprogrammierung Diskussionen Lua Unterseiten
Modul Deutsch English

Modul: Dokumentation

Diese Seite enthält Code in der Programmiersprache Lua. Einbindungszahl Cirrus

Dies ist die (produktive) Mutterversion eines global benutzten Lua-Moduls.
Wenn die serial-Information nicht übereinstimmt, müsste eine Kopie hiervon in das lokale Wiki geschrieben werden.
Versionsbezeichnung auf WikiData: 2024-09-22

Updating notwendig

(lokal: 2016-09-28)

local Export = { serial = "2016-09-28",
                 suite  = "JSTOR" }
--[=[
Template:JSTOR
and other issues dealing with JSTOR ID.
]=]
local Externals



local Config = {
   self        = Export.suite,
   errCat      = false,
   errClass    = "error_jstor",
   errClasses  = false,
   errHide     = false,
   errNS       = false,
   errInvalid  = { en = "Invalid:",
                   de = "Ungültig:" },
   errMissing  = { en = "Missing ID",
                   de = "ID fehlt" },
   errUnkown   = { en = "Unkown parameter:",
                   de = "Parameter unbekannt:" },
   showArticle = "JSTOR"
}



local function factory( apply )
    -- Localization of messages
    --     apply  -- string, with message key
    -- Returns message text; at least english
    local r
    entry = Config[ apply ]
    if entry then
        r = entry[ mw.language.getContentLanguage():getCode() ]
        if not r then
            r = entry.en
        end
    else
        r = string.format( "<span class=\"error\">????.%s.????</span>",
                           apply )
    end
    return r
end -- factory()



local function faculty( adjust )
    -- Test template arg for boolean
    --     adjust  -- string or nil
    -- Returns boolean
    local s = type( adjust )
    local r
    if s == "string" then
        r = mw.text.trim( adjust )
        r = ( r ~= ""  and  r ~= "0" )
    elseif s == "boolean" then
        r = adjust
    else
        r = false
    end
    return r
end -- faculty()



local function fault( alert, about )
    -- Format message with class="error" or similar
    --     alert  -- string, with message key
    --     about  -- string, with explanation
    -- Returns message with markup
    local story = factory( alert )
    local r, scope, style
    if Config.self then
        story = string.format( "%s * %s", Config.self, story )
    end
    if not Config.frame then
        Config.frame = mw.getCurrentFrame()
    end
    if Config.frame:preprocess( "{{REVISIONID}}" ) == "" then
        Config.errCat  = false
        Config.errHide = false
        scope          = string.format( "%s error", Config.errClass )
    else
        scope = Config.errClass
    end
    if Config.errHide then
        style = "style='display:none'"
    else
        style = ""
    end
    if Config.errClasses then
        scope = string.format( "%s %s",
                               scope, Config.errClasses )
    end
    r = string.format( "<span class=\"%s\" %s>%s</span>",
                       scope, style, story )
    if about then
        r = string.format( "%s %s", r, about )
    end
    if Config.errCat then
        if Config.errNS then
            local ns = mw.title.getCurrentTitle().namespace
            local st = type( Config.errNS )
            if st == "string" then
                local space  = string.format( ".*%%s%d%%s.*", ns )
                local spaces = string.format( " %s ", Config.errNS )
                if spaces:match( space ) then
                    Config.errNS = false
                end
            elseif st == "table" then
                for i = 1, #Config.errNS do
                    if Config.errNS[ i ] == ns then
                        Config.errNS = false
                        break    -- for i
                    end
                end -- for i
            end
        end
        if not Config.errNS then
            r = string.format( "%s[[Category:%s]]", r, Config.errCat )
        end
    end
    return r
end -- fault()



local function fetch( auxilary )
    -- Fetch module
    --     auxilary  -- URIutil library, or false
    -- Returns table of library, or string with error message
    local r
    if Externals then
        r = Externals.URIutil
    else
        Externals = { }
        if type( auxilary ) == "table" then
            Externals.URIutil = auxilary
            r                 = Externals.URIutil
        end
    end
    if not r then
        local lucky
        lucky, r = pcall( require, "Module:URIutil" )
        if type( r ) == "table" then
            Externals.URIutil = r.URIutil()
            r                 = Externals.URIutil
        else
            r = string.format( "<span class=\"error\">%s</span>", r )
        end
    end
    return r
end -- fetch()



Export.failsafe = function ( assert )
    local r
    if not assert  or  assert <= Export.serial then
        r = Export.serial
    else
        r = false
    end
    return r
end -- Export.failsafe()



Export.feasible = function ( article, area, auxilary )
    -- Check code, normalize
    --     article   -- string, with JSTOR ID
    --     area      -- string, with "stable", "journals", or false
    --     auxilary  -- URIutil library, or false
    -- Returns string, with improved ID, or false
    local r      = article
    local suite  = area or "stable"
    local legal, URIutil
    if suite == "stable" then
        if r:find( "/", 1, true ) then
            URIutil = fetch( auxilary )
            if type( URIutil ) == "table" then
                legal = URIutil.isDOI( r )
            end
        else
            legal = r:match( "^i?[1-9][0-9]*$" )  or
                    r:match( "^j%.%w+%.?[0-9]*$" )
        end
    elseif suite == "journals" then
        URIutil = fetch( auxilary )
        if type( URIutil ) == "table" then
            legal = URIutil.isISSNvalid( r )
            r     = r:gsub( "-", "" )
                     :gsub( "x", "X" )
        end
    end
    if not legal then
        r = false
    end
    return r
end -- Export.feasible()



Export.format = function ( article, area, appear, auxilary )
    -- Analyze code, create URL, format
    --     article   -- string, with JSTOR ID
    --     area      -- string, with "stable", "journals", or false
    --     appear    -- string, with link title, or false
    --     auxilary  -- URIutil library, or false
    -- Returns string, with external link or error message
    local r     = Export.feasible( article, area, auxilary )
    local suite = area or "stable"
    if r then
        local show = appear
        if show then
            show = mw.text.trim( show )
            if ( show == "" ) then
                show = false
            end
        end
        if not show then
            show = article
        end
        r = string.format( "[http://www.jstor.org/%s/%s %s]",
                           suite, r, show )
        if not appear then
            if Config.showArticle then
                r = string.format( "[[%s|JSTOR]]:%s",
                                   Config.showArticle, r )
            else
                r = "JSTOR:" .. r
            end
        end
    else
        r = string.format( "%s %s/''%s''",
                           fault( "errInvalid" ),  suite,  article )
    end
    return r
end -- Export.format()



-- Export
local p = { }

p.main = function ( argsF, argsT )
    -- Invocation
    --     argsF  -- table, with #invoke parameters, or false
    --     argsT  -- table, with template parameters
    -- Returns appropriate string
    local r, show, stuff, suite
    if argsF then
        Config.errCat     = argsF.errCat
        Config.errClasses = argsF.errClasses
        Config.errHide    = faculty( argsF.errHide )
        Config.errNS      = argsF.errNS
        if argsF.showArticle ~= nil then
            if argsF.showArticle == "" then
                Config.showArticle = false
            else
                Config.showArticle = argsF.showArticle
            end
        end
    end
    if type( argsT ) == "table" then
        local s, unknown
        r = { }
        for k, v in pairs( argsT ) do
            s = type( k )
            if s == "number" then
                if ( k == 1 ) then
                    stuff = mw.text.trim( v )
                    if ( stuff == "" ) then
                        stuff = false
                    end
                    k = false
                elseif ( k == 2 ) then
                    v = mw.text.trim( v )
                    if ( v ~= "" ) then
                        show = v
                    end
                    k = false
                else
                    k = tostring( k )
                end
            elseif s == "string" then
                if argsT.show then
                    if ( argsT.show ~= "" ) then
                        show = argsT.show
                    end
                    k = false
                elseif argsT.suite then
                    if ( argsT.suite ~= "" ) then
                        suite = argsT.suite
                    end
                    k = false
                elseif argsT.demo  or  faculty( argsT.NoCat ) then
                    Config.errCat  = false
                    Config.errHide = false
                    k = false
                end
            end
            if k then
                if not unknown then
                    unknown = { }
                end
                table.insert( unknown, k )
            end
        end -- for k, v
        if unknown then
            r = string.format( "'<code>%s</code>' in Template:JSTOR",
                               table.concat( unknown, " " ) )
            r = fault( "errUnkown", r )
        elseif not stuff then
            r = fault( "errMissing" )
        end
    else
        r = false
    end
    if type( r ) == "table" then
        r = Export.format( stuff, suite, show )
    end
    return r
end -- p.main()



p.f = function ( frame )
    local lucky, r
    Config.frame = frame
    lucky, r = pcall( p.main, frame.args, frame:getParent().args )
    if not lucky then
        r = string.format( "<span class=\"error\">%s * %s</span>",
                           frame:getTitle(), r )
    end
    return r
end -- p.f()



p.failsafe = function ( frame )
    local since = frame.args[ 1 ]
    if since then
        since = mw.text.trim( since )
        if since == "" then
            since = false
        end
    end
    return Export.failsafe( since )  or  ""
end -- p.failsafe()



p.JSTOR = function ()
    return Export
end -- p.JSTOR()

return p