Module:documentation: difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
fix whatlinkshere link to hide redirects like it's meant to |
No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 12: | Line 12: | ||
["cologneblue"] = "Cologne Blue"; |
["cologneblue"] = "Cologne Blue"; |
||
["modern" ] = "Modern"; |
["modern" ] = "Modern"; |
||
} |
|||
local data_modules_regex_cats = { |
|||
["^Module:data tables/data..?.?.?$"] = "User:Isomorphyc's datatables" |
|||
} |
} |
||
Line 69: | Line 73: | ||
else |
else |
||
if title.contentModel == "Scribunto" then |
if title.contentModel == "Scribunto" then |
||
⚫ | |||
if user_name then |
if user_name then |
||
fallback_docs = 'documentation/fallback/user module' |
fallback_docs = 'documentation/fallback/user module' |
||
automatic_cat = "User sandbox modules" |
|||
else |
else |
||
local categorized = false |
|||
⚫ | |||
for r, cat in pairs(data_modules_regex_cats) do |
|||
if mw.ustring.match(title.fullText, r) then |
|||
automatic_cat = cat; |
|||
break |
|||
end |
|||
end |
|||
end |
end |
||
cats[#cats + 1] = automatic_cat |
|||
if not fallback_docs then |
if not fallback_docs then |
||
cats[#cats + 1] = "Templates and modules needing documentation" |
cats[#cats + 1] = "Templates and modules needing documentation" |
Revision as of 07:24, 31 October 2016
- The following documentation is located at Module:documentation/documentation. [edit]
- Useful links: subpage list • transclusions • testcases
Serves {{documentation}}
and {{translit module documentation}}
. {{documentation}}
is added to modules automatically (through MediaWiki:Scribunto-doc-page-show if the doc page exists, otherwise through MediaWiki:Scribunto-doc-page-does-not-exist); added to user JavaScript pages automatically (through MediaWiki:Clearyourcache); and manually added to template pages. It automatically adds categories, or categories and documentation, to some modules based on their titles.
More specifically, for modules:
- When there is no doc page for the module, Module:documentation checks for various sorts of special modules (based on the module title) and autogenerates the documentation and categories of those modules. If this check fails, the module is added to Category:Templates and modules needing documentation, and Module:module categorization is called to autogenerate the categories for lang-specific modules of the form
LANGCODE-TYPE
, optionally with a subpage (e.g.LANGCODE-TYPE/data
,LANGCODE-TYPE/testcases
,LANGCODE-TYPE/data/testcases
, or any other subpage). If this check also fails, the module is added to Category:Uncategorized modules. - When there is a doc page for the module, the contents of that page take precedence over any autogenerated content. However, if that page does not have an
<includeonly>...</includeonly>
section and does not have an invocation of{{module cat}}
, the same checks are done as when no doc page exists (including checks for specially-titled modules and falling back to calling Module:module categorization), but only for the purposes of autogenerating categories. If no such categories could be determined, the module is added to Category:Uncategorized modules.
More specifically, for templates:
- ... (DOCUMENT ME)
Ideas:
- Make more usable on other Wiktionaries by creating data module with translations of text, and moving module regex to separate module.
Automatic module documentation generators
Module error: The function "module_auto_doc_table" does not exist.
local export = {}
-- it is either here, or in [[Module:ugly hacks]], and it is not in ugly hacks.
function export.CONTENTMODEL()
return mw.title.getCurrentTitle().contentModel
end
local skins = {
["common" ] = "";
["vector" ] = "Vector";
["monobook" ] = "Monobook";
["cologneblue"] = "Cologne Blue";
["modern" ] = "Modern";
}
local data_modules_regex_cats = {
["^Module:data tables/data..?.?.?$"] = "User:Isomorphyc's datatables"
}
function export.show(frame)
local output = { '\n<div class="documentation" style="display:block; clear:both">\n' }
local cats = {}
if (not frame.args.hr) or (frame.args.hr == "above") then
output[#output + 1] = "----\n"
end
local title = ((frame.args['for'] ~= "") and frame.args['for']) and mw.title.new(frame.args['for']) or mw.title.getCurrentTitle()
local doc_title = mw.title.new((frame.args['from'] ~= "") and frame.args['from'] or (title.fullText .. '/documentation'))
local pagetype = mw.getContentLanguage():lcfirst(title.nsText) .. " page"
local preload
local user_name, skin_name
if title.contentModel == "javascript" then
pagetype = "script"
preload = 'Template:documentation/preloadTemplate' -- XXX
if title.nsText == 'User' then
user_name = title.rootText
end
elseif title.contentModel == "css" then
pagetype = "style sheet"
preload = 'Template:documentation/preloadTemplate' -- XXX
if title.nsText == 'User' then
user_name = title.rootText
end
elseif title.contentModel == "Scribunto" then
pagetype = "module"
preload = 'Template:documentation/preloadModule'
user_name = title.rootText:match("^User:(.+)")
elseif title.nsText == "Template" then
pagetype = "template"
preload = 'Template:documentation/preloadTemplate'
elseif title.nsText == "Wiktionary" then
pagetype = "project page"
preload = 'Template:documentation/preloadTemplate' -- XXX
end
local old_title
if doc_title.isRedirect then
old_title = doc_title
doc_title = mw.title.new(string.match(doc_title:getContent(), "^#[Rr][Ee][Dd][Ii][Rr][Ee][Cc][Tt]%s*:?%s*%[%[([^%[%]]-)%]%]"))
end
local fallback_docs
output[#output + 1] = "<dl class=\"plainlinks\" style=\"font-size: smaller;\">"
if doc_title.exists then
output[#output + 1] =
"<dd><i style=\"font-size: larger;\">The following [[Help:Documenting templates and modules|documentation]] is located at [[" .. doc_title.fullText .. "]]. " ..
"<sup>[[" .. doc_title:fullUrl { action = 'edit' } .. " edit]]</sup> </i></dd>"
else
if title.contentModel == "Scribunto" then
local automatic_cat = "Uncategorized modules"
if user_name then
fallback_docs = 'documentation/fallback/user module'
automatic_cat = "User sandbox modules"
else
local categorized = false
for r, cat in pairs(data_modules_regex_cats) do
if mw.ustring.match(title.fullText, r) then
automatic_cat = cat;
break
end
end
end
cats[#cats + 1] = automatic_cat
if not fallback_docs then
cats[#cats + 1] = "Templates and modules needing documentation"
end
elseif title.nsText == "Template" then
cats[#cats + 1] = "Uncategorized templates"
if not fallback_docs then
cats[#cats + 1] = "Templates and modules needing documentation"
end
elseif (title.contentModel == "css") or (title.contentModel == "javascript") then
if user_name then
skin_name = skins[title.text:sub(#title.rootText + 1):match("^/([a-z]+)%.[jc]ss?$")]
if skin_name then
fallback_docs = 'documentation/fallback/user ' .. title.contentModel
end
end
end
output[#output + 1] =
"<dd><i style=\"font-size: larger;\">This " .. pagetype .. " lacks a [[Help:Documenting templates and modules|documentation subpage]]. " ..
(fallback_docs and "You may " or "Please ") ..
"[" .. doc_title:fullUrl { action = 'edit', preload = preload } .. " create it].</i></dd>\n"
end
if title.fullText:match("^MediaWiki:Gadget%-") then
local is_gadget = false
local gadget_list = mw.title.new("MediaWiki:Gadgets-definition"):getContent()
for line in mw.text.gsplit(gadget_list, "\n") do
local gadget, opts, items = line:match("^%*%s*([A-Za-z][A-Za-z0-9_%-]*)%[(.-)%]|(.+)$")
if not gadget then
gadget, items = line:match("^%*%s*([A-Za-z][A-Za-z0-9_%-]*)|(.+)$")
end
if gadget then
items = mw.text.split(items, "|")
for i, item in ipairs(items) do
if title.fullText == ("MediaWiki:Gadget-" .. item) then
is_gadget = true
output[#output + 1] = "<dd> ''This script is a part of the <code>"
output[#output + 1] = gadget
output[#output + 1] = "</code> gadget (["
output[#output + 1] = tostring(mw.uri.fullUrl('MediaWiki:Gadgets-definition', 'action=edit'))
output[#output + 1] = " edit definitions])'' <dl>"
output[#output + 1] = "<dd> ''Description (["
output[#output + 1] = tostring(mw.uri.fullUrl('MediaWiki:Gadget-' .. gadget, 'action=edit'))
output[#output + 1] = " edit])'': "
output[#output + 1] = mw.message.new('Gadget-' .. gadget):plain()
output[#output + 1] = " </dd>"
table.remove(items, i)
if #items > 0 then
for j, item in ipairs(items) do
items[j] = '[[MediaWiki:Gadget-' .. item .. '|' .. item .. ']]'
end
output[#output + 1] = "<dd> ''Other parts'': "
output[#output + 1] = mw.text.listToText(items)
output[#output + 1] = "</dd>"
end
output[#output + 1] = "</dl></dd>"
break
end
end
end
end
if not is_gadget then
output[#output + 1] = "<dd> ''This script is not a part of any ["
output[#output + 1] = tostring(mw.uri.fullUrl('Special:Gadgets', 'uselang=en'))
output[#output + 1] = ' gadget] (['
output[#output + 1] = tostring(mw.uri.fullUrl('MediaWiki:Gadgets-definition', 'action=edit'))
output[#output + 1] = ' edit definitions]).</dd>'
end
end
if old_title then
output[#output + 1] = "<dd> ''Redirected from'' ["
output[#output + 1] = old_title:fullUrl { redirect = 'no' }
output[#output + 1] = " "
output[#output + 1] = old_title.fullText
output[#output + 1] = "] (["
output[#output + 1] = old_title:fullUrl { action = 'edit' }
output[#output + 1] = " edit]).</dd>\n"
end
local links = {}
if title.isSubpage then
links[#links + 1] = "[[:" .. title.nsText .. ":" .. title.rootText .. "|root page]]"
links[#links + 1] = "[[Special:PrefixIndex/" .. title.nsText .. ":" .. title.rootText .. "/|root page's subpages]]"
else
links[#links + 1] = "[[Special:PrefixIndex/" .. title.fullText .. "/|subpage list]]"
end
if (title.contentModel == "javascript") or (title.contentModel == "css") then
links[#links + 1] = "[[Special:WhatLinksHere/" .. title.fullText .. "|what links here]]"
if user_name then
links[#links + 1] = "[[Special:MyPage" .. title.text:sub(#title.rootText + 1) .. "|your own]]"
end
else
links[#links + 1] =
'[' .. tostring(mw.uri.fullUrl('Special:WhatLinksHere/' .. title.fullText, 'hidelinks=1&hideredirs=1')) ..
' transclusions]'
if title.contentModel ~= "Scribunto" then
links[#links + 1] =
'[' .. tostring(mw.uri.fullUrl('Special:WhatLinksHere/' .. title.fullText, 'hidelinks=1&hidetrans=1')) ..
' redirects]'
end
end
if title.contentModel == "Scribunto" then
if title.isSubpage and (title.subpageText == "testcases") then
links[#links + 1] = "[[:" .. title.nsText .. ":" .. title.baseText .. "|tested module]]"
else
links[#links + 1] = "[[" .. title.fullText .. "/testcases|testcases]]"
end
if user_name then
links[#links + 1] = "[[User:" .. user_name .. "|user page]]"
links[#links + 1] = "[[User talk:" .. user_name .. "|user talk page]]"
links[#links + 1] = "[[Special:PrefixIndex/User:" .. user_name .. "/|userspace]]"
end
end
if #links > 0 then
output[#output + 1] =
"<dd> ''Useful links'': " .. table.concat(links, " • ") .. "</dd>"
end
output[#output + 1] = "</dl>\n"
if doc_title.exists then
output[#output + 1] = frame:expandTemplate { title = doc_title.fullText }
elseif fallback_docs then
output[#output + 1] = frame:expandTemplate {
title = fallback_docs;
args = {
['user'] = user_name;
['page'] = title.fullText;
['skin name'] = skin_name;
}
}
end
if frame.args.hr == "below" then
output[#output + 1] = '\n<hr style="clear: both;" />'
else
output[#output + 1] = '\n<br style="clear: both;" />'
end
for _, cat in ipairs(cats) do
output[#output + 1] = "[[Category:" .. cat .. "]]"
end
output[#output + 1] = "</div>\n"
return table.concat(output)
end
return export