-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwikitrek-BeginEndPage.lua
153 lines (130 loc) · 5.25 KB
/
wikitrek-BeginEndPage.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
-- [P2G] Auto upload by PageToGitHub on 2024-01-12T22:41:57+01:00
-- [P2G] This code from page Modulo:wikitrek-BeginEndPage
-- <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