「モジュール:Documentation」の版間の差分
ja>Paine Ellsworth per edit request on talk page - make the doc environment behave correctly, giving the actual template name on the doc page rather than the name of the "doc" subpage |
細 1版 をインポートしました |
||
(同じ利用者による、間の1版が非表示) | |||
3行目: | 3行目: | ||
-- Get required modules. | -- Get required modules. | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
local messageBox = require('Module:Message box') | |||
-- Get the config table. | -- Get the config table. | ||
11行目: | 12行目: | ||
-- Often-used functions. | -- Often-used functions. | ||
local ugsub = mw.ustring.gsub | local ugsub = mw.ustring.gsub | ||
---------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | ||
33行目: | 33行目: | ||
expectType = expectType or 'string' | expectType = expectType or 'string' | ||
if type(msg) ~= expectType then | if type(msg) ~= expectType then | ||
error(' | error('メッセージ: cfg.' .. cfgKey .. 'の入力エラー。(想定:' .. expectType .. '、実際:' .. type(msg) .. ')', 2) | ||
end | end | ||
if not valArray then | if not valArray then | ||
41行目: | 41行目: | ||
local function getMessageVal(match) | local function getMessageVal(match) | ||
match = tonumber(match) | match = tonumber(match) | ||
return valArray[match] or error(' | return valArray[match] or error('メッセージ: メッセージ設定で$' .. match .. 'キーの値が見つかりませんでした。' .. cfgKey, 4) | ||
end | end | ||
51行目: | 51行目: | ||
local function makeWikilink(page, display) | local function makeWikilink(page, display) | ||
if display then | if display then | ||
return format('[[%s|%s]]', page, display) | return mw.ustring.format('[[%s|%s]]', page, display) | ||
else | else | ||
return format('[[%s]]', page) | return mw.ustring.format('[[%s]]', page) | ||
end | end | ||
end | end | ||
67行目: | 67行目: | ||
local function makeUrlLink(url, display) | local function makeUrlLink(url, display) | ||
return format('[%s %s]', url, display) | return mw.ustring.format('[%s %s]', url, display) | ||
end | end | ||
82行目: | 82行目: | ||
end | end | ||
-- 'documentation-toolbar' | -- 'documentation-toolbar' | ||
return | return '<span class="' .. message('toolbar-class') .. '">(' | ||
.. table.concat(ret, ' | ') .. ')</span>' | |||
table.concat(ret, ' | ') | |||
end | end | ||
143行目: | 140行目: | ||
-- 'documentation-container' | -- 'documentation-container' | ||
:addClass(message('container')) | :addClass(message('container')) | ||
:newline() | :newline() | ||
:tag('div') | :tag('div') | ||
184行目: | 178行目: | ||
-- env.sandboxTitle - the /sandbox subpage. | -- env.sandboxTitle - the /sandbox subpage. | ||
-- env.testcasesTitle - the /testcases subpage. | -- env.testcasesTitle - the /testcases subpage. | ||
-- env.printTitle - the print version of the template, located at the /Print subpage. | |||
-- | -- | ||
-- Data includes: | -- Data includes: | ||
237行目: | 232行目: | ||
local title = env.title | local title = env.title | ||
local subpage = title.subpageText | local subpage = title.subpageText | ||
if subpage == message('sandbox-subpage') or subpage == message('testcases-subpage' | if subpage == message('sandbox-subpage') or subpage == message('testcases-subpage') then | ||
return mw.title.makeTitle(subjectSpace, title.baseText) | return mw.title.makeTitle(subjectSpace, title.baseText) | ||
else | else | ||
277行目: | 272行目: | ||
--]] | --]] | ||
return mw.title.new(env.docpageBase .. '/' .. message('testcases-subpage')) | return mw.title.new(env.docpageBase .. '/' .. message('testcases-subpage')) | ||
end | |||
function envFuncs.printTitle() | |||
--[[ | |||
-- Title object for the /Print subpage. | |||
-- Messages: | |||
-- 'print-subpage' --> 'Print' | |||
--]] | |||
return env.templateTitle:subPageTitle(message('print-subpage')) | |||
end | end | ||
317行目: | 321行目: | ||
local sandboxTitle = env.sandboxTitle | local sandboxTitle = env.sandboxTitle | ||
if templateTitle.exists and sandboxTitle.exists then | if templateTitle.exists and sandboxTitle.exists then | ||
local compareUrl = mw.uri. | local compareUrl = mw.uri.fullUrl( | ||
'Special:ComparePages', | 'Special:ComparePages', | ||
{ page1 = templateTitle.prefixedText, page2 = sandboxTitle.prefixedText} | { page1 = templateTitle.prefixedText, page2 = sandboxTitle.prefixedText} | ||
353行目: | 357行目: | ||
-- | -- | ||
-- Messages: | -- Messages: | ||
-- 'sandbox-notice-image' --> '[[ | -- 'sandbox-notice-image' --> '[[Image:Sandbox.svg|50px|alt=|link=]]' | ||
-- 'sandbox-notice-blurb' --> 'This is the $1 for $2.' | -- 'sandbox-notice-blurb' --> 'This is the $1 for $2.' | ||
-- 'sandbox-notice-diff-blurb' --> 'This is the $1 for $2 ($3).' | -- 'sandbox-notice-diff-blurb' --> 'This is the $1 for $2 ($3).' | ||
363行目: | 367行目: | ||
-- 'sandbox-notice-testcases-link-display' --> 'test cases' | -- 'sandbox-notice-testcases-link-display' --> 'test cases' | ||
-- 'sandbox-category' --> 'Template sandboxes' | -- 'sandbox-category' --> 'Template sandboxes' | ||
--]=] | --]=] | ||
local title = env.title | local title = env.title | ||
379行目: | 381行目: | ||
-- Get the text. We start with the opening blurb, which is something like | -- Get the text. We start with the opening blurb, which is something like | ||
-- "This is the template sandbox for [[Template:Foo]] (diff)." | -- "This is the template sandbox for [[Template:Foo]] (diff)." | ||
local text = ' | local text = '' | ||
local pagetype | local pagetype | ||
if subjectSpace == 10 then | if subjectSpace == 10 then | ||
pagetype = message('sandbox-notice-pagetype-template') | pagetype = message('sandbox-notice-pagetype-template') | ||
elseif subjectSpace == 828 then | elseif subjectSpace == 828 then | ||
pagetype = message('sandbox-notice-pagetype-module') | pagetype = message('sandbox-notice-pagetype-module') | ||
else | else | ||
pagetype = message('sandbox-notice-pagetype-other') | pagetype = message('sandbox-notice-pagetype-other') | ||
end | end | ||
local templateLink = makeWikilink(templateTitle.prefixedText) | local templateLink = makeWikilink(templateTitle.prefixedText) | ||
416行目: | 415行目: | ||
end | end | ||
end | end | ||
-- Add the sandbox to the sandbox category. | -- Add the sandbox to the sandbox category. | ||
omargs.text = text .. makeCategoryLink( | omargs.text = text .. makeCategoryLink(message('sandbox-category')) | ||
-- 'documentation-clear' | -- 'documentation-clear' | ||
437行目: | 435行目: | ||
local editProt = protectionLevels.edit and protectionLevels.edit[1] | local editProt = protectionLevels.edit and protectionLevels.edit[1] | ||
local moveProt = protectionLevels.move and protectionLevels.move[1] | local moveProt = protectionLevels.move and protectionLevels.move[1] | ||
-- 日本語版独自仕様: 編集保護と移動保護で保護レベルが異なる場合に、両方のアイコンを表示する | |||
local ret = '' | |||
if editProt then | if editProt then | ||
-- The page is edit-protected. | -- The page is edit-protected. | ||
ret = ret .. require('Module:Protection banner')._main{ | |||
message('protection-reason-edit'), small = true | message('protection-reason-edit'), small = true | ||
} | } | ||
end | |||
-- The page is move | if moveProt and moveProt ~= editProt and moveProt ~= 'autoconfirmed' then | ||
-- The page is move-protected. | |||
ret = ret .. require('Module:Protection banner')._main{ | |||
action = 'move', small = true | action = 'move', small = true | ||
} | } | ||
end | end | ||
return ret | |||
end | end | ||
501行目: | 500行目: | ||
-- 'history-link-display' --> 'history' | -- 'history-link-display' --> 'history' | ||
-- 'purge-link-display' --> 'purge' | -- 'purge-link-display' --> 'purge' | ||
-- 'file-docpage-preload' --> 'Template:Documentation/preload-filespace' | |||
-- 'module-preload' --> 'Template:Documentation/preload-module-doc' | -- 'module-preload' --> 'Template:Documentation/preload-module-doc' | ||
-- 'docpage-preload' --> 'Template:Documentation/preload' | -- 'docpage-preload' --> 'Template:Documentation/preload' | ||
511行目: | 511行目: | ||
return nil | return nil | ||
end | end | ||
if docTitle.isRedirect then | if docTitle.isRedirect then | ||
docTitle = docTitle.redirectTarget | docTitle = docTitle.redirectTarget | ||
end | end | ||
local data = {} | |||
data.title = title | |||
data.docTitle = docTitle | |||
-- View, display, edit, and purge links if /doc exists. | |||
data.viewLinkDisplay = message('view-link-display') | |||
data.editLinkDisplay = message('edit-link-display') | |||
data.historyLinkDisplay = message('history-link-display') | |||
data.purgeLinkDisplay = message('purge-link-display') | |||
-- Create link if /doc doesn't exist. | -- Create link if /doc doesn't exist. | ||
local preload = args.preload | local preload = args.preload | ||
if not preload then | if not preload then | ||
if subjectSpace == 828 then -- Module namespace | if subjectSpace == 6 then -- File namespace | ||
preload = message('file-docpage-preload') | |||
elseif subjectSpace == 828 then -- Module namespace | |||
preload = message('module-preload') | preload = message('module-preload') | ||
else | else | ||
524行目: | 534行目: | ||
end | end | ||
end | end | ||
data.preload = preload | |||
data.createLinkDisplay = message('create-link-display') | |||
return data | |||
end | end | ||
function p.renderStartBoxLinks(data) | function p.renderStartBoxLinks(data) | ||
--[[ | --[[ | ||
-- Generates the [view][edit][history][purge] or [create | -- Generates the [view][edit][history][purge] or [create] links from the data table. | ||
-- @data - a table of data generated by p.makeStartBoxLinksData | -- @data - a table of data generated by p.makeStartBoxLinksData | ||
--]] | --]] | ||
local function escapeBrackets(s) | |||
-- Escapes square brackets with HTML entities. | |||
s = s:gsub('%[', '[') -- Replace square brackets with HTML entities. | |||
s = s:gsub('%]', ']') | |||
return s | |||
end | |||
local ret | |||
local docTitle = data.docTitle | local docTitle = data.docTitle | ||
local title = data.title | |||
local | |||
if docTitle.exists then | if docTitle.exists then | ||
local viewLink = makeWikilink(docTitle.prefixedText, data.viewLinkDisplay) | local viewLink = makeWikilink(docTitle.prefixedText, data.viewLinkDisplay) | ||
local editLink = | local editLink = makeUrlLink(docTitle:fullUrl{action = 'edit'}, data.editLinkDisplay) | ||
local historyLink = | local historyLink = makeUrlLink(docTitle:fullUrl{action = 'history'}, data.historyLinkDisplay) | ||
local purgeLink = makeUrlLink(title:fullUrl{action = 'purge'}, data.purgeLinkDisplay) | |||
ret = '[%s] [%s] [%s] [%s]' | |||
ret = escapeBrackets(ret) | |||
ret = mw.ustring.format(ret, viewLink, editLink, historyLink, purgeLink) | |||
else | else | ||
local createLink = makeUrlLink(docTitle: | local createLink = makeUrlLink(docTitle:fullUrl{action = 'edit', preload = data.preload}, data.createLinkDisplay) | ||
ret = '[%s]' | |||
ret = escapeBrackets(ret) | |||
ret = mw.ustring.format(ret, createLink) | |||
end | end | ||
return ret | return ret | ||
629行目: | 642行目: | ||
:tag('span') | :tag('span') | ||
:addClass(data.headingClass) | :addClass(data.headingClass) | ||
:cssText(data.headingStyleText) | :cssText(data.headingStyleText) | ||
:wikitext(data.heading) | :wikitext(data.heading) | ||
730行目: | 742行目: | ||
end | end | ||
text = text .. ' ' .. (p.makeSubpagesBlurb(args, env) or '') --"Subpages of this template" | text = text .. ' ' .. (p.makeSubpagesBlurb(args, env) or '') --"Subpages of this template" | ||
local printBlurb = p.makePrintBlurb(args, env) -- Two-line blurb about print versions of templates. | |||
if printBlurb then | |||
text = text .. '<br />' .. printBlurb | |||
end | |||
end | end | ||
end | end | ||
local box = mw.html.create('div') | local box = mw.html.create('div') | ||
box:attr('role', 'note') | box:attr('role', 'note') | ||
-- 'documentation-metadata' | |||
:addClass(message('end-box-class')) | :addClass(message('end-box-class')) | ||
-- 'plainlinks' | -- 'plainlinks' | ||
766行目: | 782行目: | ||
return nil | return nil | ||
end | end | ||
local ret | |||
if docTitle.exists then | if docTitle.exists then | ||
-- /doc exists; link to it. | -- /doc exists; link to it. | ||
local docLink = makeWikilink(docTitle.prefixedText) | local docLink = makeWikilink(docTitle.prefixedText) | ||
local editUrl = docTitle:fullUrl{action = 'edit'} | |||
local editDisplay = message('edit-link-display') | local editDisplay = message('edit-link-display') | ||
local editLink = | local editLink = makeUrlLink(editUrl, editDisplay) | ||
local historyUrl = docTitle:fullUrl{action = 'history'} | |||
local historyDisplay = message('history-link-display') | local historyDisplay = message('history-link-display') | ||
local historyLink = | local historyLink = makeUrlLink(historyUrl, historyDisplay) | ||
ret = message('transcluded-from-blurb', {docLink}) | |||
.. ' ' | .. ' ' | ||
.. makeToolbar(editLink, historyLink) | .. makeToolbar(editLink, historyLink) | ||
779行目: | 798行目: | ||
elseif env.subjectSpace == 828 then | elseif env.subjectSpace == 828 then | ||
-- /doc does not exist; ask to create it. | -- /doc does not exist; ask to create it. | ||
local createUrl = docTitle: | local createUrl = docTitle:fullUrl{action = 'edit', preload = message('module-preload')} | ||
local createDisplay = message('create-link-display') | local createDisplay = message('create-link-display') | ||
local createLink = makeUrlLink(createUrl, createDisplay) | local createLink = makeUrlLink(createUrl, createDisplay) | ||
ret = message('create-module-doc-blurb', {createLink}) | |||
.. '<br />' | .. '<br />' | ||
end | end | ||
return ret | |||
end | end | ||
829行目: | 849行目: | ||
local sandboxDisplay = message('sandbox-link-display') | local sandboxDisplay = message('sandbox-link-display') | ||
local sandboxLink = makeWikilink(sandboxPage, sandboxDisplay) | local sandboxLink = makeWikilink(sandboxPage, sandboxDisplay) | ||
local sandboxEditUrl = sandboxTitle:fullUrl{action = 'edit'} | |||
local sandboxEditDisplay = message('sandbox-edit-link-display') | local sandboxEditDisplay = message('sandbox-edit-link-display') | ||
local sandboxEditLink = | local sandboxEditLink = makeUrlLink(sandboxEditUrl, sandboxEditDisplay) | ||
local compareUrl = env.compareUrl | local compareUrl = env.compareUrl | ||
local compareLink | local compareLink | ||
845行目: | 866行目: | ||
sandboxPreload = message('template-sandbox-preload') | sandboxPreload = message('template-sandbox-preload') | ||
end | end | ||
local sandboxCreateUrl = sandboxTitle: | local sandboxCreateUrl = sandboxTitle:fullUrl{action = 'edit', preload = sandboxPreload} | ||
local sandboxCreateDisplay = message('sandbox-create-link-display') | local sandboxCreateDisplay = message('sandbox-create-link-display') | ||
local sandboxCreateLink = makeUrlLink(sandboxCreateUrl, sandboxCreateDisplay) | local sandboxCreateLink = makeUrlLink(sandboxCreateUrl, sandboxCreateDisplay) | ||
local mirrorSummary = message('mirror-edit-summary', {makeWikilink(templatePage)}) | local mirrorSummary = message('mirror-edit-summary', {makeWikilink(templatePage)}) | ||
local mirrorPreload = message('mirror-link-preload') | local mirrorPreload = message('mirror-link-preload') | ||
local mirrorUrl = sandboxTitle: | local mirrorUrl = sandboxTitle:fullUrl{action = 'edit', preload = mirrorPreload, summary = mirrorSummary} | ||
if subjectSpace == 828 then | if subjectSpace == 828 then | ||
mirrorUrl = sandboxTitle: | mirrorUrl = sandboxTitle:fullUrl{action = 'edit', preload = templateTitle.prefixedText, summary = mirrorSummary} | ||
end | end | ||
local mirrorDisplay = message('mirror-link-display') | local mirrorDisplay = message('mirror-link-display') | ||
862行目: | 883行目: | ||
local testcasesDisplay = message('testcases-link-display') | local testcasesDisplay = message('testcases-link-display') | ||
local testcasesLink = makeWikilink(testcasesPage, testcasesDisplay) | local testcasesLink = makeWikilink(testcasesPage, testcasesDisplay) | ||
local testcasesEditUrl = testcasesTitle: | local testcasesEditUrl = testcasesTitle:fullUrl{action = 'edit'} | ||
local testcasesEditDisplay = message('testcases-edit-link-display') | local testcasesEditDisplay = message('testcases-edit-link-display') | ||
local testcasesEditLink = | local testcasesEditLink = makeUrlLink(testcasesEditUrl, testcasesEditDisplay) | ||
-- for Modules, add testcases run link if exists | -- for Modules, add testcases run link if exists | ||
if testcasesTitle.contentModel == "Scribunto" | if testcasesTitle.contentModel == "Scribunto" and testcasesTitle.talkPageTitle and testcasesTitle.talkPageTitle.exists then | ||
local testcasesRunLinkDisplay = message('testcases-run-link-display') | local testcasesRunLinkDisplay = message('testcases-run-link-display') | ||
local testcasesRunLink = makeWikilink(testcasesTitle.talkPageTitle.prefixedText, testcasesRunLinkDisplay) | local testcasesRunLink = makeWikilink(testcasesTitle.talkPageTitle.prefixedText, testcasesRunLinkDisplay) | ||
880行目: | 901行目: | ||
testcasesPreload = message('template-testcases-preload') | testcasesPreload = message('template-testcases-preload') | ||
end | end | ||
local testcasesCreateUrl = testcasesTitle: | local testcasesCreateUrl = testcasesTitle:fullUrl{action = 'edit', preload = testcasesPreload} | ||
local testcasesCreateDisplay = message('testcases-create-link-display') | local testcasesCreateDisplay = message('testcases-create-link-display') | ||
local testcasesCreateLink = makeUrlLink(testcasesCreateUrl, testcasesCreateDisplay) | local testcasesCreateLink = makeUrlLink(testcasesCreateUrl, testcasesCreateDisplay) | ||
941行目: | 962行目: | ||
) | ) | ||
return message('subpages-blurb', {subpagesLink}) | return message('subpages-blurb', {subpagesLink}) | ||
end | |||
function p.makePrintBlurb(args, env) | |||
--[=[ | |||
-- Generates the blurb displayed when there is a print version of the template available. | |||
-- @args - a table of arguments passed by the user | |||
-- @env - environment table containing title objects, etc., generated with p.getEnvironment | |||
-- | |||
-- Messages: | |||
-- 'print-link-display' --> '/Print' | |||
-- 'print-blurb' --> 'A [[Help:Books/for experts#Improving the book layout|print version]]' | |||
-- .. ' of this template exists at $1.' | |||
-- .. ' If you make a change to this template, please update the print version as well.' | |||
-- 'display-print-category' --> true | |||
-- 'print-category' --> 'Templates with print versions' | |||
--]=] | |||
local printTitle = env.printTitle | |||
if not printTitle then | |||
return nil | |||
end | |||
local ret | |||
if printTitle.exists then | |||
local printLink = makeWikilink(printTitle.prefixedText, message('print-link-display')) | |||
ret = message('print-blurb', {printLink}) | |||
local displayPrintCategory = message('display-print-category', nil, 'boolean') | |||
if displayPrintCategory then | |||
ret = ret .. makeCategoryLink(message('print-category')) | |||
end | |||
end | |||
return ret | |||
end | end | ||
967行目: | 1,018行目: | ||
end | end | ||
local subpage = title.subpageText | local subpage = title.subpageText | ||
local ret = '' | |||
if message('display-strange-usage-category', nil, 'boolean') | if message('display-strange-usage-category', nil, 'boolean') | ||
and ( | and ( | ||
973行目: | 1,025行目: | ||
) | ) | ||
then | then | ||
ret = ret .. makeCategoryLink(message('strange-usage-category')) | |||
end | end | ||
return | return ret | ||
end | end | ||
return p | return p |