Difference between revisions of "Module:Portal maintenance status"

From blackwiki
Jump to navigation Jump to search
test>Evad37
(add some links)
test>Evad37
(adjust level of error)
Line 29: Line 29:
 
local talkTitle = mw.title.getCurrentTitle()
 
local talkTitle = mw.title.getCurrentTitle()
 
if talkTitle.namespace ~= 101 then
 
if talkTitle.namespace ~= 101 then
return error('Wrong namespace')
+
return error('Wrong namespace', 0)
 
end
 
end
 
local portalTitle = mw.title.new("Portal:"..talkTitle.text)
 
local portalTitle = mw.title.new("Portal:"..talkTitle.text)

Revision as of 02:35, 8 June 2018

This module searches a Portal_talk: page's portal page, and returns an appropriate message based if {{Portal maintenance status}} is found in the page's wikitext, and which parameters are used. An error is reported if this module is used outside of the Portal_talk namespace. It can be demonstrated, in any namespace, with the |demo= and |demo2= parameters, which take the name of templates to "find" (instead of actually searching a page).

Usage

{{#invoke:Portal maintenance status|main}}
Looks for {{Portal maintenance status}} on a Portal_talk: page's related portal page.
Returns an appropriate message string if found or an empty string if not found, or an error if used in the wrong namespace.
{{#invoke:Portal maintenance status|historical}}
Looks for {{Historical}} on a Wikipedia_talk: page's related project page.
Returns yes if found or an empty string if not found, or an error if used in the wrong namespace.
{{#invoke:Portal maintenance status|featured}}
Looks for {{Featured portal}} on a Wikipedia_talk: page's related project page.
Returns yes if found or an empty string if not found, or an error if used in the wrong namespace.

Examples

If the portal contains {{Portal maintenance status|date=June 2026|manual=yes}}



If the portal contains {{Portal maintenance status|date=June 2026|nonstandard=yes}}



If the portal contains {{Portal maintenance status|date=June 2026|incomplete=yes}}



If the portal contains {{Portal maintenance status|date=June 2026|subpages=single}}



If the portal contains {{Portal maintenance status|date=June 2026|subpages=checked}}



If the portal contains {{Portal maintenance status|date=June 2026|note=This is an example.}}



If the portal contains {{Portal maintenance status|date=June 2026|manual=yes|nonstandard=yes|subpages=single|incomplete=yes|note=Lorem ipsum dolor sit amet.}}



If the portal does not contain the template, there should be no output



If used in the wrong namespace, an error should be reported

Lua error: Wrong namespace.


See also

  • Script error: No such module "Section link".



local p = {}

function cleanupArgs(argsTable)
	local cleanArgs = {}
	for key, val in pairs(argsTable) do
		if type(val) == 'string' then
			val = val:match('^%s*(.-)%s*$')
			if val ~= '' then
				cleanArgs[key] = val
			end
		else
			cleanArgs[key] = val
		end
	end
	return cleanArgs
end

p.main = function(frame)
	local parent = frame.getParent(frame)
	local args = cleanupArgs(frame.args)
	local demo = args.demo and true or false
	local portalContent
	if demo then
		portalContent = '{{' .. args.demo .. '}}'
		if args.demo2 then
			portalContent = portalContent  .. '{{' .. args.demo2 .. '}}'
		end
	else
		local talkTitle = mw.title.getCurrentTitle()
		if talkTitle.namespace ~= 101 then
			return error('Wrong namespace', 0)
		end
		local portalTitle = mw.title.new("Portal:"..talkTitle.text)
		portalContent = portalTitle:getContent()
	end

	local isMaintained = mw.ustring.find(portalContent, '%{%{%s*[Mm]aintained portal flag%s*%}%}') and true or false
	local isNonstandard = mw.ustring.find(portalContent, '%{%{%s*[Nn]on%-standard portal flag%s*%}%}') and true or false

	if (not isMaintained) and (not isNonstandard) then
		return ''
	end

	local text = "This portal " .. ( isMaintained and "'''is [[Wikipedia:WikiProject Portals#Specific portal maintainers|maintained]]'''" or '' ) .. ( ( isMaintained and isNonstandard ) and ' and ' or '' ) .. ( isNonstandard and "has a '''non-standard layout'''" or '' ) .. '.'
	local subtext = "Please [[WP:CAREFUL|take care]] when editing, especially if using [[WP:ASSISTED|automated editing software]]" .. ( isMaintained and ", and seek [[Wikipedia:Consensus|consensus]] before making major changes." or '.')

	return text .. '<br>' .. '<span style="font-size:90%">' .. subtext .. '</span>'
end

return p