-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwikitrek-DTEpisodio.lua
325 lines (286 loc) · 10.6 KB
/
wikitrek-DTEpisodio.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
-- [P2G] Auto upload by PageToGitHub on 2024-06-17T12:38:04+02:00
-- [P2G] This code from page Modulo:wikitrek-DTEpisodio
-- Keyword: wikitrek
local LabelOrLink = require('Modulo:DTBase').LabelOrLink
local DescrWithTemplate = require('Modulo:DTGenerico').DescrWithTemplate
local p = {}
function p.GetActors(frame, AddSemantic)
-- Personaggio (P10)
-- Prefisso (P15)
-- Interpreti (P21)
local item = mw.wikibase.getEntityIdForCurrentPage()
if not item then
item = 'Q1'
end
if AddSemantic == nil then
AddSemantic = true
end
if not item then return ':-(' end
local results = {}
local statements = mw.wikibase.getAllStatements(item, 'P21')
for _, statement in pairs(statements) do
local Result = {}
local actorQ = statement.mainsnak.datavalue['value']['id']
-- Se servisse l'entità, bisognerebbe fare
-- local actorEntity = mw.wikibase.getEntity(actorQ)
-- local actorLabel = actorEntity:getLabel()
-- Se tutti gli attori avessero SiteLink
-- mw.wikibase.getSitelink(actorQ)
local actorLabel = mw.wikibase.getLabel(actorQ)
local actorLink = mw.wikibase.getSitelink(actorQ) or "Special:AboutTopic/" .. actorQ
local CharQ
local CharEntity
local CharLabel
local CharLabelEntity
local CharLink
local MakeWikiLink
if statement['qualifiers']['P10'] then
CharQ = statement['qualifiers']['P10'][1].datavalue['value']['id']
CharEntity = mw.wikibase.getEntity(CharQ)
CharLabelEntity = CharEntity:getLabel()
--[==[
CharLink = mw.wikibase.getSitelink(CharQ)
if not CharLink then
CharLink = CharLabelEntity
end]==]
--CharLink = mw.wikibase.getSitelink(CharQ) or CharLabelEntity
CharLink = mw.wikibase.getSitelink(CharQ) or "Special:AboutTopic/" .. CharQ
MakeWikiLink = true
else
MakeWikiLink = false
end
if statement['qualifiers']['P20'] then
CharLabel = statement['qualifiers']['P20'][1].datavalue['value']
else
CharLabel = CharLabelEntity
end
local Prefix
if statement['qualifiers']['P15'] then
Prefix = statement['qualifiers']['P15'][1].datavalue['value'] .. ' '
else
Prefix = ''
end
local Suffix
if statement['qualifiers']['P19'] then
Suffix = ' ' .. statement['qualifiers']['P19'][1].datavalue['value']
else
Suffix = ''
end
local AppearanceType
if statement['qualifiers']['P22'] then
AppearanceType = mw.wikibase.getLabel(statement['qualifiers']['P22'][1].datavalue['value']['id'])
else
AppearanceType = "''Nessun tipo''"
end
--[=[
To add additional semantic properties
{{#set:
|Emily Coutts=Keyla Detmer
|Keyla Detmer=Emily Coutts
}}
{{#set:|Keyla Detmer=Emily Coutts}}
]=]
--Character
if MakeWikiLink then
if AddSemantic then
if string.sub(CharLink, 1, 8) == "Special:" then
Result['Character'] = Prefix .. '[[' .. CharLink .. '|' .. CharLabel .. ']]' .. Suffix .. frame:callParserFunction('#set:', 'Personaggio=' .. CharLabel)
else
Result['Character'] = Prefix .. '[[' .. CharLink .. '|' .. CharLabel .. ']]' .. Suffix .. frame:callParserFunction('#set:', 'Personaggio=' .. CharLink)
end
else
Result['Character'] = Prefix .. '[[' .. CharLink .. '|' .. CharLabel .. ']]' .. Suffix
end
else
Result['Character'] = Prefix .. CharLabel .. Suffix
end
--Actor
if AddSemantic then
--Result['Actor'] = '[[Interprete::' .. actorLabel .. ']]' .. frame:callParserFunction('#set:', actorLabel .. '=' .. CharLabel)
if string.sub(CharLink, 1, 8) == "Special:" then
Result['Actor'] = '[[' .. actorLink .. '|' .. actorLabel .. ']]' .. frame:callParserFunction('#set:', actorLabel .. '=' .. CharLabel) .. frame:callParserFunction('#set:', 'Interprete=' .. actorLabel)
else
Result['Actor'] = '[[' .. actorLink .. '|' .. actorLabel .. ']]' .. frame:callParserFunction('#set:', actorLabel .. '=' .. CharLink) .. frame:callParserFunction('#set:', 'Interprete=' .. actorLabel)
end
else
Result['Actor'] = '[[' .. actorLink .. '|' .. actorLabel .. ']]'
end
Result['Type'] = AppearanceType
results[#results + 1] = Result
end
return results
end
function p.ListFirstAir(frame, AddSemantic)
local CurrItem = mw.wikibase.getEntityIdForCurrentPage()
if not CurrItem then
return nil
end
if not AddSemantic then
AddSemantic = true
end
local Results = {}
local Statements = mw.wikibase.getAllStatements(CurrItem, 'P2')
if #Statements == 0 then
return nil
end
for _, Statement in pairs(Statements) do
local Result
local DateLabel
if AddSemantic then
DateLabel = "[[Data di trasmissione::" .. Statement['mainsnak'].datavalue['value'].time .. "|" .. frame:expandTemplate{ title = 'TimeL', args = {Tipo='ITEstesa', Istante=Statement['mainsnak'].datavalue['value'].time} } .. "]]"
else
DateLabel = frame:expandTemplate{ title = 'TimeL', args = {Tipo='ITEstesa', Istante=Statement['mainsnak'].datavalue['value'].time} }
end
Result = '<li>' .. DateLabel .. " su ''" .. Statement['qualifiers']['P4'][1].datavalue['value'] .. "'' (" .. Statement['qualifiers']['P34'][1].datavalue['value'] .. ")</li>"
Results[#Results + 1] = Result
end
return '<ul>' .. table.concat(Results, string.char(10)) .. '</ul>'
end
function p.ListActors(frame)
local Actors = p.GetActors(frame, true)
local Results = {}
local Groups = {}
local FinalList = ""
-- table.sort(Attori)
for _, Role in pairs(Actors) do
if not Groups[Role.Type] then
Groups[Role.Type] = '* ' .. Role.Character .. ': ' .. Role.Actor
else
Groups[Role.Type] = Groups[Role.Type] .. string.char(10) .. '* ' .. Role.Character .. ': ' .. Role.Actor
end
Results[#Results + 1] = '* ' .. Role.Character .. ': ' .. Role.Actor .. frame:expandTemplate{ title = 'Etichetta', args = {Tipo=Role.Type} }
end
for Key, Group in pairs(Groups) do
FinalList = FinalList .. "'''''" .. frame:expandTemplate{ title = 'Etichetta', args = {Tipo=Key} } .. "'''''" .. string.char(10) .. Group .. string.char(10) .. string.char(10)
end
-- return table.concat(Results, string.char(10))
return FinalList
end
function p.LinkFromP(Property)
local EpisodeTitle
local Link
local item = mw.wikibase.getEntity() --local item = mw.wikibase.getEntityIdForCurrentPage()
if not item then return '' end
if not item['claims'][Property] then
EpisodeTitle = "''Nessuno''"
Link = EpisodeTitle
else
EpisodeTitle = item['claims'][Property][1]['mainsnak'].datavalue['value']
--Link = '[[' .. EpisodeTitle .. '|' .. EpisodeTitle .. ']]'
Link = LabelOrLink(EpisodeTitle['id'])
end
return Link
end
function p.LinkPrevious()
--[===[
local EpisodeTitle
local Link
local item = mw.wikibase.getEntity() --local item = mw.wikibase.getEntityIdForCurrentPage()
if not item then return '' end
if not item['claims']['P7'][1] then
EpisodeTitle = "''Nessuno''"
Link = EpisodeTitle
else
EpisodeTitle = item['claims']['P7'][1]['mainsnak'].datavalue['value']
Link = '[[' .. EpisodeTitle .. '|' .. EpisodeTitle .. ']]'
end
]===]
return p.LinkFromP('P7')
end
function p.LinkNext()
return p.LinkFromP('P23')
end
function p.SeasonInfo()
-- |BoxTitolo=Stagione 2 di Discovery
-- |Icona={{#statements:Icona|from=Q1}}
--[===[
local SeasonNumber
local SeriesQ
local SeriesName
local FileName
]===]
local Item = mw.wikibase.getEntity()
if not Item then
Item = mw.wikibase.getEntity('Q1')
end
local SeasonData = p.SeasonInfoRaw(Item)
--[===[
SeasonNumber = Item['claims']['P18'][1]['mainsnak'].datavalue['value'].amount
SeriesQ = Item['claims']['P16'][1]['mainsnak'].datavalue['value']['id']
SeriesName = mw.wikibase.getLabel(SeriesQ)
FileName = mw.wikibase.getEntity(SeriesQ)['claims']['P3'][1]['mainsnak'].datavalue['value']
]===]
-- return mw.text.nowiki("|BoxTitolo=Stagione " .. SeasonData.SeasonNumber .. " di ''" .. SeasonData.SeriesAbbr .. "''|FileIcona=" .. SeasonData.FileName)
return "Stagione " .. SeasonData.SeasonNumber .. " di ''" .. SeasonData.SeriesAbbr
end
function p.SeasonInfoRaw(Entity)
--[===[
local SeasonNumber
local SeriesQ
local SeriesName
local SeriesAbbr
local FileName
]===]
local Result = {}
local Item = mw.wikibase.getEntity()
if not Item then
Item = Entity
end
Result['SeasonNumber'] = string.format('%u', Item.claims['P18'][1].mainsnak.datavalue.value.amount)
if Item.claims['P16'] then
SeriesQ = Item.claims['P16'][1].mainsnak.datavalue.value.id
else
SeriesQ = mw.wikibase.getEntity(Item.claims['P14'][1].mainsnak.datavalue.value.id).claims['P16'][1].mainsnak.datavalue.value.id
end
Result['SeriesName'] = mw.wikibase.getLabel(SeriesQ)
Result['FileName'] = mw.wikibase.getEntity(SeriesQ)['claims']['P3'][1].mainsnak.datavalue.value
Result['SeriesAbbr'] = mw.wikibase.getEntity(SeriesQ)['claims']['P24'][1].mainsnak.datavalue.value
return Result
end
function p.FileIcon()
-- |FileIcona=dsg.png
local SeriesQ
local FileName
local Item = mw.wikibase.getEntity()
if not Item then
Item = mw.wikibase.getEntity('Q1')
end
SeriesQ = Item['claims']['P16'][1]['mainsnak'].datavalue['value']['id']
FileName = mw.wikibase.getEntity(SeriesQ)['claims']['P3'][1]['mainsnak'].datavalue['value']
return FileName
end
function p.Incipit(frame)
local SeasonData = p.SeasonInfoRaw()
--return frame:expandTemplate{ title = 'DataBoxEpisodio' } .. string.char(10) .. "[[" .. mw.title.getCurrentTitle().text .. "]] è un episodio della stagione " .. SeasonData.SeasonNumber .. " di ''[[" .. SeasonData.SeriesName .. "]]''." .. string.char(10)
return "[[" .. mw.title.getCurrentTitle().text .. "]] è un episodio della stagione " .. SeasonData.SeasonNumber .. " di ''[[" .. SeasonData.SeriesName .. "]]''." .. string.char(10)
end
function p.IncipitTree(frame)
local SeasonData = p.SeasonInfoRaw()
mw.smw.set("Serie=" .. SeasonData.SeriesName)
mw.smw.set("Istanza=Episodio di " .. SeasonData.SeriesAbbr)
mw.smw.set("Stagione=" .. SeasonData.SeasonNumber)
local SeasonOrdinals =
{
"prima",
"seconda",
"terza",
"quarta",
"quinta",
"sesta",
"settima",
"ottava",
"nona",
"decima"
}
if not mw.wikibase.getDescription() then
if not mw.wikibase.getEntity().claims['P20'] then
return "'''''" .. mw.title.getCurrentTitle().text .. "''''' è un episodio della [[Stagione " .. SeasonData.SeasonNumber .. " di " .. SeasonData.SeriesAbbr .. "|" .. SeasonOrdinals[tonumber(SeasonData.SeasonNumber)] .. " stagione]] di ''[[" .. SeasonData.SeriesName .. "]]''." .. string.char(10)
else
return "''''" .. mw.title.getCurrentTitle().text .. "'''' è " .. mw.wikibase.getEntity().claims['P20'][1].mainsnak.datavalue['value'] .. string.char(10)
end
else
--return "'''''" .. mw.title.getCurrentTitle().text .. "'''''" .. " è " .. mw.wikibase.getDescription() .. string.char(10)
return "'''''" .. mw.title.getCurrentTitle().text .. "'''''" .. " è " .. DescrWithTemplate(frame) .. string.char(10)
end
end
return p