Модуль:Gar-doc

Материал из Справочника наблюдателя
Перейти к:навигация, поиск

(i)      Описание модуля[]

Документация отсутствует!


local p = {}

local global = mw.ext.luaglobal

function p.list( frame )
	local pages = mw.text.trim( frame.args[1] )
	if pages == '-'  or pages == '' then
		global.set( 'garComment', {} )
		return
	end
	pages = string.match( pages, '^[%s\n%*]*(.+)$')
	local ll = mw.text.split( pages, ' *\n[%* ]*' )
	local title = 'К:' .. mw.title.getCurrentTitle().text

	local titlen = string.len( title ) + 1
	local garComment = {}
	for _, subp in ipairs( ll ) do
		if string.sub( subp, titlen, titlen ) == '/' then
			garComment[string.sub( subp, titlen+1, -1 )] = true
		end
	end
	global.set( 'garComment', garComment )
end

function p.check( frame )
	local u = mw.text.trim( frame.args[1] )
	u = tonumber(u) or u
	local garComment = global.get( 'garComment' ) or {}
--	mw.logObject( garComment )
	if garComment[u] == true then
		global.add( 'garCommentUsed', u )
		return 'yes'
	end
	return 'no'
end

function p.left( frame )
	local garComment = global.get( 'garComment' )
	local garCommentUsed = global.get ( 'garCommentUsed' ) or {}
	for _, u in ipairs( garCommentUsed ) do
		garComment[u] = nil
	end
	local ux = {}
	for u, _ in pairs( garComment ) do
		table.insert( ux, '[[К:' .. mw.title.getCurrentTitle().text .. '/' .. u .. '|' .. u .. ']]' )
	end
	if #ux ~= 0 then
		return '<p class=error>Лишние комментарии: ' .. table.concat( ux, ', ' ) .. '</p>'
	end
end

return p