Modulo:Sandbox/Statistiche discussione

Da Wikipedia, l'enciclopedia libera.
Vai alla navigazione Vai alla ricerca
---
-- This Lua module is designed to extract some information about a talk page
--
-- This is just a stub
--

-- create a Lua "package"
local p = {}

---
-- Get the content of whatever page (if possible)
--
-- This method is intended to be called from Lua
-- and not from wikitext.
--
-- @param pageTitle Complete page title
-- @return Page content or nil if nothing can be returned
--
function p._content( pageTitle )

	local title = mw.title.new( pageTitle )
	if not title then
		error( "this page title is not valid: " .. pageTitle )
	end

	local content = title:getContent()

	return content
end

---
-- Try to parse all the user firms from a wikitext
--
-- The returned object is a table containing these information:
--   {
--     wikitext = "Raw text of the line"
--     name = "User name"
--     date = "2020-10-10 00:00:01 UTC+2"
--   }
-- @param content Some wikitext
-- @return Table of information about firms 
function p._parseFirms( content )

	local firms = {}

	local FIRM_PATTERN = '%[%[Utente:([a-zA-Z])|'

	local firm, date
	for line in mw.text.gsplit( content, "[\n\r]+" ) do

		firm = mw.ustring.match( s, FIRM_PATTERN )

		if firm then

			firms[ #firms +1 ] = {
				wikitext = line,
				firm     = firm,
				date     = date
			
			}

		end
	end

	return firms
end

-- make the package available
return p