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