Module:Uses TemplateStyles

From Wiki.Agency
Revision as of 08:54, 23 October 2018 by Matt Fitzpatrick (talk) (reduced alt attribute to "CSS")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Documentation for this module may be created at Module:Uses TemplateStyles/doc

-- This module implements the {{Uses TemplateStyles}} template.
local yesno = require('Module:Yesno')
local mList = require('Module:List')
local mTableTools = require('Module:TableTools')
local mMessageBox = require('Module:Message box')

local p = {}

function p.main(frame)
	local origArgs = frame:getParent().args
	local args = {}
	for k, v in pairs(origArgs) do
		v = v:match('^%s*(.-)%s*$')
		if v ~= '' then
			args[k] = v
		end
	end
	return p._main(args)
end

function p._main(args)
	local tStyles = mTableTools.compressSparseArray(args)
	local box = p.renderBox(tStyles)
	local trackingCategories = p.renderTrackingCategories(args, tStyles)
	return box .. trackingCategories
end

function p.renderBox(tStyles)
	local boxArgs = {}
	if #tStyles < 1 then
		boxArgs.text = '<strong class="error">Error: no TemplateStyles specified</strong>'
	else
		local tStylesLinks = {}
		for i, ts in ipairs(tStyles) do
			local sandboxLink = nil
			local tsTitle = mw.title.new(ts)
			if tsTitle then
				local tsSandboxTitle = mw.title.new(string.format('%s:%s/sandbox/%s', tsTitle.nsText, tsTitle.baseText, tsTitle.subpageText))
				if tsSandboxTitle and tsSandboxTitle.exists then
					sandboxLink = string.format(' ([[:%s|sandbox]])', tsSandboxTitle.prefixedText)
				end
			end
			tStylesLinks[i] = string.format('[[:%s]]%s', ts, sandboxLink or '')
		end
		local tStylesList = mList.makeList('bulleted', tStylesLinks)
		boxArgs.text = 'This ' .. 
			(mw.title.getCurrentTitle():inNamespaces(828,829) and 'module' or 'template') ..
			' uses [[Wikipedia:TemplateStyles|TemplateStyles]]:\n' .. tStylesList
	end
	boxArgs.type = 'notice'
	boxArgs.small = true
	boxArgs.image = '[[File:Farm-Fresh css add.png|32px|alt=CSS]]'
	return mMessageBox.main('mbox', boxArgs)
end

