Moduł:Portal: Różnice pomiędzy wersjami
Z Nonsensopedii, polskiej encyklopedii humoru
Ostrzyciel (dyskusja • edycje) M |
Polskacafe (dyskusja • edycje) (zastąpiono nową treścią w ramach nowego systemu portali (bo działa)) |
||
(Nie pokazano 5 wersji utworzonych przez jednego użytkownika) | |||
Linia 2: | Linia 2: | ||
local p = {} |
local p = {} |
||
local function |
local function makeShowStatus(text_or_nil) |
||
local |
local text = text_or_nil or '' |
||
local showstatus = {mobileonly=false, desktoponly=false} |
|||
local text = args['panel' .. num] |
|||
if text == |
if text == "mobileonly" then |
||
showstatus.mobileonly = true |
|||
elseif text == "desktoponly" then |
|||
local title = args['ptytuł' .. num] or '' |
|||
showstatus.desktoponly = true |
|||
end |
|||
showstatus.tostring = function() |
|||
local final = "" |
|||
if showstatus.mobileonly then final = final .. "mobileonly" end |
|||
if showstatus.desktoponly then final = final .. " desktoponly" end |
|||
final = mw.text.trim(final) |
|||
return final |
|||
end |
|||
return showstatus |
|||
end |
|||
local function makeInfoSet(args, num, showstatus_maybe_nil) |
|||
local showstatus = makeShowStatus(showstatus_maybe_nil) |
|||
local infoSet = {color="#c7c7c7", text="", title="", showstatus=showstatus} |
|||
infoSet.text = args['panel' .. num] or '' |
|||
infoSet.title = args['ptytuł' .. num] or '' |
|||
if args.kolor ~= nil then |
|||
infoSet.color = args.kolor |
|||
end |
|||
return infoSet |
|||
end |
|||
local function makePanel(infoSet, stack) |
|||
local panelDiv = mw.html.create( 'div' ) |
|||
local h2 = mw.html.create( 'h2' ) |
local h2 = mw.html.create( 'h2' ) |
||
h2:css('border-bottom', '2px solid' .. color .. '!important') |
h2:css('border-bottom', '2px solid' .. infoSet.color .. '!important') |
||
:addClass("portal-panel-header") |
|||
:wikitext(title) |
|||
:wikitext(infoSet.title) |
|||
table.insert(stack, tostring(h2) .. '\n' .. text) |
|||
panelDiv:addClass("portal-panel") |
|||
:addClass(infoSet.showstatus.tostring()) |
|||
:wikitext(tostring(h2) .. '<div class="portal-panel-content">\n' .. infoSet.text .. '\n</div>') |
|||
table.insert(stack, tostring(panelDiv)) |
|||
end |
end |
||
Linia 18: | Linia 47: | ||
local function findRelevantPages(args) |
local function findRelevantPages(args) |
||
local pages = {} |
local pages = {} |
||
local categories = {} |
|||
-- Artykuły podane explicite |
-- Artykuły podane explicite |
||
Linia 37: | Linia 67: | ||
if r.exists == '1' then |
if r.exists == '1' then |
||
table.insert(pages, r.fulltext) |
table.insert(pages, r.fulltext) |
||
end |
|||
end |
|||
-- znajdź w warunkach wyszukiwania kategorie nadrzędne |
|||
for m in mw.ustring.gmatch(args['kategorie'], '%[%[[^%]]+%]%]') do |
|||
local cond = mw.text.trim(mw.ustring.sub(m, 3, -3)) |
|||
if mw.ustring.find(mw.ustring.lower(cond), 'kategoria:') == 1 or |
|||
mw.ustring.find(mw.ustring.lower(cond), 'category:') == 1 then |
|||
cond = mw.ustring.sub(cond, mw.ustring.find(cond, ':', 1, true) + 1) |
|||
for _, cat in ipairs(mw.text.split(cond, '||', true)) do |
|||
table.insert(categories, 'Kategoria:' .. mw.text.trim(cat)) |
|||
end |
|||
end |
end |
||
end |
end |
||
Linia 42: | Linia 84: | ||
-- Ustawiamy właściwości semantyczne |
-- Ustawiamy właściwości semantyczne |
||
mw.smw.set( { |
|||
if #arts > 0 then |
|||
['Zawiera artykuł'] = pages, |
|||
mw.smw.set( { |
|||
['Zawiera kategorię'] = categories, |
|||
} ) |
|||
end |
|||
end |
end |
||
function p. |
function p.generate(frame) |
||
local args = tools.getArgs(frame) |
local args = tools.getArgs(frame) |
||
findRelevantPages(args) |
findRelevantPages(args) |
||
local ilstack, irstack = {}, {} |
|||
local lstack, rstack = {}, {} |
local lstack, rstack = {}, {} |
||
local curSpecial = 0 |
|||
local function subpanel(num) |
local function subpanel(num) |
||
if args['panel' .. num] == '-' or args['panel' .. num] == '' then |
|||
return |
|||
end |
|||
if num % 2 == 1 then |
if num % 2 == 1 then |
||
local panelInfo = makeInfoSet(args, num) |
|||
table.insert(ilstack, panelInfo) |
|||
curSpecial = 0 |
|||
else |
else |
||
local lpanelInfo = makeInfoSet(args, num, "mobileonly") |
|||
local rpanelInfo = makeInfoSet(args, num, "desktoponly") |
|||
table.insert(ilstack, lpanelInfo) |
|||
table.insert(irstack, rpanelInfo) |
|||
curSpecial = curSpecial + 1 |
|||
end |
|||
end |
|||
local function execute() |
|||
if curSpecial > 0 then |
|||
local maxLeft = table.maxn(ilstack) |
|||
local maxRight = table.maxn(irstack) |
|||
for i = 0, (curSpecial - 1) do |
|||
table.remove(ilstack, maxLeft - i) |
|||
irstack[maxRight-i].showstatus.desktoponly = false |
|||
end |
|||
end |
|||
for i, v in ipairs(ilstack) do |
|||
makePanel(v, lstack) |
|||
end |
|||
for i, v in ipairs(irstack) do |
|||
makePanel(v, rstack) |
|||
end |
end |
||
end |
end |
||
Linia 67: | Linia 139: | ||
else break end |
else break end |
||
end |
end |
||
execute() |
|||
lstack = table.concat(lstack, '\n') |
lstack = table.concat(lstack, '\n') |
||
rstack = table.concat(rstack, '\n') |
rstack = table.concat(rstack, '\n') |
||
local |
local column = '<div class="portal-kolumna portal-kolumna-' |
||
return '< |
return '<div class="portal-main-content">' .. column .. 'left">' .. lstack .. '</div>' .. |
||
column .. 'right">' .. rstack .. '</div></div>' |
|||
end |
|||
function p.mobile(frame) |
|||
local args = tools.getArgs(frame) |
|||
findRelevantPages(args) |
|||
local stack = {} |
|||
for i = 1, 50 do |
|||
if args['panel' .. i] ~= nil then makePanel(args, stack, i) |
|||
else break end |
|||
end |
|||
return table.concat(stack, '\n') |
|||
end |
end |
||
Aktualna wersja na dzień 03:04, 3 kwi 2022
local tools = require('Moduł:Narzędzia')
local p = {}
local function makeShowStatus(text_or_nil)
local text = text_or_nil or ''
local showstatus = {mobileonly=false, desktoponly=false}
if text == "mobileonly" then
showstatus.mobileonly = true
elseif text == "desktoponly" then
showstatus.desktoponly = true
end
showstatus.tostring = function()
local final = ""
if showstatus.mobileonly then final = final .. "mobileonly" end
if showstatus.desktoponly then final = final .. " desktoponly" end
final = mw.text.trim(final)
return final
end
return showstatus
end
local function makeInfoSet(args, num, showstatus_maybe_nil)
local showstatus = makeShowStatus(showstatus_maybe_nil)
local infoSet = {color="#c7c7c7", text="", title="", showstatus=showstatus}
infoSet.text = args['panel' .. num] or ''
infoSet.title = args['ptytuł' .. num] or ''
if args.kolor ~= nil then
infoSet.color = args.kolor
end
return infoSet
end
local function makePanel(infoSet, stack)
local panelDiv = mw.html.create( 'div' )
local h2 = mw.html.create( 'h2' )
h2:css('border-bottom', '2px solid' .. infoSet.color .. '!important')
:addClass("portal-panel-header")
:wikitext(infoSet.title)
panelDiv:addClass("portal-panel")
:addClass(infoSet.showstatus.tostring())
:wikitext(tostring(h2) .. '<div class="portal-panel-content">\n' .. infoSet.text .. '\n</div>')
table.insert(stack, tostring(panelDiv))
end
-- Znajduje zbiór stron "należących" do portalu i dodaje odpowiednie
-- właściwości semantyczne do śledzenia tego.
local function findRelevantPages(args)
local pages = {}
local categories = {}
-- Artykuły podane explicite
local arts = mw.text.split( args['artykuły'] or '', '#', true )
for _, art in ipairs(arts) do
local art2 = mw.text.trim(art)
if art2 ~= '' then
table.insert(pages, mw.text.trim(art))
end
end
-- Wyszukiwanie wg kategorii
if args['kategorie'] then
local res = mw.smw.getQueryResult{
args['kategorie'] .. ' [[Modification date::+]]',
limit=1000 -- większych portali raczej nie powinno być
}
for _, r in ipairs(res.results or {}) do
if r.exists == '1' then
table.insert(pages, r.fulltext)
end
end
-- znajdź w warunkach wyszukiwania kategorie nadrzędne
for m in mw.ustring.gmatch(args['kategorie'], '%[%[[^%]]+%]%]') do
local cond = mw.text.trim(mw.ustring.sub(m, 3, -3))
if mw.ustring.find(mw.ustring.lower(cond), 'kategoria:') == 1 or
mw.ustring.find(mw.ustring.lower(cond), 'category:') == 1 then
cond = mw.ustring.sub(cond, mw.ustring.find(cond, ':', 1, true) + 1)
for _, cat in ipairs(mw.text.split(cond, '||', true)) do
table.insert(categories, 'Kategoria:' .. mw.text.trim(cat))
end
end
end
end
-- Ustawiamy właściwości semantyczne
mw.smw.set( {
['Zawiera artykuł'] = pages,
['Zawiera kategorię'] = categories,
} )
end
function p.generate(frame)
local args = tools.getArgs(frame)
findRelevantPages(args)
local ilstack, irstack = {}, {}
local lstack, rstack = {}, {}
local curSpecial = 0
local function subpanel(num)
if args['panel' .. num] == '-' or args['panel' .. num] == '' then
return
end
if num % 2 == 1 then
local panelInfo = makeInfoSet(args, num)
table.insert(ilstack, panelInfo)
curSpecial = 0
else
local lpanelInfo = makeInfoSet(args, num, "mobileonly")
local rpanelInfo = makeInfoSet(args, num, "desktoponly")
table.insert(ilstack, lpanelInfo)
table.insert(irstack, rpanelInfo)
curSpecial = curSpecial + 1
end
end
local function execute()
if curSpecial > 0 then
local maxLeft = table.maxn(ilstack)
local maxRight = table.maxn(irstack)
for i = 0, (curSpecial - 1) do
table.remove(ilstack, maxLeft - i)
irstack[maxRight-i].showstatus.desktoponly = false
end
end
for i, v in ipairs(ilstack) do
makePanel(v, lstack)
end
for i, v in ipairs(irstack) do
makePanel(v, rstack)
end
end
for i = 1, 50 do
if args['panel' .. i] ~= nil then subpanel(i)
else break end
end
execute()
lstack = table.concat(lstack, '\n')
rstack = table.concat(rstack, '\n')
local column = '<div class="portal-kolumna portal-kolumna-'
return '<div class="portal-main-content">' .. column .. 'left">' .. lstack .. '</div>' ..
column .. 'right">' .. rstack .. '</div></div>'
end
return p