背景色がついた文章が変更のあった箇所になります。背景色の示す意味は以下の通りです。
比較結果
<div><p>このモジュールについての説明文ページを モジュール:Hatnote/doc に作成できます</p></div><div><a href='#L-1'></a>-- <nowiki><a href='#L-2'></a>--------------------------------------------------------------------------------<a href='#L-3'></a>-- Module:Hatnote --<a href='#L-4'></a>-- --<a href='#L-5'></a>-- This module produces hatnote links and links to related articles. It --<a href='#L-6'></a>-- implements the {{hatnote}} and {{format link}} meta-templates and includes --<a href='#L-7'></a>-- helper functions for other Lua hatnote modules. --<a href='#L-8'></a>--------------------------------------------------------------------------------<a href='#L-9'></a><a href='#L-10'></a>local libraryUtil = require('libraryUtil')<a href='#L-11'></a>local checkType = libraryUtil.checkType<a href='#L-12'></a>local mArguments = require('Dev:Arguments')<a href='#L-13'></a>local yesno = require('Dev:Yesno')<a href='#L-14'></a>local mTableTools = require('Dev:TableTools')<a href='#L-15'></a>local i18n = require('Dev:I18n').loadMessages('Hatnote')<a href='#L-16'></a>local hatnote = {}<a href='#L-17'></a><a href='#L-18'></a>--------------------------------------------------------------------------------<a href='#L-19'></a>-- Helper functions<a href='#L-20'></a>--------------------------------------------------------------------------------<a href='#L-21'></a><a href='#L-22'></a>local function getArgs(frame)<a href='#L-23'></a> -- Fetches the arguments from the parent frame. Whitespace is trimmed and<a href='#L-24'></a> -- blanks are removed.<a href='#L-25'></a> return mArguments.getArgs(frame, {parentOnly = true})<a href='#L-26'></a>end<a href='#L-27'></a><a href='#L-28'></a>local function removeInitialColon(s)<a href='#L-29'></a> -- Removes the initial colon from a string, if present.<a href='#L-30'></a> return s:match('^:?(.*)')<a href='#L-31'></a>end<a href='#L-32'></a><a href='#L-33'></a>function hatnote.findNamespaceId(link, removeColon)<a href='#L-34'></a> -- Finds the namespace id (namespace number) of a link or a pagename. This<a href='#L-35'></a> -- function will not work if the link is enclosed in double brackets. Colons<a href='#L-36'></a> -- are trimmed from the start of the link by default. To skip colon<a href='#L-37'></a> -- trimming, set the removeColon parameter to false.<a href='#L-38'></a> checkType('findNamespaceId', 1, link, 'string')<a href='#L-39'></a> checkType('findNamespaceId', 2, removeColon, 'boolean', true)<a href='#L-40'></a> if removeColon ~= false then<a href='#L-41'></a> link = removeInitialColon(link)<a href='#L-42'></a> end<a href='#L-43'></a> local namespace = link:match('^(.-):')<a href='#L-44'></a> if namespace then<a href='#L-45'></a> local nsTable = mw.site.namespaces[namespace]<a href='#L-46'></a> if nsTable then<a href='#L-47'></a> return nsTable.id<a href='#L-48'></a> end<a href='#L-49'></a> end<a href='#L-50'></a> return 0<a href='#L-51'></a>end<a href='#L-52'></a><a href='#L-53'></a>function hatnote.formatPages(...)<a href='#L-54'></a> -- Formats a list of pages using formatLink and returns it as an array. Nil<a href='#L-55'></a> -- values are not allowed.<a href='#L-56'></a> local pages = {...}<a href='#L-57'></a> local ret={}<a href='#L-58'></a> for i, page in ipairs(pages) do<a href='#L-59'></a> ret[i] = hatnote._formatLink(page)<a href='#L-60'></a> end<a href='#L-61'></a> return ret<a href='#L-62'></a>end<a href='#L-63'></a><a href='#L-64'></a>function hatnote.formatPageTables(...)<a href='#L-65'></a> -- Takes a list of page/display tables and returns it as a list of<a href='#L-66'></a> -- formatted links. Nil values are not allowed.<a href='#L-67'></a> local pages = {...}<a href='#L-68'></a> local links = {}<a href='#L-69'></a> for i, t in ipairs(pages) do<a href='#L-70'></a> checkType('formatPageTables', i, t, 'table')<a href='#L-71'></a> local link = t[1]<a href='#L-72'></a> local display = t[2]<a href='#L-73'></a> links[i] = hatnote._formatLink(link, display)<a href='#L-74'></a> end<a href='#L-75'></a> return links<a href='#L-76'></a>end<a href='#L-77'></a><a href='#L-78'></a>function hatnote.makeWikitextError(msg, helpLink, addTrackingCategory, title)<a href='#L-79'></a> -- Formats an error message to be returned to wikitext. If<a href='#L-80'></a> -- addTrackingCategory is not false after being returned from<a href='#L-81'></a> -- [[Module:Yesno]], and if we are not on a talk page, a tracking category<a href='#L-82'></a> -- is added.<a href='#L-83'></a> checkType('makeWikitextError', 1, msg, 'string')<a href='#L-84'></a> checkType('makeWikitextError', 2, helpLink, 'string', true)<a href='#L-85'></a> title = title or mw.title.getCurrentTitle()<a href='#L-86'></a> -- Make the help link text.<a href='#L-87'></a> local helpText<a href='#L-88'></a> if helpLink then<a href='#L-89'></a> helpText=' ([[' .. helpLink .. '|' .. i18n:msg('help') .. ']])'<a href='#L-90'></a> else<a href='#L-91'></a> helpText=''<a href='#L-92'></a> end<a href='#L-93'></a> -- Make the category text.<a href='#L-94'></a> local category<a href='#L-95'></a> if not title.isTalkPage and yesno(addTrackingCategory) ~= false then<a href='#L-96'></a> category = i18n:msg('cat-errors')<a href='#L-97'></a> category = string.format(<a href='#L-98'></a> '[[%s:%s]]',<a href='#L-99'></a> mw.site.namespaces[14].name,<a href='#L-100'></a> category<a href='#L-101'></a> )<a href='#L-102'></a> else<a href='#L-103'></a> category = ''<a href='#L-104'></a> end<a href='#L-105'></a> return string.format(<a href='#L-106'></a> i18n:msg('error'),<a href='#L-107'></a> msg,<a href='#L-108'></a> helpText,<a href='#L-109'></a> category<a href='#L-110'></a> )<a href='#L-111'></a>end<a href='#L-112'></a><a href='#L-113'></a>function hatnote.disambiguate(page, disambiguator)<a href='#L-114'></a> -- Formats a page title with a disambiguation parenthetical,<a href='#L-115'></a> -- i.e. "Example" → "Example (disambiguation)".<a href='#L-116'></a> checkType('disambiguate', 1, page, 'string')<a href='#L-117'></a> checkType('disambiguate', 2, disambiguator, 'string', true)<a href='#L-118'></a> disambiguator = disambiguator or i18n:msg('disambiguation')<a href='#L-119'></a> return string.format(i18n:msg('brackets'), page, disambiguator)<a href='#L-120'></a>end<a href='#L-121'></a><a href='#L-122'></a>--------------------------------------------------------------------------------<a href='#L-123'></a>-- Format link<a href='#L-124'></a>--<a href='#L-125'></a>-- Makes a wikilink from the given link and display values. Links are escaped<a href='#L-126'></a>-- with colons if necessary, and links to sections are detected and displayed<a href='#L-127'></a>-- with " § " as a separator rather than the standard MediaWiki "#". Used in<a href='#L-128'></a>-- the {{format link}} template.<a href='#L-129'></a>--------------------------------------------------------------------------------<a href='#L-130'></a><a href='#L-131'></a>function hatnote.formatLink(frame)<a href='#L-132'></a> local args = getArgs(frame)<a href='#L-133'></a> local link = args[1]<a href='#L-134'></a> local display = args[2]<a href='#L-135'></a> if not link then<a href='#L-136'></a> return hatnote.makeWikitextError(<a href='#L-137'></a> i18n:msg('error-link'),<a href='#L-138'></a> 'w:c:dev:Template:Format link#Errors',-- there is no actual docs for this. not even on wikipedia<a href='#L-139'></a> args.category<a href='#L-140'></a> )<a href='#L-141'></a> end<a href='#L-142'></a> return hatnote._formatLink(link, display)<a href='#L-143'></a>end<a href='#L-144'></a><a href='#L-145'></a>function hatnote._formatLink(link, display)<a href='#L-146'></a> checkType('_formatLink', 1, link, 'string')<a href='#L-147'></a> checkType('_formatLink', 2, display, 'string', true)<a href='#L-148'></a><a href='#L-149'></a> -- Remove the initial colon for links where it was specified manually.<a href='#L-150'></a> link = removeInitialColon(link)<a href='#L-151'></a><a href='#L-152'></a> -- Find whether a faux display value has been added with the {{!}} magic<a href='#L-153'></a> -- word.<a href='#L-154'></a> if not display then<a href='#L-155'></a> local prePipe, postPipe = link:match('^(.-)|(.*)$')<a href='#L-156'></a> link = prePipe or link<a href='#L-157'></a> display = postPipe<a href='#L-158'></a> end<a href='#L-159'></a><a href='#L-160'></a> -- Find the display value.<a href='#L-161'></a> if not display then<a href='#L-162'></a> local page, section = link:match('^(.-)#(.*)$')<a href='#L-163'></a> if page then<a href='#L-164'></a> display = page .. ' § ' .. section<a href='#L-165'></a> end<a href='#L-166'></a> end<a href='#L-167'></a><a href='#L-168'></a> -- Assemble the link.<a href='#L-169'></a> if display then<a href='#L-170'></a> return string.format(<a href='#L-171'></a> '[[:%s|%s]]',<a href='#L-172'></a> string.gsub(link, '|(.*)$', ''), --display overwrites manual piping<a href='#L-173'></a> display<a href='#L-174'></a> )<a href='#L-175'></a> else<a href='#L-176'></a> return string.format('[[:%s]]', link)<a href='#L-177'></a> end<a href='#L-178'></a>end<a href='#L-179'></a><a href='#L-180'></a>--------------------------------------------------------------------------------<a href='#L-181'></a>-- Hatnote<a href='#L-182'></a>--<a href='#L-183'></a>-- Produces standard hatnote text. Implements the {{hatnote}} template.<a href='#L-184'></a>--------------------------------------------------------------------------------<a href='#L-185'></a><a href='#L-186'></a>function hatnote.hatnote(frame)<a href='#L-187'></a> local args = getArgs(frame)<a href='#L-188'></a> local s = args[1]<a href='#L-189'></a> local options = {}<a href='#L-190'></a> if not s then<a href='#L-191'></a> return hatnote.makeWikitextError(<a href='#L-192'></a> i18n:msg('error-text'),<a href='#L-193'></a> 'w:c:dev:Template:Hatnote#Errors',<a href='#L-194'></a> args.category<a href='#L-195'></a> )<a href='#L-196'></a> end<a href='#L-197'></a> options.extraclasses = args.extraclasses<a href='#L-198'></a> options.selfref = args.selfref<a href='#L-199'></a> return hatnote._hatnote(s, options)<a href='#L-200'></a>end<a href='#L-201'></a><a href='#L-202'></a>function hatnote._hatnote(s, options)<a href='#L-203'></a> checkType('_hatnote', 1, s, 'string')<a href='#L-204'></a> checkType('_hatnote', 2, options, 'table', true)<a href='#L-205'></a> options = options or {}<a href='#L-206'></a> local classes = {'notice', 'hatnote'}<a href='#L-207'></a> local extraclasses = options.extraclasses<a href='#L-208'></a> local selfref = options.selfref<a href='#L-209'></a> if type(extraclasses)=='string' then<a href='#L-210'></a> classes[#classes + 1] = extraclasses<a href='#L-211'></a> end<a href='#L-212'></a> if selfref then<a href='#L-213'></a> classes[#classes + 1] = 'selfref'<a href='#L-214'></a> end<a href='#L-215'></a> return string.format(<a href='#L-216'></a> '<div role="note" class="%s">%s</div>',<a href='#L-217'></a> table.concat(classes, ' '),<a href='#L-218'></a> s<a href='#L-219'></a> )<a href='#L-220'></a>end<a href='#L-221'></a><a href='#L-222'></a>--------------------------------------------------------------------------------<a href='#L-223'></a>-- Module:Hatnote list --<a href='#L-224'></a>-- --<a href='#L-225'></a>-- This module produces and formats lists for use in hatnotes. In particular, --<a href='#L-226'></a>-- it implements the for-see list, i.e. lists of "For X, see Y" statements, --<a href='#L-227'></a>-- as used in {{about}}, and its variants. Also introduced are andList & --<a href='#L-228'></a>-- orList helpers for formatting lists with those conjunctions. --<a href='#L-229'></a>--------------------------------------------------------------------------------<a href='#L-230'></a><a href='#L-231'></a>--------------------------------------------------------------------------------<a href='#L-232'></a>-- List stringification helper functions<a href='#L-233'></a>--<a href='#L-234'></a>-- These functions are used for stringifying lists, usually page lists inside<a href='#L-235'></a>-- the "Y" portion of "For X, see Y" for-see items.<a href='#L-236'></a>--------------------------------------------------------------------------------<a href='#L-237'></a><a href='#L-238'></a>--default options table used across the list stringification functions<a href='#L-239'></a>local stringifyListDefaultOptions = {<a href='#L-240'></a> conjunction = i18n:msg('conjunction'),<a href='#L-241'></a> separator = i18n:msg('separator'),<a href='#L-242'></a> altSeparator = i18n:msg('altSeparator'),<a href='#L-243'></a> space = i18n:msg('space'),<a href='#L-244'></a> formatted = false<a href='#L-245'></a>}<a href='#L-246'></a><a href='#L-247'></a>-- Stringifies a list generically; probably shouldn't be used directly<a href='#L-248'></a>function stringifyList(list, options)<a href='#L-249'></a> -- Type-checks, defaults, and a shortcut<a href='#L-250'></a> checkType("stringifyList", 1, list, "table")<a href='#L-251'></a> if #list==0 then return nil end<a href='#L-252'></a> checkType("stringifyList", 2, options, "table", true)<a href='#L-253'></a> options = options or {}<a href='#L-254'></a> for k, v in pairs(stringifyListDefaultOptions) do<a href='#L-255'></a> if options[k]==nil then options[k] = v end<a href='#L-256'></a> end<a href='#L-257'></a> local s = options.space<a href='#L-258'></a> -- Format the list if requested<a href='#L-259'></a> if options.formatted then list=hatnote.formatPages(unpack(list)) end<a href='#L-260'></a> -- Set the separator; if any item contains it, use the alternate separator<a href='#L-261'></a> local separator = options.separator<a href='#L-262'></a> --searches display text only<a href='#L-263'></a> function searchDisp(t, f)<a href='#L-264'></a> return string.find(string.sub(t, (string.find(t, '|') or 0) + 1), f)<a href='#L-265'></a> end<a href='#L-266'></a> for k, v in pairs(list) do<a href='#L-267'></a> if searchDisp(v, separator) then<a href='#L-268'></a> separator = options.altSeparator<a href='#L-269'></a> break<a href='#L-270'></a> end<a href='#L-271'></a> end<a href='#L-272'></a> -- Set the conjunction, apply Oxford comma, and force a comma if #1 has "§"<a href='#L-273'></a> local oxfordLangs = {<a href='#L-274'></a> -- list of languages that does respect oxford commas<a href='#L-275'></a> ['en'] = true,<a href='#L-276'></a> ['en-us'] = true,<a href='#L-277'></a> ['en-gb'] = true,<a href='#L-278'></a> }<a href='#L-279'></a><a href='#L-280'></a> local conjunction = s .. options.conjunction .. s<a href='#L-281'></a> if #list==2 and searchDisp(list[1], "§") or #list > 2 then<a href='#L-282'></a> conjunction = (oxfordLangs[i18n.defaultLang] and separator or '') .. conjunction<a href='#L-283'></a> end<a href='#L-284'></a> -- Return the formatted string<a href='#L-285'></a> return mw.text.listToText(list, separator .. s, conjunction)<a href='#L-286'></a>end<a href='#L-287'></a><a href='#L-288'></a>--DRY function<a href='#L-289'></a>function conjList (conj, list, fmt)<a href='#L-290'></a> return stringifyList(list, {conjunction = conj, formatted = fmt})<a href='#L-291'></a>end<a href='#L-292'></a><a href='#L-293'></a>-- Stringifies lists with "and" or "or"<a href='#L-294'></a>function hatnote.andList (...) return conjList(i18n:msg('conj-and'), ...) end<a href='#L-295'></a>function hatnote.orList (...) return conjList(i18n:msg('conj-or'), ...) end<a href='#L-296'></a><a href='#L-297'></a>--------------------------------------------------------------------------------<a href='#L-298'></a>-- For see<a href='#L-299'></a>--<a href='#L-300'></a>-- Makes a "For X, see [[Y]]." list from raw parameters. Intended for the<a href='#L-301'></a>-- {{about}} templates and their variants.<a href='#L-302'></a>--------------------------------------------------------------------------------<a href='#L-303'></a><a href='#L-304'></a>--default options table used across the forSee family of functions<a href='#L-305'></a>local forSeeDefaultOptions = {<a href='#L-306'></a> andKeyword = i18n:msg('conj-and'),<a href='#L-307'></a> title = mw.title.getCurrentTitle().text,<a href='#L-308'></a> otherText=i18n:msg('other-uses'),<a href='#L-309'></a> forSeeForm = i18n:msg('for')<a href='#L-310'></a>}<a href='#L-311'></a><a href='#L-312'></a>--Collapses duplicate punctuation<a href='#L-313'></a>function punctuationCollapse (text)<a href='#L-314'></a> local replacements = {<a href='#L-315'></a> ["%.%.$"] = ".",<a href='#L-316'></a> ["%?%.$"] = "?",<a href='#L-317'></a> ["%!%.$"] = "!",<a href='#L-318'></a> ["%.%]%]%.$"] = ".]]",<a href='#L-319'></a> ["%?%]%]%.$"] = "?]]",<a href='#L-320'></a> ["%!%]%]%.$"] = "!]]"<a href='#L-321'></a> }<a href='#L-322'></a> for k, v in pairs(replacements) do text=string.gsub(text, k, v) end<a href='#L-323'></a> return text<a href='#L-324'></a>end<a href='#L-325'></a><a href='#L-326'></a>-- Structures arguments into a table for stringification, & options<a href='#L-327'></a>function hatnote.forSeeArgsToTable (args, from, options)<a href='#L-328'></a> -- Type-checks and defaults<a href='#L-329'></a> checkType("forSeeArgsToTable", 1, args, 'table')<a href='#L-330'></a> checkType("forSeeArgsToTable", 2, from, 'number', true)<a href='#L-331'></a> from = from or 1<a href='#L-332'></a> checkType("forSeeArgsToTable", 3, options, 'table', true)<a href='#L-333'></a> options = options or {}<a href='#L-334'></a> for k, v in pairs(forSeeDefaultOptions) do<a href='#L-335'></a> if options[k]==nil then options[k] = v end<a href='#L-336'></a> end<a href='#L-337'></a> -- maxArg's gotten manually because getArgs() and table.maxn aren't friends<a href='#L-338'></a> local maxArg = 0<a href='#L-339'></a> for k, v in pairs(args) do<a href='#L-340'></a> if type(k)=='number' and k > maxArg then maxArg = k end<a href='#L-341'></a> end<a href='#L-342'></a> -- Structure the data out from the parameter list:<a href='#L-343'></a> -- * forTable is the wrapper table, with forRow rows<a href='#L-344'></a> -- * Rows are tables of a "use" string & a "pages" table of pagename strings<a href='#L-345'></a> -- * Blanks are left empty for defaulting elsewhere, but can terminate list<a href='#L-346'></a> local forTable = {}<a href='#L-347'></a> local i = from<a href='#L-348'></a> local terminated = false<a href='#L-349'></a> -- Loop to generate rows<a href='#L-350'></a> repeat<a href='#L-351'></a> -- New empty row<a href='#L-352'></a> local forRow = {}<a href='#L-353'></a> -- On blank use, assume list's ended & break at end of this loop<a href='#L-354'></a> forRow.use = args[i]<a href='#L-355'></a> if not args[i] then terminated = true end<a href='#L-356'></a> -- New empty list of pages<a href='#L-357'></a> forRow.pages = {}<a href='#L-358'></a> -- Insert first pages item if present<a href='#L-359'></a> table.insert(forRow.pages, args[i + 1])<a href='#L-360'></a> -- If the param after next is "and", do inner loop to collect params<a href='#L-361'></a> -- until the "and"'s stop. Blanks are ignored: "1|and||and|3" → {1, 3}<a href='#L-362'></a> while args[i + 2]==options.andKeyword do<a href='#L-363'></a> if args[i + 3] then<a href='#L-364'></a> table.insert(forRow.pages, args[i + 3])<a href='#L-365'></a> end<a href='#L-366'></a> -- Increment to next "and"<a href='#L-367'></a> i = i + 2<a href='#L-368'></a> end<a href='#L-369'></a> -- Increment to next use<a href='#L-370'></a> i = i + 2<a href='#L-371'></a> -- Append the row<a href='#L-372'></a> table.insert(forTable, forRow)<a href='#L-373'></a> until terminated or i > maxArg<a href='#L-374'></a><a href='#L-375'></a> return forTable<a href='#L-376'></a>end<a href='#L-377'></a><a href='#L-378'></a>-- Stringifies a table as formatted by forSeeArgsToTable<a href='#L-379'></a>function hatnote.forSeeTableToString (forSeeTable, options)<a href='#L-380'></a> -- Type-checks and defaults<a href='#L-381'></a> checkType("forSeeTableToString", 1, forSeeTable, "table")<a href='#L-382'></a> checkType("forSeeTableToString", 2, options, "table", true)<a href='#L-383'></a> options = options or {}<a href='#L-384'></a> for k, v in pairs(forSeeDefaultOptions) do<a href='#L-385'></a> if options[k]==nil then options[k] = v end<a href='#L-386'></a> end<a href='#L-387'></a> -- Stringify each for-see item into a list<a href='#L-388'></a> local strList={}<a href='#L-389'></a> for k, v in pairs(forSeeTable) do<a href='#L-390'></a> local useStr = v.use or options.otherText<a href='#L-391'></a> local pagesStr = hatnote.andList(v.pages, true) or<a href='#L-392'></a> hatnote._formatLink(hatnote.disambiguate(options.title))<a href='#L-393'></a> local forSeeStr = string.format(options.forSeeForm, useStr, pagesStr)<a href='#L-394'></a> forSeeStr = punctuationCollapse(forSeeStr)<a href='#L-395'></a> table.insert(strList, forSeeStr)<a href='#L-396'></a> end<a href='#L-397'></a> -- Return the concatenated list<a href='#L-398'></a> return table.concat(strList, ' ')<a href='#L-399'></a>end<a href='#L-400'></a><a href='#L-401'></a>-- Produces a "For X, see [[Y]]" string from arguments. Expects index gaps<a href='#L-402'></a>-- but not blank/whitespace values. Ignores named args and args < "from".<a href='#L-403'></a>function hatnote._forSee (args, from, options)<a href='#L-404'></a> local forSeeTable = hatnote.forSeeArgsToTable(args, from, options)<a href='#L-405'></a> return hatnote.forSeeTableToString(forSeeTable, options)<a href='#L-406'></a>end<a href='#L-407'></a><a href='#L-408'></a>-- As _forSee, but uses the frame.<a href='#L-409'></a>function hatnote.forSee (frame, from, options)<a href='#L-410'></a> return hatnote._forSee(mArguments.getArgs(frame), from, options)<a href='#L-411'></a>end<a href='#L-412'></a><a href='#L-413'></a>--------------------------------------------------------------------------------<a href='#L-414'></a>-- Produces a labelled pages-list hatnote.<a href='#L-415'></a>-- The main frame (template definition) takes 1 or 2 arguments, for a singular<a href='#L-416'></a>-- and (optionally) plural label respectively:<a href='#L-417'></a>-- * {{#invoke:Hatnote|labelledList|Singular label|Plural label}}<a href='#L-418'></a>-- The resulting template takes pagename & label parameters normally.<a href='#L-419'></a>--------------------------------------------------------------------------------<a href='#L-420'></a>-- Defaults global to this module<a href='#L-421'></a>local LPLHdefaults = {<a href='#L-422'></a> label = i18n:msg('see-also'), --Final fallback for label argument<a href='#L-423'></a> labelForm = i18n:msg('colon'),<a href='#L-424'></a> prefixes = {'label', 'label ', 'l'},<a href='#L-425'></a> template = 'Module:Hatnote'<a href='#L-426'></a>}<a href='#L-427'></a><a href='#L-428'></a>-- Helper function that pre-combines display parameters into page arguments.<a href='#L-429'></a>-- Also compresses sparse arrays, as a desirable side-effect.<a href='#L-430'></a>function hatnote.preprocessDisplays (args, prefixes)<a href='#L-431'></a> -- Prefixes specify which parameters, in order, to check for display options<a href='#L-432'></a> -- They each have numbers auto-appended, e.g. 'label1', 'label 1', & 'l1'<a href='#L-433'></a> prefixes = prefixes or LPLHdefaults.prefixes<a href='#L-434'></a> local pages = {}<a href='#L-435'></a> for k, v in pairs(args) do<a href='#L-436'></a> if type(k)=='number' then<a href='#L-437'></a> local display<a href='#L-438'></a> for i = 1, #prefixes do<a href='#L-439'></a> display = args[prefixes[i] .. k]<a href='#L-440'></a> if display then break end<a href='#L-441'></a> end<a href='#L-442'></a> local page = display and<a href='#L-443'></a> string.format('%s|%s', string.gsub(v, '|.*$', ''), display) or v<a href='#L-444'></a> pages[#pages + 1] = page<a href='#L-445'></a> end<a href='#L-446'></a> end<a href='#L-447'></a> return pages<a href='#L-448'></a>end<a href='#L-449'></a><a href='#L-450'></a>function hatnote.labelledList (frame)<a href='#L-451'></a> local labels = {frame.args[1] or LPLHdefaults.label}<a href='#L-452'></a> labels[2] = frame.args[2] or labels[1]<a href='#L-453'></a> local template = frame:getParent():getTitle()<a href='#L-454'></a> local args = mArguments.getArgs(frame, {parentOnly = true})<a href='#L-455'></a> local pages = hatnote.preprocessDisplays(args)<a href='#L-456'></a> local options = {<a href='#L-457'></a> extraclasses = frame.args.extraclasses,<a href='#L-458'></a> category = args.category,<a href='#L-459'></a> selfref = frame.args.selfref or args.selfref,<a href='#L-460'></a> template = template<a href='#L-461'></a> }<a href='#L-462'></a> return hatnote._labelledList(pages, labels, options)<a href='#L-463'></a>end<a href='#L-464'></a><a href='#L-465'></a>function hatnote._labelledList (pages, labels, options)<a href='#L-466'></a> labels = labels or {}<a href='#L-467'></a> if #pages==0 then<a href='#L-468'></a> return hatnote.makeWikitextError(<a href='#L-469'></a> i18n:msg('error-pagename', 2),<a href='#L-470'></a> (options.template or LPLHdefaults.template) .. '#Errors',<a href='#L-471'></a> options.category<a href='#L-472'></a> )<a href='#L-473'></a> end<a href='#L-474'></a> label = (#pages==1 and labels[1] or labels[2]) or LPLHdefaults.label<a href='#L-475'></a> local text=string.format(<a href='#L-476'></a> options.labelForm or LPLHdefaults.labelForm,<a href='#L-477'></a> label,<a href='#L-478'></a> hatnote.andList(pages, true)<a href='#L-479'></a> )<a href='#L-480'></a> local hnOptions = {<a href='#L-481'></a> extraclasses = options.extraclasses,<a href='#L-482'></a> selfref = options.selfref<a href='#L-483'></a> }<a href='#L-484'></a> return hatnote._hatnote(text, hnOptions)<a href='#L-485'></a>end<a href='#L-486'></a><a href='#L-487'></a><a href='#L-488'></a>--------------------------------------------------------------------------------<a href='#L-489'></a>-- About<a href='#L-490'></a>--<a href='#L-491'></a>-- These functions implement the {{about}} hatnote template.<a href='#L-492'></a>--------------------------------------------------------------------------------<a href='#L-493'></a>function hatnote.about (frame)<a href='#L-494'></a> -- A passthrough that gets args from the frame and all<a href='#L-495'></a> args = mArguments.getArgs(frame)<a href='#L-496'></a> return hatnote._about(args)<a href='#L-497'></a>end<a href='#L-498'></a><a href='#L-499'></a><a href='#L-500'></a>function hatnote._about (args, options)<a href='#L-501'></a> -- Produces "about" hatnote.<a href='#L-502'></a><a href='#L-503'></a> -- Type checks and defaults<a href='#L-504'></a> checkType('_about', 1, args, 'table', true)<a href='#L-505'></a> args = args or {}<a href='#L-506'></a> checkType('_about', 2, options, 'table', true)<a href='#L-507'></a> options = options or {}<a href='#L-508'></a> local defaultOptions = {<a href='#L-509'></a> aboutForm = i18n:msg('about', mw.title.getCurrentTitle().namespace),<a href='#L-510'></a> defaultPageType = i18n:msg('page'),<a href='#L-511'></a> namespace = mw.title.getCurrentTitle().namespace,<a href='#L-512'></a> otherText=nil, --included for complete list<a href='#L-513'></a> pageTypesByNamespace = {<a href='#L-514'></a> [0] = i18n:msg('pagetype-0'),<a href='#L-515'></a> [14] = i18n:msg('pagetype-14')<a href='#L-516'></a> },<a href='#L-517'></a> sectionString = i18n:msg('section')<a href='#L-518'></a> }<a href='#L-519'></a> for k, v in pairs(defaultOptions) do<a href='#L-520'></a> if options[k]==nil then options[k] = v end<a href='#L-521'></a> end<a href='#L-522'></a><a href='#L-523'></a> -- Set initial "about" string<a href='#L-524'></a> local pageType = (args.section and options.sectionString) or<a href='#L-525'></a> options.pageTypesByNamespace[options.namespace] or<a href='#L-526'></a> options.defaultPageType<a href='#L-527'></a> local about=''<a href='#L-528'></a> if args[1] then<a href='#L-529'></a> about=string.format(options.aboutForm, pageType, args[1])<a href='#L-530'></a> end<a href='#L-531'></a><a href='#L-532'></a> --Allow passing through certain options<a href='#L-533'></a> local fsOptions = {<a href='#L-534'></a> otherText=options.otherText<a href='#L-535'></a> }<a href='#L-536'></a><a href='#L-537'></a> -- Set for-see list<a href='#L-538'></a> local forSee = " " .. hatnote._forSee(args, 2, fsOptions)<a href='#L-539'></a><a href='#L-540'></a> -- Concatenate and return<a href='#L-541'></a> return hatnote._hatnote(about .. forSee, {extraclasses = 'context-link about dablink'})<a href='#L-542'></a>end<a href='#L-543'></a><a href='#L-544'></a>--------------------------------------------------------------------------------<a href='#L-545'></a>-- Details<a href='#L-546'></a>--<a href='#L-547'></a>-- These functions implement the {{details}} hatnote template.<a href='#L-548'></a>--------------------------------------------------------------------------------<a href='#L-549'></a>function hatnote.details (frame)<a href='#L-550'></a> local args = mArguments.getArgs(frame, {parentOnly = true})<a href='#L-551'></a> local topic, category = args.topic, args.category<a href='#L-552'></a> local options = {<a href='#L-553'></a> selfref = args.selfref,<a href='#L-554'></a> extraclasses = 'context-link details dablink'<a href='#L-555'></a> }<a href='#L-556'></a> args = mTableTools.compressSparseArray(args)<a href='#L-557'></a> if #args==0 then<a href='#L-558'></a> return hatnote.makeWikitextError(<a href='#L-559'></a> i18n:msg('error-pagename'),<a href='#L-560'></a> 'w:c:dev:Template:Details#Errors',-- another undocumented thing<a href='#L-561'></a> category<a href='#L-562'></a> )<a href='#L-563'></a> end<a href='#L-564'></a> return hatnote._details(args, topic, options)<a href='#L-565'></a>end<a href='#L-566'></a><a href='#L-567'></a>function hatnote._details (list, topic, options)<a href='#L-568'></a> list=hatnote.andList(list, true)<a href='#L-569'></a> topic = topic or i18n:msg('topic')<a href='#L-570'></a> local text=string.format(i18n:msg('details'), topic, list)<a href='#L-571'></a> return hatnote._hatnote(text, options)<a href='#L-572'></a>end<a href='#L-573'></a><a href='#L-574'></a>--------------------------------------------------------------------------------<a href='#L-575'></a>-- For<a href='#L-576'></a>--<a href='#L-577'></a>-- These functions implement the {{for}} hatnote template.<a href='#L-578'></a>--------------------------------------------------------------------------------<a href='#L-579'></a>function hatnote.For (frame)<a href='#L-580'></a> return hatnote._For(mArguments.getArgs(frame))<a href='#L-581'></a>end<a href='#L-582'></a><a href='#L-583'></a>--Implements {{For}} but takes a manual arguments table<a href='#L-584'></a>function hatnote._For (args)<a href='#L-585'></a> local use = args[1]<a href='#L-586'></a> local category = ''<a href='#L-587'></a> if (not use or use==i18n:msg('other-uses')) and<a href='#L-588'></a> (not args.category or yesno(args.category)) then<a href='#L-589'></a> category = '[[Category:' .. i18n:msg('cat-unusual-parameters') .. ']]'<a href='#L-590'></a> end<a href='#L-591'></a> local pages = {}<a href='#L-592'></a> function two (a, b) return a, b, 1 end --lets us run ipairs from 2<a href='#L-593'></a> for k, v in two(ipairs(args)) do table.insert(pages, v) end<a href='#L-594'></a> return hatnote._hatnote(<a href='#L-595'></a> hatnote.forSeeTableToString({{use = use, pages = pages}}),<a href='#L-596'></a> {selfref = args.selfref}<a href='#L-597'></a> ) .. category<a href='#L-598'></a>end<a href='#L-599'></a><a href='#L-600'></a>--------------------------------------------------------------------------------<a href='#L-601'></a>-- Further<a href='#L-602'></a>--<a href='#L-603'></a>-- These functions implement the {{further}} hatnote template.<a href='#L-604'></a>--------------------------------------------------------------------------------<a href='#L-605'></a>function hatnote.further(frame)<a href='#L-606'></a> local args = mArguments.getArgs(frame, {parentOnly = true})<a href='#L-607'></a> local pages = mTableTools.compressSparseArray(args)<a href='#L-608'></a> if #pages < 1 then<a href='#L-609'></a> return hatnote.makeWikitextError(<a href='#L-610'></a> i18n:msg('error-pagename', 2),<a href='#L-611'></a> 'w:c:dev:Template:Further#Errors',-- undocumented thing #3<a href='#L-612'></a> args.category<a href='#L-613'></a> )<a href='#L-614'></a> end<a href='#L-615'></a> local options = {<a href='#L-616'></a> selfref = args.selfref,<a href='#L-617'></a> extraclasses = 'context-link further dablink'<a href='#L-618'></a> }<a href='#L-619'></a> return hatnote._further(pages, options)<a href='#L-620'></a>end<a href='#L-621'></a><a href='#L-622'></a>function hatnote._further(pages, options)<a href='#L-623'></a> local text=i18n:msg('further2') .. hatnote.andList(pages, true)<a href='#L-624'></a> return hatnote._hatnote(text, options)<a href='#L-625'></a>end<a href='#L-626'></a><a href='#L-627'></a>--------------------------------------------------------------------------------<a href='#L-628'></a>-- Main<a href='#L-629'></a>--<a href='#L-630'></a>-- These functions implement the {{main}} hatnote template.<a href='#L-631'></a>--------------------------------------------------------------------------------<a href='#L-632'></a>function hatnote.main(frame)<a href='#L-633'></a> local args = mArguments.getArgs(frame, {parentOnly = true})<a href='#L-634'></a> local pages = {}<a href='#L-635'></a> for k, v in pairs(args) do<a href='#L-636'></a> if type(k)=='number' then<a href='#L-637'></a> local display = args['label ' .. k] or args['l' .. k]<a href='#L-638'></a> local page = display and<a href='#L-639'></a> string.format('%s|%s', string.gsub(v, '|.*$', ''), display) or v<a href='#L-640'></a> pages[#pages + 1] = page<a href='#L-641'></a> end<a href='#L-642'></a> end<a href='#L-643'></a> if #pages==0 and mw.title.getCurrentTitle().namespace==0 then<a href='#L-644'></a> return hatnote.makeWikitextError(<a href='#L-645'></a> i18n:msg('error-pagename', 2),<a href='#L-646'></a> 'w:c:dev:Template:Main#Errors',-- undocumented thing #4<a href='#L-647'></a> args.category<a href='#L-648'></a> )<a href='#L-649'></a> end<a href='#L-650'></a> local options = {<a href='#L-651'></a> selfref = args.selfref<a href='#L-652'></a> }<a href='#L-653'></a> return hatnote._main(pages, options)<a href='#L-654'></a>end<a href='#L-655'></a><a href='#L-656'></a>function hatnote._main(args, options)<a href='#L-657'></a> -- Get the list of pages. If no first page was specified we use the current<a href='#L-658'></a> -- page name.<a href='#L-659'></a> local currentTitle = mw.title.getCurrentTitle()<a href='#L-660'></a> if #args==0 then args = {currentTitle.text} end<a href='#L-661'></a> local firstPage = string.gsub(args[1], '|.*$', '')<a href='#L-662'></a> -- Make the formatted link text<a href='#L-663'></a> list=hatnote.andList(args, true)<a href='#L-664'></a> -- Build the text.<a href='#L-665'></a> local isPlural = #args > 1<a href='#L-666'></a> -- Find the pagetype.<a href='#L-667'></a> local pageType = hatnote.findNamespaceId(firstPage)==0 and i18n:msg('article', isPlural and 2 or 1) or i18n:msg('page', isPlural and 2 or 1)<a href='#L-668'></a> local mainForm<a href='#L-669'></a> local curNs = currentTitle.namespace<a href='#L-670'></a> if (curNs==14) or (curNs==15) then --category/talk namespaces<a href='#L-671'></a> mainForm = isPlural and i18n:msg('main-category', 2)<a href='#L-672'></a> or<a href='#L-673'></a> i18n:msg('main-category', 1)<a href='#L-674'></a> else<a href='#L-675'></a> mainForm = isPlural and i18n:msg('main', 2) or i18n:msg('main', 1)<a href='#L-676'></a> end<a href='#L-677'></a> local text=string.format(mainForm, pageType, list)<a href='#L-678'></a> options = options or {}<a href='#L-679'></a> local hnOptions = {<a href='#L-680'></a> selfref = options.selfref,<a href='#L-681'></a> extraclasses = 'context-link main dablink'<a href='#L-682'></a> }<a href='#L-683'></a> return hatnote._hatnote(text, hnOptions)<a href='#L-684'></a>end<a href='#L-685'></a><a href='#L-686'></a>--------------------------------------------------------------------------------<a href='#L-687'></a>-- See also<a href='#L-688'></a>--<a href='#L-689'></a>-- These functions implement the {{see also}} hatnote template.<a href='#L-690'></a>--------------------------------------------------------------------------------<a href='#L-691'></a>function hatnote.seeAlso(frame)<a href='#L-692'></a> local args = mArguments.getArgs(frame, {parentOnly = true})<a href='#L-693'></a> local pages = {}<a href='#L-694'></a> for k, v in pairs(args) do<a href='#L-695'></a> if type(k)=='number' then<a href='#L-696'></a> local display = args['label ' .. k] or args['l' .. k]<a href='#L-697'></a> local page = display and<a href='#L-698'></a> string.format('%s|%s', string.gsub(v, '|.*$', ''), display) or v<a href='#L-699'></a> pages[#pages + 1] = page<a href='#L-700'></a> end<a href='#L-701'></a> end<a href='#L-702'></a> if not pages[1] then<a href='#L-703'></a> return hatnote.makeWikitextError(<a href='#L-704'></a> i18n:msg('error-pagename', 2),<a href='#L-705'></a> 'w:c:dev:Template:See also#Errors',-- undocumented thing #5<a href='#L-706'></a> args.category<a href='#L-707'></a> )<a href='#L-708'></a> end<a href='#L-709'></a> local options = {<a href='#L-710'></a> selfref = args.selfref<a href='#L-711'></a> }<a href='#L-712'></a> return hatnote._seeAlso(pages, options)<a href='#L-713'></a>end<a href='#L-714'></a><a href='#L-715'></a>function hatnote._seeAlso(args, options)<a href='#L-716'></a> checkType('_seeAlso', 1, args, 'table')<a href='#L-717'></a> checkType('_seeAlso', 2, options, 'table', true)<a href='#L-718'></a> options = options or {}<a href='#L-719'></a> local list=hatnote.andList(args, true)<a href='#L-720'></a> local text=string.format(i18n:msg('see-also2'), list)<a href='#L-721'></a> -- Pass options through.<a href='#L-722'></a> local hnOptions = {<a href='#L-723'></a> selfref = options.selfref,<a href='#L-724'></a> extraclasses = 'context-link seealso dablink'<a href='#L-725'></a> }<a href='#L-726'></a> return hatnote._hatnote(text, hnOptions)<a href='#L-727'></a>end<a href='#L-728'></a><a href='#L-729'></a>hatnote['for'] = hatnote.For<a href='#L-730'></a><a href='#L-731'></a>return hatnote</div>
<br><br>
<br>
特に記載のない限り、コミュニティのコンテンツはCC BY-SAライセンスの下で利用可能です。
この記事は、CC BY-SAのもとで公表された<a href="https://fifty-people-craft.fandom.com/ja/wiki/%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB:Hatnote">「モジュール:Hatnote」</a>を改変し作成しました。特に記載されていない限り、CC BY-SAのもとで利用可能です。