function p.renderTrackingCategories(args, tStyles, titleObj)
	if yesno(args.nocat) then
		return ''
	end
	
	local cats = {}
	
	-- Error category
	if #tStyles < 1 then
		cats[#cats + 1] = 'Uses TemplateStyles templates with errors'
	end
	
	-- TemplateStyles category
	titleObj = titleObj or mw.title.getCurrentTitle()
	local subpageBlacklist = {
		doc = true,
		sandbox = true,
		sandbox2 = true,
		testcases = true
	}
	if titleObj.namespace == 10 
		and not subpageBlacklist[titleObj.subpageText]
	then
		local category = args.category
		if not category then
			category = category or 'Templates using TemplateStyles'
		end
		cats[#cats + 1] = category
		local currentProt = titleObj.protectionLevels["edit"] and titleObj.protectionLevels["edit"][1] or nil
		for i, ts in ipairs(tStyles) do
			local tsTitleObj = mw.title.new(ts)
			local tsProt = tsTitleObj.protectionLevels["edit"] and tsTitleObj.protectionLevels["edit"][1] or nil
			if tsProt ~= currentProt then
				cats[#cats + 1] = "Templates using TemplateStyles with a different protection level"
				break
			end
		end
	end
	
	for i, cat in ipairs(cats) do
		cats[i] = string.format('[[Category:%s]]', cat)
	end
	return table.concat(cats)
end

return p

Navigation menu

Internal error - Wiki.Agency

Internal error

Jump to: navigation, search

[aacwHMhmJK1W-HszXDOB_gAAAVw] /index.php?oldid=1045&title=Module%3AUses_TemplateStyles Error from line 206 of /home/fufnptjmtte3/public_html/wiki.agency/includes/MagicWordArray.php: Call to undefined function each()

Backtrace:

#0 /home/fufnptjmtte3/public_html/wiki.agency/includes/MagicWordArray.php(327): MagicWordArray->parseMatch()
#1 /home/fufnptjmtte3/public_html/wiki.agency/includes/parser/Parser.php(3040): MagicWordArray->matchStartAndRemove()
#2 /home/fufnptjmtte3/public_html/wiki.agency/includes/parser/Preprocessor_DOM.php(1229): Parser->braceSubstitution()
#3 /home/fufnptjmtte3/public_html/wiki.agency/includes/parser/Parser.php(3262): PPFrame_DOM->expand()
#4 /home/fufnptjmtte3/public_html/wiki.agency/includes/parser/Preprocessor_DOM.php(1229): Parser->braceSubstitution()
#5 /home/fufnptjmtte3/public_html/wiki.agency/includes/parser/Preprocessor_DOM.php(1751): PPFrame_DOM->expand()
#6 /home/fufnptjmtte3/public_html/wiki.agency/includes/parser/Preprocessor_DOM.php(1763): PPTemplateFrame_DOM->getNamedArgument()
#7 /home/fufnptjmtte3/public_html/wiki.agency/extensions/Scribunto/engines/LuaCommon/LuaCommon.php(653): PPTemplateFrame_DOM->getArgument()
#8 /home/fufnptjmtte3/public_html/wiki.agency/extensions/Scribunto/engines/LuaStandalone/LuaStandaloneEngine.php(449): Scribunto_LuaEngine->getExpandedArgument()
#9 /home/fufnptjmtte3/public_html/wiki.agency/extensions/Scribunto/engines/LuaStandalone/LuaStandaloneEngine.php(426): Scribunto_LuaStandaloneInterpreter->callback()
#10 /home/fufnptjmtte3/public_html/wiki.agency/extensions/Scribunto/engines/LuaStandalone/LuaStandaloneEngine.php(474): Scribunto_LuaStandaloneInterpreter->handleCall()
#11 /home/fufnptjmtte3/public_html/wiki.agency/extensions/Scribunto/engines/LuaStandalone/LuaStandaloneEngine.php(346): Scribunto_LuaStandaloneInterpreter->dispatch()
#12 /home/fufnptjmtte3/public_html/wiki.agency/extensions/Scribunto/engines/LuaCommon/LuaCommon.php(286): Scribunto_LuaStandaloneInterpreter->callFunction()
#13 /home/fufnptjmtte3/public_html/wiki.agency/extensions/Scribunto/engines/LuaCommon/LuaCommon.php(936): Scribunto_LuaEngine->executeFunctionChunk()
#14 /home/fufnptjmtte3/public_html/wiki.agency/extensions/Scribunto/common/Hooks.php(138): Scribunto_LuaModule->invoke()
#15 /home/fufnptjmtte3/public_html/wiki.agency/includes/parser/Parser.php(3383): ScribuntoHooks::invokeHook()
#16 /home/fufnptjmtte3/public_html/wiki.agency/includes/parser/Parser.php(3106): Parser->callParserFunction()
#17 /home/fufnptjmtte3/public_html/wiki.agency/includes/parser/Preprocessor_DOM.php(1229): Parser->braceSubstitution()
#18 /home/fufnptjmtte3/public_html/wiki.agency/includes/parser/Parser.php(3262): PPFrame_DOM->expand()
#19 /home/fufnptjmtte3/public_html/wiki.agency/includes/parser/Preprocessor_DOM.php(1229): Parser->braceSubstitution()
#20 /home/fufnptjmtte3/public_html/wiki.agency/includes/parser/Parser.php(3262): PPFrame_DOM->expand()
#21 /home/fufnptjmtte3/public_html/wiki.agency/includes/parser/Preprocessor_DOM.php(1229): Parser->braceSubstitution()
#22 /home/fufnptjmtte3/public_html/wiki.agency/includes/parser/Parser.php(2921): PPFrame_DOM->expand()
#23 /home/fufnptjmtte3/public_html/wiki.agency/includes/parser/Parser.php(1277): Parser->replaceVariables()
#24 /home/fufnptjmtte3/public_html/wiki.agency/includes/parser/Parser.php(451): Parser->internalParse()
#25 /home/fufnptjmtte3/public_html/wiki.agency/includes/content/WikitextContent.php(329): Parser->parse()
#26 /home/fufnptjmtte3/public_html/wiki.agency/includes/content/AbstractContent.php(516): WikitextContent->fillParserOutput()
#27 /home/fufnptjmtte3/public_html/wiki.agency/includes/jobqueue/jobs/RefreshLinksJob.php(226): AbstractContent->getParserOutput()
#28 /home/fufnptjmtte3/public_html/wiki.agency/includes/jobqueue/jobs/RefreshLinksJob.php(122): RefreshLinksJob->runForTitle()
#29 /home/fufnptjmtte3/public_html/wiki.agency/includes/jobqueue/JobRunner.php(295): RefreshLinksJob->run()
#30 /home/fufnptjmtte3/public_html/wiki.agency/includes/jobqueue/JobRunner.php(193): JobRunner->executeJob()
#31 /home/fufnptjmtte3/public_html/wiki.agency/includes/MediaWiki.php(962): JobRunner->run()
#32 /home/fufnptjmtte3/public_html/wiki.agency/includes/MediaWiki.php(948): MediaWiki->triggerSyncJobs()
#33 /home/fufnptjmtte3/public_html/wiki.agency/includes/MediaWiki.php(900): MediaWiki->triggerJobs()
#34 /home/fufnptjmtte3/public_html/wiki.agency/includes/MediaWiki.php(719): MediaWiki->restInPeace()
#35 /home/fufnptjmtte3/public_html/wiki.agency/includes/MediaWiki.php(740): MediaWiki->{closure}()
#36 /home/fufnptjmtte3/public_html/wiki.agency/includes/MediaWiki.php(553): MediaWiki->doPostOutputShutdown()
#37 /home/fufnptjmtte3/public_html/wiki.agency/index.php(43): MediaWiki->run()
#38 {main}

Navigation menu