Moduł zawiera zestaw funkcji związanych z obsługą strony głównej.

Funkcja Przeznaczenie Zapis Opis parametrów
najnowsze Zestawia wycinki artykułów do umieszczenia na stronie głównej {{#invoke:Strona główna|najnowsze|limit=limit}}
  1. limit - liczba artykułów do wyświetlenia

Funkcje

najnowsze

Parametry
  1. limit (nazwany)
Działanie

Funkcja pobiera co najwyżej limit wycinków artykułów ze stron postaci Szablon:Strona główna/Artykuł # i wstawia je w kod HTML używany do wyświetlenia ich na stronie głównej w układzie dwukolumnowym. Jeżeli {{Wiadomość specjalna}} ma jąkąś zawartość, jest ona wstawiana do głównego pola na stronie.

Jeśli parametr limit ma wartość większą niż liczba istniejących szablonów z wycinkami, wyświetlone zostaną tylko te istniejące.


local p = {}

function p.najnowsze(frame)
	local limit = tonumber(frame.args.limit) or 5
	local specialNews = frame:expandTemplate{ title='Wiadomość specjalna', args={ ['duży']='tak' } }
	local nextArticle = 1
	local nameTemplate = 'Strona główna/Artykuł '
	
	local excerpts = {}
	if specialNews ~= '' then
		table.insert(excerpts, specialNews)
		limit = limit - 1
	else
		local article1 = frame:expandTemplate{ title=nameTemplate..'1', args={ ['duży']='tak' } }
		table.insert(excerpts, article1)
		nextArticle = 2
	end

	for i = nextArticle, limit do
		local title = mw.title.makeTitle('Szablon', nameTemplate..i)
		if not title.exists then
			break
		end
		
		local articleN = frame:expandTemplate{ title=nameTemplate..i }
		table.insert(excerpts, articleN)
	end
	
	
	local out = {}
	table.insert(out, '<div class="featured">')
	table.insert(out, excerpts[1])
	table.insert(out, '</div>')
	
	table.insert(out, '<div class="recent"><div class="column">')
	local colBreak = math.ceil(#excerpts / 2)
	for i = 2, #excerpts do
		table.insert(out, '<div class="article-box">')
		table.insert(out, excerpts[i])
		table.insert(out, '</div>')
		
		if i == colBreak then
			table.insert(out, '</div><div class="column">')
		end
	end
	table.insert(out, '</div></div>')
	
	return table.concat(out)
end

return p