Modulo:BeginEndPage: differenze tra le versioni

Da Wikitrek.
Vai alla navigazione Vai alla ricerca
mNessun oggetto della modifica
Nessun oggetto della modifica
 
(10 versioni intermedie di uno stesso utente non sono mostrate)
Riga 23: Riga 23:
function p.buildUniversalIncipit(frame)
function p.buildUniversalIncipit(frame)
local args = frame:getParent().args
local args = frame:getParent().args
return p._main(args)
return p._buildUniversalIncipit(args)
end
end


Riga 47: Riga 47:
return ret
return ret
end
end
--------------------------------------------------------------------------------
-- Build and return the list of shortcodes for series, season and episode
--
-- @param {Frame} Info from MW session
-- @return {string} The full incipit wikitext
--------------------------------------------------------------------------------
function p.BuildShortCode(frame)
local args = frame:getParent().args
return p._BuildShortCode(args)
end
--------------------------------------------------------------------------------
-- Build and return the list of shortcodes for series, season and episode
--
-- @param {Frame} Info from MW session
-- @return {string} The full incipit wikitext
--------------------------------------------------------------------------------
function p.ShortCodeFromProdNo(frame)
local ProdNo = frame.args[1]
p._BuildShortCode("", tonumber(string.sub(ProdNo, 1, 1)), tonumber(string.sub(ProdNo, 2)))
end
--------------------------------------------------------------------------------
-- Gets episode's data from DataTrek and passes them
--
-- @param {Frame} Info from MW session
--------------------------------------------------------------------------------
function p.ShortCodeFromDT(frame)
local CurrentEntity = mw.wikibase.getEntity()
local Acronym
local Season
local Episode
if CurrentEntity.claims['P18'] == nil then
return ""
else
Acronym = PropertiesOnTree("P25", 3, false, false, true) or "Err"
Season = tonumber(CurrentEntity.claims['P18'][1].mainsnak.datavalue.value['amount'])
Episode = tonumber(CurrentEntity.claims['P178'][1].mainsnak.datavalue.value['amount'])
return p._BuildShortCode(Acronym, Season, Episode)
end
end
--------------------------------------------------------------------------------
-- Set the Semantic property related to episode shortcodes for
-- series, season and episode
--
-- @param {Series} Acronym of the series' name
-- @param {Season} Ordinal of the season
-- @param {Season} Ordinal of the episode in the season
--------------------------------------------------------------------------------
function p._BuildShortCode(Series, Season, Episode)
--local Templates = {"S0.E00", " s00e00", "s00e000"}
local Templates = {"%dx%02d", "S%d.E%02d", " s%02de%02d", "s%02de%03d"}
if Season < 1 or Season > 99 then
Season = 0
end
if Episode < 1 or Episode > 99 then
Episode = 0
end
Series = string.upper(string.sub(Series, 1, 3))
for _, Template in pairs(Templates) do
mw.smw.set("Codice breve=" .. Series .. " " .. string.format(Template, Season, Episode))
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Function to launch template for DataBoxes
-- Function to launch template for DataBoxes
Riga 63: Riga 141:
--FinalString = string.sub(PropertiesOnTree("P177", 3, false, false, true), string.len(NSPrefix))
--FinalString = string.sub(PropertiesOnTree("P177", 3, false, false, true), string.len(NSPrefix))
TemplateName = PropertiesOnTree(PropertyNumber, 3, false, false, true)
TemplateName = PropertiesOnTree(PropertyNumber, 3, false, false, true)
if PropertiesOnTree(PropertyNumber, 3, false, false, true) == nil or PropertiesOnTree(PropertyNumber, 3, false, false, true) == "" then
if type(TemplateName) == "table" or TemplateName == nil or TemplateName == "" then
FinalString = PropertiesOnTree(PropertyNumber, 3, false, false, true)[1]
FinalString = ""
else
else
--FinalString = frame:expandTemplate{title = string.sub(TemplateName, string.len(NSPrefix) + 1)}
FinalString = frame:expandTemplate{title = string.sub(TemplateName, string.len(NSPrefix) + 1)}
FinalString =  PropertiesOnTree(PropertyNumber, 3, false, false, true)[1]
end
end

Versione attuale delle 23:41, 12 gen 2024

Page layout

Page layout for reference purpose.
-- <nowiki>
--------------------------------------------------------------------------------
-- This module handles incipit and epilogue of pages.
-- Comments are compatible with LDoc https://github.com/lunarmodules/ldoc
--
-- @module p
-- @author Luca Mauri [[Utente:Lucamauri]]
-- @keyword: wikitrek
-- Keyword: wikitrek
--------------------------------------------------------------------------------

