Jump to content

Module:Good Articles

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Wnt (talk | contribs) at 12:49, 17 April 2014 (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.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {}

p.main = function (frame)
	local NNN = 2 -- provide counts only over this threshold
	local args = require("Module:Arguments").getArgs(frame)
	-- expect args.shortcut e.g. GA/H, args.type e.g. History, args.text a long list
	local subpage = frame:preprocess("{{SUBPAGENAME}}") -- I never did look up if there's a better way to do this...
	local header = ""
	local shortcuts = ""
	local type = args.type or "error: specify type = Good Articles type"
	local image = ''
	if args.image then image = '[[' .. args.image .. '|22px|left]]' end
	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
    replace = function(t)
        local xxxx, links = mw.ustring.gsub(t, "(%[%[[^%[%]]-%]%])", "%1", nil) -- count how many links
        if links >= NNN then
            t = t .. "<small> (" .. tostring(links) .. "&nbsp;articles)</small>"
        end
        return t .. "\n"
    end
    local sectionfooter = [===[\n</div>\n</div>\n<!-- end of list -->]===]
    -- comments in the text below are historical from the page's own markup
    local output = header .. [===[<!-- only include header on this page -->
__NOTOC__
<div style="clear:both;">
<!-- DO NOT REMOVE THIS DIV, USED TO FORCE IE TO DISPLAY BACKGROUND FOR ARTS DIV -->
</div>
<div style="clear:both;">
<span id="]===] .. type .. [===[" />
<div style="padding:5px 5px 8px 5px; background-color:#66CC66; text-align:left; font-size:larger;">]===] .. image .. [===[''']===] .. type .. [===['''</div>
<div style="text-align:left;">
</div>
</div>
]===] .. text
    local section = 0
    local finaltext = ''
    repeat
    	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' .. tostring(section)]

        local text = mw.ustring.gsub(text, "(==.-)\n%f[=]", replace)
    	if (image) then 
    		image = '[[' .. image .. '|22px|left]]'
    	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 .. [===[</div>\n<div class="NavContent" style="text-align:left;">\n\n==&shy;&nbsp;==\n]===] .. text .. sectionfooter
    until false
    return output .. finaltext
end

return p