Help:Template limits: Difference between revisions

Content deleted Content added
m Synoman Barris moved page Wikipedia:Template limits to Help:Template limits: Requested by Extraordinary Writ at WP:RM/TR: Per RM closure at Special:PermaLink/1079258876#Requested move 18 March 2022. Fully move-protected; sysop needed.
 
(32 intermediate revisions by 20 users not shown)
Line 1:
{{pp-vandalism|small=yes}}{{pp-move-indef}}
{{infopage|WP:TLIMIT|H:TLIMIT}}
{{pp-move-indef}}
{{infopage|WP:TLIMIT}}
 
The [[MediaWiki]] software that powers Wikipedia has several parameters that limit the complexity of a page, and the amount of data that can be included. These limits mainly concern data that is [[Wikipedia:Transclusion|transcluded]] or [[Wikipedia:Substitution|substituted]] during expansion of a page, as opposed to data directly in the source of the page itself. This page explains how and why these limits are applied, and how users can work within the limits.
Line 15 ⟶ 14:
 
===Working within the limits===
When a page reaches the template limits, the most common solution is to make the templates shorter, using methods described below. If this isn't possible, it may be necessary to include more data directly in the page source, rather than transcluding it from templates (e.g., formatting references by hand or using <code><nowiki><references /></nowiki></code> instead of <nowiki>{{tl|Reflist}}</nowiki>). On the other hand, a template can help the server avoid doing duplicate work, see below.
 
===When do problems arise?===
Line 22 ⟶ 21:
 
===How can you find out?===
Once the page body is processed, an HTML comment is added towards the end of the HTML code of the page with the final values of the various counters. For example, the page [[HIV/AIDS]] (on 8January August1, 20122024) contains the following comment in its generated HTML source:
 
<syntaxhighlight lang="html4stricthtml">
<!--
NewPP limit report
Parsed by mw1416
Preprocessor node count: 173488/1000000
Cached time: 20231227101515
Post-expand include size: 1557895/2048000 bytes
Cache expiry: 2592000
Template argument size: 561438/2048000 bytes
Reduced expiry: false
Highest expansion depth: 29/40
Complications: [vary‐revision‐sha1, show‐toc]
Expensive parser function count: 7/500
LuaCPU time usage: 02.331s767 seconds
Real time usage: 3.151 seconds
Preprocessor visited node count: 17348820971/1000000
Post-expandPost‐expand include size: 1557895928915/20480002097152 bytes
Template argument size: 5614389264/20480002097152 bytes
Highest expansion depth: 2915/40100
Expensive parser function count: 751/500
Unstrip recursion depth: 1/20
Unstrip post‐expand size: 1121339/5000000 bytes
Lua time usage: 1.705/10.000 seconds
Lua memory usage: 1.2510566120/52428800 MBbytes
Lua Profile:
MediaWiki\Extension\Scribunto\Engines\LuaSandbox\LuaSandboxCallback::preprocess 180 ms 10.6%
? 160 ms 9.4%
MediaWiki\Extension\Scribunto\Engines\LuaSandbox\LuaSandboxCallback::callParserFunction 140 ms 8.2%
MediaWiki\Extension\Scribunto\Engines\LuaSandbox\LuaSandboxCallback::plain 140 ms 8.2%
MediaWiki\Extension\Scribunto\Engines\LuaSandbox\LuaSandboxCallback::gsub 80 ms 4.7%
MediaWiki\Extension\Scribunto\Engines\LuaSandbox\LuaSandboxCallback::find 80 ms 4.7%
dataWrapper <mw.lua:672> 80 ms 4.7%
select_one <Module:Citation/CS1/Utilities:426> 80 ms 4.7%
recursiveClone <mwInit.lua:41> 80 ms 4.7%
<mwInit.lua:41> 60 ms 3.5%
[others] 620 ms 36.5%
Number of Wikibase entities loaded: 0/400
-->
</syntaxhighlight>
 
(Some items may not be present on other wikis, depending on which extensions they have installed; for example, the "Lua" items are added by [[mw:Extension:Scribunto|Extension:Scribunto]].)
(On wikis with a Module namespace the items "Lua time usage" and "Lua memory usage" are added to this list.)
 
Because of the way the counters are increased, the firstpreprocessor threevisited countsnode count, post-expand include size, and template argument size will usually be less than thetheir limits. If any of these sizesitems are close to thetheir limit, then it is likely that some of the templates have not been expanded. Each occurrence of an unexpanded template is identified in the page body by an HTML comment containing an error message.
 
