Module:Documentation: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
m (Protected "Module:Documentation": this module is used in literally every template page, DO NOT MAKE CHANGES TO THIS UNLESS YOU LIKE BREAKING THE WIKI ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite) [Delete=Allow only administrators] (indefinite))) |
(Split Category:Template sandboxes per CfD) |
||
Line 11: | Line 11: | ||
-- Often-used functions. |
-- Often-used functions. |
||
local ugsub = mw.ustring.gsub |
local ugsub = mw.ustring.gsub |
||
local format = mw.ustring.format |
|||
---------------------------------------------------------------------------- |
---------------------------------------------------------------------------- |
||
Line 50: | Line 51: | ||
local function makeWikilink(page, display) |
local function makeWikilink(page, display) |
||
if display then |
if display then |
||
return |
return format('[[%s|%s]]', page, display) |
||
else |
else |
||
return |
return format('[[%s]]', page) |
||
end |
end |
||
end |
end |
||
Line 66: | Line 67: | ||
local function makeUrlLink(url, display) |
local function makeUrlLink(url, display) |
||
return |
return format('[%s %s]', url, display) |
||
end |
end |
||
Line 81: | Line 82: | ||
end |
end |
||
-- 'documentation-toolbar' |
-- 'documentation-toolbar' |
||
⚫ | |||
return '<span class="' .. message('toolbar-class') .. '">(' |
|||
'<span class="%s">(%s)</span>', |
|||
message('toolbar-class'), |
|||
table.concat(ret, ' | ') |
|||
) |
|||
end |
end |
||
Line 313: | Line 317: | ||
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.canonicalUrl( |
||
'Special:ComparePages', |
'Special:ComparePages', |
||
{ page1 = templateTitle.prefixedText, page2 = sandboxTitle.prefixedText} |
{ page1 = templateTitle.prefixedText, page2 = sandboxTitle.prefixedText} |
||
Line 349: | Line 353: | ||
-- |
-- |
||
-- Messages: |
-- Messages: |
||
-- 'sandbox-notice-image' --> '[[ |
-- 'sandbox-notice-image' --> '[[File: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).' |
||
Line 359: | Line 363: | ||
-- 'sandbox-notice-testcases-link-display' --> 'test cases' |
-- 'sandbox-notice-testcases-link-display' --> 'test cases' |
||
-- 'sandbox-category' --> 'Template sandboxes' |
-- 'sandbox-category' --> 'Template sandboxes' |
||
-- 'module-sandbox-category' --> 'Module sandboxes' |
|||
-- 'other-sandbox-category' --> 'Sandboxes outside of template or module namespace' |
|||
--]=] |
--]=] |
||
local title = env.title |
local title = env.title |
||
Line 374: | Line 380: | ||
-- "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, sandboxCat |
||
if subjectSpace == 10 then |
if subjectSpace == 10 then |
||
pagetype = message('sandbox-notice-pagetype-template') |
pagetype = message('sandbox-notice-pagetype-template') |
||
sandboxCat = message('sandbox-category') |
|||
elseif subjectSpace == 828 then |
elseif subjectSpace == 828 then |
||
pagetype = message('sandbox-notice-pagetype-module') |
pagetype = message('sandbox-notice-pagetype-module') |
||
sandboxCat = message('module-sandbox-category') |
|||
else |
else |
||
pagetype = message('sandbox-notice-pagetype-other') |
pagetype = message('sandbox-notice-pagetype-other') |
||
sandboxCat = message('other-sandbox-category') |
|||
end |
end |
||
local templateLink = makeWikilink(templateTitle.prefixedText) |
local templateLink = makeWikilink(templateTitle.prefixedText) |
||
Line 407: | Line 416: | ||
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(sandboxCat) |
||
-- 'documentation-clear' |
-- 'documentation-clear' |
||
Line 505: | Line 515: | ||
end |
end |
||
local data = {} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
-- Create link if /doc doesn't exist. |
-- Create link if /doc doesn't exist. |
||
local preload = args.preload |
local preload = args.preload |
||
Line 522: | Line 524: | ||
end |
end |
||
end |
end |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
end |
end |
||
Line 532: | Line 543: | ||
-- @data - a table of data generated by p.makeStartBoxLinksData |
-- @data - a table of data generated by p.makeStartBoxLinksData |
||
--]] |
--]] |
||
⚫ | |||
-- yes, we do intend to purge the template page on which the documentation appears |
|||
⚫ | |||
local function escapeBrackets(s) |
|||
-- Escapes square brackets with HTML entities. |
|||
s = s:gsub('%[', '[') -- Replace square brackets with HTML entities. |
|||
s = s:gsub('%]', ']') |
|||
⚫ | |||
end |
|||
local ret |
|||
⚫ | |||
local title = data.title |
|||
⚫ | |||
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 = makeWikilink("Special:EditPage/" .. docTitle.prefixedText, data.editLinkDisplay) |
||
local historyLink = |
local historyLink = makeWikilink("Special:PageHistory/" .. docTitle.prefixedText, data.historyLinkDisplay) |
||
return "[" .. viewLink .. "] [" .. editLink .. "] [" .. historyLink .. "] [" .. purgeLink .. "]" |
|||
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:canonicalUrl{action = 'edit', preload = data.preload}, data.createLinkDisplay) |
||
return "[" .. createLink .. "] [" .. purgeLink .. "]" |
|||
ret = '[%s] [%s]' |
|||
ret = escapeBrackets(ret) |
|||
ret = mw.ustring.format(ret, createLink, purgeLink) |
|||
end |
end |
||
return ret |
return ret |
||
Line 771: | Line 770: | ||
-- /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 = makeWikilink("Special:EditPage/" .. docTitle.prefixedText, editDisplay) |
||
local historyUrl = docTitle:fullUrl{action = 'history'} |
|||
local historyDisplay = message('history-link-display') |
local historyDisplay = message('history-link-display') |
||
local historyLink = |
local historyLink = makeWikilink("Special:PageHistory/" .. docTitle.prefixedText, historyDisplay) |
||
ret = message('transcluded-from-blurb', {docLink}) |
ret = message('transcluded-from-blurb', {docLink}) |
||
.. ' ' |
.. ' ' |
||
Line 783: | Line 780: | ||
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:canonicalUrl{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) |
||
Line 834: | Line 831: | ||
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 = makeWikilink("Special:EditPage/" .. sandboxPage, sandboxEditDisplay) |
||
local compareUrl = env.compareUrl |
local compareUrl = env.compareUrl |
||
local compareLink |
local compareLink |
||
Line 851: | Line 847: | ||
sandboxPreload = message('template-sandbox-preload') |
sandboxPreload = message('template-sandbox-preload') |
||
end |
end |
||
local sandboxCreateUrl = sandboxTitle: |
local sandboxCreateUrl = sandboxTitle:canonicalUrl{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:canonicalUrl{action = 'edit', preload = mirrorPreload, summary = mirrorSummary} |
||
if subjectSpace == 828 then |
if subjectSpace == 828 then |
||
mirrorUrl = sandboxTitle: |
mirrorUrl = sandboxTitle:canonicalUrl{action = 'edit', preload = templateTitle.prefixedText, summary = mirrorSummary} |
||
end |
end |
||
local mirrorDisplay = message('mirror-link-display') |
local mirrorDisplay = message('mirror-link-display') |
||
Line 868: | Line 864: | ||
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:canonicalUrl{action = 'edit'} |
||
local testcasesEditDisplay = message('testcases-edit-link-display') |
local testcasesEditDisplay = message('testcases-edit-link-display') |
||
local testcasesEditLink = |
local testcasesEditLink = makeWikilink("Special:EditPage/" .. testcasesPage, testcasesEditDisplay) |
||
-- for Modules, add testcases run link if exists |
-- for Modules, add testcases run link if exists |
||
if testcasesTitle.contentModel == "Scribunto" and testcasesTitle.talkPageTitle and testcasesTitle.talkPageTitle.exists then |
if testcasesTitle.contentModel == "Scribunto" and testcasesTitle.talkPageTitle and testcasesTitle.talkPageTitle.exists then |
||
Line 886: | Line 882: | ||
testcasesPreload = message('template-testcases-preload') |
testcasesPreload = message('template-testcases-preload') |
||
end |
end |
||
local testcasesCreateUrl = testcasesTitle: |
local testcasesCreateUrl = testcasesTitle:canonicalUrl{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) |