text:
Template:Table style/doc

Usage

 * This template allows shorthand table styling parameters. It supports up to 10 CSS style commands (e.g. "text-align:right;"), each bound to a shorthand code.
 * If you want to add a shorthand entry, add it to table style/parse.
 * Natural language codes that are not in the list of below, can be used in addition, or in combination with the shorthand codes. Natural language codes need to be terminated with the semicolon, while shorthand codes include the semicolon.
 * Units are px, em, %, but they are not part of the code. Consider the units in context.

Suggested codes

 * Suggested shorthand codes, indicated with yellow background do not exist.
 * The new shorthand codes (added on 2019-09-03) are additions and not replacements. Both codes are valid.
 * The digits in the suggested codes were padded with 0 for uniformity.

List of parameters

 * The suggested shorthand codes don't exist.
 * They would be additions and all codes both codes are valid.
 * These suggested shorthand codes were padded uniformity.
 * Shorthand codes may use use px, em, %, but these not indicated in the code.

Examples
  produces style="text-align:right; border:1px solid black; font-variant:small-caps;"

  produces style="text-align:right; vertical-align:top; padding-right:2.0em;"

Natural language code combined with shorthand code:
  produces style="text-align:right; padding-right:2.0em;"

Where to place the template in a table?
Either at the start of the table, or on a row break, or for an individual cell.

In the following example the templates first sets the text in all the cells to be centered. Then on the second row (after the heading row) all the text in the row to be left justified, finally the third row second column (the number of years) to be right justified.

Display as:

title: Template:Table style/doc


text: Template:Table style/parse

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

title: Template:Table style/parse


text:
Template:Uses TemplateStyles/doc

This template is used to show that templates have been converted to use TemplateStyles. It is placed at the top of the template's /doc page. It automatically adds the template to Category:Templates using TemplateStyles, or to one of its subcategories.

Usage

 * Basic :

 * All parameters :

The first TemplateStyles page name is required.

TemplateStyles sandboxes
Note that if a sandbox version of the TemplateStyle exists, it will also be linked. This is only for sandbox versions. The subpage name of the sandbox version should be the same, but as a subpage of the templates sandbox. For example, if the TemplateStyles page name is, then the sandbox version should be

Template category
This template adds pages to Category:Templates using TemplateStyles if the page is in the template namespace, and it is not on any of the subpages /doc, /sandbox, /sandbox2 or /testcases. You can specify a different category with the category parameter, e.g. Lua String-based templates.

Error category
If no modules are specified, the transcluded page will be added to Category:Uses TemplateStyles templates with errors.

Protection level category
TemplateStyles should have the same protection level as the template they are used on. If a difference is detected, the transcluded page will be added to Category:Templates using TemplateStyles with a different protection level.

Category suppression
To suppress all categorisation, use true. (As well as "true", the values "yes", "y", and "1" will also work.)

title: Template:Uses TemplateStyles/doc


text:
Template:Documentation/styles.css

