Moduł:Stopka portal: Różnice pomiędzy wersjami
Z Nonsensopedii, polskiej encyklopedii humoru
Ostrzyciel (dyskusja • edycje) M |
Ostrzyciel (dyskusja • edycje) M |
||
(Nie pokazano 16 pośrednich wersji utworzonych przez tego samego użytkownika) | |||
Linia 10: | Linia 10: | ||
text = { |
text = { |
||
"Zobacz więcej artykułów w '''[[Portal:Historia|portalu o historii]]'''." |
"Zobacz więcej artykułów w '''[[Portal:Historia|portalu o historii]]'''." |
||
} |
}, |
||
locative = 'historii', |
|||
} |
|||
}, |
|||
['Informatyka'] = { |
|||
letter = '', -- Tux ;) |
|||
color = '#235bc1', |
|||
text = { |
|||
"Zobacz więcej artykułów w '''[[Portal:Informatyka|portalu o informatyce]]'''." |
|||
}, |
|||
locative = 'informatyce', |
|||
}, |
|||
['Polityka'] = { |
|||
letter = 'P', |
|||
color = '#090082', |
|||
text = { |
|||
"Zobacz więcej artykułów w '''[[Portal:Polityka|portalu o polityce]]'''." |
|||
}, |
|||
locative = 'polityce', |
|||
}, |
|||
} |
} |
||
-- extra ordered list for navigation ordering |
|||
local portalList = { |
|||
'Historia', 'Informatyka', 'Polityka' |
|||
} |
|||
-- Appends a portal initial to an HTML builder object |
|||
local function makeInitial(builder, name, info) |
|||
return builder:tag('span') |
|||
:addClass('n-portal-initial') |
|||
:addClass('link-kolor') |
|||
:cssText('color: ' .. info.color) |
|||
:node('[[Portal:' .. name .. '|' .. info.letter .. ']]') |
|||
:done() |
|||
end |
|||
-- Makes a div with a nice link to portal by the given name -> see the LUT above |
|||
local function makePortalItem(name) |
|||
local info = portals[name] |
|||
if info then |
|||
div = mw.html.create('div') |
|||
:addClass('n-portal-link') |
|||
div = makeInitial(div, name, info) |
|||
div = div:tag('span') |
|||
:addClass('n-portal-link-text') |
|||
:node(info.text[math.random(#info.text)]) |
|||
:done() |
|||
return tostring(div) |
|||
else |
|||
return '' |
|||
end |
|||
end |
|||
-- for {{stopka}} |
|||
function p.getText() |
function p.getText() |
||
local text = '' |
local text = '' |
||
Linia 23: | Linia 77: | ||
for _, r in ipairs(res.results) do |
for _, r in ipairs(res.results) do |
||
text = text .. makePortalItem(mw.ustring.gsub(r.fulltext, 'Portal:', '')) |
|||
local info = portals[name] |
|||
if info then |
|||
text = text |
|||
.. '<div class="n-portal-link"><span class="n-portal-initial link-kolor" ' |
|||
.. 'style="color: ' .. info.color .. ';">[[Portal:' .. name .. '|' |
|||
.. info.letter .. ']]</span><span class="n-portal-link-text">' |
|||
.. info.text[math.random(#info.text)] .. '</span></div>' |
|||
end |
|||
end |
end |
||
Linia 38: | Linia 83: | ||
end |
end |
||
-- for {{KatPortal}} |
|||
function p.getKatText(frame, args) |
|||
args = tools.getArgs(frame) |
|||
local i = 1 |
|||
local links = {} |
|||
while args[tostring(i)] do |
|||
local linkTitle = (portals[args[tostring(i)]] or {}).locative or "'''BŁĄD – nieznany portal'''" |
|||
table.insert(links, '[[Portal:' .. args[tostring(i)] .. '|' .. linkTitle .. ']]') |
|||
i = i + 1 |
|||
end |
|||
local text = tools.concatListPl(links) |
|||
if #links == 0 then |
|||
return 'Błąd: nie podano żadnych portali.' |
|||
elseif #links == 1 then |
|||
text = "Zobacz więcej artykułów w portalu o " .. text .. '.' |
|||
else |
|||
text = "Zobacz więcej artykułów w portalach o " .. text .. '.' |
|||
end |
|||
return text |
|||
end |
|||
function p.getNavigation() |
|||
local cont = mw.html.create('div') |
|||
:addClass('n-portal-nav-container') |
|||
for _, name in pairs(portalList) do |
|||
info = portals[name] |
|||
cont = cont:tag('div') |
|||
:addClass('n-portal-nav-item') |
|||
cont = makeInitial(cont, name, info) |
|||
cont = cont:tag('span') |
|||
:addClass('n-portal-nav-text') |
|||
:node('[[Portal:' .. name .. '|' .. name .. ']]') |
|||
:done() |
|||
:done() |
|||
end |
|||
return tostring(cont) |
|||
end |
|||
return p |
return p |
Aktualna wersja na dzień 10:13, 2 kwi 2022
Generuje linki do portali w szablonie {{Stopka}}
. Zobacz też: Moduł:Stopka.
local tools = require('Moduł:Narzędzia')
local p = {}
-- Portale dodawaj alfabetycznie.
-- Edytuj śmiało, teksty zachęcające do kliknięcia w link są losowane z podanej tu puli
local portals = {
['Historia'] = {
letter = 'H',
color = '#820000',
text = {
"Zobacz więcej artykułów w '''[[Portal:Historia|portalu o historii]]'''."
},
locative = 'historii',
},
['Informatyka'] = {
letter = '', -- Tux ;)
color = '#235bc1',
text = {
"Zobacz więcej artykułów w '''[[Portal:Informatyka|portalu o informatyce]]'''."
},
locative = 'informatyce',
},
['Polityka'] = {
letter = 'P',
color = '#090082',
text = {
"Zobacz więcej artykułów w '''[[Portal:Polityka|portalu o polityce]]'''."
},
locative = 'polityce',
},
}
-- extra ordered list for navigation ordering
local portalList = {
'Historia', 'Informatyka', 'Polityka'
}
-- Appends a portal initial to an HTML builder object
local function makeInitial(builder, name, info)
return builder:tag('span')
:addClass('n-portal-initial')
:addClass('link-kolor')
:cssText('color: ' .. info.color)
:node('[[Portal:' .. name .. '|' .. info.letter .. ']]')
:done()
end
-- Makes a div with a nice link to portal by the given name -> see the LUT above
local function makePortalItem(name)
local info = portals[name]
if info then
div = mw.html.create('div')
:addClass('n-portal-link')
div = makeInitial(div, name, info)
div = div:tag('span')
:addClass('n-portal-link-text')
:node(info.text[math.random(#info.text)])
:done()
return tostring(div)
else
return ''
end
end
-- for {{stopka}}
function p.getText()
local text = ''
local title = mw.title.getCurrentTitle()
local res = mw.smw.getQueryResult{
'[[Zawiera artykuł::' .. title.fullText .. ']]',
'[[Portal:+]]'
}
for _, r in ipairs(res.results) do
text = text .. makePortalItem(mw.ustring.gsub(r.fulltext, 'Portal:', ''))
end
return text
end
-- for {{KatPortal}}
function p.getKatText(frame, args)
args = tools.getArgs(frame)
local i = 1
local links = {}
while args[tostring(i)] do
local linkTitle = (portals[args[tostring(i)]] or {}).locative or "'''BŁĄD – nieznany portal'''"
table.insert(links, '[[Portal:' .. args[tostring(i)] .. '|' .. linkTitle .. ']]')
i = i + 1
end
local text = tools.concatListPl(links)
if #links == 0 then
return 'Błąd: nie podano żadnych portali.'
elseif #links == 1 then
text = "Zobacz więcej artykułów w portalu o " .. text .. '.'
else
text = "Zobacz więcej artykułów w portalach o " .. text .. '.'
end
return text
end
function p.getNavigation()
local cont = mw.html.create('div')
:addClass('n-portal-nav-container')
for _, name in pairs(portalList) do
info = portals[name]
cont = cont:tag('div')
:addClass('n-portal-nav-item')
cont = makeInitial(cont, name, info)
cont = cont:tag('span')
:addClass('n-portal-nav-text')
:node('[[Portal:' .. name .. '|' .. name .. ']]')
:done()
:done()
end
return tostring(cont)
end
return p