Module:Lockbox/sandbox: Difference between revisions

Content deleted Content added
add a comment about what is going on
improve comment, and don't transclude the parent title
Line 17:
local output = {}
-- checkCheck if the transcluding page is cascade-protected.
--
-- XXX: unfortunately there is no other way; title.protectionLevels does not report cascading protection status
-- Only pages transcluded from a cascade-protected page appear in
-- CASCADINGSOURCES, so normally we would not be able to tell if the lockbox
-- parent titleitself is cascade-protected. To work around this, makewe generate thea
-- transclusion from the lockbox to itself, so that it will have an entry
-- for itself in CASCADINGSOURCES.
--
-- We cannot generate this transclusion using the title object for the
-- parent title (the lockbox), as if the lockbox is transcluded on another
-- page, we will generate a transclusion *from* the lockbox *to* that page
-- as well, and the page will be cascade-protected. Instead we generate it
-- with the title object for the current title.
--
-- When the current title is the grandparentparent title or(i.e. up,we itare willrendering not bethe
-- lockbox page), this creates the required entry in the link table in the
-- database. When the current title is the grandparent title or up (i.e. we
-- are rendering a page transcluding the lockbox), transclusions are only
-- created from the page itself, not from the lockbox, and it is not
-- cascade-protected.
--
-- This creates an extaneous self-transclusion for all pages using the
-- module, but we treat that as a necessary evil.
--
-- XXX: there seems to be no way to check for cascading protection using a
-- Scribunto API, so we have to use frame:preprocess with the
-- CASCADINGSOURCES parser function.
do
local parent_title = frame:getParent():getTitle()
-- Only pages transcluded from a cascade-protected page appear in
-- CASCADINGSOURCES, so normally we would not be able to tell if the
-- parent title is cascade-protected. To work around this, make the
-- current page transclude itself. If the current title is the parent
-- title, this will add an entry for it to CASCADINGSOURCES. If the
-- current title is the grandparent title or up, it will not be
-- cascade-protected itself as the page will not be parsed. (And that's
-- a good job, as parsing it would cause a template loop.)
mw.title.getCurrentTitle():getContent() -- Generate self-transclusion
generate_transclusion(local parent_title = frame:getParent():getTitle()
if frame:preprocess("{{CASCADINGSOURCES:" .. parent_title .. "}}") == "" then
output[#output + 1] = '<strong class="warning">Warning: the page "' .. parent_title .. '" is not cascade-protected.</strong>\n'