Update 1 April 2013:
<syntaxhighlight lang="html4strict">
<!--
NewPP limit report
Preprocessor visited node count: 19190/1000000
Preprocessor generated node count: 94558/1500000
Post-expand include size: 714878/2048000 bytes
Template argument size: 25507/2048000 bytes
Highest expansion depth: 13/40
Expensive parser function count: 13/500
Lua time usage: 0.331s
Lua memory usage: 1.25 MB
-->
</syntaxhighlight>
 
Click "Parser profiling data" at the bottom of a preview to see similar data for the preview without saving it.
Line 69 ⟶ 77:
 
== Post-expand include size ==
{{shortcut|WP:PEIS}}{{Tracked|T275319|open}}{{Tracked|T189108|open}}
The '''post-expand include size''' is the sum of the lengths of the expanded wikitexts generated by templates, parser functions and variables. Whenever the parser is instructed by the source code of a page to expand a template etc. (that is, to replace it by transclusion or substitution), the parser adds together the length of the expanded wikitext generated by the template etc. and the current counter value of the page. If this sum is more than the '''post-expand limit''' (same as the [[WP:CHOKING|max article size limit]]), the initial template etc. is not replaced and an error message is added as a comment in the output HTML. Otherwise the post-expand counter is increased to the new value, and parsing continues. A template that is expanded more than once in the page contributes more than once to its post-expand include size.
 
The '''post-expand include size''' is the sum of the lengths of the expanded wikitexts generated by templates, parser functions and variables. Whenever the parser is instructed by the source code of a page to expand a template etc. (that is, to replace it by transclusion or substitution), the parser adds together the length of the expanded wikitext generated by the template etc. and the current counter value of the page. If this sum is more than the '''post-expand limit''' (same as the [[WP:CHOKING|max article size limit]]; see <code>[[mw:Manual:$wgMaxArticleSize|$wgMaxArticleSize]]</code>), the initial template etc. is not replaced and an error message is added as a comment in the output HTML. Otherwise the post-expand counter is increased to the new value, and parsing continues. A template that is expanded more than once in the page contributes more than once to its post-expand include size.
Template invocations with no arguments have an expanded text cache. So if <code><nowiki>{{foo}}</nowiki></code> includes the second-level meta-template <code><nowiki>{{bar}}</nowiki></code>, then multiple invocations of <code><nowiki>{{foo}}</nowiki></code> will only increment the post-expand include size for the fully-expanded <code><nowiki>{{foo}}</nowiki></code>; the secondary include <code><nowiki>{{bar}}</nowiki></code> is only counted once. But if you included the same template multiple times with <code><nowiki>{{foo|arg}}</nowiki></code>, then the secondary templates are counted each time, even if the argument is the same.
 
Template invocations with no arguments have an expanded text cache. So if <code><nowiki>{{foo}}</nowiki></code> includes the second-level meta-template <code><nowiki>{{bar}}</nowiki></code>, then multiple invocations of <code><nowiki>{{foo}}</nowiki></code> will only increment the post-expand include size for the fully-expanded <code><nowiki>{{foo}}</nowiki></code>; the secondary includeinclusion <code><nowiki>{{bar}}</nowiki></code> is only counted once. But if you included the same template multiple times with <code><nowiki>{{foo|arg}}</nowiki></code>, then the secondary templates are counted each time, even if the argument is the same.
 