local PropertiesOnTree = require('Modulo:DTFunzioniComuni').PropertiesOnTree

local p = {}

--------------------------------------------------------------------------------
-- Take parameters out of the frame and pass them to p._buildUniversalIncipit().
-- Return the result.
--
-- @param {Frame} Info from MW session
-- @return {string} The full incipit wikitext
--------------------------------------------------------------------------------
function p.buildUniversalIncipit(frame)
	local args = frame:getParent().args
	return p._buildUniversalIncipit(args)
end

--------------------------------------------------------------------------------
-- Build and return the page incipit wikitext.
--
-- @param {Frame} Info from MW session
-- @return {string} The full incipit wikitext
--------------------------------------------------------------------------------
function p._buildUniversalIncipit(args)
	local ret = {}
	local fullUrl = mw.uri.fullUrl
	local format = string.format
	for i, username in ipairs(args) do
		local url = fullUrl(mw.site.namespaces.User.name .. ':' .. username)
		url = tostring(url)
		local label = args['label' .. tostring(i)]
		url = format('[%s %s]', url, label or username)
		ret[#ret + 1] = url
	end
	ret = mw.text.listToText(ret)
	ret = '<span class="plainlinks">' .. ret .. '</span>'
	return ret
end

--------------------------------------------------------------------------------
-- Build and return the list of shortcodes for series, season and episode
--
-- @param {Frame} Info from MW session
-- @return {string} The full incipit wikitext
--------------------------------------------------------------------------------
function p.BuildShortCode(frame)
	local args = frame:getParent().args
	return p._BuildShortCode(args)
end

--------------------------------------------------------------------------------
-- Build and return the list of shortcodes for series, season and episode
--
-- @param {Frame} Info from MW session
-- @return {string} The full incipit wikitext
--------------------------------------------------------------------------------
function p.ShortCodeFromProdNo(frame)
	local ProdNo = frame.args[1]
	
	p._BuildShortCode("", tonumber(string.sub(ProdNo, 1, 1)), tonumber(string.sub(ProdNo, 2)))
end

--------------------------------------------------------------------------------
-- Gets episode's data from DataTrek and passes them
--
-- @param {Frame} Info from MW session
--------------------------------------------------------------------------------
function p.ShortCodeFromDT(frame)
	local CurrentEntity = mw.wikibase.getEntity()
	local Acronym
	local Season
	local Episode
	
	if CurrentEntity.claims['P18'] == nil then
		return ""
	else
		Acronym = PropertiesOnTree("P25", 3, false, false, true) or "Err"
		Season = tonumber(CurrentEntity.claims['P18'][1].mainsnak.datavalue.value['amount'])
		Episode = tonumber(CurrentEntity.claims['P178'][1].mainsnak.datavalue.value['amount'])
		return p._BuildShortCode(Acronym, Season, Episode)
	end
end

--------------------------------------------------------------------------------
-- Set the Semantic property related to episode shortcodes for
-- series, season and episode
--
-- @param {Series} Acronym of the series' name
-- @param {Season} Ordinal of the season
-- @param {Season} Ordinal of the episode in the season
--------------------------------------------------------------------------------
function p._BuildShortCode(Series, Season, Episode)
	--local Templates = {"S0.E00", " s00e00", "s00e000"}
	local Templates = {"%dx%02d", "S%d.E%02d", " s%02de%02d", "s%02de%03d"}
	
	if Season < 1 or Season > 99 then
		Season = 0
	end
	if Episode < 1 or Episode > 99 then
		Episode = 0
	end
	Series = string.upper(string.sub(Series, 1, 3))
	
	for _, Template in pairs(Templates) do
		mw.smw.set("Codice breve=" .. Series .. " " .. string.format(Template, Season, Episode)) 
	end
end









--------------------------------------------------------------------------------
-- Function to launch template for DataBoxes
-- Specific for Template:IncipitUniversale
--
-- @param frame Data from MW session
-- @return String with expanded templates
--------------------------------------------------------------------------------
function p.SecondaryBox(frame)
	local FinalString
	local NSPrefix = "Template:"
	local PropertyNumber = "P177"
	local TemplateName
	
	--FinalString = PropertiesOnTree("P177", 3, false, false, true)[1]
	--FinalString = string.sub(PropertiesOnTree("P177", 3, false, false, true), string.len(NSPrefix))
	TemplateName = PropertiesOnTree(PropertyNumber, 3, false, false, true)
	if type(TemplateName) == "table" or TemplateName == nil or TemplateName == "" then
		FinalString = ""
	else
		FinalString = frame:expandTemplate{title = string.sub(TemplateName, string.len(NSPrefix) + 1)}
	end
	
	return FinalString
end
return p