Changes

Jump to navigation Jump to search
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
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 mw.ustring.format('[[%s|%s]]', page, display)
+
return format('[[%s|%s]]', page, display)
 
else
 
else
return mw.ustring.format('[[%s]]', page)
+
return format('[[%s]]', page)
 
end
 
end
 
end
 
end
Line 66: Line 67:     
local function makeUrlLink(url, display)
 
local function makeUrlLink(url, display)
return mw.ustring.format('[%s %s]', url, display)
+
return format('[%s %s]', url, display)
 
end
 
end
   Line 81: Line 82:  
end
 
end
 
-- 'documentation-toolbar'
 
-- 'documentation-toolbar'
return '<span class="' .. message('toolbar-class') .. '">('
+
return format(
.. table.concat(ret, ' &#124; ') .. ')</span>'
+
'<span class="%s">(%s)</span>',
 +
message('toolbar-class'),
 +
table.concat(ret, ' &#124; ')
 +
)
 
end
 
end
   Line 233: Line 237:  
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') then
+
if subpage == message('sandbox-subpage') or subpage == message('testcases-subpage') or (subpage == message('doc-subpage') and mw.title.getCurrentTitle().namespace == env.docSpace) then
 
return mw.title.makeTitle(subjectSpace, title.baseText)
 
return mw.title.makeTitle(subjectSpace, title.baseText)
 
else
 
else
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.fullUrl(
+
local compareUrl = mw.uri.canonicalUrl(
 
'Special:ComparePages',
 
'Special:ComparePages',
 
{ page1 = templateTitle.prefixedText, page2 = sandboxTitle.prefixedText}
 
{ page1 = templateTitle.prefixedText, page2 = sandboxTitle.prefixedText}
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 373: Line 379:  
-- 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 = '__EXPECTUNUSEDTEMPLATE__'
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(message('sandbox-category'))
+
omargs.text = text .. makeCategoryLink(sandboxCat)
    
-- 'documentation-clear'
 
-- 'documentation-clear'
Line 505: Line 515:  
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
Line 522: Line 524:  
end
 
end
 
end
 
end
data.preload = preload
+
data.createLinkDisplay = message('create-link-display')
+
return {
return data
+
title = title,
 +
docTitle = docTitle,
 +
-- View, display, edit, and purge links if /doc exists.
 +
viewLinkDisplay = message('view-link-display'),
 +
editLinkDisplay = message('edit-link-display'),
 +
historyLinkDisplay = message('history-link-display'),
 +
purgeLinkDisplay = message('purge-link-display'),
 +
preload = preload,
 +
createLinkDisplay = message('create-link-display')
 +
}
 
end
 
end
   Line 532: Line 543:  
-- @data - a table of data generated by p.makeStartBoxLinksData
 
-- @data - a table of data generated by p.makeStartBoxLinksData
 
--]]
 
--]]
   
local docTitle = data.docTitle
 
local docTitle = data.docTitle
local purgeLink = makeWikilink("Special:Purge/" .. docTitle.prefixedText, data.purgeLinkDisplay)
+
-- yes, we do intend to purge the template page on which the documentation appears
 +
local purgeLink = makeWikilink("Special:Purge/" .. data.title.prefixedText, data.purgeLinkDisplay)
 
 
 
if docTitle.exists then
 
if docTitle.exists then
Line 542: Line 553:  
return "&#91;" .. viewLink .. "&#93; &#91;" .. editLink .. "&#93; &#91;" .. historyLink .. "&#93; &#91;" .. purgeLink .. "&#93;"
 
return "&#91;" .. viewLink .. "&#93; &#91;" .. editLink .. "&#93; &#91;" .. historyLink .. "&#93; &#91;" .. purgeLink .. "&#93;"
 
else
 
else
local createLink = makeUrlLink(docTitle:fullUrl{action = 'edit', preload = data.preload}, data.createLinkDisplay)
+
local createLink = makeUrlLink(docTitle:canonicalUrl{action = 'edit', preload = data.preload}, data.createLinkDisplay)
 
return  "&#91;" .. createLink .. "&#93; &#91;" .. purgeLink .. "&#93;"
 
return  "&#91;" .. createLink .. "&#93; &#91;" .. purgeLink .. "&#93;"
 
end
 
end
Line 755: Line 766:  
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.
Line 763: Line 773:  
local historyDisplay = message('history-link-display')
 
local historyDisplay = message('history-link-display')
 
local historyLink = makeWikilink("Special:PageHistory/" .. docTitle.prefixedText, historyDisplay)
 
local historyLink = makeWikilink("Special:PageHistory/" .. docTitle.prefixedText, historyDisplay)
ret = message('transcluded-from-blurb', {docLink})
+
return message('transcluded-from-blurb', {docLink})
 
.. ' '
 
.. ' '
 
.. makeToolbar(editLink, historyLink)
 
.. makeToolbar(editLink, historyLink)
Line 769: Line 779:  
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:fullUrl{action = 'edit', preload = message('module-preload')}
+
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)
ret = message('create-module-doc-blurb', {createLink})
+
return message('create-module-doc-blurb', {createLink})
 
.. '<br />'
 
.. '<br />'
 
end
 
end
return ret
   
end
 
end
   Line 836: Line 845:  
sandboxPreload = message('template-sandbox-preload')
 
sandboxPreload = message('template-sandbox-preload')
 
end
 
end
local sandboxCreateUrl = sandboxTitle:fullUrl{action = 'edit', preload = sandboxPreload}
+
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:fullUrl{action = 'edit', preload = mirrorPreload, summary = mirrorSummary}
+
local mirrorUrl = sandboxTitle:canonicalUrl{action = 'edit', preload = mirrorPreload, summary = mirrorSummary}
 
if subjectSpace == 828 then
 
if subjectSpace == 828 then
mirrorUrl = sandboxTitle:fullUrl{action = 'edit', preload = templateTitle.prefixedText, summary = mirrorSummary}
+
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 853: Line 862:  
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:fullUrl{action = 'edit'}
+
local testcasesEditUrl = testcasesTitle:canonicalUrl{action = 'edit'}
 
local testcasesEditDisplay = message('testcases-edit-link-display')
 
local testcasesEditDisplay = message('testcases-edit-link-display')
 
local testcasesEditLink = makeWikilink("Special:EditPage/" .. testcasesPage, testcasesEditDisplay)
 
local testcasesEditLink = makeWikilink("Special:EditPage/" .. testcasesPage, testcasesEditDisplay)
Line 871: Line 880:  
testcasesPreload = message('template-testcases-preload')
 
testcasesPreload = message('template-testcases-preload')
 
end
 
end
local testcasesCreateUrl = testcasesTitle:fullUrl{action = 'edit', preload = testcasesPreload}
+
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)
Line 958: Line 967:  
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 (
Line 965: Line 973:  
)
 
)
 
then
 
then
ret = ret .. makeCategoryLink(message('strange-usage-category'))
+
return makeCategoryLink(message('strange-usage-category'))
 
end
 
end
return ret
+
return ''
 
end
 
end
    
return p
 
return p
Anonymous user

Navigation menu