Module:MediawikiVersion

Documentation du module [voir] [modifier] [purger]
La documentation de ce module Scribunto écrit en Lua est incluse depuis sa sous-page de documentation.

Test of MediawikiVersion docs modifier

Test result of MediawikiVersion and datas.get_datas(args_known, QITEM) modifier

{{#invoke:MediawikiVersion|read}} 1.43.0-wmf.2 (ce9d259)

local p = {} -- Test of Mediawiki_version

datas = {}			-- "The Library:datas form some viewers for tables(in lines and columns), dropboxes, luatables..."
lua_table = {}		-- "The Library:lua_table enhances previous table library, to avoid ambiguities. To enhance, we could write here : lua_table = table."

local central_libraries = { -- New libraries to record in package.loaded[]
	{ "activity",	"The Library:activity supports the management of Lua coders sub-tasks and inter-wikis central modules.", },
	{ "datas",		"The Library:datas form some viewers for tables(in lines and columns), dropboxes, luatables...", },
	{ "events",		"The Library:events form events like erros, warnings and categories.", },
	{ "langs",		"The Library:langs supports i18n translations.", },
	{ "lua_table",	"The Library:lua_table enhances previous table library, to avoid ambiguities. To enhance, we could write here : lua_table = table.", },
	{ "mathroman",	"The Library:mathroman convert roman numbers and detect errors. It is here as an example of very small central library.", },
	{ "modes",		"The Library:modes support modes and their options, like p.read(frame).", },
	{ "testsgrp",	"The Library:testsgrp, initialises, runs and forms groups of tests for Mediawiki and users.", },
	{ "viewer",		"The Library:viewer form tableviews as objects inside the Library:viewer", },
	{ "versn",		"The Library:versn installs all central libraries, modules and their i18n translations. It also support versions management.", },
	-- Objects have a function object.new() to form several objects.
	{ "args",		"The Object:args form known arguments to import, complete from datas and finalize.", },
	{ "boxview",	"The Object:boxview, in the Library:viewer, forms boxes, their styles and structures.", },
	{ "dropbox",	"The Object:dropbox, in the Library:viewer, forms dropboxes and their styles.", },
	{ "centrobj",	"The Object:centrobj, in the Library:versn, forms the basis of libraries and their properties.", },
	{ "tableview",	"The Object:tableview, in the Library:viewer, forms some viewers for tables, in lines and columns.", },
	{ "tracker",	"The Object:tracker, in the Library:activity, forms parametrables tracks to help to debug the code.", },
}


function Mediawiki_version() -- Form Mediawiki_version, in error color if it changes.
	local currentVersion = tostring(mw.site.currentVersion)
	return currentVersion
end -- function versn.Mediawiki_version()

function datas.get_datas(args_known, QITEM) -- Get datas from modes.args_known and add wikibase datas for the page.
--	See: https://www.mediawiki.org/wiki/Mw.wikibase.entity.lua_bug_fix_instructions
--	See: https://www.mediawiki.org/wiki/Extension:Wikibase_Client/Lua#mw.wikibase.entity:getDescription
	datas.tv(1760, "P569", "Track the property 'P569' in datas.get_datas: ", val)
	local args_known = args_known or modes.args_known or p.args_known or {} -- optional value from p.args_known = {		}
	datas.prop = datas.prop or {}
--	if not datas.item then datas.item = mw.wikibase.getEntity() end
	local item = mw.wikibase.getEntity()
--	datas.prop.Label = item:getLabel()
	local Title = "Christophe Colomb" -- Christophe Colomb (Q7322)
	local mwuri = mw.uri.new() --	Server mw.uri.new for path like = /wiki/Utilisateur:Rical/Nelson_Mandela
	local Title, sub_parts = "title", mw.text.split(mwuri.path, '/') -- table of words
	for k, part in pairs(sub_parts) do Title = part end
	datas.track_val = datas.track_val .. "\n* 45: get_datas begin Title=" .. Title .. ": #args_known=" .. lua_table.level_count(args_known)
--	Victor Hugo (Q535), Aristote (Q868), Albert Einstein (Q937), Mohandas Karamchand Gandhi (Q1001), Christophe Colomb (Q7322),
--	Nelson Mandela (Q8023), Rudyard Kipling (Q34743), Martin Fleischmann (Q899264), Emmanuel Macron (Q3052772)
	local QITEM, Title, Label, prop, lang, description = QITEM, Title, Label, prop, lang, description
	datas.prop.QITEM = QITEM
	datas.track_val = datas.track_val .. "\n* 50: get_datas begin val=" .. (val or "var") .. ": #args_known=" .. lua_table.level_count(args_known)
	for key, args_opt in pairs(args_known) do -- from p.args_known = { }
		local val, snaks = nil
	--	if type(item) ~= "table" then val = nil end
		local prop = args_opt["prop"] -- Get the value of the sought property, or nil
		local statements = item:getBestStatements(prop)
		datas.track_val = datas.track_val .. "\n* 56: get_datas local statements=" .. statements
		if statements[1] and statements[1].mainsnak.datavalue then
			val = statements[1].mainsnak.datavalue.value
			datas.track_val = datas.track_val .. "\n* 59: get_datas statements[1].mainsnak.datavalue.value=" .. val
		end
		if statements[1].mainsnak.type == 'value' then
			local Id = statements[1].mainsnak.datavalue.value.id
			Id = mw.wikibase.label(Id) or ''
	--		datas.tv(1830, prop, "get_datas label(Id)=", Id)
			--TODO check if the first name is not an initial
		elseif statements[1].mainsnak.type == 'somevalue' then
			local no_prenom = "unknown"
	--		datas.tv(1834, prop, "get_datas mainsnak.type(no_prenom)=", no_prenom)
		end
	--	datas.tv(1836, "P569", "get_datas near end knowns val=", val)
	--	DAT.add(DAT, 1, "get_datas statements near end knowns", { ["QITEM"] = tostring(QITEM), ["prop"] = prop, ["lang"] = lang, ["val"] = val, } )
	--	datas.tv(1838, "P569", args_opt.prop, "end for args_opt.prop", args_opt.prop)
	--	DAT.add(DAT, 1, "some props", { ["QITEM"] = tostring(QITEM), ["prop"] = tostring(prop), ["val"] = args_opt.val or "val1", ["lang"] = args_opt.lang or "lang", } )
		--[[
		if tonumber(args_opt.val) and (args_opt.format == "year") then -- for year
			val = string.sub( ("0000" .. tostring(args_opt.val) ), -4, -1) end -- last 4 chars begining with zero chars
		if tonumber(args_opt.val) and (args_opt.format == "month") then -- for month
			val = string.sub( ("0000" .. tostring(args_opt.val) ), -6, -5) end -- last 4 chars begining with zero chars
		if tonumber(args_opt.val) and (args_opt.format == "day") then -- for day
			val = string.sub( ("0000" .. tostring(args_opt.val) ), -8, -7) end -- last 4 chars begining with zero chars
		datas.prop[key] = args_opt["val"] or args_opt["keyword"] -- insert
		--]]
		if prop == "description" then
	--		datas.tv(1851, "P569", "get_datas if prop==description", val)
	--		DAT.add(DAT, 1, "prop==description", { ["prop"] = tostring(prop), ["val"] = val or "val", ["description"] = description, } )
		end
		if (prop == "Title") or (prop == "description") or (prop == "P569") or (prop == "P570") or (prop == "Q16222597") or (prop == "P18") then
		-- birthyear=P569-format=year; deathyear=P570-format=year; QITEM=Q16222597; image=P18; QITEM=Q16222597; -- 6 lines
	--		datas.tv(1856, "P569", "if prop in list", prop)
	--		DAT.add(DAT, 1, "some props", { ["QITEM"] = tostring(QITEM), ["prop"] = tostring(prop), ["val"] = val, ["lang"] = args_opt.lang or "lang", } )
		end
	--	["deathyear"]		= {typ = "dat", need = 0, keyword = "deathyear", prop = "P570", format = "year"},
	--	["description"]		= {typ = "dat", need = 0, keyword = "description", prop = "description"},
	end
	-- use some datas
--	datas.prop.QITEM = QITEM or "Q868" -- Aristote (Q868)
--	args_known.QITEM = { ["typ"] = "dat", ["need"] = 2, ["keyword"] = "QITEM", ["prop"] = "QITEM", ["val"] = datas.prop.QITEM, } -- Albert Einstein (Q937)
--	datas.prop.description = description or "phylosophe grec" -- Aristote (Q868)
--	args_known.description	= { ["typ"] = "dat", ["need"] = 2, ["keyword"] = "description", ["val"] = datas.prop.description, ["prop"] = "description", }
	if not datas.prop.Label then datas.prop.Label = "getLabel()" end
	if not datas.prop.Label then datas.prop.Label = "Label" end
	if not datas.prop.Title then datas.prop.Title = "Title" end
	if not (datas.prop.QITEM and datas.prop.Title and datas.prop.Label) then
	datas.prop = { 
		 ["QITEM"]		= datas.prot("Q16222597"), ["Q16222597"] = datas.prot("Q16222597"), -- Q16222597
		 ["Label"]		= datas.prot("Label"), ["label"] = datas.prot("label"),
		 ["Title"]		= datas.prot("Title"), ["title"] = datas.prot("title"),
		 ["sitelink"]	= datas.prot("sitelink"),
		 ["description"]= datas.prot("description"),
		 ["image"]		= datas.prot("P18"), ["P18"] = datas.prot("P18"), -- image
		 ["sex"]		= datas.prot("P21"), ["P21"] = datas.prot("P21"), -- sex
		 ["country"]	= datas.prot("P27"), ["P27"] = datas.prot("P27"), -- country
		 ["birthyear"]	= datas.prot("P569"), ["P569"] = datas.prot("P569"), -- birthyear
		 ["deathyear"]	= datas.prot("P570"), ["P570"] = datas.prot("P570"), -- deathyear
		 ["firstname"]	= datas.prot("P734"), ["P734"] = datas.prot("P734"), -- firstname
		 ["lastname"]	= datas.prot("P735"), ["P735"] = datas.prot("P735"), -- lastname
	}
	end
	datas.prop.Title = datas.prop.Title or "Title"
	if not datas.prop.description then datas.prop.description = "description" end
	if not datas.prop.P569 then datas.prop.P569 = "P569" end
	if not datas.prop.P570 then datas.prop.Title = "P570" end
	if not datas.prop.Title then datas.prop.Title = "Title" end
	if not datas.prop.Title then datas.prop.Title = "Title" end
	if not datas.prop.Title then datas.prop.Title = "Title" end
	datas.track_val = datas.track_val .. "\n* 126: datas.get_datas end 1 #datas.prop=" .. lua_table.level_count(datas.prop)
	datas.track_val = datas.track_val .. "\n* 127: datas.prop.QITEM=" .. lua_table.level_count(datas.prop)
	--[[
	datas.prop_trk = (datas.prop_trk or "") .. viewer.ta("datas.prop.QITEM", datas.prot("QITEM") )
	datas.prop_trk = (datas.prop_trk or "") .. viewer.ta("datas.prop.Title", datas.prot("Title") )
	datas.prop_trk = (datas.prop_trk or "") .. viewer.ta("datas.prop.Label", datas.prot("label") )
	datas.prop_trk = (datas.prop_trk or "") .. viewer.ta("datas.prop.description", datas.prot("description") )
	datas.prop_trk = (datas.prop_trk or "") .. "\n* datas.get_datasend 2 = " .. viewer.ta("#datas.prop", lua_table.level_count(datas.prop) )
	datas.prop_trk = (datas.prop_trk or "") .. "\n* datas.track_val = " .. datas.tv(1820, "P569", "get_datas return", val)
	datas.prop_trk = (datas.prop_trk or "") .. "\n* datas.track_val = " .. datas.tv(1821, "P569", "get_datas return datas.prop.P569", datas.prop.P569)
	--]]
	return datas.prop
end -- datas.prop = datas.get_datas(args_known, QITEM) -- Get datas from modes.args_known and add wikibase datas for the page.

function datas.tv(line, prop, what, val) -- track a property in datas.get_datas
	datas.track_val = datas.track_val or "" -- birthyear=P569
	if prop == "P569" then
		local line = "L" .. tostring(line)
		local prop = tostring(prop)
		local what = tostring(what)
		local val = tostring(val)
		datas.track_val = datas.track_val .. "\n*  line=" .. line .. ": prop=" .. prop .. " what=" .. what .. " val=" .. val
	end
	return datas.track_val
end -- datas.track_val = datas.tv(line, prop, what, val)

function lua_table.level_count(tab) -- Count all objects in the table, or 0 if tab is not a table.
	local count = 0
	if (type(tab) ~= "table") then return count end
	for k,v in pairs(tab) do
		count = count + 1
	end
	return count
end -- c = lua_table.level_count(tab)

function datas.prot(prop)
	datas.prop = datas.prop or {}
	local prop = prop
	if type(prop) ~= "string"then prop = "prop" end
	local t = prop
	if type(prop) == "string" and not string.find(prop, "%s", 1, true) then t = datas.prop[prop] or prop end
	return t
end

function p.read(frame) -- The read mode generates the normal result for read only users.
	local res = ""
	res = res .. "<b>" .. Mediawiki_version() .. "</b>"
	return res
end -- Get Mediawiki_version

return p

--	Usual pages for Translations (for easier select the test page when edit this module in other wikis)
--	Modulenn:Central-s-br/doc				{{#invoke:Central-s-br|read}}	br = Breton = Brezhoneg
--	Modul:Central-s-de/Doku					{{#invoke:Central-s-de|read}}	de = German = Deutsch
--	Module:Central-s-en/Documentation		{{#invoke:Central-s-en|read}}	en = English = English
--	Module:Central-s-es/Documentación		{{#invoke:Central-s-es|read}}	es = Spanish = español
--	Modul:Central-w-hu/doc					{{#invoke:Central-w-hu|read}}	hu = Hungarian = Magyar
--	Module:Central-mw-en/doc				{{#invoke:Central-mw-en|read}}	en = English = English
--	Mô đun:Central-w-vi/tài liệu			{{#invoke:Central-w-vi|read}}	vi = Vietnamese = Tiếng việt
--	MediaWiki:Scribunto/Central modules reference manual
--	Utilisateur:Rical/Victor Hugo (Q535)	-- content Module:Author3
--	Utilisateur:Rical/Nelson Mandela (Q8023)-- content Module:Central-s-fr/Documentation
--	Module:Central-s-fr/Documentation		{{#invoke:Central-s-fr|read}}	fr = French = Français proto

--	Utilisateur:Rical/MediawikiVersion		-- Module to test, last change : 2018-01-12 à 20:58:47
--	Module:MediawikiVersion					-- Module to test, last change : 2018-01-12 à 20:58:47
--	Utilisateur:Rical/Try					-- For some tests
--	Module:Tests							-- Module for some tests, last change : 2018-01-12 à 20:58:47