Module:MediaWiki message helper
Appearance
- The following documentation is located at Module:MediaWiki message helper/documentation. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
- Did you mean Module:mh-pronunc?
- Did you mean Module:template parser/templates?
- Did you mean Category:Proto-Indo-European roots?
- Template:quote book (replace space with hyphen)
- Did you mean Template:quote-book?
- Template:lexico (add prefix, search case-insensitively)
- Did you mean any of these?
- Did you mean Category:Abkhaz language?
- Did you mean Category:Azerbaijani language?
- Template:1911 (add prefix)
- Did you mean Template:R:Britannica 1911?
- Template:R:Newman & Weitlaner (find template with year and lowercase letter)
- Did you mean any of these?
- Template:Meillet (find template with range of years)
- Did you mean any of these?
- Template:R:cu:Meillet1902
- Template:R:ine-bsl:Meillet:1898
- Template:R:ine:Meillet:1894
- Template:R:ine:Meillet:1897
- Template:R:sla:Meillet:1924
- Template:R:xcl:Meillet:1892
- Template:R:xcl:Meillet:1894
- Template:R:xcl:Meillet:1896
- Template:R:xcl:Meillet:1898
- Template:R:xcl:Meillet:1900
- Template:R:xcl:Meillet:1903
- Template:R:xcl:Meillet:1911-1912
- Template:R:xcl:Meillet:1913
- Template:R:xcl:Meillet:1914
- Template:R:xcl:Meillet:1914b
- Template:R:xcl:Meillet:1920
- Template:R:xcl:Meillet:1920-1921
- Template:R:xcl:Meillet:1922
- Template:R:xcl:Meillet:1925
- Template:R:xcl:Meillet:1935
- Template:R:xcl:Meillet:1936
- Did you mean any of these?
- Template:R:cu:Meillet1902
- Template:R:ine-bsl:Meillet:1898
- Template:R:ine:Meillet:1894
- Template:R:ine:Meillet:1897
- Template:R:sla:Meillet:1924
- Template:R:xcl:Meillet:1892
- Template:R:xcl:Meillet:1894
- Template:R:xcl:Meillet:1896
- Template:R:xcl:Meillet:1898
- Template:R:xcl:Meillet:1900
- Template:R:xcl:Meillet:1903
- Template:R:xcl:Meillet:1911-1912
- Template:R:xcl:Meillet:1913
- Template:R:xcl:Meillet:1914
- Template:R:xcl:Meillet:1914b
- Template:R:xcl:Meillet:1920
- Template:R:xcl:Meillet:1920-1921
- Template:R:xcl:Meillet:1922
- Template:R:xcl:Meillet:1925
- Template:R:xcl:Meillet:1935
- Template:R:xcl:Meillet:1936
- Did you mean any of these?
- Template:R:xcl:Meillet:1892
- Template:R:xcl:Meillet:1894
- Template:R:xcl:Meillet:1896
- Template:R:xcl:Meillet:1898
- Template:R:xcl:Meillet:1900
- Template:R:xcl:Meillet:1903
- Template:R:xcl:Meillet:1911-1912
- Template:R:xcl:Meillet:1913
- Template:R:xcl:Meillet:1914
- Template:R:xcl:Meillet:1914b
- Template:R:xcl:Meillet:1920
- Template:R:xcl:Meillet:1920-1921
- Template:R:xcl:Meillet:1922
- Template:R:xcl:Meillet:1925
- Template:R:xcl:Meillet:1935
- Template:R:xcl:Meillet:1936
- Template:Asatryan (find template with year slash year)
- Did you mean any of these?
- Template:R:Asatryan:1986
- Template:R:Asatryan:1988
- Template:R:Asatryan:1989
- Template:R:Asatryan:1990
- Template:R:Asatryan:1994
- Template:R:Asatryan:1997
- Template:R:Asatryan:1999/2000
- Template:R:Asatryan:2001
- Template:R:Asatryan:2001b
- Template:R:Asatryan:2009
- Template:R:Asatryan:2011
- Template:R:Asatryan:2012
- Template:R:Asatryan:2013
- Template:R:Asatryan:2013b
- Template:R:Asatryan:2014
- Template:R:Asatryan:2017
- Template:R:Asatryan:2019
- Template:R:hy:Asatryan:1962
- Template:R:hy:Asatryan:1968
- Template:R:hy:Asatryan:1976
- Template:R:hy:Asatryan:2004
- Template:R:ku:Asatryan:2009
- Template:R:xcl:Asatryan:2014
- Did you mean any of these?
- Template:R:Asatryan:1986
- Template:R:Asatryan:1988
- Template:R:Asatryan:1989
- Template:R:Asatryan:1990
- Template:R:Asatryan:1994
- Template:R:Asatryan:1997
- Template:R:Asatryan:1999/2000
- Template:R:Asatryan:2001
- Template:R:Asatryan:2001b
- Template:R:Asatryan:2009
- Template:R:Asatryan:2011
- Template:R:Asatryan:2012
- Template:R:Asatryan:2013
- Template:R:Asatryan:2013b
- Template:R:Asatryan:2014
- Template:R:Asatryan:2017
- Template:R:Asatryan:2019
- Template:R:hy:Asatryan:1962
- Template:R:hy:Asatryan:1968
- Template:R:hy:Asatryan:1976
- Template:R:hy:Asatryan:2004
- Template:R:ku:Asatryan:2009
- Template:R:xcl:Asatryan:2014
- Did you mean any of these?
- Did you mean any of these?
- Template:R:Diakonoff (add language code and space and year)
- Did you mean any of these?
- Template:R:afa-pro:Diakonoff (add space and year)
- Did you mean Template:R:afa-pro:Diakonoff 1988?
- Template:R:Hashemi (add language code and colon and year)
- Did you mean Template:R:ae:Hashemi:2015?
- Template:R:ae:Hashemi (add colon and year)
- Did you mean Template:R:ae:Hashemi:2015?
- Did you mean any of these?
- Did you mean Category:Abkhaz language?
- Category:Dendi (canonical name category should be first)
- Did you mean any of these?
- Did you mean any of these?
- Category:Sino-Tibetan languages (code
sit
) - Category:Proto-Sino-Tibetan language (code
sit-pro
)
- Category:Sino-Tibetan languages (code
- Did you mean Category:Arabic script?
- Did you mean Category:Arabic script?
local m_str_utils = require("Module:string utilities")
local dump = mw.dumpObject
local get_current_title = mw.title.getCurrentTitle
local gsplit = m_str_utils.gsplit
local make_title = mw.title.makeTitle
local new_title = mw.title.new
local pattern_escape = m_str_utils.pattern_escape
local php_trim = m_str_utils.php_trim
local ufind = m_str_utils.find
local ugsub = m_str_utils.gsub
local ulower = m_str_utils.lower
local uupper = m_str_utils.upper
local export = {}
local function get_title(frame)
local args = frame.args
local title = args and args.title or nil
return title == nil and get_current_title() or
new_title(title) or
error(("%s is not a valid title"):format(dump(title)))
end
local function print_suggestions(suggestions)
if #suggestions == 0 then
return ""
else
local prefix = "* Did you mean "
local suffix
if #suggestions > 1 then
prefix = prefix .. " any of these?\n"
suggestions = suggestions:map(function(link) return "** " .. link end)
suffix = ""
else
suffix = "?"
end
return prefix .. suggestions:concat "\n" .. suffix
end
end
-- For [[MediaWiki:Noarticletext]] on uncreated category pages.
function export.category_suggestions(frame)
local title = ugsub(get_title(frame).text, "^.", uupper)
local output = require("Module:array")()
local function make_suggestion(title, suffix)
output:insert("'''[[:Category:" .. title .. "]]'''" .. (suffix or ""))
end
local function check_for_page_from_function(func)
local suggestion = func(title)
if suggestion then
local suggestion_title = make_title(14, suggestion)
if suggestion_title and suggestion_title.exists then
make_suggestion(suggestion)
return true
end
end
return false
end
local function check_for_page_with_suffix(suffix)
return check_for_page_from_function(function(title)
return title .. " " .. suffix
end)
end
local function check_for_page_with_prefix_removed(prefix)
return check_for_page_from_function(function(title)
return title:gsub(pattern_escape(prefix), "")
end)
end
check_for_page_with_prefix_removed("List of ")
check_for_page_with_prefix_removed("list of ")
local has_language_category = check_for_page_with_suffix("language")
check_for_page_with_suffix("Language")
check_for_page_with_suffix("languages")
local has_script_category = check_for_page_with_suffix("script")
local function check_other_names_of_languages(language_name)
for code, data in pairs(require("Module:languages/data/all")) do
local function check_name_list(list)
if list then
for _, name in ipairs(list) do
-- The aliases and varieties are recursive,
-- with subtables that themselves contain names.
if type(name) == "table" then
check_name_list(name)
else
if name == language_name then
local object = require("Module:languages").makeObject(code, data)
make_suggestion(object:getCategoryName())
end
end
end
end
end
check_name_list(data.otherNames)
check_name_list(data.aliases)
check_name_list(data.varieties)
end
end
-- If title looks like a language category, then check if the language name
-- in it is a valid canonical name, or one of the otherNames for some
-- language.
-- If the title looks like a language code, check for a language or a script
-- with that code.
local function check_language_name(language_name, is_language_category, has_language_category)
local ret = false
if not has_language_category then
if require("Module:languages/canonical names")[language_name] then
if not is_language_category then
make_suggestion(language_name .. " language")
else
output:insert("* '''" .. language_name .. "''' is a valid Wiktionary language name.")
end
ret = true
end
end
-- Some otherNames are the canonical name of another language.
check_other_names_of_languages(language_name)
return ret
end
local language_name = title:match "^(.+) language$" or title:match "^(.+ Language)$"
check_language_name(language_name or title, language_name ~= nil, has_language_category)
-- Most languages (7965/8085 by last count) have uppercase letters at
-- beginning of the name and after whitespace and punctuation characters,
-- and lowercase everywhere else. Exceptions include languages
-- with apostrophes, such as Yup'ik, and languages with tone letters,
-- such as ǃXóõ.
local fixed_capitalization = ugsub(ulower(language_name or title), "%f[^%z%s%p]%a", uupper)
if fixed_capitalization ~= (language_name or title) then
check_language_name(fixed_capitalization)
end
if title:find "^[%a-]+$" then
local function check_for_valid_code(code, ...)
for _, module_name in ipairs { ... } do
local object = require("Module:" .. module_name).getByCode(code)
if object then
make_suggestion(object:getCategoryName(), " (code <code>" .. code .. "</code>)")
end
end
end
local code = title:lower()
check_for_valid_code(code, "languages", "etymology languages", "scripts", "families")
check_for_valid_code(code .. "-pro", "languages", "etymology languages")
end
local function check_script_name(script_name, is_script_category, has_script_category)
if not has_script_category then
local object = require("Module:scripts").getByCanonicalName(script_name)
if object then
if is_script_category then
output:insert("* " .. script_name .. " is a valid Wiktionary script name.")
else
make_suggestion(object:getCategoryName())
end
end
end
for code, data in pairs(require("Module:scripts/data")) do
local function check_other_names_of_script(list)
if list then
for _, name in ipairs(list) do
if type(name) == "table" then
check_other_names_of_script(name)
elseif script_name == name then
local object = require("Module:scripts").makeObject(code, data)
make_suggestion(object:getCategoryName())
end
end
end
end
check_other_names_of_script(data.otherNames)
check_other_names_of_script(data.varieties)
check_other_names_of_script(data.aliases)
end
end
local script_name = title:match "^(.+) script$"
check_script_name(script_name or title, script_name ~= nil, has_script_category)
return print_suggestions(output)
end
function export.template_suggestions(frame)
local title = get_title(frame).text
local output = require("Module:array")()
local function make_suggestion(title, suffix)
output:insert("'''[[:Template:" .. title .. "]]'''" .. (suffix or ""))
end
local function check_for_page_with_prefix(prefix)
local suggestion = prefix .. title
local suggestion_title = make_title(10, suggestion)
if suggestion_title and suggestion_title.exists then
make_suggestion(suggestion)
return true
end
return false
end
if title:find(" ", 1, true) then
local with_hyphen = title:gsub(" ", "-")
local suggestion_title = make_title(10, with_hyphen)
if suggestion_title and suggestion_title.exists then
make_suggestion(with_hyphen)
end
end
local prefixes = frame.args.prefixes
if prefixes then
for prefix in gsplit(prefixes, ",", true, true) do
check_for_page_with_prefix(prefix)
end
end
local prefix, rest = title:match "^([^: ]+) *:(.+)$"
if prefix then
prefix = prefix:upper()
else
prefix, rest = "", title
end
if prefix == "" or prefix == "R" or prefix == "RQ" then
local templates = require("Module:MediaWiki message helper/R: and RQ: templates")
local rest_pattern = pattern_escape(rest)
:gsub("%l", function(letter)
return "[" .. letter:upper() .. letter:lower() .. "]"
end)
for suggestion in templates:gmatch("%f[^%z\n][Rr][Qq]? ?:[a-z-]*[-:]?"
.. rest_pattern
.. "[ :]?%d?%d?%d?%d?[/-]?%d?%d?%d?%d?%l?%f[%z\n]") do
local suggestion_title = make_title(10, suggestion)
if suggestion_title and suggestion_title.exists then
make_suggestion(suggestion)
end
end
end
return print_suggestions(output)
end
function export.module_suggestions(frame)
local title = get_title(frame).text
local output = require("Module:array")()
local function make_suggestion(title)
output:insert("'''[[:Module:" .. title .. "]]'''")
end
local pronunciation_suffixes = require("Module:array"){"IPA", "pr", "pron", "pronunc", "pronunciation"}
if pronunciation_suffixes:some(function(suffix)
return title:find("%-" .. suffix .. "$")
end) then
for _, suggestion in ipairs(pronunciation_suffixes:map(function(suffix)
return title:gsub("%-%w+$", "-" .. suffix)
end)) do
local suggestion_title = make_title(828, suggestion)
if suggestion_title and suggestion_title.exists then
make_suggestion(suggestion)
end
end
end
-- Look for the modules actually invoked by the template with the same name
-- as the module (accounting for "Module:Template:..." cases).
local template_title = new_title(title, 10)
if template_title then
local template_text = template_title:getContent()
if template_text then
for template in require("Module:template parser").find_templates(template_text) do
if template:get_name() == "#INVOKE:" then
local args = template:get_arguments()
if args[2] then -- args[2] is the function name, so #INVOKE: will throw an error if not present
make_suggestion(php_trim(args[1])) -- args[1] is the module name
end
end
end
end
end
return print_suggestions(output)
end
function export.is_data_module_not_documentation(frame)
local title = get_title(frame)
if require("Module:pages").get_pagetype(title) == "module" then
return ufind(title.text, "^" .. (frame.args[1] or "") .. "$")
end
end
return export