Modul:Namespace detect
Dokumentacija modula
| Koristi Lua modul: |
Modul dopušta ispis teksta ovisno o imenskom prostoru u kojem je modul pozvan.
Modul sadrži Lua implementaciju predloška {{namespace detect}}.
Korištenje
{{#invoke: Namespace detect | main
| main = <!-- tekst koji se vraća ako je modul pozvan u glavnom imenskom prostoru -->
| talk = <!-- tekst koji se vraća ako je modul pozvan u bilo kojem
razgovornom prostoru (Razgovor sa suradnikom, Razgovor o predlošku, itd) -->
<!-- tekst koji se vraća za pojedine imenske prostore -->
| main =
| suradnik =
| hrvatska_internetska_enciklopedija =
| datoteka =
| mediawiki =
| predložak =
| pomoć =
| kategorija =
| portal =
| dodatak =
| nacrt =
| modul =
| gadget =
| gadget definition =
| other = <!-- tekst koji se vraća za ostale (nenavedene) imenske prostore -->
| demopage = <!-- stranica za koju pronalazimo imenski postor, ako nije trenutna stranica -->
| demospace = <!-- imenski prostor za koji pozivamo predložak (zaobilazi stvarni prostor) -->
| subjectns = <!-- ako je postavljeno na "yes", tretira razgovorne stranice kao dio imenskog prostora sadržaja
(Razgovor o predlošku = Predložak) -->
}}
Imenski prostori
Moguće vrijednosti za imenske prostore sadržaja su sljedeće:
| Name | Namespaces |
|---|---|
| draft talk | 119 |
| education program | 446 |
| mediawiki talk | 9 |
| wikipedia talk | 5 |
| other | |
| help | 12 |
| category | 14 |
| module talk | 829 |
| user talk | 3 |
| help talk | 13 |
| module | 828 |
| file talk | 7 |
| book talk | 109 |
| template | 10 |
| user | 2 |
| template talk | 11 |
| wikipedia | 4 |
| education program talk | 447 |
| book | 108 |
| talk | 1, 3, 5, 7, 9, 11, 13, 15, 101, 109, 119, 447, 829 |
| portal talk | 101 |
| main | 0 |
| draft | 118 |
| portal | 100 |
| file | 6 |
| mediawiki | 8 |
| category talk | 15 |
Funkcija tablice
Koristite sljedeći kod za prikaz tablice imenskih prostora:
{{#invoke:Namespace detect|table|talk=yes}}
Parametar |talk=yes pokazuje i imenski prostor razgovora.
Konfiguracijska datoteka modula nalazi se na Modul:Namespace detect/config.
Tehničke napomene
Modul koristi podatkovni obrazac na Module:Namespace detect/data. Ta se stranica učitava funkcijom mw.loadData, što joj omogućava procesiranje jednom po sadržajnoj stranici umjesto jednom po pozivu modula (#invoke). Time se poboljšavaju preformanse rada modula.
-- This module implements namespace detection and handling.
-- It is a direct port of the English Wikipedia version.
local p = {}
local yesno = require('Module:Yesno')
local mArguments = require('Module:Arguments')
local data = require('Module:Namespace detect/data')
local cfg = require('Module:Namespace detect/config')
local function getPageObject(page)
if type(page) == 'string' then
return mw.title.new(page)
elseif type(page) == 'table' and page.getContent then
return page
else
return mw.title.getCurrentTitle()
end
end
local function getNamespace(page)
local title = getPageObject(page)
return title.namespace
end
local function matchNamespace(ns, list)
if not list then
return false
end
for _, v in ipairs(list) do
if ns == v then
return true
end
end
return false
end
local function detectNamespace(page)
local ns = getNamespace(page)
for name, info in pairs(data) do
if matchNamespace(ns, info.namespaces) then
return name
end
end
return 'other'
end
local function getParam(args, key)
return args[key] or args[string.lower(key)] or args[string.upper(key)]
end
local function getOutput(args, ns)
local value = getParam(args, ns)
if value ~= nil then
return value
end
return getParam(args, 'other')
end
function p._main(args)
local page = getParam(args, 'page')
local ns = detectNamespace(page)
return getOutput(args, ns) or ''
end
function p.main(frame)
local args = mArguments.getArgs(frame)
return p._main(args)
end
-- Subject/talk namespace handling
local function subjectNamespace(page)
local title = getPageObject(page)
return title.subjectNsText
end
local function talkNamespace(page)
local title = getPageObject(page)
return title.talkNsText
end
function p.subjectns(frame)
local args = mArguments.getArgs(frame)
local page = getParam(args, 'page')
return subjectNamespace(page) or ''
end
function p.talkns(frame)
local args = mArguments.getArgs(frame)
local page = getParam(args, 'page')
return talkNamespace(page) or ''
end
-- Table output for documentation
function p.table(frame)
local args = mArguments.getArgs(frame)
local showTalk = yesno(args.talk, false)
local out = '{| class="wikitable"\n! Name !! Namespaces\n'
for name, info in pairs(data) do
out = out .. '|-\n| ' .. name .. ' || '
for i, ns in ipairs(info.namespaces) do
out = out .. ns
if i < #info.namespaces then
out = out .. ', '
end
end
out = out .. '\n'
end
out = out .. '|}'
return out
end
-- Return module table
return p