Модуль:FormationsList

Материал из Википедии — свободной энциклопедии
Перейти к навигации Перейти к поиску
Документация
local getArgs = require('Module:Arguments').getArgs
local F={}

function F.Formations(frame)
	local args=getArgs(frame);
	local dis=args[1] or mw.title.getCurrentTitle().fullText;
	local flist={};
	local s='';
	local o=mw.title.new(dis,'');
	if (o) then
		local page = o:getContent();
		if (page) then
			local start=mw.ustring.find(page,'\n*',0,true);
			if (start) then
				local i=1;
				repeat
					local ends=mw.ustring.find(page,'\n',start+1,true);
					if (not ends) then
						ends=#page+1;	-- last string
					end
					flist[i]=mw.text.trim(mw.ustring.sub(page,start+2,ends-1));
					start=ends;
					i=i+1;
					local char=mw.ustring.sub(page,start+1,start+1);
				until char~='*'
			end
		end
	end
	local fcount=#flist;
	if (fcount == 0) then
		fcount=tonumber(args[2]) or 0;
	end
	local femlist={'армия','дивизия','бригада','эскадрилья'};
	local fgen='формировался';
	for i=1,#femlist do
		if mw.ustring.find(dis,femlist[i]) then
			fgen='формировалась';
			break
		end
	end
	local fnum;
	if ((fcount>1) and (fcount<5)) then
		fnum='раза';
	else
		fnum='раз';
	end
	return mw.ustring.format("Всего %s %s %i %s. См. [[%s|список других формирований]]",dis,fgen,fcount,fnum,dis);
end

return F