Module:Lockbox
Appearance
From mediawiki.org
This module is subject to cascading protection. It is a highly visible module in use by a very large number of pages. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing.
This module transcludes templates whose names have been given as parameters in order to trigger cascade protection.
Usage
[edit ]{{#invoke:Lockbox|lock|silent=1
| X1
| X2
| X3
| ...
}}
See also
[edit ]The above documentation is transcluded from Module:Lockbox/doc. (edit | history)
Editors can experiment in this module’s sandbox (create | mirror) and testcases (create) pages.
Subpages of this module.
Editors can experiment in this module’s sandbox (create | mirror) and testcases (create) pages.
Subpages of this module.
localexport={} -- XXX: OUTRAGEOUS ABUSE OF SCRIBUNTO API -- Generates a transclusion without incrementing the "expensive function" count localgenerate_transclusion do localmock_title=mw.title.new(mw.title.getCurrentTitle().id) localgetContent=mock_title.getContent functiongenerate_transclusion(title) localfull_text=type(title)=='table'andtitle.fullTextortitle rawset(mock_title,'fullText',full_text) getContent(mock_title) end end localfunctionmake_wikitext_warning(msg) returnstring.format('<strong class="warning">Warning: %s.</strong>',msg) end functionexport.lock(frame) localwarnings,transclusion_list={},{} -- Check if the transcluding page is cascade-protected. -- -- Only pages transcluded from a cascade-protected page appear in -- CASCADINGSOURCES, so normally we would not be able to tell if the lockbox -- itself is cascade-protected. To work around this, we generate a -- 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 parent title (i.e. we are rendering the -- 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 mw.title.getCurrentTitle():getContent()-- Generate self-transclusion localparent_title=frame:getParent():getTitle() ifframe:preprocess('{{CASCADINGSOURCES:'..parent_title..'}}')==''then warnings[#warnings+1]=make_wikitext_warning(string.format( 'the page "%s" is not cascade-protected', parent_title )) end end -- Generate transclusions to the templates, and build the output list. fori,iteminipairs(frame.args)do item=mw.text.trim(item) localtitle=mw.title.new(item) iftitlethen localns=title.namespace localprefixed_text=title.prefixedText ifns==0then -- The item had no namespace text. If the item starts with a -- colon, assume it is a mainspace page. Otherwise, assume it is -- a template. ifitem:sub(1,1)==':'then generate_transclusion(title) table.insert(transclusion_list,'* [['..prefixed_text..']]') else generate_transclusion('Template:'..prefixed_text) table.insert(transclusion_list,'* [[Template:'..prefixed_text..']]') end elseifns==6orns==14then-- File or Category namespace generate_transclusion(title) table.insert(transclusion_list,'* [[:'..prefixed_text..']]') else generate_transclusion(title) table.insert(transclusion_list,'* [['..prefixed_text..']]') end else warnings[#warnings+1]=make_wikitext_warning(string.format( 'invalid title "%s" in argument #%d', item, i )) end end ifframe.args.silentthen return'' else -- If there were any warnings, show them at the top. Then show the list -- of transcluded pages. localret='' if#warnings>0then if#warnings>1then fori,warninginipairs(warnings)do warnings[i]='* '..warning end end ret=ret..table.concat(warnings,'\n')..'\n\n' end returnret..table.concat(transclusion_list,'\n') end end returnexport