Modul:Vorlage:UpstreamUpdate

Vorlagenprogrammierung Diskussionen Lua Unterseiten
Modul Deutsch English

Modul: Dokumentation

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


--[=[ 2015-02-07
Vorlage:UpstreamUpdate
]=]



local Support = "UpstreamUpdate"



local function fair( access, all, frame )
    -- Return template transclusion
    --     access  -- string, with page name
    --     all     -- table, with entries
    --     frame   -- object
    local r = all[ access ]
    if r then
        r = frame:expandTemplate{  title = Support,  args= { r }  }
    end
    return r
end -- fair()



local function feed( area, all )
    -- Return list of members
    --     area  -- string, with namespace number
    --     all   -- table, with entries
    local space = mw.site.namespaces[ area ].name
    local room  = { }
    local r
    for k, v in pairs( all ) do
       table.insert( room, k )
    end    -- for k, v
    table.sort( room )
    for k, v in pairs( room ) do
        if r then
            r = r .. "\n"
        else
            r = ""
        end
        r = string.format( "%s* [[%s:%s|%s]] %s %s",
                           r, space, v, v, mw.ustring.char( 8211 ),
                           all[ v ] )
    end    -- for k, v
    return r
end -- feed()



local function fiat( arglist )
    -- Perform task
    --     arglist  -- table, with parameters
    --                        .frame    -- object, or nil
    --                        .ns       -- string/number, for "space"
    --                        .service  -- string: "single", "space"
    local mode, ns, page, r
    if arglist.service == "single" then
        page = mw.title.getCurrentTitle()
        if page.contentModel ~= "wikitext" then
            mode = 1
            ns   = page.namespace
        end
    elseif arglist.service == "space" then
        mode = 2
        ns   = tonumber( arglist.ns )
    end
    if mode and ns then
        local config, frame, lucky
        if arglist.frame then
            frame = arglist.frame
        else
            frame = mw.getCurrentFrame()
        end
        config = mw.loadData( frame:getTitle() .. "/config" )
        if type( config ) == "table" then
            local room = config[ ns ]
            if type( room ) == "table" then
                if mode == 1 then
                    r = fair( page.text, room, frame )
                else
                    r = feed( ns, room )
                end
            end
        end
    end
    return r
end -- fiat()



-- Export
local p = { }

p.fire = function ( arglist )
    -- Perform task
    --     arglist  -- table, with parameters
    local lucky, r = pcall( fiat, arglist )
    if lucky then
        if not r  and  arglist.frame then
            r = ""
        end
    else
        local frame
        if arglist.frame then
            frame = arglist.frame
        else
            frame = mw.getCurrentFrame()
        end
        r = string.format( "<span class=\"error\">%s</span>", r )
    end
    return r
end -- p.fire()

p.space = function ( frame )
    return p.fire( { frame   = frame,
                     ns      = frame.args.ns,
                     service = "space" } )
end -- p.space()

p.single = function ( frame )
    return p.fire( { frame   = frame,
                     service = "single" } )
end -- p.single()

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.