Difference between revisions of "Module:No globals"
Mediawiki>Minorax m (7 revisions imported from meta:Module:No_globals) |
m (1 revision imported) |
(No difference)
|
Latest revision as of 02:09, 18 November 2020
<templatestyles src="Template:Ombox/styles.css" />
This {{
|Module=Lua module
|#default=template
}} is used on {{#if:11,040,000+ pages, which is {{#expr:(1104688900/14344) round 0}}% of all|11,040,000+ pages, which is {{#expr:(1,104,688,900/14,344) round 0}}% of all|a very large number of}} pages.
|Module=module |#default=template }} should first be tested in its [[{{
| doc | sandbox = Module:No globals | #default = Module:No globals }}/sandbox|/sandbox]] or [[{{
| doc | sandbox = Module:No globals | #default = Module:No globals }}/testcases|/testcases]] subpages{{
|Module=. |#default= or in your own user subpage. }} The tested changes can then be added to this page in a single edit. Please consider discussing any changes {{#if:|at [[{{{2}}}]]|on the [[{{
| doc | sandbox = Module talk:No globals | #default = Module talk:No globals }}|talk page]]}} before implementing them. |
{{#switch:<translate></translate> | = {{#switch:
{{#if: | | {{#ifeq:Module|Module | module | other }} }}
| module = <templatestyles src="Template:Ombox/styles.css" />
{{#switch: protected
| pre-alpha | prealpha | pa = | alpha | a = | beta | b = | release | r | general | g = | protected | protect | p = [[File:{{#if:|Cascade-protection-shackle.svg|{{#ifeq:|sysop|Full-protection-shackle-red.svg|Semi-protection-shackle-no-text.svg}}}}|40x40px|link=]] | semiprotected | semiprotect | semi = | #default =}} | {{#switch: protected
| pre-alpha | prealpha | pa = <translate> This module is rated as [[<tvar|1>Special:MyLanguage/Category:Modules in pre-alpha development</>|pre-alpha]].</translate> <translate> It is unfinished, and may or may not be in active development.</translate> <translate> It should not be used from article namespace pages.</translate> <translate> Modules remain pre-alpha until the original editor (or someone who takes one over if it is abandoned for some time) is satisfied with the basic structure.</translate>{{#switch: No globals|doc|sandbox= | {{#ifeq: | true | | }} }} | alpha | a = This module is rated as alpha. It is ready for third party input, and may be used on a few pages to see if problems arise, but should be watched. Suggestions for new features or changes in their input and output mechanisms are welcome.{{#switch: No globals|doc|sandbox= | {{#ifeq: | true | | }} }} | beta | b = This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected.{{#switch: No globals|doc|sandbox= | {{#ifeq: | true | | }} }} | release | r | general | g = This module is rated as ready for general use. It has reached a mature form and is thought to be bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing.{{#switch: No globals|doc|sandbox= | {{#ifeq: | true | | }} }} | protected | protect | p = This module is subject to {{#if:|cascading|page}} 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.{{#switch: No globals|doc|sandbox= | {{#ifeq: | true | | }} }} | #default = Module rating is invalid or not specified.}} |
| other | #default = Error: {{Module rating}} must be placed in the Module namespace. }} | #default=
Script error: No such module "Template translation".
}}
This module causes an error if any nil global is read or if any global is written to, with the exception of arg. To use, add <syntaxhighlight lang="lua" inline>require('Module:No globals')</syntaxhighlight> to the top of the module using it. The arg variable is excluded because it is necessary for Scribunto's require function to work properly. (See the Scribunto source code here.)
{{#ifeq:No globals|sandbox|| }}
local mt = getmetatable(_G) or {} function mt.__index (t, k) if k ~= 'arg' then -- perf optimization here and below: do not load Module:TNT unless there is an error error(require('Module:TNT').format('I18n/No globals', 'err-read', tostring(k)), 2) end return nil end function mt.__newindex(t, k, v) if k ~= 'arg' then error(require('Module:TNT').format('I18n/No globals', 'err-write', tostring(k)), 2) end rawset(t, k, v) end setmetatable(_G, mt)