Modul:Namespace detect: Unterschied zwischen den Versionen

new function for creating a table of possible input parameters, a couple of portability fixes
(create replacement for Template:Namespace detect)
 
(new function for creating a table of possible input parameters, a couple of portability fixes)
Zeile 35: Zeile 35:
-- The name for the parameter to set a specific page to compare:
-- The name for the parameter to set a specific page to compare:
cfg.page = 'page'
cfg.page = 'page'
-- The header for the namespace column in the wikitable containing the
-- list of possible subject-space parameters.
cfg.wikitableNamespaceHeader = 'Namespace'
-- The header for the wikitable containing the list of possible
-- subject-space parameters.
cfg.wikitableAliasesHeader = 'Aliases'


----------------------------------------------------------------------
----------------------------------------------------------------------
Zeile 97: Zeile 105:
      
      
     -- First, return arguments for mainspace.
     -- First, return arguments for mainspace.
     if namespace == '' and args[cfg.main] then
     if namespace == mw.site.namespaces[0].name and args[cfg.main] then
         return args[cfg.main]
         return args[cfg.main]
     end
     end
Zeile 105: Zeile 113:
         local nsname = mw.ustring.lower( ns.name )
         local nsname = mw.ustring.lower( ns.name )
         -- Check the namespace, and ignore main namespace values.
         -- Check the namespace, and ignore main namespace values.
         if nsname == namespace and nsname ~= '' then
         if nsid ~= 0 and nsname == namespace then
             if args[nsname] then
             if args[nsname] then
                 return args[nsname]
                 return args[nsname]
Zeile 151: Zeile 159:
      
      
     return compare()
     return compare()
end
-- Create a wikitable of all possible namespace parameters.
function p.table()
    -- Start the wikitable.
    local ret = '{| class="wikitable"'
        .. '\n|-'
        .. '\n! ' .. cfg.wikitableNamespaceHeader
        .. '\n! ' .. cfg.wikitableAliasesHeader
   
    -- Generate the row for the main namespace.
    ret = ret .. '\n|-'
        .. '\n| ' .. cfg.main
        .. '\n|'
   
    -- Generate the other wikitable rows.
    for nsid, ns in pairs( mw.site.subjectNamespaces ) do
        if nsid ~= 0 then -- Ignore the main namespace, as it is set in cfg.
            local name = '<code>' .. mw.ustring.lower( ns.name ) .. '</code>'
            local aliases = {}
            for _, v in ipairs( ns.aliases ) do
                table.insert( aliases, '<code>' .. mw.ustring.lower(v) .. '</code>' )
            end
            ret = ret .. '\n|-'
                .. '\n| ' .. name
                .. '\n| ' .. table.concat( aliases, ', ' )
        end
    end
   
    -- End the wikitable.
    ret = ret .. '\n|-'
        .. '\n|}'
   
    return ret
end
end


return p
return p