45,625
edits
No edit summary |
Tag: Undo |
||
(9 intermediate revisions by the same user not shown) | |||
Line 38: | Line 38: | ||
} | } | ||
end | end | ||
local function make_Unicode_data_documentation(title, cats) | local function make_Unicode_data_documentation(title, cats) | ||
Line 70: | Line 56: | ||
-- This provides categories and documentation for various data modules, so that | -- This provides categories and documentation for various data modules, so that | ||
-- [[Category:Uncategorized modules]] isn’t unnecessarily cluttered. | -- [[Category:Uncategorized modules]] isn’t unnecessarily cluttered. | ||
-- It is a list of tables, each of which have | -- It is a list of tables, each of which have the following possible fields: | ||
-- | -- `regex` (required): A Lua pattern to match the module's title. If it matches, the data in this entry will be used. | ||
-- Any captures in the pattern can by referenced in the `cat` field using %1 for the first capture, %2 for the | |||
-- | -- second, etc. (often used for creating the sortkey for the category). In addition, the captures are passed to the | ||
-- | -- `process` function as the third and subsequent parameters. | ||
-- | -- `process` (optional): This may be a function or a string. If it is a function, it is called as follows: | ||
-- process(TITLE, CATS, CAPTURE1, CAPTURE2, ...) | |||
-- where: | |||
-- | -- * TITLE is a title object describing the module's title; see [https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Title_objects]. | ||
-- | -- * CATS is an array object (see [[Module:array]]) of categories that the module will be added to. | ||
-- * CAPTURE1, CAPTURE2, ... contain any captures in the `regex` field. | |||
-- | -- The return value of `process` should be a string and will be used as the module's documentation. | ||
-- If `process` is a string, it is the name of a submodule under 'Module:documentation/functions/' which returns a | |||
-- function, of the same type as described above. If `process` is omitted entirely, the module will have no | |||
-- documentation. | |||
-- | -- `cat` (optional): A string naming the category into which the module should be placed. Captures specified in `regex` | ||
-- may be referenced in this string using %1 for the first capture, %2 for the second, etc. Currently, in order to put | |||
-- | -- the module into multiple categories, you need to write a `process` function that adds categories to the CATS | ||
-- parameter passed in. | |||
-- | |||
-- | |||
local module_regex = { | local module_regex = { | ||
{ | { | ||
regex = "^Module:languages/.+$", | regex = "^Module:languages/.+$", | ||
cat = " | cat = "Language and script modules", | ||
}, | }, | ||
{ | { | ||
regex = "^Module:scripts/.+$", | regex = "^Module:scripts/.+$", | ||
cat = " | cat = "Language and script modules", | ||
}, | }, | ||
{ | { | ||
Line 111: | Line 98: | ||
regex = "^Module:zh/data/dial%-pron/.+$", | regex = "^Module:zh/data/dial%-pron/.+$", | ||
cat = "Chinese dialectal pronunciation data modules", | cat = "Chinese dialectal pronunciation data modules", | ||
process = "zh dial or syn", | |||
}, | }, | ||
{ | { | ||
regex = "^Module:zh/data/dial%-syn/.+$", | regex = "^Module:zh/data/dial%-syn/.+$", | ||
cat = "Chinese dialectal synonyms data modules", | cat = "Chinese dialectal synonyms data modules", | ||
process = "zh dial or syn", | |||
}, | }, | ||
{ | { | ||
regex = "^Module:zh/data/glyph%-data/.+$", | regex = "^Module:zh/data/glyph%-data/.+$", | ||
cat = "Chinese historical character forms data modules", | cat = "Chinese historical character forms data modules", | ||
process = function(title, cats) | |||
local character = title.fullText:match("^Module:zh/data/glyph%-data/(.+)") | local character = title.fullText:match("^Module:zh/data/glyph%-data/(.+)") | ||
if character then | if character then | ||
Line 132: | Line 119: | ||
regex = "^Module:zh/data/ltc%-pron/(.+)$", | regex = "^Module:zh/data/ltc%-pron/(.+)$", | ||
cat = "Middle Chinese pronunciation data modules|%1", | cat = "Middle Chinese pronunciation data modules|%1", | ||
process = "zh data", | |||
}, | }, | ||
{ | { | ||
regex = "^Module:zh/data/och%-pron%-BS/(.+)$", | regex = "^Module:zh/data/och%-pron%-BS/(.+)$", | ||
cat = "Old Chinese (Baxter-Sagart) pronunciation data modules|%1", | cat = "Old Chinese (Baxter-Sagart) pronunciation data modules|%1", | ||
process = "zh data", | |||
}, | }, | ||
{ | { | ||
regex = "^Module:zh/data/och%-pron%-ZS/(.+)$", | regex = "^Module:zh/data/och%-pron%-ZS/(.+)$", | ||
cat = "Old Chinese (Zhengzhang) pronunciation data modules|%1", | cat = "Old Chinese (Zhengzhang) pronunciation data modules|%1", | ||
process = "zh data", | |||
}, | }, | ||
{ | { | ||
-- capture rest of zh/data submodules | |||
regex = "^Module:zh/data/(.+)$", | regex = "^Module:zh/data/(.+)$", | ||
cat = "Chinese data modules|%1", | cat = "Chinese data modules|%1", | ||
Line 151: | Line 138: | ||
{ | { | ||
regex = "^Module:mul/guoxue%-data/cjk%-?(.*)$", | regex = "^Module:mul/guoxue%-data/cjk%-?(.*)$", | ||
process = "guoxue-data", | |||
}, | }, | ||
{ | { | ||
regex = "^Module:Unicode data/(.+)$", | regex = "^Module:Unicode data/(.+)$", | ||
cat = "Unicode data modules|%1", | cat = "Unicode data modules|%1", | ||
process = make_Unicode_data_documentation, | |||
}, | }, | ||
{ | { | ||
regex = "^Module:number list/data/(.+)$", | regex = "^Module:number list/data/(.+)$", | ||
process = "number list", | |||
}, | }, | ||
{ | { | ||
regex = "^Module:accel/(.+)$", | regex = "^Module:accel/(.+)$", | ||
process = function(title, cats) | |||
local lang_code = title.subpageText | |||
local lang = lang_cache[lang_code] | |||
if lang then | |||
cats:insert(lang:getCanonicalName() .. " modules|accel") | |||
cats:insert(("Accel submodules|%s"):format(lang:getCanonicalName())) | |||
return ("This module contains new entry creation rules for %s; see [[WT:ACCEL]] for an overview, and [[Module:accel]] for information on creating new rules.") | |||
:format(lang:makeCategoryLink()) | |||
end | |||
end, | |||
}, | }, | ||
{ | { | ||
regex = "^Module:inc%-ash/dial/data/(.+)$", | regex = "^Module:inc%-ash/dial/data/(.+)$", | ||
cat = "Ashokan Prakrit modules|%1", | cat = "Ashokan Prakrit modules|%1", | ||
process = function(title, cats) | |||
local word = title.fullText:match("^Module:inc%-ash/dial/data/(.+)$") | local word = title.fullText:match("^Module:inc%-ash/dial/data/(.+)$") | ||
if word then | if word then | ||
Line 188: | Line 177: | ||
{ | { | ||
regex = "^Module:[%l-]+:Dialects$", | regex = "^Module:[%l-]+:Dialects$", | ||
process = function(title, cats) | |||
local content = title:getContent() | local content = title:getContent() | ||
local has_aliases = content:find("aliases") ~= nil | local has_aliases = content:find("aliases") ~= nil | ||
Line 200: | Line 188: | ||
{ | { | ||
regex = "^.+%-translit$", | regex = "^.+%-translit$", | ||
cat = | process = "translit", | ||
}, | |||
{ | |||
regex = "^Module:category tree/poscatboiler/data/lang%-specific/(.+)$", | |||
process = function(title, cats, lang_code) | |||
local lang = lang_cache[lang_code] | |||
if lang then | |||
local langname = lang:getCanonicalName() | |||
cats:insert("Category tree data modules/poscatboiler|" .. langname) | |||
cats:insert(langname .. " modules") | |||
cats:insert(langname .. " data modules") | |||
return "This module handles generating the descriptions and categorization for " .. langname .. " category pages " | |||
.. "of the format \"" .. langname .. " LABEL\" where LABEL can be any text. Examples are " | |||
.. "[[:Category:Bulgarian conjugation 2.1 verbs]] and [[:Category:Russian velar-stem neuter-form nouns]]. " | |||
.. "This module is part of the poscatboiler system, which is a general framework for generating the " | |||
.. "descriptions and categorization of category pages.\n\n" | |||
.. "For more information, see [[Module:category tree/poscatboiler/data/lang-specific/documentation]]." | |||
end | |||
end | |||
}, | |||
{ | |||
regex = "^Module:category tree/poscatboiler/data/(.+)$", | |||
cat = "Category tree data modules/poscatboiler|%1", | |||
}, | |||
{ | |||
regex = "^Module:ja/data/(.+)$", | |||
cat = "Japanese data modules|%1", | |||
}, | |||
{ | |||
regex = "^Module:Swadesh/data/(.+)$", | |||
cat = "Swadesh modules|%1", | |||
}, | |||
{ | |||
regex = "^Module:typing%-aids", | |||
process = function(title, cats) | |||
local data_suffix = title.fullText:match("^Module:typing%-aids/data/(.+)$") | |||
if data_suffix then | |||
cats:insert("Data modules") | |||
if data_suffix:find "^[%l-]+$" then | |||
local lang = require "Module:languages".getByCode(data_suffix) | |||
if lang then | |||
cats:insert(lang:getCanonicalName() .. " modules") | |||
end | |||
elseif data_suffix:find "^%u%l%l%l$" then | |||
local script = require "Module:scripts".getByCode(data_suffix) | |||
if script then | |||
cats:insert(script:getCategoryName()) | |||
end | |||
end | |||
end | |||
end, | |||
}, | |||
{ | |||
regex = "^Module:R:([a-z%-]+):(.+)$", | |||
process = function(title, cats, lang_code, refname) | |||
local lang = lang_cache[lang_code] | |||
if lang then | |||
cats:insert(lang:getCanonicalName() .. " modules|" .. refname) | |||
cats:insert(("Reference modules|%s"):format(lang:getCanonicalName())) | |||
return mw.getCurrentFrame():preprocess("This module implements the reference template {{temp|R:" .. | |||
lang_code .. ":" .. refname .. "}}.") | |||
end | |||
end, | |||
}, | }, | ||
} | } | ||
Line 286: | Line 335: | ||
else | else | ||
if contentModel == "Scribunto" then | if contentModel == "Scribunto" then | ||
local | local automatic_cats = nil | ||
if user_name then | if user_name then | ||
fallback_docs = | fallback_docs = "documentation/fallback/user module" | ||
automatic_cats = {"User sandbox modules"} | |||
else | else | ||
for _, data in ipairs(module_regex) do | for _, data in ipairs(module_regex) do | ||
local captures = {mw.ustring.match(title.fullText, data.regex)} | |||
if #captures > 0 then | |||
local cat | local cat | ||
local | local process_function | ||
if type(data. | if type(data.process) == "function" then | ||
process_function = data.process | |||
elseif type(data. | elseif type(data.process) == "string" then | ||
doc_content_module = "Module:documentation/functions/" .. data. | doc_content_module = "Module:documentation/functions/" .. data.process | ||
process_function = require(doc_content_module) | |||
end | end | ||
if | if process_function then | ||
doc_content = | doc_content = process_function(title, cats, unpack(captures)) | ||
end | end | ||
cat = data.cat | cat = data.cat | ||
if cat then | if cat then | ||
if type(cat) == "string" then | |||
cat = {cat} | |||
end | |||
for _, c in ipairs(cat) do | |||
-- gsub() and Lua :gsub() return two arguments, which causes all sorts of problems. | |||
-- Terrible design, there should have been a separate two-argument function. | |||
local gsub_sucks = mw.ustring.gsub(title.fullText, data.regex, c) | |||
table.insert(cats, gsub_sucks) | |||
end | |||
end | end | ||
break | break | ||
Line 318: | Line 372: | ||
end | end | ||
end | end | ||
if not automatic_cats then | |||
if not | |||
local success, auto_cats = | local success, auto_cats = | ||
pcall(require("Module:module categorization").categorize, frame, true) | pcall(require("Module:module categorization").categorize, frame, true) | ||
Line 329: | Line 382: | ||
end | end | ||
end | end | ||
if title.subpageText == "templates" then | if title.subpageText == "templates" then | ||
cats:insert("Template interface modules") | cats:insert("Template interface modules") | ||
end | end | ||
if automatic_cats then | |||
for _, c in ipairs(automatic_cats) do | |||
cats:insert(c) | |||
end | |||
end | |||
-- meaning module is not in user’s sandbox or one of many datamodule boring series | -- meaning module is not in user’s sandbox or one of many datamodule boring series | ||
needs_doc = not ( | needs_doc = not (automatic_cats or doc_content or fallback_docs) | ||
elseif title.nsText == "Template" then | elseif title.nsText == "Template" then | ||
--cats:insert("Uncategorized templates") | --cats:insert("Uncategorized templates") | ||
Line 494: | Line 551: | ||
if page_exists(sandbox_of) then | if page_exists(sandbox_of) then | ||
diff = " (" .. compare_pages(title.fullText, sandbox_of, "diff") .. ")" | diff = " (" .. compare_pages(title.fullText, sandbox_of, "diff") .. ")" | ||
end | end | ||
Line 527: | Line 582: | ||
if title.nsText == "Template" then | if title.nsText == "Template" then | ||
-- Error search: all(any namespace), hastemplate (show pages using the template), insource (show source code), incategory (any/specific error) -- [[mw:Help:CirrusSearch]], [[w:Help:Searching/Regex]] | |||
-- apparently same with/without: &profile=advanced&fulltext=1 | |||
local errorq = 'searchengineselect=mediawiki&search=all: hastemplate:\"'..title.rootText..'\" insource:\"'..title.rootText..'\" incategory:' | |||
local eincategory = "Pages_with_module_errors|ParserFunction_errors|DisplayTitle_errors|Pages_with_ISBN_errors|Pages_with_ISSN_errors|Pages_with_reference_errors|Pages_with_syntax_highlighting_errors|Pages_with_TemplateStyles_errors" | |||
links:insert( | |||
'[' .. tostring(mw.uri.fullUrl('Special:Search', errorq..eincategory )) .. ' errors]' | |||
.. ' (' .. | |||
'[' .. tostring(mw.uri.fullUrl('Special:Search', errorq..'ParserFunction_errors' )) .. ' parser]' | |||
.. '/' .. | |||
'[' .. tostring(mw.uri.fullUrl('Special:Search', errorq..'Pages_with_module_errors' )) .. ' module]' | |||
.. ')' | |||
) | |||
if title.isSubpage and title.text:find("/sandbox%d*%f[/%z]") then -- This is a sandbox template. | if title.isSubpage and title.text:find("/sandbox%d*%f[/%z]") then -- This is a sandbox template. | ||
-- At the moment there are no user sandbox templates with subpage | -- At the moment there are no user sandbox templates with subpage | ||
Line 541: | Line 610: | ||
if page_exists(sandbox_of) then | if page_exists(sandbox_of) then | ||
diff = " (" .. compare_pages(title.fullText, sandbox_of, "diff") .. ")" | diff = " (" .. compare_pages(title.fullText, sandbox_of, "diff") .. ")" | ||
end | end | ||
Line 563: | Line 630: | ||
output:insert("</dl>\n") | output:insert("</dl>\n") | ||
-- Show error from [[Module:category tree/topic cat/data]] on its submodules' | |||
-- documentation to, for instance, warn about duplicate labels. | |||
if title.fullText:find("Module:category tree/topic cat/data", 1, true) == 1 then | |||
local ok, err = pcall(require, "Module:category tree/topic cat/data") | |||
if not ok then | |||
output:insert('<span class="error">' .. err .. '</span>\n\n') | |||
end | |||
end | |||
if doc_title.exists then | if doc_title.exists then |