Module:Documentation: Difference between revisions

Jump to navigation Jump to search
m>Mr. Stradivarius
don't use mw.uri.encode - title:fullUrl already encodes the strings for us
m>Mr. Stradivarius
use a makeToolbar function instead of writing out the toolbars by hand
Line 27: Line 27:
return mw.ustring.format('[%s %s]', url, display)
return mw.ustring.format('[%s %s]', url, display)
end
end
local function makeToolbar(...)
local ret = {}
local lim = select('#', ...)
if lim < 1 then
return nil
end
for i = 1, lim do
ret[#ret + 1] = select(i, ...)
end
return '<small style="font-style: normal;">(' .. table.concat(ret, ' &#124; ') .. ')</small>'
end


----------------------------------------------------------------------------
----------------------------------------------------------------------------
Line 271: Line 283:
local editLink = makeUrlLink(docTitle:fullUrl{action = 'edit'}, 'edit')
local editLink = makeUrlLink(docTitle:fullUrl{action = 'edit'}, 'edit')
local historyLink = makeUrlLink(docTitle:fullUrl{action = 'history'}, 'history')
local historyLink = makeUrlLink(docTitle:fullUrl{action = 'history'}, 'history')
text = text .. 'The above [[Wikipedia:Template documentation|documentation]] is [[Wikipedia:Transclusion|transcluded]] from ' .. docLink .. '.'
text = text .. 'The above [[Wikipedia:Template documentation|documentation]] is [[Wikipedia:Transclusion|transcluded]] from ' .. docLink .. '. '
.. ' <small style="font-style: normal;">(' .. editLink .. ' &#124; ' .. historyLink .. ')</small> <br />'
.. makeToolbar(editLink, historyLink) .. '<br />'
elseif subjectSpace == 828 then
elseif subjectSpace == 828 then
-- /doc does not exist; ask to create it.
-- /doc does not exist; ask to create it.
Line 288: Line 300:
local sandboxEditLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit'}, 'edit')
local sandboxEditLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit'}, 'edit')
local compareLink = makeUrlLink(mw.title.new('Special:ComparePages'):fullUrl{page1 = templatePage, page2 = sandbox}, 'diff')
local compareLink = makeUrlLink(mw.title.new('Special:ComparePages'):fullUrl{page1 = templatePage, page2 = sandbox}, 'diff')
text = text .. sandboxLink .. ' <small style="font-style: normal">(' .. sandboxEditLink .. ' | ' .. compareLink .. ')</small>'
text = text .. sandboxLink .. ' ' .. makeToolbar(sandboxEditLink, compareLink)
else
else
local sandboxPreload = 'Template:Documentation/preload-' .. (subjectSpace == 828 and 'module-' or '') .. 'sandbox'
local sandboxPreload = 'Template:Documentation/preload-' .. (subjectSpace == 828 and 'module-' or '') .. 'sandbox'
Line 294: Line 306:
local mirrorSummary = 'Create sandbox version of ' .. makeWikilink(templatePage)
local mirrorSummary = 'Create sandbox version of ' .. makeWikilink(templatePage)
local mirrorLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit', preload = templatePage, summary = mirrorSummary}, 'mirror')
local mirrorLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit', preload = templatePage, summary = mirrorSummary}, 'mirror')
text = text .. 'sandbox <small style="font-style: normal">(' .. sandboxCreateLink .. ' | ' .. mirrorLink .. ')</small>'
text = text .. 'sandbox ' .. makeToolbar(sandboxCreateLink, mirrorLink)
end
end
text = text .. ' and '
text = text .. ' and '
Line 301: Line 313:
local testcasesLink = makeWikilink(testcases, 'testcases')
local testcasesLink = makeWikilink(testcases, 'testcases')
local testcasesEditLink = makeUrlLink(testcaseTitle:fullUrl{action = 'edit'}, 'edit')
local testcasesEditLink = makeUrlLink(testcaseTitle:fullUrl{action = 'edit'}, 'edit')
text = text .. testcasesLink .. ' <small style="font-style: normal">(' .. testcasesEditLink .. ')</small>'
text = text .. testcasesLink .. ' ' .. makeToolbar(testcasesEditLink)
else
else
local testcasesPreload = 'Template:Documentation/preload-' .. (subjectSpace == 828 and 'module-' or '') .. 'testcases'
local testcasesPreload = 'Template:Documentation/preload-' .. (subjectSpace == 828 and 'module-' or '') .. 'testcases'
local testcasesCreateLink = makeUrlLink(testcaseTitle:fullUrl{action = 'edit', preload = testcasesPreload}, 'create')
local testcasesCreateLink = makeUrlLink(testcaseTitle:fullUrl{action = 'edit', preload = testcasesPreload}, 'create')
text = text .. 'testcases <small style="font-style: normal">(' .. testcasesCreateLink .. ')</small>'
text = text .. 'testcases ' .. makeToolbar(testcasesCreateLink)
end
end
text = text .. ' pages. <br />'
text = text .. ' pages. <br />'