Module:Lockbox/sandbox: Difference between revisions

Content deleted Content added
improve comment, and don't transclude the parent title
use title objects to make page-name parsing more robust
Line 8:
local getContent = mock_title.getContent
function generate_transclusion(title)
local full_text = type(title) == 'table' and title.fullText or title
rawset(mock_title, 'fullText', titlefull_text)
getContent(mock_title)
end
-- I can do the same thing without rawset.
end
 
local function make_wikitext_warning(msg)
return string.format('<strong class="warning">Warning: %s.</strong>\n', msg)
end
 
Line 48 ⟶ 53:
local parent_title = frame:getParent():getTitle()
if frame:preprocess("{{CASCADINGSOURCES:" .. parent_title .. "}}") == "" then
output[#output + 1] = make_wikitext_warning(string.format(
output[#output + 1] = '<strong class="warning">Warning: the page "' .. parent_title .. '" is not cascade-protected.</strong>\n'
'the page "%s" is not cascade-protected',
parent_title
))
end
end
local match = string.match
 
-- Generate transclusions to the templates, and build the output.
for _i, item in ipairs(frame.args) do
itemlocal title = mw.texttitle.trimnew(item)
if title then
local ns, rest = match(item, "^(.-):(.*)")
local ns = title.namespace
if not ns or not mw.site.namespaces[ns] then
local prefixed_text = title.prefixedText
generate_transclusion('Template:' .. item)
elseif if restns ~== ''0 then
output[#output + 1] = '* [[Template:' .. item .. ']]'
-- The item had no namespace text. If the item starts with a
elseif (ns == "File") or (ns == "Image") then
-- colon, assume it is a mainspace page. Otherwise, assume it is
generate_transclusion(item)
-- a template.
output[#output + 1] = '* [[:' .. item .. ']]'
elseif if ns == "Category"item:find('^%s*:') then
generate_transclusion(itemtitle)
output[#output + 1] = '* [[:' .. itemprefixed_text .. ']]'
else
elseif rest ~= '' then
generate_transclusion(item'Template:' .. prefixed_text)
output[#output + 1] = '* [[Template:' .. itemprefixed_text .. ']]'
end
elseif ns == 6 or ns == 14 then -- File or Category namespace
generate_transclusion('Template:' .. itemtitle)
output[#output + 1] = '* [[Template:' .. itemprefixed_text .. ']]'
else
generate_transclusion(itemtitle)
output[#output + 1] = '* [[:' .. itemprefixed_text .. ']]'
end
else
output[#output + 1] = make_wikitext_warning(string.format(
'invalid title "%s" in argument #%d',
frame.args[i],
i
))
end
end