/*Template documentation*/ .template-documentation { clear: both; margin: 1em 0 0 0; border: 1px solid #aaddff; background-color: #eef5ff; padding: 5px; } /* force edit links to right in start box span#doc_editlinks { float: right !important; margin-right: 0.50em !important; } */

title: Template:Documentation/styles.css


text:
Template:Effective protection level

local p = {}

-- Returns the permission required to perform a given action on a given title. -- If no title is specified, the title of the page being displayed is used. function p._main(action, pagename) local title if type(pagename) == 'table' and pagename.prefixedText then title = pagename elseif pagename then title = mw.title.new(pagename) else title = mw.title.getCurrentTitle end pagename = title.prefixedText if action == 'autoreview' then local level = mw.getCurrentFrame:callParserFunction('PENDINGCHANGELEVEL', pagename) if level == 'review' then return 'reviewer' elseif level ~= '' then return level else return nil -- not '*'. a page not being PC-protected is distinct from it being PC-protected with anyone able to review. also not '', as that would mean PC-protected but nobody can review end elseif action ~= 'edit' and action ~= 'move' and action ~= 'create' and action ~= 'upload' then error( 'First parameter must be one of edit, move, create, upload, autoreview', 2 ) end if title.namespace == 8 then -- MediaWiki namespace return 'sysop' elseif title.namespace == 2 and title.isSubpage and ( title.contentModel == 'javascript' or title.contentModel == 'css' ) then -- user JS or CSS page return 'sysop' end local level = title.protectionLevels[action] and title.protectionLevels[action][1] if level == 'sysop' or level == 'editprotected' then return 'sysop' elseif title.cascadingProtection.restrictions[action] and title.cascadingProtection.restrictions[action][1] then -- used by a cascading-protected page return 'sysop' elseif level == 'templateeditor' then return 'templateeditor' elseif action == 'move' then local blacklistentry = mw.ext.TitleBlacklist.test('edit', pagename) -- Testing action edit is correct, since this is for the source page. The target page name gets tested with action move. if blacklistentry and not blacklistentry.params.autoconfirmed then return 'templateeditor' elseif title.namespace == 6 then return 'filemover' else return 'autoconfirmed' end end local blacklistentry = mw.ext.TitleBlacklist.test(action, pagename) if blacklistentry then return blacklistentry.params.autoconfirmed and 'autoconfirmed' or 'templateeditor' elseif level == 'editsemiprotected' then -- create-semiprotected pages return this for some reason return 'autoconfirmed' elseif level then return level elseif action == 'upload' then return 'autoconfirmed' elseif action == 'create' and title.namespace % 2 == 0 and title.namespace ~= 118 then -- You need to be registered, but not autoconfirmed, to create non-talk pages other than drafts return 'user' else return '*' end end

setmetatable(p, { __index = function(t, k)	return function(frame)		return t._main(k, frame.args[1])	end end })

return p

title: Template:Effective protection level


text:
Template:File link

-- This module provides a library for formatting file wikilinks.

local yesno = require('Module:Yesno') local checkType = require('libraryUtil').checkType

local p = {}

function p._main(args) checkType('_main', 1, args, 'table')

-- This is basically libraryUtil.checkTypeForNamedArg, but we are rolling our -- own function to get the right error level. local function checkArg(key, val, level) if type(val) ~= 'string' then error(string.format( "type error in '%s' parameter of '_main' (expected string, got %s)", key, type(val) ), level) end end

local ret = {}

-- Adds a positional parameter to the buffer. local function addPositional(key) local val = args[key] if not val then return nil end checkArg(key, val, 4) ret[#ret + 1] = val end

-- Adds a named parameter to the buffer. We assume that the parameter name -- is the same as the argument key. local function addNamed(key) local val = args[key] if not val then return nil end checkArg(key, val, 4) ret[#ret + 1] = key .. '=' .. val end

-- Filename checkArg('file', args.file, 3) ret[#ret + 1] = 'File:' .. args.file

-- Format if args.format then checkArg('format', args.format) if args.formatfile then checkArg('formatfile', args.formatfile) ret[#ret + 1] = args.format .. '=' .. args.formatfile else ret[#ret + 1] = args.format end end

-- Border if yesno(args.border) then ret[#ret + 1] = 'border' end

addPositional('location') addPositional('alignment') addPositional('size') addNamed('upright') addNamed('link') addNamed('alt') addNamed('page') addNamed('class') addNamed('lang') addNamed('start') addNamed('end') addNamed('thumbtime') addPositional('caption')

return string.format('%s', table.concat(ret, '|')) end

function p.main(frame) local origArgs = require('Module:Arguments').getArgs(frame, {		wrappers = 'Template:File link'	}) if not origArgs.file then error("'file' parameter missing from Template:File link", 0) end

-- Copy the arguments that were passed to a new table to avoid looking up -- every possible parameter in the frame object. local args = {} for k, v in pairs(origArgs) do -- Make _BLANK a special argument to add a blank parameter. For use in -- conditional templates etc. it is useful for blank arguments to be		-- ignored, but we still need a way to specify them so that we can do -- things like. if v == '_BLANK' then v = '' end args[k] = v	end return p._main(args) end

return p

title: Template:File link


text: Template:\sandbox

title: Template:\sandbox


text:
Module:Documentation

-- This module implements.

-- Get required modules. local getArgs = require('Module:Arguments').getArgs

-- Get the config table. local cfg = mw.loadData('Module:Documentation/config')

local p = {}

-- Often-used functions. local ugsub = mw.ustring.gsub

-- Helper functions -- -- These are defined as local functions, but are made available in the p -- table for testing purposes.

local function message(cfgKey, valArray, expectType) --	-- Gets a message from the cfg table and formats it if appropriate.	-- The function raises an error if the value from the cfg table is not	-- of the type expectType. The default type for expectType is 'string'.	-- If the table valArray is present, strings such as $1, $2 etc. in the	-- message are substituted with values from the table keys [1], [2] etc.	-- For example, if the message "foo-message" had the value 'Foo $2 bar $1.',	-- message('foo-message', {'baz', 'qux'}) would return "Foo qux bar baz."	-- local msg = cfg[cfgKey] expectType = expectType or 'string' if type(msg) ~= expectType then error('message: type error in message cfg.' .. cfgKey .. ' (' .. expectType .. ' expected, got ' .. type(msg) .. ')', 2)	end if not valArray then return msg end

local function getMessageVal(match) match = tonumber(match) return valArray[match] or error('message: no value found for key $' .. match .. ' in message cfg.' .. cfgKey, 4) end

return ugsub(msg, '$([1-9][0-9]*)', getMessageVal) end

p.message = message

local function makeWikilink(page, display) if display then return mw.ustring.format('%s', page, display) else return mw.ustring.format('%s', page) end end

p.makeWikilink = makeWikilink

local function makeCategoryLink(cat, sort) local catns = mw.site.namespaces[14].name return makeWikilink(catns .. ':' .. cat, sort) end

p.makeCategoryLink = makeCategoryLink

local function makeUrlLink(url, display) return mw.ustring.format('[%s %s]', url, display) end

p.makeUrlLink = makeUrlLink

local function makeToolbar(...) local ret = {} local lim = select('#', ...) if lim < 1 then return nil end for i = 1, lim do		ret[#ret + 1] = select(i, ...) end -- 'documentation-toolbar' return '('		.. table.concat(ret, ' | ') .. ') ' end

p.makeToolbar = makeToolbar

-- Argument processing

local function makeInvokeFunc(funcName) return function (frame) local args = getArgs(frame, {			valueFunc = function (key, value)				if type(value) == 'string' then					value = value:match('^%s*(.-)%s*$') -- Remove whitespace.					if key == 'heading' or value ~= '' then						return value					else						return nil					end				else					return value				end			end		}) return p[funcName](args) end end

-- Entry points

function p.nonexistent(frame) if mw.title.getCurrentTitle.subpageText == 'testcases' then return frame:expandTemplate{title = 'module test cases notice'} else return p.main(frame) end end

p.main = makeInvokeFunc('_main')

function p._main(args) --	-- This function defines logic flow for the module.	-- @args - table of arguments passed by the user	-- local env = p.getEnvironment(args) local root = mw.html.create root :wikitext(p._getModuleWikitext(args, env)) :wikitext(p.protectionTemplate(env)) :wikitext(p.sandboxNotice(args, env)) :tag('div') -- 'documentation-container' :addClass(message('container')) :attr('role', 'complementary') :attr('aria-labelledby', args.heading ~= '' and 'documentation-heading' or nil) :attr('aria-label', args.heading == '' and 'Documentation' or nil) :newline :tag('div') -- 'documentation' :addClass(message('main-div-classes')) :newline :wikitext(p._startBox(args, env)) :wikitext(p._content(args, env)) :tag('div') -- 'documentation-clear' :addClass(message('clear')) :done :newline :done :wikitext(p._endBox(args, env)) :done :wikitext(p.addTrackingCategories(env)) -- 'Module:Documentation/styles.css' return mw.getCurrentFrame:extensionTag (		'templatestyles', '', {src=cfg['templatestyles']	}) .. tostring(root) end

-- Environment settings

function p.getEnvironment(args) --	-- Returns a table with information about the environment, including title	-- objects and other namespace- or path-related data.	-- @args - table of arguments passed by the user	--	-- Title objects include:	-- env.title - the page we are making documentation for (usually the current title)	-- env.templateTitle - the template (or module, file, etc.)	-- env.docTitle - the /doc subpage.	-- env.sandboxTitle - the /sandbox subpage.	-- env.testcasesTitle - the /testcases subpage.	--	-- Data includes:	-- env.protectionLevels - the protection levels table of the title object.	-- env.subjectSpace - the number of the title's subject namespace.	-- env.docSpace - the number of the namespace the title puts its documentation in.	-- env.docpageBase - the text of the base page of the /doc, /sandbox and /testcases pages, with namespace.	-- env.compareUrl - URL of the Special:ComparePages page comparing the sandbox with the template.	-- 	-- All table lookups are passed through pcall so that errors are caught. If an error occurs, the value	-- returned will be nil.	-- local env, envFuncs = {}, {}

-- Set up the metatable. If triggered we call the corresponding function in the envFuncs table. The value -- returned by that function is memoized in the env table so that we don't call any of the functions -- more than once. (Nils won't be memoized.) setmetatable(env, {		__index = function (t, key)			local envFunc = envFuncs[key]			if envFunc then				local success, val = pcall(envFunc)				if success then					env[key] = val -- Memoise the value.					return val				end			end			return nil		end	})

function envFuncs.title -- The title object for the current page, or a test page passed with args.page. local title local titleArg = args.page if titleArg then title = mw.title.new(titleArg) else title = mw.title.getCurrentTitle end return title end

function envFuncs.templateTitle --		-- The template (or module, etc.) title object.		-- Messages:		-- 'sandbox-subpage' --> 'sandbox'		-- 'testcases-subpage' --> 'testcases'		-- local subjectSpace = env.subjectSpace local title = env.title local subpage = title.subpageText if subpage == message('sandbox-subpage') or subpage == message('testcases-subpage') then return mw.title.makeTitle(subjectSpace, title.baseText) else return mw.title.makeTitle(subjectSpace, title.text) end end

function envFuncs.docTitle --		-- Title object of the /doc subpage.		-- Messages:		-- 'doc-subpage' --> 'doc'		-- local title = env.title local docname = args[1] -- User-specified doc page. local docpage if docname then docpage = docname else docpage = env.docpageBase .. '/' .. message('doc-subpage') end return mw.title.new(docpage) end function envFuncs.sandboxTitle --		-- Title object for the /sandbox subpage.		-- Messages:		-- 'sandbox-subpage' --> 'sandbox'		-- return mw.title.new(env.docpageBase .. '/' .. message('sandbox-subpage')) end function envFuncs.testcasesTitle --		-- Title object for the /testcases subpage.		-- Messages:		-- 'testcases-subpage' --> 'testcases'		-- return mw.title.new(env.docpageBase .. '/' .. message('testcases-subpage')) end

function envFuncs.protectionLevels -- The protection levels table of the title object. return env.title.protectionLevels end

function envFuncs.subjectSpace -- The subject namespace number. return mw.site.namespaces[env.title.namespace].subject.id	end

function envFuncs.docSpace -- The documentation namespace number. For most namespaces this is the -- same as the subject namespace. However, pages in the Article, File, -- MediaWiki or Category namespaces must have their /doc, /sandbox and -- /testcases pages in talk space. local subjectSpace = env.subjectSpace if subjectSpace == 0 or subjectSpace == 6 or subjectSpace == 8 or subjectSpace == 14 then return subjectSpace + 1 else return subjectSpace end end

function envFuncs.docpageBase -- The base page of the /doc, /sandbox, and /testcases subpages. -- For some namespaces this is the talk page, rather than the template page. local templateTitle = env.templateTitle local docSpace = env.docSpace local docSpaceText = mw.site.namespaces[docSpace].name -- Assemble the link. docSpace is never the main namespace, so we can hardcode the colon. return docSpaceText .. ':' .. templateTitle.text end function envFuncs.compareUrl -- Diff link between the sandbox and the main template using Special:ComparePages. local templateTitle = env.templateTitle local sandboxTitle = env.sandboxTitle if templateTitle.exists and sandboxTitle.exists then local compareUrl = mw.uri.fullUrl(				'Special:ComparePages',				{ page1 = templateTitle.prefixedText, page2 = sandboxTitle.prefixedText}			) return tostring(compareUrl) else return nil end end

return env end

-- Auxiliary templates

p.getModuleWikitext = makeInvokeFunc('_getModuleWikitext')

function p._getModuleWikitext(args, env) local currentTitle = mw.title.getCurrentTitle if currentTitle.contentModel ~= 'Scribunto' then return end pcall(require, currentTitle.prefixedText) -- if it fails, we don't care local moduleWikitext = package.loaded["Module:Module wikitext"] if moduleWikitext then return moduleWikitext.main end end

function p.sandboxNotice(args, env) --	local title = env.title local sandboxTitle = env.sandboxTitle local templateTitle = env.templateTitle local subjectSpace = env.subjectSpace if not (subjectSpace and title and sandboxTitle and templateTitle		and mw.title.equals(title, sandboxTitle)) then return nil end -- Build the table of arguments to pass to. We need just two fields, "image" and "text". local omargs = {} omargs.image = message('sandbox-notice-image') -- Get the text. We start with the opening blurb, which is something like -- "This is the template sandbox for Template:Foo (diff)." local text = '' local pagetype if subjectSpace == 10 then pagetype = message('sandbox-notice-pagetype-template') elseif subjectSpace == 828 then pagetype = message('sandbox-notice-pagetype-module') else pagetype = message('sandbox-notice-pagetype-other') end local templateLink = makeWikilink(templateTitle.prefixedText) local compareUrl = env.compareUrl if compareUrl then local compareDisplay = message('sandbox-notice-compare-link-display') local compareLink = makeUrlLink(compareUrl, compareDisplay) text = text .. message('sandbox-notice-diff-blurb', {pagetype, templateLink, compareLink}) else text = text .. message('sandbox-notice-blurb', {pagetype, templateLink}) end -- Get the test cases page blurb if the page exists. This is something like -- "See also the companion subpage for test cases." local testcasesTitle = env.testcasesTitle if testcasesTitle and testcasesTitle.exists then if testcasesTitle.contentModel == "Scribunto" then local testcasesLinkDisplay = message('sandbox-notice-testcases-link-display') local testcasesRunLinkDisplay = message('sandbox-notice-testcases-run-link-display') local testcasesLink = makeWikilink(testcasesTitle.prefixedText, testcasesLinkDisplay) local testcasesRunLink = makeWikilink(testcasesTitle.talkPageTitle.prefixedText, testcasesRunLinkDisplay) text = text .. ' ' .. message('sandbox-notice-testcases-run-blurb', {testcasesLink, testcasesRunLink}) else local testcasesLinkDisplay = message('sandbox-notice-testcases-link-display') local testcasesLink = makeWikilink(testcasesTitle.prefixedText, testcasesLinkDisplay) text = text .. ' ' .. message('sandbox-notice-testcases-blurb', {testcasesLink}) end end -- Add the sandbox to the sandbox category. omargs.text = text .. makeCategoryLink(message('sandbox-category'))

-- 'documentation-clear' return ' ' .. require('Module:Message box').main('ombox', omargs) end

function p.protectionTemplate(env) -- Generates the padlock icon in the top right. -- @env - environment table containing title objects, etc., generated with p.getEnvironment -- Messages: -- 'protection-template' --> 'pp-template' -- 'protection-template-args' --> {docusage = 'yes'} local protectionLevels = env.protectionLevels if not protectionLevels then return nil end local editProt = protectionLevels.edit and protectionLevels.edit[1] local moveProt = protectionLevels.move and protectionLevels.move[1] if editProt then -- The page is edit-protected. return require('Module:Protection banner')._main{ message('protection-reason-edit'), small = true }	elseif moveProt and moveProt ~= 'autoconfirmed' then -- The page is move-protected but not edit-protected. Exclude move -- protection with the level "autoconfirmed", as this is equivalent to -- no move protection at all. return require('Module:Protection banner')._main{ action = 'move', small = true }	else return nil end end

-- Start box

p.startBox = makeInvokeFunc('_startBox')

function p._startBox(args, env) --	-- This function generates the start box.	-- @args - a table of arguments passed by the user	-- @env - environment table containing title objects, etc., generated with p.getEnvironment	-- 	-- The actual work is done by p.makeStartBoxLinksData and p.renderStartBoxLinks which make	-- the [view] [edit] [history] [purge] links, and by p.makeStartBoxData and p.renderStartBox	-- which generate the box HTML.	-- env = env or p.getEnvironment(args) local links local content = args.content if not content or args[1] then -- No need to include the links if the documentation is on the template page itself. local linksData = p.makeStartBoxLinksData(args, env) if linksData then links = p.renderStartBoxLinks(linksData) end end -- Generate the start box html. local data = p.makeStartBoxData(args, env, links) if data then return p.renderStartBox(data) else -- User specified no heading. return nil end end

function p.makeStartBoxLinksData(args, env) --	-- Does initial processing of data to make the [view] [edit] [history] [purge] links.	-- @args - a table of arguments passed by the user	-- @env - environment table containing title objects, etc., generated with p.getEnvironment	-- 	-- Messages:	-- 'view-link-display' --> 'view'	-- 'edit-link-display' --> 'edit'	-- 'history-link-display' --> 'history'	-- 'purge-link-display' --> 'purge'	-- 'module-preload' --> 'Template:Documentation/preload-module-doc'	-- 'docpage-preload' --> 'Template:Documentation/preload'	-- 'create-link-display' --> 'create'	-- local subjectSpace = env.subjectSpace local title = env.title local docTitle = env.docTitle if not title or not docTitle then return nil end if docTitle.isRedirect then docTitle = docTitle.redirectTarget end

local data = {} data.title = title data.docTitle = docTitle -- View, display, edit, and purge links if /doc exists. data.viewLinkDisplay = message('view-link-display') data.editLinkDisplay = message('edit-link-display') data.historyLinkDisplay = message('history-link-display') data.purgeLinkDisplay = message('purge-link-display') -- Create link if /doc doesn't exist. local preload = args.preload if not preload then if subjectSpace == 828 then -- Module namespace preload = message('module-preload') else preload = message('docpage-preload') end end data.preload = preload data.createLinkDisplay = message('create-link-display') return data end

function p.renderStartBoxLinks(data) --	-- Generates the [view][edit][history][purge] or [create][purge] links from the data table.	-- @data - a table of data generated by p.makeStartBoxLinksData	-- local function escapeBrackets(s) -- Escapes square brackets with HTML entities. s = s:gsub('%[', '[') -- Replace square brackets with HTML entities. s = s:gsub('%]', ']') return s	end

local ret local docTitle = data.docTitle local title = data.title local purgeLink = makeUrlLink(title:fullUrl{action = 'purge'}, data.purgeLinkDisplay) if docTitle.exists then local viewLink = makeWikilink(docTitle.prefixedText, data.viewLinkDisplay) local editLink = makeUrlLink(docTitle:fullUrl{action = 'edit'}, data.editLinkDisplay) local historyLink = makeUrlLink(docTitle:fullUrl{action = 'history'}, data.historyLinkDisplay) ret = '[%s] [%s] [%s] [%s]' ret = escapeBrackets(ret) ret = mw.ustring.format(ret, viewLink, editLink, historyLink, purgeLink) else local createLink = makeUrlLink(docTitle:fullUrl{action = 'edit', preload = data.preload}, data.createLinkDisplay) ret = '[%s] [%s]' ret = escapeBrackets(ret) ret = mw.ustring.format(ret, createLink, purgeLink) end return ret end

function p.makeStartBoxData(args, env, links) --	local subjectSpace = env.subjectSpace if not subjectSpace then -- Default to an "other namespaces" namespace, so that we get at least some output -- if an error occurs. subjectSpace = 2 end local data = {} -- Heading local heading = args.heading -- Blank values are not removed. if heading == '' then -- Don't display the start box if the heading arg is defined but blank. return nil end if heading then data.heading = heading elseif subjectSpace == 10 then -- Template namespace data.heading = message('documentation-icon-wikitext') .. ' ' .. message('template-namespace-heading') elseif subjectSpace == 828 then -- Module namespace data.heading = message('documentation-icon-wikitext') .. ' ' .. message('module-namespace-heading') elseif subjectSpace == 6 then -- File namespace data.heading = message('file-namespace-heading') else data.heading = message('other-namespaces-heading') end -- Heading CSS local headingStyle = args['heading-style'] if headingStyle then data.headingStyleText = headingStyle else -- 'documentation-heading' data.headingClass = message('main-div-heading-class') end -- Data for the [view][edit][history][purge] or [create] links. if links then -- 'mw-editsection-like plainlinks' data.linksClass = message('start-box-link-classes') data.links = links end return data end

function p.renderStartBox(data) -- Renders the start box html. -- @data - a table of data generated by p.makeStartBoxData. local sbox = mw.html.create('div') sbox -- 'documentation-startbox' :addClass(message('start-box-class')) :newline :tag('span') :addClass(data.headingClass) :attr('id', 'documentation-heading') :cssText(data.headingStyleText) :wikitext(data.heading) local links = data.links if links then sbox:tag('span') :addClass(data.linksClass) :attr('id', data.linksId) :wikitext(links) end return tostring(sbox) end

-- Documentation content

p.content = makeInvokeFunc('_content')

function p._content(args, env) -- Displays the documentation contents -- @args - a table of arguments passed by the user -- @env - environment table containing title objects, etc., generated with p.getEnvironment env = env or p.getEnvironment(args) local docTitle = env.docTitle local content = args.content if not content and docTitle and docTitle.exists then content = args._content or mw.getCurrentFrame:expandTemplate{title = docTitle.prefixedText} end -- The line breaks below are necessary so that "=== Headings ===" at the start and end -- of docs are interpreted correctly. return '\n' .. (content or '') .. '\n' end

p.contentTitle = makeInvokeFunc('_contentTitle')

function p._contentTitle(args, env) env = env or p.getEnvironment(args) local docTitle = env.docTitle if not args.content and docTitle and docTitle.exists then return docTitle.prefixedText else return '' end end

-- End box

p.endBox = makeInvokeFunc('_endBox')

function p._endBox(args, env) --[=[	-- This function generates the end box (also known as the link box). -- @args - a table of arguments passed by the user -- @env - environment table containing title objects, etc., generated with p.getEnvironment -- 	--]=]	-- Get environment data. env = env or p.getEnvironment(args) local subjectSpace = env.subjectSpace local docTitle = env.docTitle if not subjectSpace or not docTitle then return nil end -- Check whether we should output the end box at all. Add the end -- box by default if the documentation exists or if we are in the -- user, module or template namespaces. local linkBox = args['link box'] if linkBox == 'off' or not (			docTitle.exists			or subjectSpace == 2			or subjectSpace == 828			or subjectSpace == 10		) then return nil end

-- Assemble the link box. local text = '' if linkBox then text = text .. linkBox else text = text .. (p.makeDocPageBlurb(args, env) or '') -- "This documentation is transcluded from Foo." if subjectSpace == 2 or subjectSpace == 10 or subjectSpace == 828 then -- We are in the user, template or module namespaces. -- Add sandbox and testcases links. -- "Editors can experiment in this template's sandbox and testcases pages." text = text .. (p.makeExperimentBlurb(args, env) or '') .. ' '			if not args.content and not args[1] then -- "Please add categories to the /doc subpage." -- Don't show this message with inline docs or with an explicitly specified doc page, -- as then it is unclear where to add the categories. text = text .. (p.makeCategoriesBlurb(args, env) or '') end text = text .. ' ' .. (p.makeSubpagesBlurb(args, env) or '') --"Subpages of this template" end end local box = mw.html.create('div') -- 'documentation-metadata' box:attr('role', 'note') :addClass(message('end-box-class')) -- 'plainlinks' :addClass(message('end-box-plainlinks')) :wikitext(text) :done

return '\n' .. tostring(box) end

function p.makeDocPageBlurb(args, env) --[=[	-- Makes the blurb "This documentation is transcluded from Template:Foo (edit, history)". -- @args - a table of arguments passed by the user -- @env - environment table containing title objects, etc., generated with p.getEnvironment -- 	-- Messages: -- 'edit-link-display' --> 'edit' -- 'history-link-display' --> 'history' -- 'transcluded-from-blurb' --> -- 'The above documentation -- is transcluded from $1.' -- 'module-preload' --> 'Template:Documentation/preload-module-doc' -- 'create-link-display' --> 'create' -- 'create-module-doc-blurb' --> -- 'You might want to $1 a documentation page for this Scribunto module.' --]=]	local docTitle = env.docTitle if not docTitle then return nil end local ret if docTitle.exists then -- /doc exists; link to it. local docLink = makeWikilink(docTitle.prefixedText) local editUrl = docTitle:fullUrl{action = 'edit'} local editDisplay = message('edit-link-display') local editLink = makeUrlLink(editUrl, editDisplay) local historyUrl = docTitle:fullUrl{action = 'history'} local historyDisplay = message('history-link-display') local historyLink = makeUrlLink(historyUrl, historyDisplay) ret = message('transcluded-from-blurb', {docLink}) .. ' '			.. makeToolbar(editLink, historyLink) .. ' '	elseif env.subjectSpace == 828 then -- /doc does not exist; ask to create it. local createUrl = docTitle:fullUrl{action = 'edit', preload = message('module-preload')} local createDisplay = message('create-link-display') local createLink = makeUrlLink(createUrl, createDisplay) ret = message('create-module-doc-blurb', {createLink}) .. ' '	end return ret end

function p.makeExperimentBlurb(args, env) -- diff) and testcases (edit) pages."	-- @args - a table of arguments passed by the user	-- @env - environment table containing title objects, etc., generated with p.getEnvironment	-- 	-- Messages:	-- 'sandbox-link-display' --> 'sandbox'	-- 'sandbox-edit-link-display' --> 'edit'	-- 'compare-link-display' --> 'diff'	-- 'module-sandbox-preload' --> 'Template:Documentation/preload-module-sandbox'	-- 'template-sandbox-preload' --> 'Template:Documentation/preload-sandbox'	-- 'sandbox-create-link-display' --> 'create'	-- 'mirror-edit-summary' --> 'Create sandbox version of $1'	-- 'mirror-link-display' --> 'mirror'	-- 'mirror-link-preload' --> 'Template:Documentation/mirror'	-- 'sandbox-link-display' --> 'sandbox'	-- 'testcases-link-display' --> 'testcases'	-- 'testcases-edit-link-display'--> 'edit'	-- 'template-sandbox-preload' --> 'Template:Documentation/preload-sandbox'	-- 'testcases-create-link-display' --> 'create'	-- 'testcases-link-display' --> 'testcases'	-- 'testcases-edit-link-display' --> 'edit'	-- 'module-testcases-preload' --> 'Template:Documentation/preload-module-testcases'	-- 'template-testcases-preload' --> 'Template:Documentation/preload-testcases'	-- 'experiment-blurb-module' --> 'Editors can experiment in this module's $1 and $2 pages.'	-- 'experiment-blurb-template' --> 'Editors can experiment in this template's $1 and $2 pages.'	-- local subjectSpace = env.subjectSpace local templateTitle = env.templateTitle local sandboxTitle = env.sandboxTitle local testcasesTitle = env.testcasesTitle local templatePage = templateTitle.prefixedText if not subjectSpace or not templateTitle or not sandboxTitle or not testcasesTitle then return nil end -- Make links. local sandboxLinks, testcasesLinks if sandboxTitle.exists then local sandboxPage = sandboxTitle.prefixedText local sandboxDisplay = message('sandbox-link-display') local sandboxLink = makeWikilink(sandboxPage, sandboxDisplay) local sandboxEditUrl = sandboxTitle:fullUrl{action = 'edit'} local sandboxEditDisplay = message('sandbox-edit-link-display') local sandboxEditLink = makeUrlLink(sandboxEditUrl, sandboxEditDisplay) local compareUrl = env.compareUrl local compareLink if compareUrl then local compareDisplay = message('compare-link-display') compareLink = makeUrlLink(compareUrl, compareDisplay) end sandboxLinks = sandboxLink .. ' ' .. makeToolbar(sandboxEditLink, compareLink) else local sandboxPreload if subjectSpace == 828 then sandboxPreload = message('module-sandbox-preload') else sandboxPreload = message('template-sandbox-preload') end local sandboxCreateUrl = sandboxTitle:fullUrl{action = 'edit', preload = sandboxPreload} local sandboxCreateDisplay = message('sandbox-create-link-display') local sandboxCreateLink = makeUrlLink(sandboxCreateUrl, sandboxCreateDisplay) local mirrorSummary = message('mirror-edit-summary', {makeWikilink(templatePage)}) local mirrorPreload = message('mirror-link-preload') local mirrorUrl = sandboxTitle:fullUrl{action = 'edit', preload = mirrorPreload, summary = mirrorSummary} if subjectSpace == 828 then mirrorUrl = sandboxTitle:fullUrl{action = 'edit', preload = templateTitle.prefixedText, summary = mirrorSummary} end local mirrorDisplay = message('mirror-link-display') local mirrorLink = makeUrlLink(mirrorUrl, mirrorDisplay) sandboxLinks = message('sandbox-link-display') .. ' ' .. makeToolbar(sandboxCreateLink, mirrorLink) end if testcasesTitle.exists then local testcasesPage = testcasesTitle.prefixedText local testcasesDisplay = message('testcases-link-display') local testcasesLink = makeWikilink(testcasesPage, testcasesDisplay) local testcasesEditUrl = testcasesTitle:fullUrl{action = 'edit'} local testcasesEditDisplay = message('testcases-edit-link-display') local testcasesEditLink = makeUrlLink(testcasesEditUrl, testcasesEditDisplay) -- for Modules, add testcases run link if exists if testcasesTitle.contentModel == "Scribunto" and testcasesTitle.talkPageTitle and testcasesTitle.talkPageTitle.exists then local testcasesRunLinkDisplay = message('testcases-run-link-display') local testcasesRunLink = makeWikilink(testcasesTitle.talkPageTitle.prefixedText, testcasesRunLinkDisplay) testcasesLinks = testcasesLink .. ' ' .. makeToolbar(testcasesEditLink, testcasesRunLink) else testcasesLinks = testcasesLink .. ' ' .. makeToolbar(testcasesEditLink) end else local testcasesPreload if subjectSpace == 828 then testcasesPreload = message('module-testcases-preload') else testcasesPreload = message('template-testcases-preload') end local testcasesCreateUrl = testcasesTitle:fullUrl{action = 'edit', preload = testcasesPreload} local testcasesCreateDisplay = message('testcases-create-link-display') local testcasesCreateLink = makeUrlLink(testcasesCreateUrl, testcasesCreateDisplay) testcasesLinks = message('testcases-link-display') .. ' ' .. makeToolbar(testcasesCreateLink) end local messageName if subjectSpace == 828 then messageName = 'experiment-blurb-module' else messageName = 'experiment-blurb-template' end return message(messageName, {sandboxLinks, testcasesLinks}) end

function p.makeCategoriesBlurb(args, env) --	-- Generates the text "Please add categories to the /doc subpage."	-- @args - a table of arguments passed by the user	-- @env - environment table containing title objects, etc., generated with p.getEnvironment	-- Messages:	-- 'doc-link-display' --> '/doc'	-- 'add-categories-blurb' --> 'Please add categories to the $1 subpage.'	-- local docTitle = env.docTitle if not docTitle then return nil end local docPathLink = makeWikilink(docTitle.prefixedText, message('doc-link-display')) return message('add-categories-blurb', {docPathLink}) end

function p.makeSubpagesBlurb(args, env) --	-- Generates the "Subpages of this template" link.	-- @args - a table of arguments passed by the user	-- @env - environment table containing title objects, etc., generated with p.getEnvironment	-- Messages:	-- 'template-pagetype' --> 'template'	-- 'module-pagetype' --> 'module'	-- 'default-pagetype' --> 'page'	-- 'subpages-link-display' --> 'Subpages of this $1'	-- local subjectSpace = env.subjectSpace local templateTitle = env.templateTitle if not subjectSpace or not templateTitle then return nil end local pagetype if subjectSpace == 10 then pagetype = message('template-pagetype') elseif subjectSpace == 828 then pagetype = message('module-pagetype') else pagetype = message('default-pagetype') end local subpagesLink = makeWikilink(		'Special:PrefixIndex/' .. templateTitle.prefixedText .. '/',		message('subpages-link-display', {pagetype})	) return message('subpages-blurb', {subpagesLink}) end

-- Tracking categories

function p.addTrackingCategories(env) --	-- Check if is transcluded on a /doc or /testcases page.	-- @env - environment table containing title objects, etc., generated with p.getEnvironment	-- Messages:	-- 'display-strange-usage-category' --> true	-- 'doc-subpage' --> 'doc'	-- 'testcases-subpage' --> 'testcases'	-- 'strange-usage-category' --> 'Wikibooks pages with strange ((documentation)) usage'	-- 	-- /testcases pages in the module namespace are not categorised, as they may have	--  transcluded automatically.	-- local title = env.title local subjectSpace = env.subjectSpace if not title or not subjectSpace then return nil end local subpage = title.subpageText local ret = '' if message('display-strange-usage-category', nil, 'boolean') and (			subpage == message('doc-subpage')			or subjectSpace ~= 828 and subpage == message('testcases-subpage')		) then ret = ret .. makeCategoryLink(message('strange-usage-category')) end return ret end

return p

title: Module:Documentation


text:
Module:Uses TemplateStyles

local yesno = require('Module:Yesno') local mList = require('Module:List') local mTableTools = require('Module:TableTools') local mMessageBox = require('Module:Message box') local TNT = require('Module:TNT')

local p = {}

local function format(msg, ...) return TNT.format('I18n/Uses TemplateStyles', msg, ...) end

local function getConfig return mw.loadData('Module:Uses TemplateStyles/config') end

local function renderBox(tStyles) local boxArgs = { type = 'notice', small = true, image = string.format('', format('logo-alt')) }	if #tStyles < 1 then boxArgs.text = string.format(' %s ', format('error-emptylist')) else local cfg = getConfig local tStylesLinks = {} for i, ts in ipairs(tStyles) do			local link = string.format('%s', ts) local sandboxLink = nil local tsTitle = mw.title.new(ts) if tsTitle and cfg['sandbox_title'] then local tsSandboxTitle = mw.title.new(string.format( '%s:%s/%s/%s', tsTitle.nsText, tsTitle.baseText, cfg['sandbox_title'], tsTitle.subpageText)) if tsSandboxTitle and tsSandboxTitle.exists then sandboxLink = format('sandboxlink', link, ':' .. tsSandboxTitle.prefixedText) end end tStylesLinks[i] = sandboxLink or link end local tStylesList = mList.makeList('bulleted', tStylesLinks) boxArgs.text = format(			mw.title.getCurrentTitle:inNamespaces(828,829) and 'header-module' or 'header-template') .. '\n' .. tStylesList end return mMessageBox.main('mbox', boxArgs) end

local function renderTrackingCategories(args, tStyles, titleObj) if yesno(args.nocat) then return '' end local cfg = getConfig local cats = {} -- Error category if #tStyles < 1 and cfg['error_category'] then cats[#cats + 1] = cfg['error_category'] end -- TemplateStyles category titleObj = titleObj or mw.title.getCurrentTitle if (titleObj.namespace == 10 or titleObj.namespace == 828) and not cfg['subpage_blacklist'][titleObj.subpageText] then local category = args.category or cfg['default_category'] if category then cats[#cats + 1] = category end if not yesno(args.noprotcat) and (cfg['protection_conflict_category'] or cfg['padlock_pattern']) then local currentProt = titleObj.protectionLevels["edit"] and titleObj.protectionLevels["edit"][1] or nil local addedLevelCat = false local addedPadlockCat = false 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 cfg['padlock_pattern'] and tsProt and not addedPadlockCat then local content = tsTitleObj:getContent if not content:find(cfg['padlock_pattern']) then cats[#cats + 1] = cfg['missing_padlock_category'] addedPadlockCat = true end end if cfg['protection_conflict_category'] and currentProt and tsProt ~= currentProt and not addedLevelCat then currentProt = cfg['protection_hierarchy'][currentProt] or 0 tsProt = cfg['protection_hierarchy'][tsProt] or 0 if tsProt < currentProt then addedLevelCat = true cats[#cats + 1] = cfg['protection_conflict_category'] end end end end end for i, cat in ipairs(cats) do		cats[i] = string.format('', cat) end return table.concat(cats) end

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

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

return p

title: Module:Uses TemplateStyles


text:
Module:Documentation/config

-- --                              Configuration for Module:Documentation -- -- Here you can set the values of the parameters and messages used in Module:Documentation to -- localise it to your wiki and your language. Unless specified otherwise, values given here -- should be string values.

local cfg = {} -- Do not edit this line.

-- Protection template configuration

-- cfg['protection-reason-edit'] -- The protection reason for edit-protected templates to pass to -- Module:Protection banner. cfg['protection-reason-edit'] = 'template'

--[[

-- Sandbox notice configuration -- -- On sandbox pages the module can display a template notifying users that the current page is a -- sandbox, and the location of test cases pages, etc. The module decides whether the page is a -- sandbox or not based on the value of cfg['sandbox-subpage']. The following settings configure the -- messages that the notices contains.

--]]

-- cfg['sandbox-notice-image'] -- The image displayed in the sandbox notice. cfg['sandbox-notice-image'] = ''

-- -- cfg['sandbox-notice-pagetype-template'] -- cfg['sandbox-notice-pagetype-module'] -- cfg['sandbox-notice-pagetype-other'] -- The page type of the sandbox page. The message that is displayed depends on the current subject -- namespace. This message is used in either cfg['sandbox-notice-blurb'] or -- cfg['sandbox-notice-diff-blurb']. -- cfg['sandbox-notice-pagetype-template'] = 'template sandbox page' cfg['sandbox-notice-pagetype-module'] = 'module sandbox page' cfg['sandbox-notice-pagetype-other'] = 'sandbox page'

-- -- cfg['sandbox-notice-blurb'] -- cfg['sandbox-notice-diff-blurb'] -- cfg['sandbox-notice-diff-display'] -- Either cfg['sandbox-notice-blurb'] or cfg['sandbox-notice-diff-blurb'] is the opening sentence -- of the sandbox notice. The latter has a diff link, but the former does not. $1 is the page -- type, which is either cfg['sandbox-notice-pagetype-template'], -- cfg['sandbox-notice-pagetype-module'] or cfg['sandbox-notice-pagetype-other'] depending what -- namespace we are in. $2 is a link to the main template page, and $3 is a diff link between -- the sandbox and the main template. The display value of the diff link is set by -- cfg['sandbox-notice-compare-link-display']. -- cfg['sandbox-notice-blurb'] = 'This is the $1 for $2.' cfg['sandbox-notice-diff-blurb'] = 'This is the $1 for $2 ($3).' cfg['sandbox-notice-compare-link-display'] = 'diff'

-- -- cfg['sandbox-notice-testcases-blurb'] -- cfg['sandbox-notice-testcases-link-display'] -- cfg['sandbox-notice-testcases-run-blurb'] -- cfg['sandbox-notice-testcases-run-link-display'] -- cfg['sandbox-notice-testcases-blurb'] is a sentence notifying the user that there is a test cases page -- corresponding to this sandbox that they can edit. $1 is a link to the test cases page. -- cfg['sandbox-notice-testcases-link-display'] is the display value for that link. -- cfg['sandbox-notice-testcases-run-blurb'] is a sentence notifying the user that there is a test cases page -- corresponding to this sandbox that they can edit, along with a link to run it. $1 is a link to the test -- cases page, and $2 is a link to the page to run it. -- cfg['sandbox-notice-testcases-run-link-display'] is the display value for the link to run the test -- cases. -- cfg['sandbox-notice-testcases-blurb'] = 'See also the companion subpage for $1.' cfg['sandbox-notice-testcases-link-display'] = 'test cases' cfg['sandbox-notice-testcases-run-blurb'] = 'See also the companion subpage for $1 ($2).' cfg['sandbox-notice-testcases-run-link-display'] = 'run'

-- cfg['sandbox-category'] -- A category to add to all template sandboxes. cfg['sandbox-category'] = 'Template sandboxes'

-- Start box configuration

-- cfg['documentation-icon-wikitext'] -- The wikitext for the icon shown at the top of the template. cfg['documentation-icon-wikitext'] = ''

-- cfg['template-namespace-heading'] -- The heading shown in the template namespace. cfg['template-namespace-heading'] = 'Template documentation'

-- cfg['module-namespace-heading'] -- The heading shown in the module namespace. cfg['module-namespace-heading'] = 'Module documentation'

-- cfg['file-namespace-heading'] -- The heading shown in the file namespace. cfg['file-namespace-heading'] = 'Summary'

-- cfg['other-namespaces-heading'] -- The heading shown in other namespaces. cfg['other-namespaces-heading'] = 'Documentation'

-- cfg['view-link-display'] -- The text to display for "view" links. cfg['view-link-display'] = 'view'

-- cfg['edit-link-display'] -- The text to display for "edit" links. cfg['edit-link-display'] = 'edit'

-- cfg['history-link-display'] -- The text to display for "history" links. cfg['history-link-display'] = 'history'

-- cfg['purge-link-display'] -- The text to display for "purge" links. cfg['purge-link-display'] = 'purge'

-- cfg['create-link-display'] -- The text to display for "create" links. cfg['create-link-display'] = 'create'

-- Link box (end box) configuration

-- cfg['transcluded-from-blurb'] -- Notice displayed when the docs are transcluded from another page. $1 is a wikilink to that page. cfg['transcluded-from-blurb'] = 'The above documentation is transcluded from $1.'

-- -- cfg['create-module-doc-blurb'] -- Notice displayed in the module namespace when the documentation subpage does not exist. -- $1 is a link to create the documentation page with the preload cfg['module-preload'] and the -- display cfg['create-link-display']. -- cfg['create-module-doc-blurb'] = 'You might want to $1 a documentation page for this Scribunto module.'

-- Experiment blurb configuration

--[[ -- cfg['experiment-blurb-template'] -- cfg['experiment-blurb-module'] -- The experiment blurb is the text inviting editors to experiment in sandbox and test cases pages. -- It is only shown in the template and module namespaces. With the default English settings, it -- might look like this: -- -- Editors can experiment in this template's sandbox (edit | diff) and testcases (edit) pages. -- -- In this example, "sandbox", "edit", "diff", "testcases", and "edit" would all be links. -- -- There are two versions, cfg['experiment-blurb-template'] and cfg['experiment-blurb-module'], depending -- on what namespace we are in. -- -- Parameters: -- -- $1 is a link to the sandbox page. If the sandbox exists, it is in the following format: -- --    cfg['sandbox-link-display'] (cfg['sandbox-edit-link-display'] | cfg['compare-link-display']) -- -- If the sandbox doesn't exist, it is in the format: -- --     cfg['sandbox-link-display'] (cfg['sandbox-create-link-display'] | cfg['mirror-link-display']) -- -- The link for cfg['sandbox-create-link-display'] link preloads the page with cfg['template-sandbox-preload'] -- or cfg['module-sandbox-preload'], depending on the current namespace. The link for cfg['mirror-link-display'] -- loads a default edit summary of cfg['mirror-edit-summary']. -- -- $2 is a link to the test cases page. If the test cases page exists, it is in the following format: -- --     cfg['testcases-link-display'] (cfg['testcases-edit-link-display'] | cfg['testcases-run-link-display']) -- -- If the test cases page doesn't exist, it is in the format: -- --     cfg['testcases-link-display'] (cfg['testcases-create-link-display']) -- -- If the test cases page doesn't exist, the link for cfg['testcases-create-link-display'] preloads the -- page with cfg['template-testcases-preload'] or cfg['module-testcases-preload'], depending on the current -- namespace. --]] cfg['experiment-blurb-template'] = "Editors can experiment in this template's $1 and $2 pages." cfg['experiment-blurb-module'] = "Editors can experiment in this module's $1 and $2 pages."

-- Sandbox link configuration

-- cfg['sandbox-subpage'] -- The name of the template subpage typically used for sandboxes. cfg['sandbox-subpage'] = 'sandbox'

-- cfg['template-sandbox-preload'] -- Preload file for template sandbox pages. cfg['template-sandbox-preload'] = 'Template:Documentation/preload-sandbox'

-- cfg['module-sandbox-preload'] -- Preload file for Lua module sandbox pages. cfg['module-sandbox-preload'] = 'Template:Documentation/preload-module-sandbox'

-- cfg['sandbox-link-display'] -- The text to display for "sandbox" links. cfg['sandbox-link-display'] = 'sandbox'

-- cfg['sandbox-edit-link-display'] -- The text to display for sandbox "edit" links. cfg['sandbox-edit-link-display'] = 'edit'

-- cfg['sandbox-create-link-display'] -- The text to display for sandbox "create" links. cfg['sandbox-create-link-display'] = 'create'

-- cfg['compare-link-display'] -- The text to display for "compare" links. cfg['compare-link-display'] = 'diff'

-- cfg['mirror-edit-summary'] -- The default edit summary to use when a user clicks the "mirror" link. $1 is a wikilink to the -- template page. cfg['mirror-edit-summary'] = 'Create sandbox version of $1'

-- cfg['mirror-link-display'] -- The text to display for "mirror" links. cfg['mirror-link-display'] = 'mirror'

-- cfg['mirror-link-preload'] -- The page to preload when a user clicks the "mirror" link. cfg['mirror-link-preload'] = 'Template:Documentation/mirror'

-- Test cases link configuration

-- cfg['testcases-subpage'] -- The name of the template subpage typically used for test cases. cfg['testcases-subpage'] = 'testcases'

-- cfg['template-testcases-preload'] -- Preload file for template test cases pages. cfg['template-testcases-preload'] = 'Template:Documentation/preload-testcases'

-- cfg['module-testcases-preload'] -- Preload file for Lua module test cases pages. cfg['module-testcases-preload'] = 'Template:Documentation/preload-module-testcases'

-- cfg['testcases-link-display'] -- The text to display for "testcases" links. cfg['testcases-link-display'] = 'testcases'

-- cfg['testcases-edit-link-display'] -- The text to display for test cases "edit" links. cfg['testcases-edit-link-display'] = 'edit'

-- cfg['testcases-run-link-display'] -- The text to display for test cases "run" links. cfg['testcases-run-link-display'] = 'run'

-- cfg['testcases-create-link-display'] -- The text to display for test cases "create" links. cfg['testcases-create-link-display'] = 'create'

-- Add categories blurb configuration

-- -- cfg['add-categories-blurb'] -- Text to direct users to add categories to the /doc subpage. Not used if the "content" or -- "docname fed" arguments are set, as then it is not clear where to add the categories. $1 is a -- link to the /doc subpage with a display value of cfg['doc-link-display']. -- cfg['add-categories-blurb'] = 'Add categories to the $1 subpage.'

-- cfg['doc-link-display'] -- The text to display when linking to the /doc subpage. cfg['doc-link-display'] = '/doc'

-- Subpages link configuration

-- -- cfg['subpages-blurb'] -- The "Subpages of this template" blurb. $1 is a link to the main template's subpages with a -- display value of cfg['subpages-link-display']. In the English version this blurb is simply -- the link followed by a period, and the link display provides the actual text. -- cfg['subpages-blurb'] = '$1.'

-- -- cfg['subpages-link-display'] -- The text to display for the "subpages of this page" link. $1 is cfg['template-pagetype'], -- cfg['module-pagetype'] or cfg['default-pagetype'], depending on whether the current page is in -- the template namespace, the module namespace, or another namespace. -- cfg['subpages-link-display'] = 'Subpages of this $1'

-- cfg['template-pagetype'] -- The pagetype to display for template pages. cfg['template-pagetype'] = 'template'

-- cfg['module-pagetype'] -- The pagetype to display for Lua module pages. cfg['module-pagetype'] = 'module'

-- cfg['default-pagetype'] -- The pagetype to display for pages other than templates or Lua modules. cfg['default-pagetype'] = 'page'

-- Doc link configuration

-- cfg['doc-subpage'] -- The name of the subpage typically used for documentation pages. cfg['doc-subpage'] = 'doc'

-- cfg['docpage-preload'] -- Preload file for template documentation pages in all namespaces. cfg['docpage-preload'] = 'Template:Documentation/preload'

-- cfg['module-preload'] -- Preload file for Lua module documentation pages. cfg['module-preload'] = 'Template:Documentation/preload-module-doc'

-- HTML and CSS configuration

-- cfg['templatestyles'] -- The name of the TemplateStyles page where CSS is kept. -- Sandbox CSS will be at Module:Documentation/sandbox/styles.css when needed. cfg['templatestyles'] = 'Module:Documentation/styles.css'

-- cfg['container'] -- Class which can be used to set flex or grid CSS on the -- two child divs documentation and documentation-metadata cfg['container'] = 'documentation-container'

-- cfg['main-div-classes'] -- Classes added to the main HTML "div" tag. cfg['main-div-classes'] = 'documentation'

-- cfg['main-div-heading-class'] -- Class for the main heading for templates and modules and assoc. talk spaces cfg['main-div-heading-class'] = 'documentation-heading'

-- cfg['start-box-class'] -- Class for the start box cfg['start-box-class'] = 'documentation-startbox'

-- cfg['start-box-link-classes'] -- Classes used for the [view][edit][history] or [create] links in the start box. -- mw-editsection-like is per Village pump (technical)/Archive 117 cfg['start-box-link-classes'] = 'mw-editsection-like plainlinks'

-- cfg['end-box-class'] -- Class for the end box. cfg['end-box-class'] = 'documentation-metadata'

-- cfg['end-box-plainlinks'] -- Plainlinks cfg['end-box-plainlinks'] = 'plainlinks'

-- cfg['toolbar-class'] -- Class added for toolbar links. cfg['toolbar-class'] = 'documentation-toolbar'

-- cfg['clear'] -- Just used to clear things. cfg['clear'] = 'documentation-clear'

-- Tracking category configuration

-- cfg['display-strange-usage-category'] -- Set to true to enable output of cfg['strange-usage-category'] if the module is used on a /doc subpage -- or a /testcases subpage. This should be a boolean value (either true or false). cfg['display-strange-usage-category'] = true

-- cfg['strange-usage-category'] -- Category to output if cfg['display-strange-usage-category'] is set to true and the module is used on a -- /doc subpage or a /testcases subpage. cfg['strange-usage-category'] = 'Wikibooks pages with strange ((documentation)) usage'

--[[

-- End configuration -- -- Don't edit anything below this line.

--]]

return cfg

title: Module:Documentation/config


text:
Module:Protection banner

-- This module implements and its daughter templates such as --,  and.

-- Initialise necessary modules. require('strict') local makeFileLink = require('Module:File link')._main local effectiveProtectionLevel = require('Module:Effective protection level')._main local effectiveProtectionExpiry = require('Module:Effective protection expiry')._main local yesno = require('Module:Yesno')

-- Lazily initialise modules and objects we don't always need. local getArgs, makeMessageBox, lang

-- Set constants. local CONFIG_MODULE = 'Module:Protection banner/config'

-- Helper functions

local function makeCategoryLink(cat, sort) if cat then return string.format(			'%s',			mw.site.namespaces[14].name,			cat,			sort		) end end

-- Validation function for the expiry and the protection date local function validateDate(dateString, dateType) if not lang then lang = mw.language.getContentLanguage end local success, result = pcall(lang.formatDate, lang, 'U', dateString) if success then result = tonumber(result) if result then return result end end error(string.format( 'invalid %s: %s', dateType, tostring(dateString) ), 4) end

local function makeFullUrl(page, query, display) return string.format(		'[%s %s]',		tostring(mw.uri.fullUrl(page, query)),		display	) end

-- Given a directed graph formatted as node -> table of direct successors, -- get a table of all nodes reachable from a given node (though always -- including the given node). local function getReachableNodes(graph, start) local toWalk, retval = {[start] = true}, {} while true do		-- Can't use pairs since we're adding and removing things as we're iterating local k = next(toWalk) -- This always gets the "first" key if k == nil then return retval end toWalk[k] = nil retval[k] = true for _,v in ipairs(graph[k]) do			if not retval[v] then toWalk[v] = true end end end end

-- Protection class

local Protection = {} Protection.__index = Protection

Protection.supportedActions = { edit = true, move = true, autoreview = true, upload = true }

Protection.bannerConfigFields = { 'text', 'explanation', 'tooltip', 'alt', 'link', 'image' }

function Protection.new(args, cfg, title) local obj = {} obj._cfg = cfg obj.title = title or mw.title.getCurrentTitle

-- Set action if not args.action then obj.action = 'edit' elseif Protection.supportedActions[args.action] then obj.action = args.action else error(string.format( 'invalid action: %s', tostring(args.action) ), 3)	end

-- Set level obj.level = args.demolevel or effectiveProtectionLevel(obj.action, obj.title) if not obj.level or (obj.action == 'move' and obj.level == 'autoconfirmed') then -- Users need to be autoconfirmed to move pages anyway, so treat -- semi-move-protected pages as unprotected. obj.level = '*' end

-- Set expiry local effectiveExpiry = effectiveProtectionExpiry(obj.action, obj.title) if effectiveExpiry == 'infinity' then obj.expiry = 'indef' elseif effectiveExpiry ~= 'unknown' then obj.expiry = validateDate(effectiveExpiry, 'expiry date') end

-- Set reason if args[1] then obj.reason = mw.ustring.lower(args[1]) if obj.reason:find('|') then error('reasons cannot contain the pipe character ("|")', 3) end end

-- Set protection date if args.date then obj.protectionDate = validateDate(args.date, 'protection date') end -- Set banner config do obj.bannerConfig = {} local configTables = {} if cfg.banners[obj.action] then configTables[#configTables + 1] = cfg.banners[obj.action][obj.reason] end if cfg.defaultBanners[obj.action] then configTables[#configTables + 1] = cfg.defaultBanners[obj.action][obj.level] configTables[#configTables + 1] = cfg.defaultBanners[obj.action].default end configTables[#configTables + 1] = cfg.masterBanner for i, field in ipairs(Protection.bannerConfigFields) do			for j, t in ipairs(configTables) do				if t[field] then obj.bannerConfig[field] = t[field] break end end end end return setmetatable(obj, Protection) end

function Protection:isProtected return self.level ~= '*' end

function Protection:isTemporary return type(self.expiry) == 'number' end

function Protection:makeProtectionCategory local cfg = self._cfg local title = self.title -- Exit if the page is not protected. if not self:isProtected then return '' end -- Get the expiry key fragment. local expiryFragment if self.expiry == 'indef' then expiryFragment = self.expiry elseif type(self.expiry) == 'number' then expiryFragment = 'temp' end

-- Get the namespace key fragment. local namespaceFragment = cfg.categoryNamespaceKeys[title.namespace] if not namespaceFragment and title.namespace % 2 == 1 then namespaceFragment = 'talk' end -- Define the order that key fragments are tested in. This is done with an	-- array of tables containing the value to be tested, along with its -- position in the cfg.protectionCategories table. local order = { {val = expiryFragment,   keypos = 1}, {val = namespaceFragment, keypos = 2}, {val = self.reason,      keypos = 3}, {val = self.level,       keypos = 4}, {val = self.action,      keypos = 5} }

--	-- The old protection templates used an ad-hoc protection category system,	-- with some templates prioritising namespaces in their categories, and	-- others prioritising the protection reason. To emulate this in this module	-- we use the config table cfg.reasonsWithNamespacePriority to set the	-- reasons for which namespaces have priority over protection reason.	-- If we are dealing with one of those reasons, move the namespace table to	-- the end of the order table, i.e. give it highest priority. If not, the	-- reason should have highest priority, so move that to the end of the table	-- instead.	-- table.insert(order, table.remove(order, self.reason and cfg.reasonsWithNamespacePriority[self.reason] and 2 or 3)) --	-- Define the attempt order. Inactive subtables (subtables with nil "value"	-- fields) are moved to the end, where they will later be given the key	-- "all". This is to cut down on the number of table lookups in	-- cfg.protectionCategories, which grows exponentially with the number of	-- non-nil keys. We keep track of the number of active subtables with the	-- noActive parameter.	-- local noActive, attemptOrder do local active, inactive = {}, {} for i, t in ipairs(order) do			if t.val then active[#active + 1] = t			else inactive[#inactive + 1] = t			end end noActive = #active attemptOrder = active for i, t in ipairs(inactive) do			attemptOrder[#attemptOrder + 1] = t		end end --	-- Check increasingly generic key combinations until we find a match. If a	-- specific category exists for the combination of key fragments we are	-- given, that match will be found first. If not, we keep trying different	-- key fragment combinations until we match using the key	-- "all-all-all-all-all".	--	-- To generate the keys, we index the key subtables using a binary matrix	-- with indexes i and j. j is only calculated up to the number of active	-- subtables. For example, if there were three active subtables, the matrix	-- would look like this, with 0 corresponding to the key fragment "all", and	-- 1 corresponding to other key fragments.	-- 	--  j 1  2  3	-- i  	-- 1   1  1  1	-- 2   0  1  1	-- 3   1  0  1	-- 4   0  0  1	-- 5   1  1  0	-- 6   0  1  0	-- 7   1  0  0	-- 8   0  0  0	-- 	-- Values of j higher than the number of active subtables are set	-- to the string "all".	--	-- A key for cfg.protectionCategories is constructed for each value of i.	-- The position of the value in the key is determined by the keypos field in	-- each subtable.	-- local cats = cfg.protectionCategories for i = 1, 2^noActive do		local key = {} for j, t in ipairs(attemptOrder) do			if j > noActive then key[t.keypos] = 'all' else local quotient = i / 2 ^ (j - 1) quotient = math.ceil(quotient) if quotient % 2 == 1 then key[t.keypos] = t.val else key[t.keypos] = 'all' end end end key = table.concat(key, '|') local attempt = cats[key] if attempt then return makeCategoryLink(attempt, title.text) end end return '' end

function Protection:isIncorrect local expiry = self.expiry return not self:isProtected or type(expiry) == 'number' and expiry < os.time end

function Protection:isTemplateProtectedNonTemplate local action, namespace = self.action, self.title.namespace return self.level == 'templateeditor' and (			(action ~= 'edit' and action ~= 'move')			or (namespace ~= 10 and namespace ~= 828)		) end

function Protection:makeCategoryLinks local msg = self._cfg.msg local ret = { self:makeProtectionCategory } if self:isIncorrect then ret[#ret + 1] = makeCategoryLink(			msg['tracking-category-incorrect'],			self.title.text		) end if self:isTemplateProtectedNonTemplate then ret[#ret + 1] = makeCategoryLink(			msg['tracking-category-template'],			self.title.text		) end return table.concat(ret) end

-- Blurb class

local Blurb = {} Blurb.__index = Blurb

Blurb.bannerTextFields = { text = true, explanation = true, tooltip = true, alt = true, link = true }

function Blurb.new(protectionObj, args, cfg) return setmetatable({		_cfg = cfg,		_protectionObj = protectionObj,		_args = args	}, Blurb) end

-- Private methods --

function Blurb:_formatDate(num) -- Formats a Unix timestamp into dd Month, YYYY format. lang = lang or mw.language.getContentLanguage local success, date = pcall(		lang.formatDate,		lang,		self._cfg.msg['expiry-date-format'] or 'j F Y',		'@' .. tostring(num)	) if success then return date end end

function Blurb:_getExpandedMessage(msgKey) return self:_substituteParameters(self._cfg.msg[msgKey]) end

function Blurb:_substituteParameters(msg) if not self._params then local parameterFuncs = {}

parameterFuncs.CURRENTVERSION    = self._makeCurrentVersionParameter parameterFuncs.EDITREQUEST       = self._makeEditRequestParameter parameterFuncs.EXPIRY            = self._makeExpiryParameter parameterFuncs.EXPLANATIONBLURB  = self._makeExplanationBlurbParameter parameterFuncs.IMAGELINK         = self._makeImageLinkParameter parameterFuncs.INTROBLURB        = self._makeIntroBlurbParameter parameterFuncs.INTROFRAGMENT     = self._makeIntroFragmentParameter parameterFuncs.PAGETYPE          = self._makePagetypeParameter parameterFuncs.PROTECTIONBLURB   = self._makeProtectionBlurbParameter parameterFuncs.PROTECTIONDATE    = self._makeProtectionDateParameter parameterFuncs.PROTECTIONLEVEL   = self._makeProtectionLevelParameter parameterFuncs.PROTECTIONLOG     = self._makeProtectionLogParameter parameterFuncs.TALKPAGE          = self._makeTalkPageParameter parameterFuncs.TOOLTIPBLURB      = self._makeTooltipBlurbParameter parameterFuncs.TOOLTIPFRAGMENT   = self._makeTooltipFragmentParameter parameterFuncs.VANDAL            = self._makeVandalTemplateParameter self._params = setmetatable({}, {			__index = function (t, k)				local param				if parameterFuncs[k] then					param = parameterFuncs[k](self)				end				param = param or ''				t[k] = param				return param			end		}) end msg = msg:gsub('${(%u+)}', self._params) return msg end

function Blurb:_makeCurrentVersionParameter -- A link to the page history or the move log, depending on the kind of -- protection. local pagename = self._protectionObj.title.prefixedText if self._protectionObj.action == 'move' then -- We need the move log link. return makeFullUrl(			'Special:Log',			{type = 'move', page = pagename},			self:_getExpandedMessage('current-version-move-display')		) else -- We need the history link. return makeFullUrl(			pagename,			{action = 'history'},			self:_getExpandedMessage('current-version-edit-display')		) end end

function Blurb:_makeEditRequestParameter local mEditRequest = require('Module:Submit an edit request') local action = self._protectionObj.action local level = self._protectionObj.level -- Get the edit request type. local requestType if action == 'edit' then if level == 'autoconfirmed' then requestType = 'semi' elseif level == 'extendedconfirmed' then requestType = 'extended' elseif level == 'templateeditor' then requestType = 'template' end end requestType = requestType or 'full' -- Get the display value. local display = self:_getExpandedMessage('edit-request-display')

return mEditRequest._link{type = requestType, display = display} end

function Blurb:_makeExpiryParameter local expiry = self._protectionObj.expiry if type(expiry) == 'number' then return self:_formatDate(expiry) else return expiry end end

function Blurb:_makeExplanationBlurbParameter -- Cover special cases first. if self._protectionObj.title.namespace == 8 then -- MediaWiki namespace return self:_getExpandedMessage('explanation-blurb-nounprotect') end

-- Get explanation blurb table keys local action = self._protectionObj.action local level = self._protectionObj.level local talkKey = self._protectionObj.title.isTalkPage and 'talk' or 'subject'

-- Find the message in the explanation blurb table and substitute any -- parameters. local explanations = self._cfg.explanationBlurbs local msg if explanations[action][level] and explanations[action][level][talkKey] then msg = explanations[action][level][talkKey] elseif explanations[action][level] and explanations[action][level].default then msg = explanations[action][level].default elseif explanations[action].default and explanations[action].default[talkKey] then msg = explanations[action].default[talkKey] elseif explanations[action].default and explanations[action].default.default then msg = explanations[action].default.default else error(string.format( 'could not find explanation blurb for action "%s", level "%s" and talk key "%s"', action, level, talkKey ), 8)	end return self:_substituteParameters(msg) end

function Blurb:_makeImageLinkParameter local imageLinks = self._cfg.imageLinks local action = self._protectionObj.action local level = self._protectionObj.level local msg if imageLinks[action][level] then msg = imageLinks[action][level] elseif imageLinks[action].default then msg = imageLinks[action].default else msg = imageLinks.edit.default end return self:_substituteParameters(msg) end

function Blurb:_makeIntroBlurbParameter if self._protectionObj:isTemporary then return self:_getExpandedMessage('intro-blurb-expiry') else return self:_getExpandedMessage('intro-blurb-noexpiry') end end

function Blurb:_makeIntroFragmentParameter if self._protectionObj:isTemporary then return self:_getExpandedMessage('intro-fragment-expiry') else return self:_getExpandedMessage('intro-fragment-noexpiry') end end

function Blurb:_makePagetypeParameter local pagetypes = self._cfg.pagetypes return pagetypes[self._protectionObj.title.namespace] or pagetypes.default or error('no default pagetype defined', 8) end

function Blurb:_makeProtectionBlurbParameter local protectionBlurbs = self._cfg.protectionBlurbs local action = self._protectionObj.action local level = self._protectionObj.level local msg if protectionBlurbs[action][level] then msg = protectionBlurbs[action][level] elseif protectionBlurbs[action].default then msg = protectionBlurbs[action].default elseif protectionBlurbs.edit.default then msg = protectionBlurbs.edit.default else error('no protection blurb defined for protectionBlurbs.edit.default', 8) end return self:_substituteParameters(msg) end

function Blurb:_makeProtectionDateParameter local protectionDate = self._protectionObj.protectionDate if type(protectionDate) == 'number' then return self:_formatDate(protectionDate) else return protectionDate end end

function Blurb:_makeProtectionLevelParameter local protectionLevels = self._cfg.protectionLevels local action = self._protectionObj.action local level = self._protectionObj.level local msg if protectionLevels[action][level] then msg = protectionLevels[action][level] elseif protectionLevels[action].default then msg = protectionLevels[action].default elseif protectionLevels.edit.default then msg = protectionLevels.edit.default else error('no protection level defined for protectionLevels.edit.default', 8) end return self:_substituteParameters(msg) end

function Blurb:_makeProtectionLogParameter local pagename = self._protectionObj.title.prefixedText if self._protectionObj.action == 'autoreview' then -- We need the pending changes log. return makeFullUrl(			'Special:Log',			{type = 'stable', page = pagename},			self:_getExpandedMessage('pc-log-display')		) else -- We need the protection log. return makeFullUrl(			'Special:Log',			{type = 'protect', page = pagename},			self:_getExpandedMessage('protection-log-display')		) end end

function Blurb:_makeTalkPageParameter return string.format(		'%s',		mw.site.namespaces[self._protectionObj.title.namespace].talk.name,		self._protectionObj.title.text,		self._args.section or 'top',		self:_getExpandedMessage('talk-page-link-display')	) end

function Blurb:_makeTooltipBlurbParameter if self._protectionObj:isTemporary then return self:_getExpandedMessage('tooltip-blurb-expiry') else return self:_getExpandedMessage('tooltip-blurb-noexpiry') end end

function Blurb:_makeTooltipFragmentParameter if self._protectionObj:isTemporary then return self:_getExpandedMessage('tooltip-fragment-expiry') else return self:_getExpandedMessage('tooltip-fragment-noexpiry') end end

function Blurb:_makeVandalTemplateParameter return require('Module:Vandal-m')._main{ self._args.user or self._protectionObj.title.baseText } end

-- Public methods --

function Blurb:makeBannerText(key) -- Validate input. if not key or not Blurb.bannerTextFields[key] then error(string.format( '"%s" is not a valid banner config field', tostring(key) ), 2)	end

-- Generate the text. local msg = self._protectionObj.bannerConfig[key] if type(msg) == 'string' then return self:_substituteParameters(msg) elseif type(msg) == 'function' then msg = msg(self._protectionObj, self._args) if type(msg) ~= 'string' then error(string.format( 'bad output from banner config function with key "%s"' .. ' (expected string, got %s)', tostring(key), type(msg) ), 4)		end return self:_substituteParameters(msg) end end

-- BannerTemplate class

local BannerTemplate = {} BannerTemplate.__index = BannerTemplate

function BannerTemplate.new(protectionObj, cfg) local obj = {} obj._cfg = cfg

-- Set the image filename. local imageFilename = protectionObj.bannerConfig.image if imageFilename then obj._imageFilename = imageFilename else -- If an image filename isn't specified explicitly in the banner config, -- generate it from the protection status and the namespace. local action = protectionObj.action local level = protectionObj.level local namespace = protectionObj.title.namespace local reason = protectionObj.reason -- Deal with special cases first. if (			namespace == 10			or namespace == 828			or reason and obj._cfg.indefImageReasons[reason]			) and action == 'edit' and level == 'sysop' and not protectionObj:isTemporary then -- Fully protected modules and templates get the special red "indef" -- padlock. obj._imageFilename = obj._cfg.msg['image-filename-indef'] else -- Deal with regular protection types. local images = obj._cfg.images if images[action] then if images[action][level] then obj._imageFilename = images[action][level] elseif images[action].default then obj._imageFilename = images[action].default end end end end return setmetatable(obj, BannerTemplate) end

function BannerTemplate:renderImage local filename = self._imageFilename or self._cfg.msg['image-filename-default'] or 'Transparent.gif' return makeFileLink{ file = filename, size = (self.imageWidth or 20) .. 'px', alt = self._imageAlt, link = self._imageLink, caption = self.imageCaption } end

-- Banner class

local Banner = setmetatable({}, BannerTemplate) Banner.__index = Banner

function Banner.new(protectionObj, blurbObj, cfg) local obj = BannerTemplate.new(protectionObj, cfg) -- This doesn't need the blurb. obj.imageWidth = 40 obj.imageCaption = blurbObj:makeBannerText('alt') -- Large banners use the alt text for the tooltip. obj._reasonText = blurbObj:makeBannerText('text') obj._explanationText = blurbObj:makeBannerText('explanation') obj._page = protectionObj.title.prefixedText -- Only makes a difference in testing. return setmetatable(obj, Banner) end

function Banner:__tostring -- Renders the banner. makeMessageBox = makeMessageBox or require('Module:Message box').main local reasonText = self._reasonText or error('no reason text set', 2) local explanationText = self._explanationText local mbargs = { page = self._page, type = 'protection', image = self:renderImage, text = string.format(			"%s%s",			reasonText,			explanationText and ' ' .. explanationText or ''		) }	return makeMessageBox('mbox', mbargs) end

-- Padlock class

local Padlock = setmetatable({}, BannerTemplate) Padlock.__index = Padlock

function Padlock.new(protectionObj, blurbObj, cfg) local obj = BannerTemplate.new(protectionObj, cfg) -- This doesn't need the blurb. obj.imageWidth = 20 obj.imageCaption = blurbObj:makeBannerText('tooltip') obj._imageAlt = blurbObj:makeBannerText('alt') obj._imageLink = blurbObj:makeBannerText('link') obj._indicatorName = cfg.padlockIndicatorNames[protectionObj.action] or cfg.padlockIndicatorNames.default or 'pp-default' return setmetatable(obj, Padlock) end

function Padlock:__tostring local frame = mw.getCurrentFrame -- The nowiki tag helps prevent whitespace at the top of articles. return frame:extensionTag{name = 'nowiki'} .. frame:extensionTag{ name = 'indicator', args = {name = self._indicatorName}, content = self:renderImage } end

-- Exports

local p = {}

function p._exportClasses -- This is used for testing purposes. return { Protection = Protection, Blurb = Blurb, BannerTemplate = BannerTemplate, Banner = Banner, Padlock = Padlock, } end

function p._main(args, cfg, title) args = args or {} cfg = cfg or require(CONFIG_MODULE)

local protectionObj = Protection.new(args, cfg, title)

local ret = {}

-- If a page's edit protection is equally or more restrictive than its -- protection from some other action, then don't bother displaying anything -- for the other action (except categories). if protectionObj.action == 'edit' or		args.demolevel or		not getReachableNodes(			cfg.hierarchy,			protectionObj.level		)[effectiveProtectionLevel('edit', protectionObj.title)] then -- Initialise the blurb object local blurbObj = Blurb.new(protectionObj, args, cfg) -- Render the banner if protectionObj:isProtected then ret[#ret + 1] = tostring(				(yesno(args.small) and Padlock or Banner)				.new(protectionObj, blurbObj, cfg)			) end end

-- Render the categories if yesno(args.category) ~= false then ret[#ret + 1] = protectionObj:makeCategoryLinks end return table.concat(ret) end

function p.main(frame, cfg) cfg = cfg or require(CONFIG_MODULE)

-- Find default args, if any. local parent = frame.getParent and frame:getParent local defaultArgs = parent and cfg.wrappers[parent:getTitle:gsub('/sandbox$', '')]

-- Find user args, and use the parent frame if we are being called from a	-- wrapper template. getArgs = getArgs or require('Module:Arguments').getArgs local userArgs = getArgs(frame, {		parentOnly = defaultArgs,		frameOnly = not defaultArgs	})

-- Build the args table. User-specified args overwrite default args. local args = {} for k, v in pairs(defaultArgs or {}) do		args[k] = v	end for k, v in pairs(userArgs) do		args[k] = v	end return p._main(args, cfg) end

return p

title: Module:Protection banner


text:
Module:File link

-- This module provides a library for formatting file wikilinks.

local yesno = require('Module:Yesno') local checkType = require('libraryUtil').checkType

local p = {}

function p._main(args) checkType('_main', 1, args, 'table')

-- This is basically libraryUtil.checkTypeForNamedArg, but we are rolling our -- own function to get the right error level. local function checkArg(key, val, level) if type(val) ~= 'string' then error(string.format( "type error in '%s' parameter of '_main' (expected string, got %s)", key, type(val) ), level) end end

local ret = {}

-- Adds a positional parameter to the buffer. local function addPositional(key) local val = args[key] if not val then return nil end checkArg(key, val, 4) ret[#ret + 1] = val end

-- Adds a named parameter to the buffer. We assume that the parameter name -- is the same as the argument key. local function addNamed(key) local val = args[key] if not val then return nil end checkArg(key, val, 4) ret[#ret + 1] = key .. '=' .. val end

-- Filename checkArg('file', args.file, 3) ret[#ret + 1] = 'File:' .. args.file

-- Format if args.format then checkArg('format', args.format) if args.formatfile then checkArg('formatfile', args.formatfile) ret[#ret + 1] = args.format .. '=' .. args.formatfile else ret[#ret + 1] = args.format end end

-- Border if yesno(args.border) then ret[#ret + 1] = 'border' end

addPositional('location') addPositional('alignment') addPositional('size') addNamed('upright') addNamed('link') addNamed('alt') addNamed('page') addNamed('class') addNamed('lang') addNamed('start') addNamed('end') addNamed('thumbtime') addPositional('caption')

return string.format('%s', table.concat(ret, '|')) end

function p.main(frame) local origArgs = require('Module:Arguments').getArgs(frame, {		wrappers = 'Template:File link'	}) if not origArgs.file then error("'file' parameter missing from Template:File link", 0) end

-- Copy the arguments that were passed to a new table to avoid looking up -- every possible parameter in the frame object. local args = {} for k, v in pairs(origArgs) do -- Make _BLANK a special argument to add a blank parameter. For use in -- conditional templates etc. it is useful for blank arguments to be		-- ignored, but we still need a way to specify them so that we can do -- things like. if v == '_BLANK' then v = '' end args[k] = v	end return p._main(args) end

return p

title: Module:File link


text:
Module:Effective protection level

local p = {}

-- Returns the permission required to perform a given action on a given title. -- If no title is specified, the title of the page being displayed is used. function p._main(action, pagename) local title if type(pagename) == 'table' and pagename.prefixedText then title = pagename elseif pagename then title = mw.title.new(pagename) else title = mw.title.getCurrentTitle end pagename = title.prefixedText if action == 'autoreview' then local level = mw.ext.FlaggedRevs.getStabilitySettings(title) level = level and level.autoreview if level == 'review' then return 'reviewer' elseif level ~= '' then return level else return nil -- not '*'. a page not being PC-protected is distinct from it being PC-protected with anyone able to review. also not '', as that would mean PC-protected but nobody can review end elseif action ~= 'edit' and action ~= 'move' and action ~= 'create' and action ~= 'upload' then error( 'First parameter must be one of edit, move, create, upload, autoreview', 2 ) end if title.namespace == 8 then -- MediaWiki namespace if title.contentModel == 'javascript' or title.contentModel == 'css' then -- site JS or CSS page return 'interfaceadmin' else -- any non-JS/CSS MediaWiki page return 'sysop' end elseif title.namespace == 2 and title.isSubpage then if title.contentModel == 'javascript' or title.contentModel == 'css' then -- user JS or CSS page return 'interfaceadmin' elseif title.contentModel == 'json' then -- user JSON page return 'sysop' end end local level = title.protectionLevels[action] and title.protectionLevels[action][1] if level == 'sysop' or level == 'editprotected' then return 'sysop' elseif title.cascadingProtection.restrictions[action] and title.cascadingProtection.restrictions[action][1] then -- used by a cascading-protected page return 'sysop' elseif level == 'templateeditor' then return 'templateeditor' elseif action == 'move' then local blacklistentry = mw.ext.TitleBlacklist.test('edit', pagename) -- Testing action edit is correct, since this is for the source page. The target page name gets tested with action move. if blacklistentry and not blacklistentry.params.autoconfirmed then return 'templateeditor' elseif title.namespace == 6 then return 'filemover' elseif level == 'extendedconfirmed' then return 'extendedconfirmed' else return 'autoconfirmed' end end local blacklistentry = mw.ext.TitleBlacklist.test(action, pagename) if blacklistentry then if not blacklistentry.params.autoconfirmed then return 'templateeditor' elseif level == 'extendedconfirmed' then return 'extendedconfirmed' else return 'autoconfirmed' end elseif level == 'editsemiprotected' then -- create-semiprotected pages return this for some reason return 'autoconfirmed' elseif level then return level elseif action == 'upload' then return 'autoconfirmed' elseif action == 'create' and title.namespace % 2 == 0 and title.namespace ~= 118 then -- You need to be registered, but not autoconfirmed, to create non-talk pages other than drafts return 'user' else return '*' end end

setmetatable(p, { __index = function(t, k)	return function(frame)		return t._main(k, frame.args[1])	end end })

return p

title: Module:Effective protection level


text:
Module:Effective protection expiry

local p = {}

-- Returns the expiry of a restriction of an action on a given title, or unknown if it cannot be known. -- If no title is specified, the title of the page being displayed is used. function p._main(action, pagename) local title if type(pagename) == 'table' and pagename.prefixedText then title = pagename elseif pagename then title = mw.title.new(pagename) else title = mw.title.getCurrentTitle end pagename = title.prefixedText if action == 'autoreview' then local stabilitySettings = mw.ext.FlaggedRevs.getStabilitySettings(title) return stabilitySettings and stabilitySettings.expiry or 'unknown' elseif action ~= 'edit' and action ~= 'move' and action ~= 'create' and action ~= 'upload' then error( 'First parameter must be one of edit, move, create, upload, autoreview', 2 ) end local rawExpiry = mw.getCurrentFrame:callParserFunction('PROTECTIONEXPIRY', action, pagename) if rawExpiry == 'infinity' then return 'infinity' elseif rawExpiry == '' then return 'unknown' else local year, month, day, hour, minute, second = rawExpiry:match(			'^(%d%d%d%d)(%d%d)(%d%d)(%d%d)(%d%d)(%d%d)$'		) if year then return string.format(				'%s-%s-%sT%s:%s:%s',				year, month, day, hour, minute, second			) else error('internal error in Module:Effective protection expiry; malformed expiry timestamp') end end end

setmetatable(p, { __index = function(t, k)	return function(frame)		return t._main(k, frame.args[1])	end end })

return p

title: Module:Effective protection expiry