https://mw-live.lojban.org/api.php?action=feedcontributions&user=86.135.251.105&feedformat=atomLojban - User contributions [en]2024-03-28T18:50:12ZUser contributionsMediaWiki 1.38.4https://mw-live.lojban.org/index.php?title=Template:Mbox_templates&diff=84377Template:Mbox templates2014-02-02T13:41:54Z<p>86.135.251.105: </p>
<hr />
<div>{{nmbox<br />
| image = [[File:Template-info.svg|50px]]<br />
| header = [[Template:Mbox|Message box templates]]<br />
| text = {{Tlx|ambox}} &bull; {{Tlx|asbox}} &bull; {{Tlx|cmbox}} &bull; {{Tlx|dmbox}} &bull; {{Tlx|fmbox}} &bull; {{Tlx|imbox}} &bull; {{Tlx|ombox}} &bull; {{Tlx|tmbox}}<br />
}}</div>86.135.251.105https://mw-live.lojban.org/index.php?title=Module:Documentation/config&diff=84387Module:Documentation/config2014-02-02T13:34:16Z<p>86.135.251.105: Created page with "---------------------------------------------------------------------------------------------------- -- -- Configuration for Module:Documentation..."</p>
<hr />
<div>----------------------------------------------------------------------------------------------------<br />
--<br />
-- Configuration for Module:Documentation<br />
--<br />
-- Here you can set the values of the parameters and messages used in Module:Documentation to<br />
-- localise it to your wiki and your language. Unless specified otherwise, values given here<br />
-- should be string values.<br />
----------------------------------------------------------------------------------------------------<br />
<br />
local cfg = {} -- Do not edit this line.<br />
<br />
----------------------------------------------------------------------------------------------------<br />
-- Protection template configuration<br />
----------------------------------------------------------------------------------------------------<br />
<br />
-- cfg['protection-template']<br />
-- The name of the template that displays the protection icon (a padlock on enwiki).<br />
cfg['protection-template'] = 'pp-template'<br />
<br />
--[[<br />
-- cfg['protection-template-args']<br />
-- Any arguments to send to the protection template. This should be a Lua table.<br />
-- For example, if the protection template is "pp-template", and the wikitext template invocation<br />
-- looks like "{{pp-template|docusage=yes}}", then this table should look like "{docusage = 'yes'}".<br />
--]]<br />
cfg['protection-template-args'] = {docusage = 'yes'}<br />
<br />
--[[<br />
----------------------------------------------------------------------------------------------------<br />
-- Sandbox notice configuration<br />
--<br />
-- On sandbox pages the module can display a template notifying users that the current page is a<br />
-- sandbox, and the location of test cases pages, etc. The module decides whether the page is a<br />
-- sandbox or not based on the value of cfg['sandbox-subpage']. The following settings configure the<br />
-- messages that the notices contains.<br />
----------------------------------------------------------------------------------------------------<br />
--]]<br />
<br />
-- cfg['sandbox-notice-image']<br />
-- The image displayed in the sandbox notice.<br />
cfg['sandbox-notice-image'] = '[[Image:Sandbox.png|50px|alt=|link=]]'<br />
<br />
--[[<br />
-- cfg['sandbox-notice-pagetype-template']<br />
-- cfg['sandbox-notice-pagetype-module']<br />
-- cfg['sandbox-notice-pagetype-other']<br />
-- The page type of the sandbox page. The message that is displayed depends on the current subject<br />
-- namespace. This message is used in either cfg['sandbox-notice-blurb'] or<br />
-- cfg['sandbox-notice-diff-blurb'].<br />
--]]<br />
cfg['sandbox-notice-pagetype-template'] = '[[Wikipedia:Template test cases|template sandbox]] page'<br />
cfg['sandbox-notice-pagetype-module'] = '[[Wikipedia:Template test cases|module sandbox]] page'<br />
cfg['sandbox-notice-pagetype-other'] = 'sandbox page'<br />
<br />
--[[<br />
-- cfg['sandbox-notice-blurb']<br />
-- cfg['sandbox-notice-diff-blurb']<br />
-- cfg['sandbox-notice-diff-display']<br />
-- Either cfg['sandbox-notice-blurb'] or cfg['sandbox-notice-diff-blurb'] is the opening sentence<br />
-- of the sandbox notice. The latter has a diff link, but the former does not. $1 is the page<br />
-- type, which is either cfg['sandbox-notice-pagetype-template'],<br />
-- cfg['sandbox-notice-pagetype-module'] or cfg['sandbox-notice-pagetype-other'] depending what<br />
-- namespace we are in. $2 is a link to the main template page, and $3 is a diff link between<br />
-- the sandbox and the main template. The display value of the diff link is set by <br />
-- cfg['sandbox-notice-compare-link-display'].<br />
--]]<br />
cfg['sandbox-notice-blurb'] = 'This is the $1 for $2.'<br />
cfg['sandbox-notice-diff-blurb'] = 'This is the $1 for $2 ($3).'<br />
cfg['sandbox-notice-compare-link-display'] = 'diff'<br />
<br />
--[[<br />
-- cfg['sandbox-notice-testcases-blurb']<br />
-- cfg['sandbox-notice-testcases-link-display']<br />
-- cfg['sandbox-notice-testcases-blurb'] is a sentence notifying the user that there is a test cases page<br />
-- corresponding to this sandbox that they can edit. $1 is a link to the test cases page.<br />
-- cfg['sandbox-notice-testcases-link-display'] is the display value for that link.<br />
--]]<br />
cfg['sandbox-notice-testcases-blurb'] = 'See also the companion subpage for $1.'<br />
cfg['sandbox-notice-testcases-link-display'] = 'test cases'<br />
<br />
-- cfg['sandbox-category']<br />
-- A category to add to all template sandboxes.<br />
cfg['sandbox-category'] = 'Template sandboxes'<br />
<br />
----------------------------------------------------------------------------------------------------<br />
-- Start box configuration<br />
----------------------------------------------------------------------------------------------------<br />
<br />
-- cfg['documentation-icon-wikitext']<br />
-- The wikitext for the icon shown at the top of the template.<br />
cfg['documentation-icon-wikitext'] = '[[File:Template-info.png|50px|link=|alt=Documentation icon]]'<br />
<br />
-- cfg['template-namespace-heading']<br />
-- The heading shown in the template namespace.<br />
cfg['template-namespace-heading'] = 'Template documentation'<br />
<br />
-- cfg['module-namespace-heading']<br />
-- The heading shown in the module namespace.<br />
cfg['module-namespace-heading'] = 'Module documentation'<br />
<br />
-- cfg['file-namespace-heading']<br />
-- The heading shown in the file namespace.<br />
cfg['file-namespace-heading'] = 'Summary'<br />
<br />
-- cfg['other-namespaces-heading']<br />
-- The heading shown in other namespaces.<br />
cfg['other-namespaces-heading'] = 'Documentation'<br />
<br />
-- cfg['view-link-display']<br />
-- The text to display for "view" links.<br />
cfg['view-link-display'] = 'view'<br />
<br />
-- cfg['edit-link-display']<br />
-- The text to display for "edit" links.<br />
cfg['edit-link-display'] = 'edit'<br />
<br />
-- cfg['history-link-display']<br />
-- The text to display for "history" links.<br />
cfg['history-link-display'] = 'history'<br />
<br />
-- cfg['purge-link-display']<br />
-- The text to display for "purge" links.<br />
cfg['purge-link-display'] = 'purge'<br />
<br />
-- cfg['create-link-display']<br />
-- The text to display for "create" links.<br />
cfg['create-link-display'] = 'create'<br />
<br />
----------------------------------------------------------------------------------------------------<br />
-- Link box (end box) configuration<br />
----------------------------------------------------------------------------------------------------<br />
<br />
-- cfg['transcluded-from-blurb']<br />
-- Notice displayed when the docs are transcluded from another page. $1 is a wikilink to that page.<br />
cfg['transcluded-from-blurb'] = 'The above [[Wikipedia:Template documentation|documentation]] is [[Wikipedia:Transclusion|transcluded]] from $1.'<br />
<br />
--[[<br />
-- cfg['create-module-doc-blurb']<br />
-- Notice displayed in the module namespace when the documentation subpage does not exist.<br />
-- $1 is a link to create the documentation page with the preload cfg['module-preload'] and the<br />
-- display cfg['create-link-display'].<br />
--]]<br />
cfg['create-module-doc-blurb'] = 'You might want to $1 a documentation page for this [[Wikipedia:Lua|Scribunto module]].'<br />
<br />
----------------------------------------------------------------------------------------------------<br />
-- Experiment blurb configuration<br />
----------------------------------------------------------------------------------------------------<br />
<br />
--[[<br />
-- cfg['experiment-blurb-template']<br />
-- cfg['experiment-blurb-module']<br />
-- The experiment blurb is the text inviting editors to experiment in sandbox and test cases pages.<br />
-- It is only shown in the template and module namespaces. With the default English settings, it<br />
-- might look like this:<br />
--<br />
-- Editors can experiment in this template's sandbox (edit | diff) and testcases (edit) pages.<br />
--<br />
-- In this example, "sandbox", "edit", "diff", "testcases", and "edit" would all be links.<br />
--<br />
-- There are two versions, cfg['experiment-blurb-template'] and cfg['experiment-blurb-module'], depending<br />
-- on what namespace we are in.<br />
-- <br />
-- Parameters:<br />
--<br />
-- $1 is a link to the sandbox page. If the sandbox exists, it is in the following format:<br />
--<br />
-- cfg['sandbox-link-display'] (cfg['sandbox-edit-link-display'] | cfg['compare-link-display'])<br />
-- <br />
-- If the sandbox doesn't exist, it is in the format:<br />
--<br />
-- cfg['sandbox-link-display'] (cfg['sandbox-create-link-display'] | cfg['mirror-link-display'])<br />
-- <br />
-- The link for cfg['sandbox-create-link-display'] link preloads the page with cfg['template-sandbox-preload']<br />
-- or cfg['module-sandbox-preload'], depending on the current namespace. The link for cfg['mirror-link-display']<br />
-- loads a default edit summary of cfg['mirror-edit-summary'].<br />
--<br />
-- $2 is a link to the test cases page. If the test cases page exists, it is in the following format:<br />
--<br />
-- cfg['testcases-link-display'] (cfg['testcases-edit-link-display'])<br />
--<br />
-- If the test cases page doesn't exist, it is in the format:<br />
-- <br />
-- cfg['testcases-link-display'] (cfg['testcases-create-link-display'])<br />
--<br />
-- If the test cases page doesn't exist, the link for cfg['testcases-create-link-display'] preloads the<br />
-- page with cfg['template-testcases-preload'] or cfg['module-testcases-preload'], depending on the current<br />
-- namespace.<br />
--]]<br />
cfg['experiment-blurb-template'] = "Editors can experiment in this template's $1 and $2 pages."<br />
cfg['experiment-blurb-module'] = "Editors can experiment in this module's $1 and $2 pages."<br />
<br />
----------------------------------------------------------------------------------------------------<br />
-- Sandbox link configuration<br />
----------------------------------------------------------------------------------------------------<br />
<br />
-- cfg['sandbox-subpage']<br />
-- The name of the template subpage typically used for sandboxes.<br />
cfg['sandbox-subpage'] = 'sandbox'<br />
<br />
-- cfg['template-sandbox-preload']<br />
-- Preload file for template sandbox pages.<br />
cfg['template-sandbox-preload'] = 'Template:Documentation/preload-sandbox'<br />
<br />
-- cfg['module-sandbox-preload']<br />
-- Preload file for Lua module sandbox pages.<br />
cfg['module-sandbox-preload'] = 'Template:Documentation/preload-module-sandbox'<br />
<br />
-- cfg['sandbox-link-display']<br />
-- The text to display for "sandbox" links.<br />
cfg['sandbox-link-display'] = 'sandbox'<br />
<br />
-- cfg['sandbox-edit-link-display']<br />
-- The text to display for sandbox "edit" links.<br />
cfg['sandbox-edit-link-display'] = 'edit'<br />
<br />
-- cfg['sandbox-create-link-display']<br />
-- The text to display for sandbox "create" links.<br />
cfg['sandbox-create-link-display'] = 'create'<br />
<br />
-- cfg['compare-link-display']<br />
-- The text to display for "compare" links.<br />
cfg['compare-link-display'] = 'diff'<br />
<br />
-- cfg['mirror-edit-summary']<br />
-- The default edit summary to use when a user clicks the "mirror" link. $1 is a wikilink to the<br />
-- template page.<br />
cfg['mirror-edit-summary'] = 'Create sandbox version of $1'<br />
<br />
-- cfg['mirror-link-display']<br />
-- The text to display for "mirror" links.<br />
cfg['mirror-link-display'] = 'mirror'<br />
<br />
----------------------------------------------------------------------------------------------------<br />
-- Test cases link configuration<br />
----------------------------------------------------------------------------------------------------<br />
<br />
-- cfg['testcases-subpage']<br />
-- The name of the template subpage typically used for test cases.<br />
cfg['testcases-subpage'] = 'testcases'<br />
<br />
-- cfg['template-testcases-preload']<br />
-- Preload file for template test cases pages.<br />
cfg['template-testcases-preload'] = 'Template:Documentation/preload-testcases'<br />
<br />
-- cfg['module-testcases-preload']<br />
-- Preload file for Lua module test cases pages.<br />
cfg['module-testcases-preload'] = 'Template:Documentation/preload-module-testcases'<br />
<br />
-- cfg['testcases-link-display']<br />
-- The text to display for "testcases" links.<br />
cfg['testcases-link-display'] = 'testcases'<br />
<br />
-- cfg['testcases-edit-link-display']<br />
-- The text to display for test cases "edit" links.<br />
cfg['testcases-edit-link-display'] = 'edit'<br />
<br />
-- cfg['testcases-create-link-display']<br />
-- The text to display for test cases "create" links.<br />
cfg['testcases-create-link-display'] = 'create'<br />
<br />
----------------------------------------------------------------------------------------------------<br />
-- Add categories blurb configuration<br />
----------------------------------------------------------------------------------------------------<br />
<br />
--[[<br />
-- cfg['add-categories-blurb']<br />
-- Text to direct users to add categories to the /doc subpage. Not used if the "content" or<br />
-- "docname fed" arguments are set, as then it is not clear where to add the categories. $1 is a<br />
-- link to the /doc subpage with a display value of cfg['doc-link-display'].<br />
--]]<br />
cfg['add-categories-blurb'] = 'Please add categories to the $1 subpage.'<br />
<br />
-- cfg['doc-link-display']<br />
-- The text to display when linking to the /doc subpage.<br />
cfg['doc-link-display'] = '/doc'<br />
<br />
----------------------------------------------------------------------------------------------------<br />
-- Subpages link configuration<br />
----------------------------------------------------------------------------------------------------<br />
<br />
--[[<br />
-- cfg['subpages-blurb']<br />
-- The "Subpages of this template" blurb. $1 is a link to the main template's subpages with a<br />
-- display value of cfg['subpages-link-display']. In the English version this blurb is simply<br />
-- the link followed by a period, and the link display provides the actual text.<br />
--]]<br />
cfg['subpages-blurb'] = '$1.'<br />
<br />
--[[<br />
-- cfg['subpages-link-display']<br />
-- The text to display for the "subpages of this page" link. $1 is cfg['template-pagetype'],<br />
-- cfg['module-pagetype'] or cfg['default-pagetype'], depending on whether the current page is in<br />
-- the template namespace, the module namespace, or another namespace.<br />
--]]<br />
cfg['subpages-link-display'] = 'Subpages of this $1'<br />
<br />
-- cfg['template-pagetype']<br />
-- The pagetype to display for template pages.<br />
cfg['template-pagetype'] = 'template'<br />
<br />
-- cfg['module-pagetype']<br />
-- The pagetype to display for Lua module pages.<br />
cfg['module-pagetype'] = 'module'<br />
<br />
-- cfg['default-pagetype']<br />
-- The pagetype to display for pages other than templates or Lua modules.<br />
cfg['default-pagetype'] = 'page'<br />
<br />
----------------------------------------------------------------------------------------------------<br />
-- Doc link configuration<br />
----------------------------------------------------------------------------------------------------<br />
<br />
-- cfg['doc-subpage']<br />
-- The name of the subpage typically used for documentation pages.<br />
cfg['doc-subpage'] = 'doc'<br />
<br />
-- cfg['file-docpage-preload']<br />
-- Preload file for documentation page in the file namespace.<br />
cfg['file-docpage-preload'] = 'Template:Documentation/preload-filespace'<br />
<br />
-- cfg['docpage-preload']<br />
-- Preload file for template documentation pages in all namespaces.<br />
cfg['docpage-preload'] = 'Template:Documentation/preload'<br />
<br />
-- cfg['module-preload']<br />
-- Preload file for Lua module documentation pages.<br />
cfg['module-preload'] = 'Template:Documentation/preload-module-doc'<br />
<br />
----------------------------------------------------------------------------------------------------<br />
-- Print version configuration<br />
----------------------------------------------------------------------------------------------------<br />
<br />
-- cfg['print-subpage']<br />
-- The name of the template subpage used for print versions.<br />
cfg['print-subpage'] = 'Print'<br />
<br />
-- cfg['print-link-display']<br />
-- The text to display when linking to the /Print subpage.<br />
cfg['print-link-display'] = '/Print'<br />
<br />
-- cfg['print-blurb']<br />
-- Text to display if a /Print subpage exists. $1 is a link to the subpage with a display value of cfg['print-link-display'].<br />
cfg['print-blurb'] = 'A [[Help:Books/for experts#Improving the book layout|print version]] of this template exists at $1.'<br />
.. ' If you make a change to this template, please update the print version as well.'<br />
<br />
-- cfg['display-print-category']<br />
-- Set to true to enable output of cfg['print-category'] if a /Print subpage exists.<br />
-- This should be a boolean value (either true or false).<br />
cfg['display-print-category'] = true<br />
<br />
-- cfg['print-category']<br />
-- Category to output if cfg['display-print-category'] is set to true, and a /Print subpage exists.<br />
cfg['print-category'] = 'Templates with print versions'<br />
<br />
----------------------------------------------------------------------------------------------------<br />
-- HTML and CSS configuration<br />
----------------------------------------------------------------------------------------------------<br />
<br />
-- cfg['main-div-id']<br />
-- The "id" attribute of the main HTML "div" tag.<br />
cfg['main-div-id'] = 'template-documentation'<br />
<br />
-- cfg['main-div-classes']<br />
-- The CSS classes added to the main HTML "div" tag.<br />
cfg['main-div-classes'] = 'template-documentation iezoomfix'<br />
<br />
-- cfg['start-box-linkclasses']<br />
-- The CSS classes used for the [view][edit][history] or [create] links in the start box.<br />
cfg['start-box-linkclasses'] = 'mw-editsection-like plainlinks'<br />
<br />
-- cfg['start-box-link-id']<br />
-- The HTML "id" attribute for the links in the start box.<br />
cfg['start-box-link-id'] = 'doc_editlinks'<br />
<br />
----------------------------------------------------------------------------------------------------<br />
-- {{fmbox}} template configuration<br />
----------------------------------------------------------------------------------------------------<br />
<br />
-- cfg['fmbox-id']<br />
-- The id sent to the "id" parameter of the {{fmbox}} template.<br />
cfg['fmbox-id'] = 'documentation-meta-data'<br />
<br />
-- cfg['fmbox-style']<br />
-- The value sent to the style parameter of {{fmbox}}.<br />
cfg['fmbox-style'] = 'background-color: #ecfcf4'<br />
<br />
-- cfg['fmbox-textstyle']<br />
-- The value sent to the "textstyle parameter of {{fmbox}}.<br />
cfg['fmbox-textstyle'] = 'font-style: italic'<br />
<br />
----------------------------------------------------------------------------------------------------<br />
-- Tracking category configuration<br />
----------------------------------------------------------------------------------------------------<br />
<br />
-- cfg['display-strange-usage-category']<br />
-- Set to true to enable output of cfg['strange-usage-category'] if the module is used on a /doc subpage<br />
-- or a /testcases subpage. This should be a boolean value (either true or false).<br />
cfg['display-strange-usage-category'] = true<br />
<br />
-- cfg['strange-usage-category']<br />
-- Category to output if cfg['display-strange-usage-category'] is set to true and the module is used on a<br />
-- /doc subpage or a /testcases subpage.<br />
cfg['strange-usage-category'] = 'Wikipedia pages with strange ((documentation)) usage'<br />
<br />
--[[<br />
----------------------------------------------------------------------------------------------------<br />
-- End configuration<br />
--<br />
-- Don't edit anything below this line.<br />
----------------------------------------------------------------------------------------------------<br />
--]]<br />
<br />
return cfg</div>86.135.251.105https://mw-live.lojban.org/index.php?title=Module:Message_box&diff=84389Module:Message box2014-02-02T13:04:20Z<p>86.135.251.105: Undo revision 896901 by 86.135.251.105 (talk)</p>
<hr />
<div>-- This is a meta-module for producing message box templates, including {{mbox}}, {{ambox}}, {{imbox}}, {{tmbox}}, {{ombox}}, {{cmbox}} and {{fmbox}}.<br />
<br />
-- Require necessary modules.<br />
local getArgs = require('Module:Arguments').getArgs<br />
local htmlBuilder = require('Module:HtmlBuilder')<br />
local categoryHandler = require('Module:Category handler').main<br />
local yesno = require('Module:Yesno')<br />
<br />
-- Load the configuration page.<br />
local cfgTables = mw.loadData('Module:Message box/configuration')<br />
<br />
-- Get a language object for formatDate and ucfirst.<br />
local lang = mw.language.getContentLanguage()<br />
<br />
-- Set aliases for often-used functions to reduce table lookups.<br />
local format = mw.ustring.format<br />
local tinsert = table.insert<br />
local tconcat = table.concat<br />
local trim = mw.text.trim<br />
<br />
--------------------------------------------------------------------------------<br />
-- Helper functions<br />
--------------------------------------------------------------------------------<br />
<br />
local function getTitleObject(page, ...)<br />
if type(page) == 'string' then<br />
-- Get the title object, passing the function through pcall <br />
-- in case we are over the expensive function count limit.<br />
local success, title = pcall(mw.title.new, page, ...)<br />
if success then<br />
return title<br />
end<br />
end<br />
end<br />
<br />
local function union(t1, t2)<br />
-- Returns the union of two arrays.<br />
local vals = {}<br />
for i, v in ipairs(t1) do<br />
vals[v] = true<br />
end<br />
for i, v in ipairs(t2) do<br />
vals[v] = true<br />
end<br />
local ret = {}<br />
for k in pairs(vals) do<br />
tinsert(ret, k)<br />
end<br />
table.sort(ret)<br />
return ret<br />
end<br />
<br />
local function getArgNums(args, prefix)<br />
local nums = {}<br />
for k, v in pairs(args) do<br />
local num = mw.ustring.match(tostring(k), '^' .. prefix .. '([1-9]%d*)$')<br />
if num then<br />
tinsert(nums, tonumber(num))<br />
end<br />
end<br />
table.sort(nums)<br />
return nums<br />
end<br />
<br />
--------------------------------------------------------------------------------<br />
-- Box class definition<br />
--------------------------------------------------------------------------------<br />
<br />
local box = {}<br />
box.__index = box<br />
<br />
function box.new()<br />
local obj = {}<br />
setmetatable(obj, box)<br />
return obj<br />
end<br />
<br />
function box.getNamespaceId(ns)<br />
if not ns then return end<br />
if type(ns) == 'string' then<br />
ns = lang:ucfirst(mw.ustring.lower(ns))<br />
if ns == 'Main' then<br />
ns = 0<br />
end<br />
end<br />
local nsTable = mw.site.namespaces[ns]<br />
if nsTable then<br />
return nsTable.id<br />
end<br />
end<br />
<br />
function box.getMboxType(nsid)<br />
-- Gets the mbox type from a namespace number.<br />
if nsid == 0 then<br />
return 'ambox' -- main namespace<br />
elseif nsid == 6 then<br />
return 'imbox' -- file namespace<br />
elseif nsid == 14 then<br />
return 'cmbox' -- category namespace<br />
else<br />
local nsTable = mw.site.namespaces[nsid]<br />
if nsTable and nsTable.isTalk then<br />
return 'tmbox' -- any talk namespace<br />
else<br />
return 'ombox' -- other namespaces or invalid input<br />
end<br />
end<br />
end<br />
<br />
function box:addCat(ns, cat, sort)<br />
if type(cat) ~= 'string' then return end<br />
local nsVals = {'main', 'template', 'all'}<br />
local tname<br />
for i, val in ipairs(nsVals) do<br />
if ns == val then<br />
tname = ns .. 'Cats'<br />
end<br />
end<br />
if not tname then<br />
for i, val in ipairs(nsVals) do<br />
nsVals[i] = format('"%s"', val)<br />
end<br />
error('invalid ns parameter passed to box:addCat; valid values are ' .. mw.text.listToText(nsVals, nil, ' or '))<br />
end<br />
self[tname] = self[tname] or {}<br />
if type(sort) == 'string' then<br />
tinsert(self[tname], format('[[Category:%s|%s]]', cat, sort))<br />
else<br />
tinsert(self[tname], format('[[Category:%s]]', cat))<br />
end<br />
end<br />
<br />
function box:addClass(class)<br />
if type(class) ~= 'string' then return end<br />
self.classes = self.classes or {}<br />
tinsert(self.classes, class)<br />
end<br />
<br />
function box:setTitle(args)<br />
-- Get the title object and the namespace.<br />
self.pageTitle = getTitleObject(args.page ~= '' and args.page)<br />
self.title = self.pageTitle or mw.title.getCurrentTitle()<br />
self.demospace = args.demospace ~= '' and args.demospace or nil<br />
self.nsid = box.getNamespaceId(self.demospace) or self.title.namespace<br />
end<br />
<br />
function box:getConfig(boxType)<br />
-- Get the box config data from the data page.<br />
if boxType == 'mbox' then<br />
boxType = box.getMboxType(self.nsid)<br />
end<br />
local cfg = cfgTables[boxType]<br />
if not cfg then<br />
local boxTypes = {}<br />
for k, v in pairs(dataTables) do<br />
tinsert(boxTypes, format('"%s"', k))<br />
end<br />
tinsert(boxTypes, '"mbox"')<br />
error(format('invalid message box type "%s"; valid types are %s', tostring(boxType), mw.text.listToText(boxTypes)), 2)<br />
end<br />
return cfg<br />
end<br />
<br />
function box:removeBlankArgs(cfg, args)<br />
-- Only allow blank arguments for the parameter names listed in cfg.allowBlankParams.<br />
local newArgs = {}<br />
for k, v in pairs(args) do<br />
if v ~= '' then<br />
newArgs[k] = v<br />
end<br />
end<br />
for i, param in ipairs(cfg.allowBlankParams or {}) do<br />
newArgs[param] = args[param]<br />
end<br />
return newArgs<br />
end<br />
<br />
function box:setBoxParameters(cfg, args)<br />
-- Get type data.<br />
self.type = args.type<br />
local typeData = cfg.types[self.type]<br />
self.invalidTypeError = cfg.showInvalidTypeError and self.type and not typeData and true or false<br />
typeData = typeData or cfg.types[cfg.default]<br />
self.typeClass = typeData.class<br />
self.typeImage = typeData.image<br />
<br />
-- Find if the box has been wrongly substituted.<br />
if cfg.substCheck and args.subst == 'SUBST' then<br />
self.isSubstituted = true<br />
end<br />
<br />
-- Find whether we are using a small message box.<br />
if cfg.allowSmall and (<br />
cfg.smallParam and args.small == cfg.smallParam<br />
or not cfg.smallParam and yesno(args.small)<br />
)<br />
then<br />
self.isSmall = true<br />
else<br />
self.isSmall = false<br />
end<br />
<br />
-- Add attributes, classes and styles.<br />
if cfg.allowId then<br />
self.id = args.id<br />
end<br />
self:addClass(cfg.usePlainlinksParam and yesno(args.plainlinks or true) and 'plainlinks')<br />
for _, class in ipairs(cfg.classes or {}) do<br />
self:addClass(class)<br />
end<br />
if self.isSmall then<br />
self:addClass(cfg.smallClass or 'mbox-small')<br />
end<br />
if yesno(args.hidden) then<br />
self:addClass('infobox editsection')<br />
end<br />
self:addClass(self.typeClass)<br />
self:addClass(args.class)<br />
self.style = args.style<br />
<br />
-- Set text style.<br />
self.textstyle = args.textstyle<br />
<br />
-- Find if we are on the template page or not. This functionality is only used if useCollapsibleTextFields is set,<br />
-- or if both cfg.templateCategory and cfg.templateCategoryRequireName are set.<br />
self.useCollapsibleTextFields = cfg.useCollapsibleTextFields<br />
if self.useCollapsibleTextFields or cfg.templateCategory and cfg.templateCategoryRequireName then<br />
self.name = args.name<br />
if self.name then<br />
local templateName = mw.ustring.match(self.name, '^[tT][eE][mM][pP][lL][aA][tT][eE][%s_]*:[%s_]*(.*)$') or self.name<br />
templateName = 'Template:' .. templateName<br />
self.templateTitle = getTitleObject(templateName)<br />
end<br />
self.isTemplatePage = self.templateTitle and mw.title.equals(self.title, self.templateTitle) or false<br />
end<br />
<br />
-- Process data for collapsible text fields. At the moment these are only used in {{ambox}}.<br />
if self.useCollapsibleTextFields then<br />
-- Get the self.issue value.<br />
if self.isSmall and args.smalltext then<br />
self.issue = args.smalltext<br />
else<br />
local sect<br />
if args.sect == '' then<br />
sect = 'This ' .. (cfg.sectionDefault or 'page')<br />
elseif type(args.sect) == 'string' then<br />
sect = 'This ' .. args.sect<br />
end<br />
local issue = args.issue<br />
issue = type(issue) == 'string' and issue ~= '' and issue or nil<br />
local text = args.text<br />
text = type(text) == 'string' and text or nil<br />
local issues = {}<br />
tinsert(issues, sect)<br />
tinsert(issues, issue)<br />
tinsert(issues, text)<br />
self.issue = tconcat(issues, ' ')<br />
end<br />
<br />
-- Get the self.talk value.<br />
local talk = args.talk<br />
if talk == '' -- Show talk links on the template page or template subpages if the talk parameter is blank.<br />
and self.templateTitle <br />
and (mw.title.equals(self.templateTitle, self.title) or self.title:isSubpageOf(self.templateTitle))<br />
then<br />
talk = '#'<br />
elseif talk == '' then<br />
talk = nil<br />
end<br />
if talk then<br />
-- If the talk value is a talk page, make a link to that page. Else assume that it's a section heading,<br />
-- and make a link to the talk page of the current page with that section heading.<br />
local talkTitle = getTitleObject(talk)<br />
local talkArgIsTalkPage = true<br />
if not talkTitle or not talkTitle.isTalkPage then<br />
talkArgIsTalkPage = false<br />
talkTitle = getTitleObject(self.title.text, mw.site.namespaces[self.title.namespace].talk.id)<br />
end<br />
if talkTitle and talkTitle.exists then<br />
local talkText = 'Relevant discussion may be found on'<br />
if talkArgIsTalkPage then<br />
talkText = format('%s [[%s|%s]].', talkText, talk, talkTitle.prefixedText)<br />
else<br />
talkText = format('%s the [[%s#%s|talk page]].', talkText, talkTitle.prefixedText, talk)<br />
end<br />
self.talk = talkText<br />
end<br />
end<br />
<br />
-- Get other values.<br />
self.fix = args.fix ~= '' and args.fix or nil<br />
local date<br />
if args.date and args.date ~= '' then<br />
date = args.date<br />
elseif args.date == '' and self.isTemplatePage then<br />
date = lang:formatDate('F Y')<br />
end<br />
if date then<br />
self.date = format(" <small>''(%s)''</small>", date)<br />
end<br />
self.info = args.info<br />
end<br />
<br />
-- Set the non-collapsible text field. At the moment this is used by all box types other than ambox,<br />
-- and also by ambox when small=yes.<br />
if self.isSmall then<br />
self.text = args.smalltext or args.text<br />
else<br />
self.text = args.text<br />
end<br />
<br />
-- Set the below row.<br />
self.below = cfg.below and args.below<br />
<br />
-- General image settings.<br />
self.imageCellDiv = not self.isSmall and cfg.imageCellDiv and true or false<br />
self.imageEmptyCell = cfg.imageEmptyCell<br />
if cfg.imageEmptyCellStyle then<br />
self.imageEmptyCellStyle = 'border:none;padding:0px;width:1px'<br />
end<br />
<br />
-- Left image settings.<br />
local imageLeft = self.isSmall and args.smallimage or args.image<br />
if cfg.imageCheckBlank and imageLeft ~= 'blank' and imageLeft ~= 'none'<br />
or not cfg.imageCheckBlank and imageLeft ~= 'none'<br />
then<br />
self.imageLeft = imageLeft<br />
if not imageLeft then<br />
local imageSize = self.isSmall and (cfg.imageSmallSize or '30x30px') or '40x40px'<br />
self.imageLeft = format('[[File:%s|%s|link=|alt=]]', self.typeImage or 'Imbox notice.png', imageSize)<br />
end<br />
end<br />
<br />
-- Right image settings.<br />
local imageRight = self.isSmall and args.smallimageright or args.imageright<br />
if not (cfg.imageRightNone and imageRight == 'none') then<br />
self.imageRight = imageRight<br />
end<br />
<br />
-- Add mainspace categories. At the moment these are only used in {{ambox}}.<br />
if cfg.allowMainspaceCategories then<br />
if args.cat then<br />
args.cat1 = args.cat<br />
end<br />
self.catNums = getArgNums(args, 'cat')<br />
if args.category then<br />
args.category1 = args.category<br />
end<br />
self.categoryNums = getArgNums(args, 'category')<br />
if args.all then<br />
args.all1 = args.all<br />
end<br />
self.allNums = getArgNums(args, 'all')<br />
self.categoryParamNums = union(self.catNums, self.categoryNums)<br />
self.categoryParamNums = union(self.categoryParamNums, self.allNums)<br />
-- The following is roughly equivalent to the old {{Ambox/category}}.<br />
local date = args.date<br />
date = type(date) == 'string' and date<br />
local preposition = 'from'<br />
for _, num in ipairs(self.categoryParamNums) do<br />
local mainCat = args['cat' .. tostring(num)] or args['category' .. tostring(num)]<br />
local allCat = args['all' .. tostring(num)]<br />
mainCat = type(mainCat) == 'string' and mainCat<br />
allCat = type(allCat) == 'string' and allCat<br />
if mainCat and date and date ~= '' then<br />
local catTitle = format('%s %s %s', mainCat, preposition, date)<br />
self:addCat('main', catTitle)<br />
catTitle = getTitleObject('Category:' .. catTitle)<br />
if not catTitle or not catTitle.exists then<br />
self:addCat('main', 'Articles with invalid date parameter in template')<br />
end<br />
elseif mainCat and (not date or date == '') then<br />
self:addCat('main', mainCat)<br />
end<br />
if allCat then<br />
self:addCat('main', allCat)<br />
end<br />
end<br />
end<br />
<br />
-- Add template-namespace categories.<br />
if cfg.templateCategory then<br />
if cfg.templateCategoryRequireName then<br />
if self.isTemplatePage then<br />
self:addCat('template', cfg.templateCategory)<br />
end<br />
elseif not self.title.isSubpage then<br />
self:addCat('template', cfg.templateCategory)<br />
end<br />
end<br />
<br />
-- Add template error category.<br />
if cfg.templateErrorCategory then<br />
local templateErrorCategory = cfg.templateErrorCategory<br />
local templateCat, templateSort<br />
if not self.name and not self.title.isSubpage then<br />
templateCat = templateErrorCategory<br />
elseif self.isTemplatePage then<br />
local paramsToCheck = cfg.templateErrorParamsToCheck or {}<br />
local count = 0<br />
for i, param in ipairs(paramsToCheck) do<br />
if not args[param] then<br />
count = count + 1<br />
end<br />
end<br />
if count > 0 then<br />
templateCat = templateErrorCategory<br />
templateSort = tostring(count)<br />
end<br />
if self.categoryNums and #self.categoryNums > 0 then<br />
templateCat = templateErrorCategory<br />
templateSort = 'C'<br />
end<br />
end<br />
self:addCat('template', templateCat, templateSort)<br />
end<br />
<br />
-- Categories for all namespaces.<br />
if self.invalidTypeError then<br />
local allSort = (self.nsid == 0 and 'Main:' or '') .. self.title.prefixedText<br />
self:addCat('all', 'Wikipedia message box parameter needs fixing', allSort)<br />
end<br />
if self.isSubstituted then<br />
self:addCat('all', 'Pages with incorrectly substituted templates')<br />
end<br />
<br />
-- Convert category tables to strings and pass them through [[Module:Category handler]].<br />
self.categories = categoryHandler{<br />
main = tconcat(self.mainCats or {}),<br />
template = tconcat(self.templateCats or {}),<br />
all = tconcat(self.allCats or {}),<br />
nocat = args.nocat,<br />
demospace = self.demospace,<br />
page = self.pageTitle and self.pageTitle.prefixedText or nil<br />
}<br />
end<br />
<br />
function box:export()<br />
local root = htmlBuilder.create()<br />
<br />
-- Add the subst check error.<br />
if self.isSubstituted and self.name then<br />
root<br />
.tag('b')<br />
.addClass('error')<br />
.wikitext(format(<br />
'Template <code>%s[[Template:%s|%s]]%s</code> has been incorrectly substituted.',<br />
mw.text.nowiki('{{'), self.name, self.name, mw.text.nowiki('}}')<br />
))<br />
end<br />
<br />
-- Create the box table.<br />
local boxTable = root.tag('table')<br />
boxTable<br />
.attr('id', self.id)<br />
for i, class in ipairs(self.classes or {}) do<br />
boxTable<br />
.addClass(class)<br />
end<br />
boxTable<br />
.cssText(self.style)<br />
.attr('role', 'presentation')<br />
<br />
-- Add the left-hand image.<br />
local row = boxTable.tag('tr')<br />
if self.imageLeft then<br />
local imageLeftCell = row.tag('td').addClass('mbox-image')<br />
if self.imageCellDiv then<br />
-- If we are using a div, redefine imageLeftCell so that the image is inside it.<br />
-- Divs use style="width: 52px;", which limits the image width to 52px. If any<br />
-- images in a div are wider than that, they may overlap with the text or cause<br />
-- other display problems.<br />
imageLeftCell = imageLeftCell.tag('div').css('width', '52px') <br />
end<br />
imageLeftCell<br />
.wikitext(self.imageLeft)<br />
elseif self.imageEmptyCell then<br />
-- Some message boxes define an empty cell if no image is specified, and some don't.<br />
-- The old template code in templates where empty cells are specified gives the following hint:<br />
-- "No image. Cell with some width or padding necessary for text cell to have 100% width."<br />
row.tag('td')<br />
.addClass('mbox-empty-cell') <br />
.cssText(self.imageEmptyCellStyle)<br />
end<br />
<br />
-- Add the text.<br />
local textCell = row.tag('td').addClass('mbox-text')<br />
if self.useCollapsibleTextFields then<br />
-- The message box uses advanced text parameters that allow things to be collapsible. At the<br />
-- moment, only ambox uses this.<br />
textCell<br />
.cssText(self.textstyle)<br />
local textCellSpan = textCell.tag('span')<br />
textCellSpan<br />
.addClass('mbox-text-span')<br />
.wikitext(self.issue)<br />
if not self.isSmall then<br />
textCellSpan<br />
.tag('span')<br />
.addClass('hide-when-compact')<br />
.wikitext(self.talk and ' ' .. self.talk)<br />
.wikitext(self.fix and ' ' .. self.fix)<br />
end<br />
textCellSpan<br />
.wikitext(self.date and ' ' .. self.date)<br />
if not self.isSmall then<br />
textCellSpan<br />
.tag('span')<br />
.addClass('hide-when-compact')<br />
.wikitext(self.info and ' ' .. self.info)<br />
end<br />
else<br />
-- Default text formatting - anything goes.<br />
textCell<br />
.cssText(self.textstyle)<br />
.wikitext(self.text)<br />
end<br />
<br />
-- Add the right-hand image.<br />
if self.imageRight then<br />
local imageRightCell = row.tag('td').addClass('mbox-imageright')<br />
if self.imageCellDiv then<br />
imageRightCell = imageRightCell.tag('div').css('width', '52px') -- If we are using a div, redefine imageRightCell so that the image is inside it.<br />
end<br />
imageRightCell<br />
.wikitext(self.imageRight)<br />
end<br />
<br />
-- Add the below row.<br />
if self.below then<br />
boxTable.tag('tr')<br />
.tag('td')<br />
.attr('colspan', self.imageRight and '3' or '2')<br />
.addClass('mbox-text')<br />
.cssText(self.textstyle)<br />
.wikitext(self.below)<br />
end<br />
<br />
-- Add error message for invalid type parameters.<br />
if self.invalidTypeError then<br />
root<br />
.tag('div')<br />
.css('text-align', 'center')<br />
.wikitext(format('This message box is using an invalid "type=%s" parameter and needs fixing.', self.type or ''))<br />
end<br />
<br />
-- Add categories.<br />
root<br />
.wikitext(self.categories)<br />
<br />
return tostring(root)<br />
end<br />
<br />
local function main(boxType, args)<br />
local outputBox = box.new()<br />
outputBox:setTitle(args)<br />
local cfg = outputBox:getConfig(boxType)<br />
args = outputBox:removeBlankArgs(cfg, args)<br />
outputBox:setBoxParameters(cfg, args)<br />
return outputBox:export()<br />
end<br />
<br />
local function makeWrapper(boxType)<br />
return function (frame)<br />
local args = getArgs(frame, {trim = false, removeBlanks = false})<br />
return main(boxType, args)<br />
end<br />
end<br />
<br />
local p = {<br />
main = main,<br />
mbox = makeWrapper('mbox')<br />
}<br />
<br />
for boxType in pairs(cfgTables) do<br />
p[boxType] = makeWrapper(boxType)<br />
end<br />
<br />
return p</div>86.135.251.105https://mw-live.lojban.org/index.php?title=Module:Yesno&diff=84395Module:Yesno2014-02-02T12:53:42Z<p>86.135.251.105: Created page with "-- Function allowing for consistent treatment of boolean-like wikitext input. -- It works similarly to the template {{yesno}}. return function (val, default) val = type(va..."</p>
<hr />
<div>-- Function allowing for consistent treatment of boolean-like wikitext input.<br />
-- It works similarly to the template {{yesno}}.<br />
return function (val, default)<br />
val = type(val) == 'string' and mw.ustring.lower(val) or val -- put in lower case<br />
if val == nil then<br />
return nil<br />
elseif val == false or val == 'no' or val == 'n' or val == 'false' or tonumber(val) == 0 then<br />
return false<br />
elseif val == true or val == 'yes' or val == 'y' or val == 'true' or tonumber(val) == 1 then<br />
return true<br />
else<br />
return default<br />
end<br />
end</div>86.135.251.105https://mw-live.lojban.org/index.php?title=Module:Namespace_detect&diff=84393Module:Namespace detect2014-02-02T12:53:16Z<p>86.135.251.105: Created page with "---------------------------------------------------------------------------------------------------- --..."</p>
<hr />
<div>----------------------------------------------------------------------------------------------------<br />
-- --<br />
-- NAMESPACE DETECT --<br />
-- --<br />
-- This module implements the {{namespace detect}} template in Lua, with a few --<br />
-- improvements: all namespaces and all namespace aliases are supported, and namespace --<br />
-- names are detected automatically for the local wiki. The module can also use the --<br />
-- corresponding subject namespace value if it is used on a talk page. Parameter names --<br />
-- can be configured for different wikis by altering the values in the "cfg" table. --<br />
-- --<br />
----------------------------------------------------------------------------------------------------<br />
<br />
----------------------------------------------------------------------------------------------------<br />
-- Configuration data --<br />
-- Language-specific parameter names can be set here. --<br />
----------------------------------------------------------------------------------------------------<br />
<br />
local cfg = {}<br />
<br />
-- This parameter displays content for the main namespace:<br />
cfg.main = 'main'<br />
<br />
-- This parameter displays in talk namespaces:<br />
cfg.talk = 'talk'<br />
<br />
-- This parameter displays content for "other" namespaces (namespaces for which<br />
-- parameters have not been specified, or for when cfg.demospace is set to cfg.other):<br />
cfg.other = 'other'<br />
<br />
-- This parameter makes talk pages behave as though they are the corresponding subject namespace.<br />
-- Note that this parameter is used with [[Module:Yesno]]. Edit that module to change<br />
-- the default values of "yes", "no", etc.<br />
cfg.subjectns = 'subjectns'<br />
<br />
-- This parameter sets a demonstration namespace:<br />
cfg.demospace = 'demospace'<br />
<br />
-- This parameter sets a specific page to compare:<br />
cfg.page = 'page'<br />
<br />
-- The header for the namespace column in the wikitable containing the list of possible subject-space parameters.<br />
cfg.wikitableNamespaceHeader = 'Namespace'<br />
<br />
-- The header for the wikitable containing the list of possible subject-space parameters.<br />
cfg.wikitableAliasesHeader = 'Aliases'<br />
<br />
----------------------------------------------------------------------------------------------------<br />
-- End configuration data --<br />
----------------------------------------------------------------------------------------------------<br />
<br />
local yesno = require('Module:Yesno')<br />
<br />
local p = {}<br />
<br />
function p.getPageObject(page)<br />
-- Get the page object, passing the function through pcall in case we are over the expensive function count limit.<br />
if page then<br />
local noError, pageObject = pcall(mw.title.new, page)<br />
if not noError then<br />
return nil<br />
else<br />
return pageObject<br />
end<br />
else<br />
return mw.title.getCurrentTitle()<br />
end<br />
end<br />
<br />
function p.getParamMappings()<br />
--[[ Returns a table of how parameter names map to namespace names. The keys are the actual namespace <br />
names, in lower case, and the values are the possible parameter names for that namespace, also in<br />
lower case. The table entries are structured like this:<br />
{<br />
[''] = {'main'},<br />
['wikipedia'] = {'wikipedia', 'project', 'wp'},<br />
...<br />
}<br />
]] <br />
local mappings = {}<br />
mappings[mw.ustring.lower(mw.site.namespaces[0].name)] = {cfg.main}<br />
mappings[cfg.talk] = {cfg.talk}<br />
for nsid, ns in pairs(mw.site.subjectNamespaces) do<br />
if nsid ~= 0 then -- Exclude main namespace.<br />
local nsname = mw.ustring.lower(ns.name)<br />
local canonicalName = mw.ustring.lower(ns.canonicalName)<br />
mappings[nsname] = {nsname}<br />
if canonicalName ~= nsname then<br />
table.insert(mappings[nsname], canonicalName)<br />
end<br />
for _, alias in ipairs(ns.aliases) do<br />
table.insert(mappings[nsname], mw.ustring.lower(alias))<br />
end<br />
end<br />
end<br />
return mappings<br />
end<br />
<br />
local function getNamespace(args)<br />
-- Gets the namespace name from the page object.<br />
local page = args[cfg.page]<br />
local demospace = args[cfg.demospace]<br />
local subjectns = args[cfg.subjectns]<br />
local ret<br />
if demospace then<br />
-- Handle "demospace = main" properly.<br />
if mw.ustring.lower(demospace) == cfg.main then<br />
ret = mw.site.namespaces[0].name<br />
else<br />
ret = demospace<br />
end<br />
else<br />
local pageObject = p.getPageObject(page)<br />
if pageObject then<br />
if pageObject.isTalkPage then<br />
-- If cfg.subjectns is set, get the subject namespace, otherwise use cfg.talk.<br />
if yesno(subjectns) then<br />
ret = mw.site.namespaces[pageObject.namespace].subject.name<br />
else<br />
ret = cfg.talk<br />
end<br />
else<br />
ret = pageObject.nsText<br />
end<br />
else<br />
return nil -- return nil if the page object doesn't exist.<br />
end<br />
end<br />
ret = mw.ustring.gsub(ret, '_', ' ')<br />
return mw.ustring.lower(ret)<br />
end<br />
<br />
function p._main(args)<br />
-- Get the namespace to compare the parameters to, and the parameter mapping table.<br />
local namespace = getNamespace(args)<br />
local mappings = p.getParamMappings()<br />
-- Check for any matches in the namespace arguments. The order we check them doesn't matter,<br />
-- as there can only be one match.<br />
for ns, params in pairs(mappings) do<br />
if ns == namespace then<br />
-- Check all aliases for matches. The default local namespace is checked first, as<br />
-- {{namespace detect}} checked these before alias names.<br />
for _, param in ipairs(params) do<br />
if args[param] ~= nil then<br />
return args[param]<br />
end<br />
end<br />
end<br />
end<br />
-- If there were no matches, return parameters for other namespaces. This happens if there<br />
-- was no text specified for the namespace that was detected or if the demospace parameter<br />
-- is not a valid namespace. Note that the parameter for the detected namespace must be<br />
-- completely absent for this to happen, not merely blank.<br />
if args[cfg.other] ~= nil then<br />
return args[cfg.other]<br />
end<br />
end<br />
<br />
function p.main(frame)<br />
-- If called via #invoke, use the args passed into the invoking template, or the args<br />
-- passed to #invoke if any exist. Otherwise assume args are being passed directly in.<br />
local origArgs<br />
if frame == mw.getCurrentFrame() then<br />
origArgs = frame:getParent().args<br />
for k, v in pairs(frame.args) do<br />
origArgs = frame.args<br />
break<br />
end<br />
else<br />
origArgs = frame<br />
end<br />
-- Trim whitespace and remove blank arguments for demospace and page parameters.<br />
local args = {}<br />
for k, v in pairs(origArgs) do<br />
if type(v) == 'string' then<br />
v = mw.text.trim(v) -- Trim whitespace.<br />
end<br />
if k == cfg.demospace or k == cfg.page then<br />
if v ~= '' then<br />
args[k] = v<br />
end<br />
else<br />
args[k] = v<br />
end<br />
end<br />
return p._main(args)<br />
end<br />
<br />
function p.table(frame)<br />
--[[ Create a wikitable of all subject namespace parameters, for documentation purposes. The talk <br />
parameter is optional, in case it needs to be excluded in the documentation.<br />
]]<br />
local useTalk = type(frame) == 'table' and type(frame.args) == 'table' and frame.args.talk == 'yes' -- Whether to use the talk parameter.<br />
local mappings = p.getParamMappings()<br />
-- Start the wikitable.<br />
local ret = '{| class="wikitable"'<br />
.. '\n|-'<br />
.. '\n! ' .. cfg.wikitableNamespaceHeader<br />
.. '\n! ' .. cfg.wikitableAliasesHeader<br />
<br />
-- Generate the row for the main namespace, as we want this to be first in the list.<br />
ret = ret .. '\n|-'<br />
.. '\n| <code>' .. cfg.main .. '</code>'<br />
.. '\n|'<br />
if useTalk then<br />
ret = ret .. '\n|-'<br />
.. '\n| <code>' .. cfg.talk .. '</code>'<br />
.. '\n|'<br />
end<br />
-- Enclose all parameter names in <code> tags.<br />
for ns, params in pairs(mappings) do<br />
if ns ~= mw.site.namespaces[0].name then<br />
for i, param in ipairs(params) do<br />
mappings[ns][i] = '<code>' .. param .. '</code>'<br />
end<br />
end<br />
end<br />
-- Generate the other wikitable rows.<br />
for ns, params in pairs(mappings) do<br />
if ns ~= mw.site.namespaces[0].name then -- Ignore the main namespace.<br />
ret = ret .. '\n|-'<br />
.. '\n| ' .. params[1]<br />
.. '\n| ' .. table.concat(params, ', ', 2)<br />
end<br />
end<br />
-- End the wikitable.<br />
ret = ret .. '\n|-'<br />
.. '\n|}'<br />
return ret<br />
end<br />
<br />
return p</div>86.135.251.105https://mw-live.lojban.org/index.php?title=Module:Category_handler&diff=84385Module:Category handler2014-02-02T12:52:33Z<p>86.135.251.105: Created page with "---------------------------------------------------------------------------------------------------------- --..."</p>
<hr />
<div>----------------------------------------------------------------------------------------------------------<br />
-- --<br />
-- CATEGORY HANDLER --<br />
-- --<br />
-- This module implements the {{category handler}} template in Lua, with a few improvements: all --<br />
-- namespaces and all namespace aliases are supported, and namespace names are detected --<br />
-- automatically for the local wiki. This module requires [[Module:Namespace detect]] and --<br />
-- [[Module:Yesno]] to be available on the local wiki. It can be configured for different wikis --<br />
-- by altering the values in the "cfg" table. --<br />
-- --<br />
----------------------------------------------------------------------------------------------------------<br />
<br />
----------------------------------------------------------------------------------------------------------<br />
-- Configuration data --<br />
-- Language-specific parameter names and values can be set here. --<br />
----------------------------------------------------------------------------------------------------------<br />
<br />
local cfg = {}<br />
<br />
-- The following config values set the names of parameters that suppress categorisation. They are used<br />
-- with Module:Yesno, and work as follows:<br />
--<br />
-- cfg.nocat:<br />
-- Result of yesno(args[cfg.nocat]) Effect<br />
-- true Categorisation is suppressed<br />
-- false Categorisation is allowed, and the blacklist check is skipped<br />
-- nil Categorisation is allowed<br />
--<br />
-- cfg.categories:<br />
-- Result of yesno(args[cfg.categories]) Effect<br />
-- true Categorisation is allowed, and the blacklist check is skipped<br />
-- false Categorisation is suppressed<br />
-- nil Categorisation is allowed<br />
cfg.nocat = 'nocat' <br />
cfg.categories = 'categories'<br />
<br />
-- The parameter name for the legacy "category2" parameter. This skips the blacklist if set to the<br />
-- cfg.category2Yes value, and suppresses categorisation if present but equal to anything other than<br />
-- cfg.category2Yes or cfg.category2Negative.<br />
cfg.category2 = 'category2'<br />
cfg.category2Yes = 'yes'<br />
cfg.category2Negative = '¬'<br />
<br />
-- cfg.subpage is the parameter name to specify how to behave on subpages. cfg.subpageNo is the value to<br />
-- specify to not categorise on subpages; cfg.only is the value to specify to only categorise on subpages.<br />
cfg.subpage = 'subpage'<br />
cfg.subpageNo = 'no'<br />
cfg.subpageOnly = 'only'<br />
<br />
-- The parameter for data to return in all namespaces.<br />
cfg.all = 'all'<br />
<br />
-- The parameter name for data to return if no data is specified for the namespace that is detected. This<br />
-- must be the same as the cfg.other parameter in [[Module:Namespace detect]].<br />
cfg.other = 'other'<br />
<br />
-- The parameter name used to specify a page other than the current page; used for testing and<br />
-- demonstration. This must be the same as the cfg.page parameter in [[Module:Namespace detect]].<br />
cfg.page = 'page'<br />
<br />
-- The categorisation blacklist. Pages that match Lua patterns in this list will not be categorised.<br />
-- (However, see the explanation of cfg.nocat, cfg.categories and cfg.category2 for some exceptions.)<br />
-- If the namespace name has a space in, it must be written with an underscore, e.g. "Wikipedia_talk".<br />
-- Other parts of the title can have either underscores or spaces.<br />
cfg.blacklist = {<br />
'^Main Page$', -- don't categorise the main page.<br />
<br />
-- Don't categorise the following pages or their subpages.<br />
'^Wikipedia:Cascade%-protected items$',<br />
'^Wikipedia:Cascade%-protected items/.*$',<br />
'^User:UBX$', -- The userbox "template" space.<br />
'^User:UBX/.*$',<br />
'^User_talk:UBX$',<br />
'^User_talk:UBX/.*$',<br />
<br />
-- Don't categorise subpages of these pages, but allow<br />
-- categorisation of the base page.<br />
'^Wikipedia:Template messages/.+$',<br />
<br />
'/[aA]rchive' -- Don't categorise archives.<br />
}<br />
<br />
-- This is a table of namespaces to categorise by default. They should be in the format of parameter<br />
-- names accepted by [[Module:Namespace detect]].<br />
cfg.defaultNamespaces = {<br />
'main',<br />
'file',<br />
'help',<br />
'category'<br />
}<br />
<br />
----------------------------------------------------------------------------------------------------------<br />
-- End configuration data --<br />
----------------------------------------------------------------------------------------------------------<br />
<br />
-- Get dependent modules<br />
local nsDetect = require('Module:Namespace detect')<br />
local yesno = require('Module:Yesno')<br />
<br />
----------------------------------------------------------------------------------------------------------<br />
-- Local functions --<br />
-- The following are internal functions, which we do not want to be accessible from other modules. --<br />
----------------------------------------------------------------------------------------------------------<br />
<br />
-- Find whether we need to return a category or not.<br />
local function needsCategory(pageObject, args)<br />
-- Don't categorise if the relevant options are set.<br />
if yesno(args[cfg.nocat])<br />
or yesno(args[cfg.categories]) == false<br />
or (<br />
args[cfg.category2] <br />
and args[cfg.category2] ~= cfg.category2Yes <br />
and args[cfg.category2] ~= cfg.category2Negative<br />
)<br />
then<br />
return false<br />
end<br />
-- If there is no pageObject available, then that either means that we are over<br />
-- the expensive function limit or that the title specified was invalid. Invalid<br />
-- titles will probably only be a problem during testing, so we choose the best<br />
-- fallback for being over the expensive function limit. The fallback behaviour<br />
-- of the old template was to assume the page was not a subpage, so we will do<br />
-- the same here.<br />
if args[cfg.subpage] == cfg.subpageNo and pageObject and pageObject.isSubpage then<br />
return false<br />
end<br />
if args[cfg.subpage] == cfg.subpageOnly <br />
and (not pageObject or (pageObject and not pageObject.isSubpage))<br />
then<br />
return false<br />
end<br />
return true<br />
end<br />
<br />
-- Find whether we need to check the blacklist or not.<br />
local function needsBlacklistCheck(args)<br />
if yesno(args[cfg.nocat]) == false<br />
or yesno(args[cfg.categories]) == true<br />
or args[cfg.category2] == cfg.category2Yes<br />
then<br />
return false<br />
else<br />
return true<br />
end<br />
end<br />
<br />
-- Find whether any namespace parameters have been specified.<br />
-- Mappings is the table of parameter mappings taken from<br />
-- [[Module:Namespace detect]].<br />
local function nsParamsExist(mappings, args)<br />
if args[cfg.all] or args[cfg.other] then<br />
return true<br />
end<br />
for ns, params in pairs(mappings) do<br />
for i, param in ipairs(params) do<br />
if args[param] then<br />
return true<br />
end<br />
end<br />
end<br />
return false<br />
end<br />
<br />
----------------------------------------------------------------------------------------------------------<br />
-- Global functions --<br />
-- The following functions are global, because we want them to be accessible from #invoke and --<br />
-- from other Lua modules. --<br />
----------------------------------------------------------------------------------------------------------<br />
<br />
local p = {}<br />
<br />
-- Find if a string matches the blacklist. Returns the match if one is found, or nil otherwise.<br />
-- Input should be a page title with a namespace prefix, e.g. "Wikipedia talk:Articles for deletion".<br />
function p.matchesBlacklist(page)<br />
if type(page) ~= 'string' then return end<br />
for i, pattern in ipairs(cfg.blacklist) do<br />
local match = mw.ustring.match(page, pattern)<br />
if match then<br />
return match<br />
end<br />
end<br />
end<br />
<br />
-- The main structure of the module. Checks whether we need to categorise,<br />
-- and then passes the relevant arguments to [[Module:Namespace detect]].<br />
function p._main(args)<br />
-- Get the page object and argument mappings from<br />
-- [[Module:Namespace detect]], to save us from having to rewrite the<br />
-- code.<br />
local pageObject = nsDetect.getPageObject(args[cfg.page])<br />
local mappings = nsDetect.getParamMappings()<br />
<br />
if not needsCategory(pageObject, args) then return end<br />
<br />
local ret = ''<br />
-- Check blacklist if necessary.<br />
if not needsBlacklistCheck(args) or not p.matchesBlacklist(pageObject.prefixedText) then<br />
if not nsParamsExist(mappings, args) then<br />
-- No namespace parameters exist; basic usage. Pass args[1] to<br />
-- [[Module:Namespace detect]] using the default namespace<br />
-- parameters, and return the result.<br />
local ndargs = {}<br />
for _, ndarg in ipairs(cfg.defaultNamespaces) do<br />
ndargs[ndarg] = args[1]<br />
end<br />
ndargs.page = args.page<br />
ndargs.demospace = args.demospace<br />
local ndresult = nsDetect._main(ndargs)<br />
if ndresult then<br />
ret = ret .. ndresult<br />
end<br />
else<br />
-- Namespace parameters exist; advanced usage.<br />
-- If the all parameter is specified, return it.<br />
local all = args.all<br />
if type(all) == 'string' then<br />
ret = ret .. all<br />
end<br />
<br />
-- Get the arguments to pass to [[Module:Namespace detect]].<br />
local ndargs = {}<br />
for ns, params in pairs(mappings) do<br />
for _, param in ipairs(params) do<br />
ndargs[param] = args[param] or args[cfg.other] or nil<br />
end<br />
end<br />
ndargs.other = args.other<br />
ndargs.page = args.page<br />
ndargs.demospace = args.demospace<br />
<br />
local data = nsDetect._main(ndargs)<br />
<br />
-- Work out what to return based on the result of the namespace detect call.<br />
local datanum = tonumber(data)<br />
if type(datanum) == 'number' then<br />
-- "data" is a number, so return that positional parameter.<br />
-- Remove non-positive integer values, as only positive integers<br />
-- from 1-10 were used with the old template.<br />
if datanum > 0 and math.floor(datanum) == datanum then<br />
local dataArg = args[datanum]<br />
if type(dataArg) == 'string' then<br />
ret = ret .. dataArg<br />
end<br />
end<br />
else<br />
-- "data" is not a number, so return it as it is.<br />
if type(data) == 'string' then<br />
ret = ret .. data<br />
end<br />
end<br />
end<br />
end<br />
return ret<br />
end<br />
<br />
function p.main(frame)<br />
-- If called via #invoke, use the args passed into the invoking<br />
-- template, or the args passed to #invoke if any exist. Otherwise<br />
-- assume args are being passed directly in.<br />
local origArgs<br />
if frame == mw.getCurrentFrame() then<br />
origArgs = frame:getParent().args<br />
for k, v in pairs(frame.args) do<br />
origArgs = frame.args<br />
break<br />
end<br />
else<br />
origArgs = frame<br />
end<br />
<br />
-- Trim whitespace and remove blank arguments for the following args:<br />
-- 1, 2, 3 etc., "nocat", "categories", "subpage", and "page".<br />
local args = {}<br />
for k, v in pairs(origArgs) do<br />
if type(v) == 'string' then<br />
v = mw.text.trim(v) -- Trim whitespace.<br />
end<br />
if type(k) == 'number'<br />
or k == cfg.nocat<br />
or k == cfg.categories<br />
or k == cfg.subpage<br />
or k == cfg.page<br />
then<br />
if v ~= '' then<br />
args[k] = v<br />
end<br />
else<br />
args[k] = v<br />
end<br />
end<br />
<br />
-- Lower-case "nocat", "categories", "category2", and "subpage". These<br />
-- parameters are put in lower case whenever they appear in the old<br />
-- template, so we can just do it once here and save ourselves some work.<br />
local lowercase = {cfg.nocat, cfg.categories, cfg.category2, cfg.subpage}<br />
for _, v in ipairs(lowercase) do<br />
local argVal = args[v]<br />
if type(argVal) == 'string' then<br />
args[v] = mw.ustring.lower(argVal)<br />
end<br />
end<br />
<br />
return p._main(args)<br />
end<br />
<br />
return p</div>86.135.251.105https://mw-live.lojban.org/index.php?title=Module:Arguments&diff=84246Module:Arguments2014-02-02T12:52:03Z<p>86.135.251.105: Created page with "-- This module provides easy processing of arguments passed to Scribunto from #invoke. -- It is intended for use by other Lua modules, and should not be called from #invoke di..."</p>
<hr />
<div>-- This module provides easy processing of arguments passed to Scribunto from #invoke.<br />
-- It is intended for use by other Lua modules, and should not be called from #invoke directly.<br />
<br />
local libraryUtil = require('libraryUtil')<br />
local checkType = libraryUtil.checkType<br />
<br />
local arguments = {}<br />
<br />
local nilArg = {} -- Used for memoizing nil arguments in metaArgs.<br />
<br />
-- Generate four different tidyVal functions, so that we don't have to check the options every time we call it.<br />
<br />
local function tidyValDefault(key, val)<br />
if type(val) == 'string' then<br />
val = val:match('^%s*(.-)%s*$')<br />
if val == '' then<br />
return nil<br />
else<br />
return val<br />
end<br />
else<br />
return val<br />
end<br />
end<br />
<br />
local function tidyValTrimOnly(key, val)<br />
if type(val) == 'string' then<br />
return val:match('^%s*(.-)%s*$')<br />
else<br />
return val<br />
end<br />
end<br />
<br />
local function tidyValRemoveBlanksOnly(key, val)<br />
if type(val) == 'string' then<br />
if val:find('%S') then<br />
return val<br />
else<br />
return nil<br />
end<br />
else<br />
return val<br />
end<br />
end<br />
<br />
local function tidyValNoChange(key, val)<br />
return val<br />
end<br />
<br />
function arguments.getArgs(frame, options)<br />
checkType('getArgs', 1, frame, 'table', true)<br />
checkType('getArgs', 2, options, 'table', true)<br />
frame = frame or {}<br />
options = options or {}<br />
<br />
-- Get the arguments from the frame object if available. If the frame object is not available, we are being called<br />
-- from another Lua module or from the debug console, so assign the args to a new variable so we can differentiate them.<br />
local fargs, pargs, luaArgs<br />
if type(frame.args) == 'table' and type(frame.getParent) == 'function' then<br />
if not options.parentOnly then<br />
fargs = frame.args<br />
end<br />
if not options.frameOnly then<br />
pargs = frame:getParent().args<br />
end<br />
if options.parentFirst then<br />
fargs, pargs = pargs, fargs<br />
end<br />
else<br />
luaArgs = frame<br />
end<br />
<br />
-- Set up the args and metaArgs tables. args will be the one accessed from functions, and metaArgs will hold the actual arguments.<br />
-- The metatable connects the two together.<br />
local args, metaArgs, metatable = {}, {}, {}<br />
setmetatable(args, metatable)<br />
<br />
-- Generate the tidyVal function. If it has been specified by the user, we use that; if not, we choose one of four functions<br />
-- depending on the options chosen. This is so that we don't have to call the options table every time the function is called.<br />
local tidyVal = options.valueFunc<br />
if tidyVal then<br />
if type(tidyVal) ~= 'function' then<br />
error("bad value assigned to option 'valueFunc' (function expected, got " .. type(tidyVal) .. ')', 2)<br />
end<br />
elseif options.trim ~= false then<br />
if options.removeBlanks ~= false then<br />
tidyVal = tidyValDefault<br />
else<br />
tidyVal = tidyValTrimOnly<br />
end<br />
else<br />
if options.removeBlanks ~= false then<br />
tidyVal = tidyValRemoveBlanksOnly<br />
else<br />
tidyVal = tidyValNoChange<br />
end<br />
end<br />
<br />
local function mergeArgs(iterator, tables)<br />
-- Accepts multiple tables as input and merges their keys and values into one table using the specified iterator.<br />
-- If a value is already present it is not overwritten; tables listed earlier have precedence.<br />
-- We are also memoizing nil values, but those values can be overwritten.<br />
for _, t in ipairs(tables) do<br />
for key, val in iterator(t) do<br />
local metaArgsVal = metaArgs[key]<br />
if metaArgsVal == nil or metaArgsVal == nilArg then<br />
local tidiedVal = tidyVal(key, val)<br />
if tidiedVal == nil then<br />
metaArgs[key] = nilArg<br />
else<br />
metaArgs[key] = tidiedVal<br />
end<br />
end<br />
end<br />
end<br />
end<br />
<br />
-- Set the order of precedence of the argument tables. If the variables are nil, nothing will be added to the table,<br />
-- which is how we avoid clashes between the frame/parent args and the Lua args. <br />
local argTables = {fargs}<br />
argTables[#argTables + 1] = pargs<br />
argTables[#argTables + 1] = luaArgs<br />
<br />
--[[<br />
-- Define metatable behaviour. Arguments are memoized in the metaArgs table, and are only fetched from the<br />
-- argument tables once. Nil arguments are also memoized using the nilArg variable in order to increase<br />
-- performance. Also, we keep a record in the metatable of when pairs and ipairs have been called, so we<br />
-- do not run pairs and ipairs on fargs and pargs more than once. We also do not run ipairs on fargs and<br />
-- pargs if pairs has already been run, as all the arguments will already have been copied over.<br />
--]]<br />
<br />
metatable.__index = function (t, key)<br />
local val = metaArgs[key]<br />
if val ~= nil then<br />
if val == nilArg then<br />
return nil<br />
else<br />
return val<br />
end<br />
end<br />
for _, argTable in ipairs(argTables) do<br />
local argTableVal = tidyVal(key, argTable[key])<br />
if argTableVal == nil then<br />
metaArgs[key] = nilArg<br />
else<br />
metaArgs[key] = argTableVal<br />
return argTableVal<br />
end<br />
end<br />
return nil<br />
end<br />
<br />
metatable.__newindex = function (t, key, val)<br />
if options.readOnly then<br />
error('could not write to argument table key "' .. tostring(key) .. '"; the table is read-only', 2)<br />
elseif options.noOverwrite and args[key] ~= nil then<br />
error('could not write to argument table key "' .. tostring(key) .. '"; overwriting existing arguments is not permitted', 2)<br />
elseif val == nil then<br />
metaArgs[key] = nilArg -- Memoize nils.<br />
else<br />
metaArgs[key] = val<br />
end<br />
end<br />
<br />
metatable.__pairs = function ()<br />
if not metatable.donePairs then<br />
mergeArgs(pairs, argTables)<br />
metatable.donePairs = true<br />
metatable.doneIpairs = true<br />
end<br />
return function (t, k)<br />
local nk, val = next(metaArgs, k)<br />
if val == nilArg then<br />
val = nil<br />
end<br />
return nk, val<br />
end<br />
end<br />
<br />
metatable.__ipairs = function ()<br />
if not metatable.doneIpairs then<br />
mergeArgs(ipairs, argTables)<br />
metatable.doneIpairs = true<br />
end<br />
return function (t, i)<br />
local val = metaArgs[i + 1]<br />
if val == nil then<br />
return nil<br />
elseif val == nilArg then<br />
val = nil<br />
end<br />
return i + 1, val<br />
end, nil, 0<br />
end<br />
<br />
return args<br />
end<br />
<br />
return arguments</div>86.135.251.105https://mw-live.lojban.org/index.php?title=Template:Ambox&diff=84363Template:Ambox2014-02-02T12:50:45Z<p>86.135.251.105: Replaced content with "{{#invoke:Message box|ambox}}<noinclude> {{documentation}} <!-- Categories go on the /doc subpage, and interwikis go on Wikidata. -->"</p>
<hr />
<div>{{#invoke:Message box|ambox}}<noinclude> <br />
{{documentation}} <br />
<!-- Categories go on the /doc subpage, and interwikis go on Wikidata. --></div>86.135.251.105