Moduł:Stopka portal: Różnice pomiędzy wersjami

Z Nonsensopedii, polskiej encyklopedii humoru
M (alfabetyzm)
M (no to musi walnąć)
Linia 43: Linia 43:
end
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 52: Linia 74:
for _, r in ipairs(res.results) do
for _, r in ipairs(res.results) do
local name = mw.ustring.gsub(r.fulltext, 'Portal:', '')
text = text .. makePortalItem(mw.ustring.gsub(r.fulltext, 'Portal:', ''))
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()
text = text .. tostring(div)
end
end
end
return text
return text
end

-- for {{KatStopka}}
function p.getKatText(frame, args)
local i = 1
while args[tostring(i)] do
makePortalItem(args[tostring(i)])
i = i + 1
end
end
end



Wersja z 21:18, 30 mar 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]]'''."
		}
	},
	['Informatyka'] = {
		letter = '',  -- Tux ;)
	 	color = '#235bc1',
		text = {
			"Zobacz więcej artykułów w '''[[Portal:Informatyka|portalu o informatyce]]'''."
		}
	},
	['Polityka'] = {
		letter = 'P',
	 	color = '#090082',
		text = {
			"Zobacz więcej artykułów w '''[[Portal:Polityka|portalu o 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 {{KatStopka}}
function p.getKatText(frame, args)
	local i = 1
	while args[tostring(i)] do
		makePortalItem(args[tostring(i)])
		i = i + 1
	end
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