Module:Documentation: Difference between revisions
From Video Credit Archive
Content deleted Content added
wikpedia>Mr. Stradivarius create new function to separate html rendering in the start box |
wikpedia>Mr. Stradivarius add functions for rendering start box links and for making the start box link data |
||
Line 225: | Line 225: | ||
return title.text |
return title.text |
||
end |
end |
||
end |
|||
function envFuncs.docTitle() |
|||
local title = env.title |
|||
local docname = args[1] -- Other docname, if fed. |
|||
local docspace = env.docspace |
|||
local templatePage = env.templatePage |
|||
local docpage |
|||
if docname then |
|||
docpage = docname |
|||
else |
|||
local namespace = docspace or title.nsText |
|||
local pagename = templatePage or title.text |
|||
docpage = namespace .. ':' .. pagename .. '/' .. message('docSubpage', 'string') |
|||
end |
|||
return mw.title.new(docpage) |
|||
end |
end |
||
Line 381: | Line 397: | ||
return tostring(sbox) |
return tostring(sbox) |
||
end |
|||
function p.makeStartBoxLinksData(args, env) |
|||
local data = {} |
|||
-- Get title objects. |
|||
local titleSuccess, title = env:grab('title') |
|||
if titleSuccess then |
|||
data.title = title |
|||
else |
|||
return err(title) |
|||
end |
|||
local docTitleSuccess, docTitle = env:grab('docTitle') |
|||
if docTitleSuccess then |
|||
data.docTitle = docTitle |
|||
else |
|||
return err(docTitle) |
|||
end |
|||
-- View, display, edit, and purge links if /doc exists. |
|||
data.viewLinkDisplay = message('viewLinkDisplay', 'string') |
|||
data.editLinkDisplay = message('editLinkDisplay', 'string') |
|||
data.historyLinkDisplay = message('historyLinkDisplay', 'string') |
|||
data.purgeLinkDisplay = message('purgeLinkDisplay', 'string') |
|||
-- Create link if /doc doesn't exist. |
|||
local preload = args[message('preloadArg', 'string')] |
|||
if not preload then |
|||
if env.subjectSpace == 6 then -- File namespace |
|||
preload = message('fileDocpagePreload', 'string') |
|||
else |
|||
preload = message('docpagePreload', 'string') |
|||
end |
|||
end |
|||
data.preload = preload |
|||
data.createLinkDisplay = message('createLinkDisplay', 'string') |
|||
return data |
|||
end |
|||
function p.renderStartBoxLinks(data) |
|||
-- Render the [view][edit][history][purge] or [create] links. |
|||
local ret |
|||
local docTitle = data.docTitle |
|||
local title = data.title |
|||
if docTitle.exists then |
|||
local viewLink = makeWikilink(docpage, data.viewLinkDisplay) |
|||
local editLink = makeUrlLink(docTitle:fullUrl{action = 'edit'}, data.editLinkDisplay) |
|||
local historyLink = makeUrlLink(docTitle:fullUrl{action = 'history'}, data.historyLinkDisplay) |
|||
local purgeLink = makeUrlLink(title:fullUrl{action = 'purge'}, data.purgeLinkDisplay) |
|||
ret = '[%s] [%s] [%s] [%s]' |
|||
ret = ret:gsub('%[', '[') -- Replace square brackets with HTML entities. |
|||
ret = ret:gsub('%]', ']') |
|||
ret = mw.ustring.format(ret, viewLink, editLink, historyLink, purgeLink) |
|||
else |
|||
lspan.wikitext(makeUrlLink(docTitle:fullUrl{action = 'edit', preload = data.preload}, data.createLinkDisplay)) |
|||
end |
|||
end |
end |
||