Module:Navbox: Difference between revisions
From Zelda Wiki, the Zelda encyclopedia
no edit summary
PhantomCaleb (talk | contribs) No edit summary |
PhantomCaleb (talk | contribs) No edit summary |
||
(18 intermediate revisions by 2 users not shown) | |||
Line 4: | Line 4: | ||
local utilsArg = require("Module:UtilsArg") | local utilsArg = require("Module:UtilsArg") | ||
local utilsPage = require("Module:UtilsPage") | local utilsPage = require("Module:UtilsPage") | ||
local CATEGORY_INVALID_ARGS = "[[Category:"..require("Module:Constants/category/invalidArgs").."]]" | local CATEGORY_INVALID_ARGS = "[[Category:"..require("Module:Constants/category/invalidArgs").."]]" | ||
local CATEGORY_NAVBOXES_ATTENTION = "Navigation | local CATEGORY_NAVBOXES_ATTENTION = "Navigation templates needing attention" | ||
local CATEGORY_NAVBOXES_OTHER = "[[Category:Navboxes with | local CATEGORY_NAVBOXES_BIG_GROUPS = "[[Category:Navboxes with big groups]]" | ||
local CATEGORY_NAVBOX_TEMPLATES = "Navbox | local CATEGORY_NAVBOXES_OTHER = "[[Category:Navboxes with other]]" | ||
local CATEGORY_NAVBOX_TEMPLATES = "Navbox templates" | |||
local TITLE_IMG_SIZE = "28x28px" | local TITLE_IMG_SIZE = "28x28px" | ||
Line 28: | Line 28: | ||
end | end | ||
end | end | ||
h.storeArgs(args) | |||
local navbox, categories = h.printNavbox(args) | local navbox, categories = h.printNavbox(args) | ||
Line 35: | Line 36: | ||
return navbox, categories.."[[Category:"..CATEGORY_NAVBOX_TEMPLATES.."]]", h.printReport() | return navbox, categories.."[[Category:"..CATEGORY_NAVBOX_TEMPLATES.."]]", h.printReport() | ||
elseif h.isNavboxPage() then | elseif h.isNavboxPage() then | ||
-- apply the styles that would be applied when this template is actually used | |||
navbox = tostring(mw.html.create("div") | |||
:addClass("zw-categories__navboxes-category-list") | |||
:wikitext(navbox) | |||
:done() | |||
) | |||
local styles = frame:extensionTag({ | |||
name = "templatestyles", | |||
args = { src = "Template:Categories/Styles.css" } | |||
}) | |||
navbox = styles..navbox | |||
return navbox, categories, h.printReport() | return navbox, categories, h.printReport() | ||
elseif h.isTemplate() then | elseif h.isTemplate() then | ||
Line 45: | Line 57: | ||
function h.printNavbox(args) | function h.printNavbox(args) | ||
local categories = "" | local categories = "" | ||
-- [[MediaWiki:Gadget- | -- [[MediaWiki:Gadget-Navbox.js]] automatically removes the "mw-collapsed" when there is only one navbox on the page. | ||
local navbox = mw.html.create("div") | local navbox = mw.html.create("div") | ||
:addClass("zw-navbox mw-collapsible mw-collapsed") | :addClass("zw-navbox mw-collapsible mw-collapsed") | ||
local id = args.id or args.title | local id = args.id or args.title | ||
Line 124: | Line 130: | ||
:done() | :done() | ||
:done() | :done() | ||
end | end | ||
Line 137: | Line 139: | ||
local evenOdd = (i % 2 == 0) and "even" or "odd" | local evenOdd = (i % 2 == 0) and "even" or "odd" | ||
local links = table.concat(links, " • ") | local links = table.concat(links, " • ") | ||
rows:tag("div") | rows:tag("div") | ||
:addClass("zw-navbox__row-links".. | :addClass("zw-navbox__row-links zw-navbox__row-links--"..evenOdd) | ||
:addClass(not row.group and "zw-navbox__row-links--nogroups" or nil) | |||
:tag("div") | :tag("div") | ||
:addClass("zw-navbox__row-links-content") | :addClass("zw-navbox__row-links-content") | ||
:addClass(not row.group and "zw-navbox__row-links-content--nogroups" or nil) | |||
:wikitext(links) | :wikitext(links) | ||
:done() | :done() | ||
Line 180: | Line 179: | ||
end | end | ||
function h._link(link) | function h._link(link) | ||
if string.find(link, "^%[%[Category:") then | if string.find(link, "^%[%[Category:") or string.find(link, "^%[%[File:") then | ||
return link | return link | ||
end | end | ||
Line 189: | Line 188: | ||
page = string.gsub(page, ",", ",") -- unescape any commas that were escaped in input due to splitting by , | page = string.gsub(page, ",", ",") -- unescape any commas that were escaped in input due to splitting by , | ||
page = string.gsub(page, "#.*", "") | page = string.gsub(page, "#.*", "") | ||
page = string.gsub(page, "%s*$", "") -- trim trailing whitespace | |||
h.storePage(page) | h.storePage(page) | ||
Line 196: | Line 196: | ||
return "<b>"..display.."</b>" | return "<b>"..display.."</b>" | ||
else | else | ||
local url = mw.site.server.."/"..mw.uri.encode(page, "WIKI") | local url = mw.site.server.."/wiki/"..mw.uri.encode(page, "WIKI") | ||
return string.format('<span class="plainlinks">[%s %s]</span>', url, display) | return string.format('<span class="plainlinks">[%s %s]</span>', url, display) | ||
end | end | ||
Line 202: | Line 202: | ||
-- Store data for the report function below | -- Store data for the report function below | ||
local VAR_ARGS = "navbox_args" | |||
local VAR_PAGES = "navbox_pages" | local VAR_PAGES = "navbox_pages" | ||
local VAR_GROUP_SIZES = "navbox_group_size" | local VAR_GROUP_SIZES = "navbox_group_size" | ||
Line 214: | Line 215: | ||
local utilsVar = require("Module:UtilsVar") | local utilsVar = require("Module:UtilsVar") | ||
utilsVar.add(VAR_GROUP_SIZES, group) | utilsVar.add(VAR_GROUP_SIZES, group) | ||
end | |||
end | |||
function h.storeArgs(args) | |||
if h.isNavboxPage() then | |||
local utilsVar = require("Module:UtilsVar") | |||
utilsVar.set(VAR_ARGS, args) | |||
end | end | ||
end | end | ||
Line 227: | Line 234: | ||
local utilsVar = require("Module:UtilsVar") | local utilsVar = require("Module:UtilsVar") | ||
local args = utilsVar.get(VAR_ARGS) or {} | |||
local pagesInNav = utilsVar.get(VAR_PAGES) or {} | local pagesInNav = utilsVar.get(VAR_PAGES) or {} | ||
local groupSizes = utilsVar.get(VAR_GROUP_SIZES) or {} | local groupSizes = utilsVar.get(VAR_GROUP_SIZES) or {} | ||
Line 232: | Line 240: | ||
local pagesUsingNav = utilsPage.dpl({ | local pagesUsingNav = utilsPage.dpl({ | ||
uses = "Template:"..h.templatePage(), | uses = "Template:"..h.templatePage(), | ||
notnamespace = {"User", "Template" | notnamespace = {"User", "Category"}, | ||
nottitlematch = { | |||
"%/Documentation", | |||
mw.title.getCurrentTitle().prefixedText ~= "Template:Guidelines Nav" and "Categories" or nil -- To avoid counting examples at [[Template:Categories]] as uses (but we do want to count [[Template:Guidelines Nav]]) | |||
}, | |||
}) | }) | ||
local missingLinks = utilsTable.difference(pagesUsingNav, pagesInNav) | local missingLinks = utilsTable.difference(pagesUsingNav, pagesInNav) | ||
local missingUses = utilsTable.difference(pagesInNav, pagesUsingNav) | local missingUses = utilsTable.difference(pagesInNav, pagesUsingNav) | ||
local redirects = h.reportRedirects(pagesInNav) | |||
missingLinks = utilsTable.difference(missingLinks, redirects) | |||
missingUses = utilsTable.difference(missingUses, redirects) | |||
local wantedPages = utilsTable.filter(pagesInNav, function(page) | local wantedPages = utilsTable.filter(pagesInNav, function(page) | ||
return not utilsPage.exists(page) | return not utilsPage.exists(page) | ||
end) | end) | ||
local bigGroups = utilsTable.filter(groupSizes, function(group) | local bigGroups = utilsTable.filter(groupSizes, function(group) | ||
return group.size > group.maxGroupSize | return group.size > group.maxGroupSize | ||
Line 247: | Line 262: | ||
local issues = "" | local issues = "" | ||
if categoryName and args.title and categoryName ~= args.title then | |||
issues = issues | |||
.."\n====Title Mismatch====\n" | |||
..string.format("<p>The navbox title should be <code>%s</code> rather than <code>%s</code>.</p>", categoryName, args.title) | |||
.."<p>For navboxes added by [[Template:Categories]], the navbox title must match the category name, as navboxes are listed alphabetically by category name.</p>" | |||
end | |||
if #wantedPages > 0 then | if #wantedPages > 0 then | ||
issues = issues.."\n====Red Links====\n" | issues = issues.."\n====Red Links====\n" | ||
Line 256: | Line 277: | ||
issues = issues.."\n====Redirect Links====\n" | issues = issues.."\n====Redirect Links====\n" | ||
redirects = utilsTable.map(redirects, utilsMarkup.link) | redirects = utilsTable.map(redirects, utilsMarkup.link) | ||
issues = issues.."The above navbox contains links to redirects. Please update | issues = issues.."The above navbox contains links to redirects. Please create an article to replace the redirect, or update the link to refer to the redirect target." | ||
issues = issues..utilsMarkup.bulletList(redirects) | issues = issues..utilsMarkup.bulletList(redirects) | ||
end | end | ||
Line 303: | Line 324: | ||
local report = "\n==Report==\n" | local report = "\n==Report==\n" | ||
if issues ~= "" then | if issues ~= "" then | ||
report = "<p>{{TOC}}</p>"..report -- fixes the lack of space between the navbox and the toc beneath it | |||
report = report | report = report | ||
.."\n===Issues===\n" | .."\n===Issues===\n" | ||
..issues | ..issues | ||
.."[[Category:"..CATEGORY_NAVBOXES_ATTENTION.."]]" | -- Special subcategory for big groups as it is by far the most common issue but also the least urgent, | ||
-- so it helps to keep it separate to avoid burying other more important issues | |||
if #bigGroups > 0 then | |||
report = report..CATEGORY_NAVBOXES_BIG_GROUPS | |||
else | |||
report = report.."[[Category:"..CATEGORY_NAVBOXES_ATTENTION.."]]" | |||
end | |||
else | else | ||
report = report.."<p>[[File:TFH Green Link ok.png|32px|link=]] No issues have been detected in this navbox.</p>" | report = report.."<p>[[File:TFH Green Link ok.png|32px|link=]] No issues have been detected in this navbox.</p>" | ||
Line 342: | Line 370: | ||
end | end | ||
local title = mw.title.getCurrentTitle() | |||
local category = title.subpageText | local category = title.subpageText | ||
if title.subpageText == "Documentation" then | if title.subpageText == "Documentation" then | ||
Line 384: | Line 413: | ||
purpose = "Creates [[:Category:"..CATEGORY_NAVBOX_TEMPLATES.."|navbox templates]].", | purpose = "Creates [[:Category:"..CATEGORY_NAVBOX_TEMPLATES.."|navbox templates]].", | ||
categories = {"Metatemplates"}, | categories = {"Metatemplates"}, | ||
paramOrder = {"id", "title", "titleImages", "image", "group", "links", "maxGroupSize", "footer | paramOrder = {"id", "title", "titleImages", "image", "group", "links", "maxGroupSize", "footer"}, | ||
repeatedGroup = { | repeatedGroup = { | ||
name = "rows", | name = "rows", | ||
Line 446: | Line 475: | ||
trim = true, | trim = true, | ||
nilIfEmpty = true, | nilIfEmpty = true, | ||
} | } | ||
}, | }, | ||
}, | }, |