Module:Good Articles: Difference between revisions

Content deleted Content added
Getting there. Couldn't get gsub to swallow a nil or false for parameter 3 though, which is a waste.
Changing to use subsections. Problem: for some reason the new \n's want to come out as "\n", even though I had some already which appear as newline.
Line 9:
local shortcuts = ""
local type = args.type or "error: specify type = Good Articles type"
local titleimage = args.title or args.type''
if args.image then image = '[[' .. args.image .. '|22px|left]]' end
if args and args.shortcut and subpage == type then
local sectioncount = 0
if subpage == type then -- I haven't figured out how to deal with missing shortcut so why pretend
shortcuts = frame:expandTemplate{ title = 'shortcut', args = { args.shortcut } }
header = frame:expandTemplate{ title = 'Wikipedia:Good articles/header', args = { shortcuts = shortcuts } }
end
local text = args.text or args[1] or ""
replace = function(t)
local xxxx, links = mw.ustring.gsub(t, "(%[%[[^%[%]]-%]%])", "%1", nil) -- count how many links
Line 22 ⟶ 24:
return t .. "\n"
end
local sectionfooter = [===[\n</div>\n</div>\n<!-- end of list -->]===]
text = mw.ustring.gsub(text, "(==.-)\n%f[=]", replace)
-- comments in the text below are historical from the page's own markup
local image = args.image or "error: specify image"
local footer = [===[
</div>
</div>
<!-- end of list -->]===]
 
local output = header .. [===[<!-- only include header on this page -->
__NOTOC__
Line 36 ⟶ 33:
<div style="clear:both;">
<span id="]===] .. type .. [===[" />
<div style="padding:5px 5px 8px 5px; background-color:#66CC66; text-align:left; font-size:larger;">[[]===] .. image .. [===[|22px|left]]''']===] .. type .. [===['''</div>
<div style="text-align:left;">
</div>
</div>
]===] .. text .. footer
<div style="clear:both;" class="NavFrame">
local footersection = [===[0
<span id="World history"/>
local finaltext = ''
<div class="NavHead" style="padding:2px 2px 2px 30px; background-color:#FFFAF0; text-align:left; font-size:larger;">[[]===] .. image .. [===[|22px|left]]]===] .. title .. [===[</div>
repeat
<div class="NavContent" style="text-align:left;">
section = section + 1
local text = (args['section' .. tostring(section)] or '')
if (not args['title' .. tostring(section)]) then
if (text == '') then break end -- no more sections
else
finaltext = finaltext .. text -- sections without headers get spit out at end, unwrapped
end
local image = args.['image' or.. "error: specify image"tostring(section)]
 
local text = mw.ustring.gsub(text, "(==.-)\n%f[=]", replace)
==&shy;&nbsp;==
if (image) then
]===] .. text .. footer
image = '[[' .. image .. '|22px|left]]'
return output
else
image = '' -- make section without an image
end
output = output .. [===[<div style="clear:both;" class="NavFrame">\n<span id="World history"/>\n<div class="NavHead" style="padding:2px 2px 2px 30px; background-color:#FFFAF0; text-align:left; font-size:larger;">[[]===] .. image .. title .. [===[|22px|</div>\n<div class="NavContent" style="text-align:left]];">\n\n==&shy;&nbsp;==\n]===] .. titletext .. [===[</div>sectionfooter
until false
return output .. finaltext
end