Database changes have finished applying - please report any issues you're (still) seeing to support@shoutwiki.com.
Moduuli:Suositeltu sivu
Jedipediasta, vapaasta Tähtien sota-tietosanakirjasta tänään, 18. kesäkuuta 2025
Siirry navigaatioonSiirry hakuun
Tämän moduulin ohjeistuksen voi tehdä sivulle Moduuli:Suositeltu sivu/ohje
1 local p = {}
2
3 local function getWeek()
4 local lang = mw.getContentLanguage()
5 local week = tonumber(lang:formatDate('W'))
6 if week == 53 then
7 if lang:formatDate('N') < 4 then
8 week = 52
9 else
10 week = 1
11 end
12 end
13 return week
14 end
15
16 -- Remove any links from the text, leaving
17 -- the displayed portion of the link only.
18 local function strip_links(text)
19 -- First, convert links like this: [[foo|bar]] to this: bar
20 text = text:gsub("%[%[[^%]\n]+%|([^%]\n]+)%]%]", "%1")
21 -- Next, convert links like this: [[foo]] to this: foo
22 return text:gsub("%[%[([^%]\n]+)%]%]", "%1")
23 end
24
25 local function formatPrevLink(list, week)
26 local title = list.articleData[week].title
27 local displayTitle = list.articleData[week].displayTitle
28 local italics = list.articleData[week].italics
29
30 return string.format(
31 '%s[[%s]]%s',
32 italics and "''" or '',
33 displayTitle and title .. '|' .. displayTitle or title,
34 italics and "''" or ''
35 )
36 end
37
38 local function pick_article()
39 local list = require('Moduuli:Suositeltu sivu/data')
40 local week = getWeek()
41 local pagename = list.articleData[week].title
42 local file_string = ""
43 local main_link = ""
44 local pagetext = mw.title.new(pagename):getContent()
45 local x = pagetext:gsub("%=%=(.*)", "")
46 local prev1, prev2, prev3
47 if week == 1 then
48 prev1 = week + 51
49 else
50 prev1 = week - 1
51 end
52 if week <= 2 then
53 prev2 = week + 50
54 else
55 prev2 = week - 2
56 end
57 if week <= 3 then
58 prev3 = week + 49
59 else
60 prev3 = week - 3
61 end
62
63 -- Generate image
64 local filename = x:match(".*%[%[Tiedosto:(.*)%]%].*")
65 if filename then
66 filename = filename:gsub("%|.*", "")
67 filename = filename:gsub("%]%].*", "")
68 file_string = string.format("[[Tiedosto:%s|left|200px]]\n", filename)
69 end
70
71 -- Extract the bolded segment
72 local bolded = ""
73 local front_italics = false
74 local end_italics = false
75 local intro = x:gsub(".*()%}%}\n(.*)", "%2")
76
77 local s1, e1 = intro:find("'''")
78 if intro:sub(e1 + 1, e1 + 2) == "''" then
79 e1 = e1 + 2
80 front_italics = true
81 end
82 local s2, e2 = intro:find("'''", e1 + 1)
83 if intro:sub(e2 + 1, e2 + 2) == "''" then
84 s2 = s2 + 2
85 end_italics = true
86 end
87
88 if front_italics and end_italics then
89 bolded = strip_links(intro:sub(e1 + 1, s2 - 3))
90 main_link = string.format("[[%s|%s]]", pagename, bolded)
91 s2 = s2 - 2
92 elseif front_italics then
93 bolded = strip_links(intro:sub(e1 - 1, s2 - 1))
94 main_link = string.format("[[%s|%s]]", pagename, bolded)
95 e1 = e1 - 2
96 elseif end_italics then
97 bolded = strip_links(intro:sub(e1 + 1, s2 - 1))
98 main_link = string.format("[[%s|%s]]", pagename, bolded)
99 else
100 bolded = strip_links(intro:sub(e1 + 1, s2 - 1))
101 main_link = string.format("[[%s|%s]]", pagename, bolded)
102 end
103
104 intro = intro:sub(0, e1) .. main_link .. intro:sub(s2)
105
106 -- Substitute templates, add {{Rm}}, and remove any images
107 intro = intro:gsub("\{\{'s\}\}", "<span style=\"padding-left: 0.1em;\">'</span>s")
108 intro = intro:gsub("\n\n$", string.format(
109 "\n\n\nÄskettäin etusivulla olleet sivut: %s — %s — %s",
110 formatPrevLink(list, prev1),
111 formatPrevLink(list, prev2),
112 formatPrevLink(list, prev3)
113 ))
114 if x:find("|image=") then
115 intro = intro:gsub("%[%[Tiedosto:(.*)%]%]", "")
116 end
117
118 return file_string .. intro
119 end
120
121 function p.getContinuity(frame)
122 local list = require('Moduuli:Suositeltu sivu/data')
123 local week = getWeek()
124
125 local continuity = list.articleData[week].continuity
126 if continuity == 'canon' then
127 return '[[Tiedosto:Eras-canon-edit.png|100px|link=Kaanon]]'
128 elseif continuity == 'legends' then
129 return '[[Tiedosto:LegendsBanner.png|100px|link=Star Wars Legends]]'
130 end
131 end
132
133 function p.printList(frame)
134 local list = require('Moduuli:Suositeltu sivu/data')
135 local result = ''
136 local w = 1
137 while w <= 52 do
138 result = result .. string.format('*Viikko %s: [[%s]]\n', w, list.articleData[w].title)
139 w = w + 1
140 end
141 return result
142 end
143
144 function p._main(args)
145 return pick_article()
146 end
147
148 function p.main(frame)
149 local args = {}
150 for k, v in pairs(frame:getParent().args) do
151 v = v:match('^%s*(.-)%s*$') -- trim whitespace
152 if v ~= '' then
153 args[k] = v
154 end
155 end
156 return p._main(args)
157 end
158
159 return p