Pages exceeding the post-expand include size limit are automatically added to [[:Category:{{MediaWiki:post-expand-template-inclusion-category}}]] ([https://en.wikipedia.org/w/api.php?action=query&list=categorymembers&cmtitle={{urlencode:Category:{{MediaWiki:post-expand-template-inclusion-category}}}}&cmprop=title%7Ctimestamp&cmlimit=500&cmsort=timestamp&cmdir=desc&format=xml recent additions]). [[Template:Citations broken from PEIS limit]] may be manually added to the page when citations or templates are broken as a result of the issue.
 
Pages exceeding the post-expand include size limit are automatically added to [[:Category:{{MediaWiki:post-expand-template-inclusion-category}}]] ([https://en.wikipedia.org/w/api.php?action=query&list=categorymembers&cmtitle={{urlencode:Category:{{MediaWiki:post-expand-template-inclusion-category}}}}&cmprop=title%7Ctimestamp&cmlimit=500&cmsort=timestamp&cmdir=desc&format=xml recent additions]).
[[Template:Citations broken from PEIS limit]] may be manually added to the page when citations or templates are broken as a result of the issue. See also [[phab:T189108]].
=== Using comments, noinclude and onlyinclude ===
Only data that survives the preprocessor expansion stage is counted towards the post-expand counter. The length of HTML comments in the wikitext (which are not reproduced in the HTML source produced) is not included in the post-expand counter. Code which is either inside a &lt;{{xtag|noinclude&gt;}} section or outside an &lt;{{xtag|onlyinclude&gt;}} section does not get expanded, so these sections do not contribute to the post-expand size. This also means that category tags only contribute if they are included (to categorize pages calling the template).
 
===Nested transclusions===
Note that the sizes of the wikitexts of all expanded templates and parser functions are added, even in the case of nesting (see [[phab:T15260]]), so extra levels increase the count. If page A transcludes B and B does nothing but transclude C, then the size of C will be counted ''twice'' towards the post-expand include size on page A, and similarly if a template consists of a parser function call, or a parser function has a template call as parameter, etc. ThisPossible cansubstitutions sometimesto bereduce mitigatednesting by letting the parser function produce a template name instead of a template result, e.g. by replacinginclude:
 
:<code><nowiki>{{#if:{{{test|}}}|{{template1}}|{{template2}} }}</nowiki></code>
*<syntaxhighlight lang="wikitext" inline>{{#if:{{{test|}}}|{{template1}}|{{template2}} }}</syntaxhighlight> replaced with <syntaxhighlight lang="wikitext" inline>{{ {{#if:{{{test|}}}|template1|template2}} }}</syntaxhighlight>.
with
*{{tl|navboxes}} replaced with {{tl|navboxes top}} and {{tl|navboxes bottom}}
:<code><nowiki>{{ {{#if:{{{test|}}}|template1|template2}} }}</nowiki></code>.
*{{tl|trim|...}} replaced with {{pf|if|1|...}}
*{{tlf|Episode table|episodes{{=}}...}} -> <syntaxhighlight lang="wikitext" inline>{{episode table|dontclose=y}} ... {{End|html=y|Episode table}}</syntaxhighlight>
 
=== Non-rendered transclusions ===
Non-rendered tranclusions still count towards limit. For example, a page which contains only <code><nowikisyntaxhighlight lang="wikitext" inline>{{#if:{{:Main Page}}}}</nowiki></codesyntaxhighlight> would still have a post-expand include size even though it would have no output at all.
 
The same applies to [[Wikipedia:Lua|Scribunto modules]]. For example, <code><nowikisyntaxhighlight lang="wikitext" inline>{{#invoke:Test|main}}</nowiki></codesyntaxhighlight> would still increase post-expand include size even if Module:Test were simply: <syntaxhighlight lang=lua>mw.getCurrentFrame():preprocess'{{msgnw::Main Page}}' -- remove this line and post-expand include size becomes zero
return { main = function() end } -- p.main() has no return value</syntaxhighlight>
 
=== &#35;invoke syntax ===
{{anchor|invoke syntax}}
Some templates have equivalent Lua modules, which may be transcluded with the syntax <code>&#35;invoke:''module name''</code>. This has lower PEIS than using templates which wrap that Lua module. However, if used directly in articles there is a cost to the readability (and editing) of article source code, so that is discouraged unless strictly necessary. These include:
* {{ml|navbox|navbox|...}}, {{ml|navbox with collapsible groups|navbox|...}}, inside navbox templates.
* {{ml|infobox|infoboxTemplate}}, {{ml|infobox3cols|infoboxTemplate}} inside infobox templates.
* {{ml|flag|}}, {{ml|flagg|}} for articles with large numbers of flags.
* {{ml|cite|web|}}, {{ml|cite|news|}}, e.g. where there are several hundred references.
* {{ml|episode table|main}}, {{ml|episode list|}} for episode lists.
 
=== References ===
Pages may exceed the limit when trying to display references using the {{tl|reflist}} template. Replacing it with <code><nowiki><references /></nowiki></code> may allow the references to appear, although the list may be truncated if the limit is exceeded by templates such as {{tl|cite web}}. As of 2010, the <references /> tag has the same font styling as {{tl|reflist}}, and as of 2017 it allows for responsive columns.
 
=== Splitting articles ===
The same applies to [[Wikipedia:Lua|Scribunto modules]]. For example, <code><nowiki>{{#invoke:Test|main}}</nowiki></code> would still increase post-expand include size even if Module:Test were simply: <syntaxhighlight lang=lua>mw.getCurrentFrame():preprocess'{{msgnw::Main Page}}'-- remove this line and post-expand include size becomes zero
Ideally the length of articles would be determined by content-related decisions not technical issues. However, if PEIS issues are unresolvable on an article such as a long list, it may be split into sections which each fit within the limit, following the policy at [[WP:SPLIT]].
return {main = function()end}-- p.main() has no return value</syntaxhighlight>
 
==Template argument size==
Line 96 ⟶ 122:
Example:
 
<code><nowiki>{{tlx|3x|{{tlp|2x|abcde}}}}</nowiki></code> has a template argument size of 40 bytes: the argument <code>{{2x|abcde}}</code> is counted 3 times, the argument <code>abcde</code> twice.
 
Arguments in the template call which do not match any parameter tag in the template do not count.
Line 110 ⟶ 136:
 
== Expensive parser function calls ==
{{Redirect|WP:EXPENSIVE|the essay "Redirects are costly"|WP:COSTLY}}{{Further|mw:Manual:$wgExpensiveParserFunctionLimit|Template:Expensive}}{{shortcut|WP:EXPENSIVE}}
{{Redirect-distinguish|WP:EXPENSIVE|WP:COSTLY}}
{{shortcut|WP:EXPENSIVE}}
 
There is a limit of 500 to the '''expensive parser function count''', i.e., the number of calls of expensive [[:mw:Help:Magic words#Parser functions|parser functions]], which are:
* <code>[[Help:Magic words#Conditional expressions|<nowiki>#ifexist]]</nowikicode>ifexist: [[Help:Conditional expressions|conditional expression]] which branchingbranches depending on whether a particulargiven page exists or not. If the limit on thisexpensive counterparser functions is exceeded, every additional <code>#ifexist</code> callscall will actbehave as though the pagesgiven theypage in the query dodoes not exist.
* [[mw:Help:<code>{{Magic words#Statisticsword|PAGESINCATEGORY]]}}</code> or PAGESINCAT: Number of pages in the category named ''categoryname''. Each subcategory is counted as one item.
* [[mw:Help:Magic words#Technical_metadataTechnical metadata|PAGESIZE]]
* CASCADINGSOURCES
* REVISIONUSER, when used on a page other than the current page
Line 123 ⟶ 148:
** [[mw:Extension:Scribunto/Lua reference manual#mw.site.stats.pagesInCategory|mw.site.stats.pagesInCategory]]
** Some [[mw:Extension:Scribunto/Lua reference manual#Title objects|title object]] properties and methods
* [[mw:Extension:SyntaxHighlight|{{tag|syntaxhighlight}} tags]]
 
It is also possible to manually increment the expensive parser function count from a Lua module by using [[mw:Extension:Scribunto/Lua reference manual#mw.incrementExpensiveFunctionCount|mw.incrementExpensiveFunctionCount]].
Line 129 ⟶ 155:
 
See also: [[mw:Manual:$wgExpensiveParserFunctionLimit]], [[Template:Expensive]]
 
==Unstrip post-expand size==
The '''unstrip post-expand size''' counter tracks the total bytes added via [[Wikipedia:TemplateStyles|TemplateStyles]] (the {{tag|templatestyles|e}} tag itself is counted towards the [[#Post-expand include size|post-expand include size]] count).
 
==#time==
Line 136 ⟶ 165:
 
== Special:Expandtemplates ==
When a page exceeds the limits, one crude way to solve the problem is to use [[Special:ExpandTemplates]]. As opposed to [[WP:SUBST|substitution]] it recursively expands all levels at once, without the need of specially preparing the templates with the code <code><nowiki>{{{|safesubst:}}}<noinclude/></nowiki></code> or similar (see [[bugzilla:2777|bug 2777]]). This reduces all counts to zero except the preprocessor node count, but even that will typically be reduced to a number that is well within the limit.
 
==History==
The inclusion limits were put into effect on the English Wikipedia by [[User:Tim Starling|Tim Starling]] on 14 August 2006. A new preprocessor was [[m:Migration to the new preprocessor|enabled in January 2008]], removing the "pre-expand include limit" and replacing it with a "preprocessor node count" limit.
 
The practice of using a template documentation page, while it can still be useful for other reasons, is no longer needed for avoiding documentation to be counted on pages that call the template.
 
==References==
* [http[:Special:PermanentLink//en.wikipedia.org/w/index.php?title=Wikipedia:Village_pump_%28technical%29&oldid=70023682#New_template_limitsNew template limits.2C_Special2C Special:ExpandTemplates |Village pump technical]] (discussion now moved to [[Wikipedia talk:Template limits]])
* [http://lists.wikimedia.org/pipermail/wikipedia-l/2006-August/027271.html Tim's posting on wikipedia-l]
* [[mw:NewPP parser report]]