Modul:Vorlage:LuaModuleDoc: Unterschied zwischen den Versionen

(update)
(update)
Zeile 1: Zeile 1:
--[=[ 2013-05-13
--[=[ 2013-05-14
Support {{LuaModuleDoc}}
Support {{LuaModuleDoc}}
* nav()
* nav()
Zeile 35: Zeile 35:
     return r
     return r
end -- navError()
end -- navError()
local function navInclude( collect, swift, super, ns, nsDocs )
    -- Include external content into page
    -- Precondition:
    --    collect  -- table; with arguments for pageNav transclusion
    --                1: basic module name
    --                2: number of language links  +  1
    --                3...: language link codes
    --    swift    -- string; pageNav argument
    --    super    -- string or false
    --                string: full page name of basic documentation
    --                        terminated by slash; then
    --                        include first existing language version
    --                        and brief template documentation
    --    ns      -- number; current namespace
    --    nsDocs  -- number; namespace for doc
    --    args.pageNav defined
    -- Uses:
    --    >< currentTitle
    --    LuaWiki.getArg()
    --    LuaWiki.transclude()
    --    LuaWiki.getVariable()
    --    LuaWiki.isExisting()
    --    navError()
    local r = LuaWiki.transclude( swift, collect )
    local s = false
    local t = currentTitle.talkPageTitle
    if t then
        s = t.exists
    end
    r = "<!-- LuaModuleDoc::b -->" .. r .. "<!-- LuaModuleDoc::e -->"
    if not s then
        if super then
            s = "NoTalkCentral"
        elseif ns == nsDocs + 1 then
            s = false
        else
            s = "NoTalkRedir"
        end
        if s then
            r = r .. navError( s )
        end
    end
    if super then
        local i
        for i = 3, #collect do
            s = super .. collect[ i ]
            if LuaWiki.isExisting( s ) then
                s = LuaWiki.transclude( s )
                r = r .. s:gsub( "<!-- LuaModuleDoc::b -->.*<!-- LuaModuleDoc::e -->", "" )
                break
            end
        end -- for i
        s = LuaWiki.getArg( "pageTemplateInsert", "" )
        if LuaWiki.isExisting( s ) then
            local suppress = LuaWiki.getArg( "noHint", "" )
            if #suppress == 0 then
              r = r .. LuaWiki.transclude( s,  { collect[ 1 ] } )
            end
        end
        s = LuaWiki.getArg( "categoryDocs", "" )
        if #s > 0 then
            i = mw.title.makeTitle( "Category", s )
            if i.exists then
                r = r .. "[[" .. i.prefixedText
                      .. "|" .. collect[ 1 ] .. "]]"
            end
        end
        r = r .. "__NOEDITSECTION__"
    end
    return r
end -- navInclude()




Zeile 146: Zeile 72:




local function navLangs( space, start, script )
local function navLangs( nsDocs, start, script )
     -- Analyze languages
     -- Analyze languages
     -- Precondition:
     -- Precondition:
     --    current page is supposed to transclude LuaModuleDoc
     --    current page is supposed to transclude LuaModuleDoc
     --    space  -- string; central documentation namespace
     --    nsDocs  -- number; central documentation namespace
     --    start  -- string; central documentation root
     --    start  -- string; central documentation root
     --    script  -- string; basic module name
     --    script  -- string; basic module name
Zeile 163: Zeile 89:
     --    LuaWiki.getArg()
     --    LuaWiki.getArg()
     --    navLang()
     --    navLang()
     --    navError()
     --    mw.title.makeTitle()
     local e, i, s, t
     local e, i, s, t
     local r = { }
     local r = { }
Zeile 182: Zeile 108:
         s = e[ 1 ]
         s = e[ 1 ]
         if e[ 2 ] then
         if e[ 2 ] then
             t = mw.title.makeTitle( space,  super .. s )
             t = mw.title.makeTitle( nsDocs,  super .. s )
             if not t.exists then
             if not t.exists then
                 s = false
                 s = false
Zeile 197: Zeile 123:
     return r
     return r
end -- navLangs()
end -- navLangs()
local function navMerge( start, swift, ns, nsDocs, script )
    -- Include various external content into page
    -- Precondition:
    --    start  -- string; defined pageDocRoot argument
    --    swift  -- string; defined pageNav argument
    --    nsDocs  -- number; central documentation namespace
    --    ns      -- number; current namespace
    --    script  -- string; modul name
    -- Uses:
    --    >< currentTitle
    --    navLangs()
    --    LuaWiki.transclude()
    --    navError()
    --    mw.title.makeTitle()
    --    LuaWiki.getArg()
    --    LuaWiki.isExisting()
    local r
    local s
    local super
    local t      = currentTitle.talkPageTitle
    local collect = navLangs( nsDocs, start, script )
    if ns == nsDocs and
      currentTitle.text == start .. "/" .. script then
        super = currentTitle.text .. "/"
    else
        super = false
    end
    r = LuaWiki.transclude( swift, collect )
    if t then
        s = t.exists
    else
        s = false
    end
    if not s then
        if super then
            s = "NoTalkCentral"
        elseif ns == nsDocs + 1 then
            s = false
        else
            s = "NoTalkRedir"
        end
        if s then
            r = r .. navError( s )
        end
    end
    if super then
        local i
        local d  = "{{%s*[lL]uaModuleDoc[^}]*}}%s*"
        local p1 = "^%s*" .. d .. "<onlyinclude>"
        local p2 = "%s*<noinclude>" .. d .. "</noinclude>"
        for i = 3, #collect do
            t = mw.title.makeTitle( nsDocs,  super .. collect[ i ] )
            s = t:getContent()
            if s then
                s = s:gsub( p1, "" ):gsub( p2, "" )
                if s:match( d ) then
                    r = r .. "<br />"
                          .. navError( "BadInclude", t.prefixedText )
                          .. "<br />"
                else
                    r = r .. LuaWiki.transclude( t.prefixedText )
                    break
                end
            end
        end -- for i
        s = LuaWiki.getArg( "pageTemplateInsert", "" )
        if LuaWiki.isExisting( s ) then
            local suppress = LuaWiki.getArg( "noHint", "" )
            if #suppress == 0 then
              r = r .. LuaWiki.transclude( s,  { collect[ 1 ] } )
            end
        end
        s = LuaWiki.getArg( "categoryDocs", "" )
        if #s > 0 then
            i = mw.title.makeTitle( "Category", s )
            if i.exists then
                r = r .. "[[" .. i.prefixedText
                      .. "|" .. collect[ 1 ] .. "]]"
            end
        end
        r = r .. "__NOEDITSECTION__"
    end
    return r
end -- navMerge()




Zeile 211: Zeile 224:
     --    LuaWiki.getArg()
     --    LuaWiki.getArg()
     --    navError()
     --    navError()
     --    navLangs()
     --    navMerge()
    --    navInclude()
     local r
     local r
     local start = LuaWiki.getArg( "pageDocRoot" )
     local start = LuaWiki.getArg( "pageDocRoot" )
     if type( start ) == "string" then
     if type( start ) == "string" then
         local light  = false
         local light  = false
        local story  = currentTitle.text .. "/"
         local script
         local script
         if lead then
         if lead then
Zeile 223: Zeile 234:
         else
         else
             local sub = "/([^/]+)/(.*)$"
             local sub = "/([^/]+)/(.*)$"
             script, sub = mw.ustring.match( story,
             script, sub = mw.ustring.match( currentTitle.text .. "/",
                                             "^" .. start .. sub )
                                             "^" .. start .. sub )
             if type( script ) == "string" then
             if type( script ) == "string" then
                 light = ( #sub > 0 )
                 light = ( #sub > 0 )
             else
             else
                 r      = navError( "BadPage" ) .. story
                 r      = navError( "BadPage" ) .. currentTitle.text
                 script = false
                 script = false
             end
             end
Zeile 235: Zeile 246:
             local swift = LuaWiki.getArg( "pageNav" )
             local swift = LuaWiki.getArg( "pageNav" )
             if type( swift ) == "string" then
             if type( swift ) == "string" then
                 -- nsDocs is valid, since it equals ns
                 r = navMerge( start, swift, nsDocs, ns, script )
                local space = mw.site.namespaces[ nsDocs ].name
                local super
                local collect = navLangs( space, start, script )
                if ns == nsDocs and
                  story == start .. "/" .. script .. "/" then
                    super = space .. ":" .. start .. "/" .. script .. "/"
                else
                    super = false
                end
                r = navInclude( collect, swift, super, ns, nsDocs )
             else
             else
                 r = navError( "configMissing", "pageNav" )
                 r = navError( "configMissing", "pageNav" )