「Help:テンプレートの制限」の版間の差分

削除された内容 追加された内容
英語版en:Wikipedia:Template limits as of 12:30, 25 October 2007 (UTC) よりコピー。著者:Ligulem, Patrick, Geometry guy, CesarB, CBM, et al.
 
翻訳、並べ替え、一部削除。
1行目:
{{DEFAULTSORT:てんふれとのせいけん}}
[[MediaWiki]] has several parameters that limit the amount of data that can be included into a page. These limits concern data that is
{{HJ:h|Editor toc ja}}
[[Wikipedia:Transclusion|transcluded]] or [[Wikipedia:Template substitution|substituted]] onto a page but not data directly in the source of the page itself.
ウィキペディアの使用しているソフトウェア[[MediaWiki]]には、[[トランスクルージョン]]や[[サブスティテューション]]によってページに読み込まれるデータ量を制限するためのパラメータがいくつかあります。[[Help:テンプレート|テンプレート]]をたくさん呼び出しているページは解析に時間がかかります。このことは利用者にとって不便なだけでなく、処理不可能なほど巨大なデータを MediaWiki に解析させることで[[DoS攻撃]]の手段として悪用される可能性もあります。このような攻撃を予防し、ページの読み込みが常識的なスピードで行われることを保証するために、このような制限が設定されています。
 
制限のうち、もっとも問題になりやすいのが、「'''展開前の読み込み量制限'''」(pre-expand include limit)です。これは DefaultSettings.php 中の [[mw:Manual:$wgMaxArticleSize|Manual:$wgMaxArticleSize]]で設定されており、現在の制限値は(恐らく)2 048 000 バイトです。
The inclusion limits were put into effect on the English Wikipedia by [[User:Tim Starling|Tim Starling]] on [[14 August]], [[2006]]. The most important of these limits is the '''pre-expand include limit''', which was originally 1MB but was [[Wikipedia talk:Template limits#Limit increased.2C_links_added|increased to 2MB]].
 
== 概要 ==
This documentation explains how and why these limits are applied, and how users can work within the limits.
[[MediaWiki]]ソフトウェアでは、ウィキソースをもとに[[HTML]]ページが生成されますが、読み込みデータについては[[構文解析]]の一種([[再帰下降構文解析]])を使用します。構文解析の過程では、読み込まれるデータの量を、「展開前カウンター」(pre-expand counter)と「展開後カウンター」(post-expand counter)の2つのカウンターを用いて計測しています。解析開始時点で、カウンターはゼロに設定され、テンプレートのトランスクルージョン(読み込み)またはサブスティテューション(代替)が行われるたびに計上されていきます。カウンターには上限値が設定されており、上限値を越えると展開ができなくなります。
 
具体的には、ページ内のソースコードに従って、テンプレートの展開を行うための構文解析がはじまると、ソフトウェアはまず、展開前のテンプレートのソースコードの長さを、読み込み先のページの「展開前カウンター」に計上します。このとき、もし、計上後の数値が「展開前制限値」を越えていれば、テンプレートは展開されず、生成されたHTMLソース中にコメントとしてエラーメッセージが出力されます。
== Background ==
=== What is this about? ===
The [[MediaWiki]] software, which generates the [[HTML]] of a page from its wiki source, uses a type of [[parser]] (called a [[recursive descent parser]]) to deal with included data. As the parser does this, it keeps track of the amount of data included into the page using two counters, the '''pre-expand counter''' and the '''post-expand counter'''. When the parsing of a page begins, these counters are set to zero, but they are incremented (by a variable amount) each time data is [[Wikipedia:Transclusion|transcluded]] or [[Wikipedia:Template substitution|substituted]]. There are upper limits on these counters, and the parser does not allow these limits to be exceeded.
 
計上後の数値が「展開前制限値」内であれば、「展開前カウンター」の数値が新しい値に設定され、テンプレートが展開されます。テンプレート展開後には、テンプレートによって生成されるHTMLソースコードの長さが、「展開後カウンター」に計上されます。もし計上後の数値が「展開後制限値」を越えていれば、テンプレートはページ内に読み込まれず、生成されたHTMLソース中に別のエラーメッセージが出力されます。数値が「展開御制限値」内であれば、テンプレートによって生成されたHTMLコードがページ本体のHTMLの中に組み込まれ、「展開後カウンター」の数値が新しい値に設定されます。
=== How is this done? ===
Whenever the parser is instructed by the source code of a page to expand a template (that is, to replace it by transclusion or substitution), it first adds together the length of the source code of the template (unexpanded) and the ''pre''-expand counter of the page.
* If this sum is more than the '''pre-expand limit''', the template is not replaced and an error message is added as a comment in the output HTML.
Otherwise, the pre-expand counter is increased to the new value, and the source code of the template is parsed recursively in the same way. Once this is done, the parser adds together the length of the HTML generated by the template and the ''post''-expand counter of the page.
* If this sum is more than the '''post-expand limit''', the initial template is not replaced and a different error message is added as a comment in the output HTML.
Otherwise the post-expand counter is increased to the new value, and the HTML generated by the template is added to HTML of the page body.
 
テンプレートは再帰的に展開されるため、もし読み込まれているテンプレート自体に他のテンプレートが呼び出されている場合、呼び出されている下位のテンプレートの値も、最終的に呼び出されているページのカウンターの数値に影響します。そのため、下位のテンプレートを呼び出している途中に制限値を超過した場合、テンプレートの展開が途中でとまってしまうこともありえます。
Because templates are expanded recursively, if the included data of a template itself transcludes or substitutes other templates, these subtemplates are also used to increase the ''pre''-expand and ''post''-expand counters of the page, and are not included if the limits are exceeded. Hence it is possible for a template to be only partially expanded if one of these limits is reached while the parser handles its subtemplates.
 
また、カウンターはテンプレートがページに読み込まれるたびに増加しますので、1ページ内に何度も使用されているテンプレートがあった場合、読み込まれている回数分、カウンターの数値が増加することになります。
Also note that the counters are increased each time a template is expanded and added to the page body. Hence a template that occurs more than once in the page source (or any recursively included template) can contribute many times to the pre-expand and post-expand size of the page.
 
例えば、テンプレート <code><nowiki>{{A}}</nowiki></code> に <code><nowiki>{{B}}{{B}}{{B}}{{B}}{{B}}</nowiki></code> が含まれており、テンプレート <code><nowiki>{{B}}</nowiki></code> のソースには、100バイトのプレインテキストが含まれているとします。この時、
=== Why are there limits? ===
# テンプレート <code><nowiki>{{A}}</nowiki></code> の呼び出しは、呼び出し先のページの「展開前カウンター」に25バイトを計上します。25を計上すると展開前カウンターが制限値を越えてしまう場合、テンプレート <code><nowiki>{{A}}</nowiki></code> は展開されません。
Pages with many templates are slow to parse. Not only is this an inconvenience for users, but it can also be used to mount a [[Denial of service attack|denial of service (DoS) attack]] on the servers, in which a page request forces the MediaWiki software to parse an unreasonably large quantity of data. The limits help to prevent this kind of attack, and ensure that pages are rendered in a reasonable time.
# テンプレート <code><nowiki>{{A}}</nowiki></code> を呼び出す前の段階で、展開前カウンターに余裕が250バイトあったと仮定します。この時、テンプレート <code><nowiki>{{A}}</nowiki></code> が展開されると、カウンターの残りは225バイトですから、最初の2回のテンプレート <code><nowiki>{{B}}</nowiki></code> は展開されますが、残りの3回は制限値を越えるため、展開されません。
# 上記の仮定は、「展開後カウンター」のことを考慮にいれていません。ここで、テンプレート <code><nowiki>{{A}}</nowiki></code> を呼び出す前の段階で、展開後カウンターに余裕が150バイトしかなかったと仮定します。この時、テンプレート <code><nowiki>{{B}}</nowiki></code> の展開が2回行われた後のテンプレート <code><nowiki>{{A}}</nowiki></code> が生成するHTMLソースは200バイトを越えますので、結果としてテンプレート <code><nowiki>{{A}}</nowiki></code> は呼びだし先のページに表示されません。
 
なお、HTMLコメントは、展開前カウンターには計上されますが、展開後カウンターには計上されません。
== 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.
 
== 制限がおこりやすい事例 ==
=== When do problems arise? ===
読み込み制限は、同じテンプレートを何度も使用している場合によく起こります。例えば、長い表の各行に同じテンプレートを呼び出しているような場合です。また、当然ながら、呼び出しているテンプレートのサイズが大きければ大きいほど、制限に達するのも早くなります。サイズが大きい理由としては、テンプレート本体が複雑であったり、[[Help:テンプレートの説明文|テンプレートの説明文]]が付随していたり、呼び出し先で必要なデータ以外の多くのデータを含んでいたりすることが考えられます。最終的に呼び出されているページ上で用いられているデータが小さくても、トランスクルージョンの際には呼び出し元のテンプレートページのソース全体量が計上されますので、思っているよりも簡単に制限値に達することになります。
The inclusion limits are most commonly reached on pages that use the same template many times, for example using one transclusion per row of a long table. The limits are reached more quickly when that template (or a template it calls) is large, ''e.g.'' because it is complicated, because it contains documentation, or because it contains data about all table rows instead of just the one concerned. Even though the amount of data that appears in the final page may be small, the total length of the source of the template is counted once per transclusion, and so the limit may be encountered sooner than expected. Pages that only include a few dozen templates are unlikely to exceed the inclusion limits, unless these templates themselves include a lot of data
 
== 制限値に達しているか判別するには ==
=== How can you find out? ===
「展開前カウンター」が1000バイトを越えると、生成されたページ本体のHTMLソース中に、「展開前読み込みサイズ」(pre-expand include size)と「展開後読み込みサイズ」(post-expand include size)の2つの数値の最終値が書きこまれます。例えば、[[沖縄県]](<small>[http://ja.wikipedia.org/w/index.php?title=沖縄県&oldid=15787450 2007年10月28日 (日) 08:34の版]</small>)のページの生成されたHTMLソースにはつぎのコメントが含まれています。
Once the page body is processed, if the pre-expand include counter is greater than one-thousand bytes, then an HTML comment is added towards the end of the HTML code of the page with the final values of the two counters, called the '''pre-expand include size''' and the '''post-expand include size''' of the page. For example, the page [[AIDS]] (on [[May 8]] [[2007]]) contains the following comment in its generated HTML source:
 
<pre>
&lt;!--
Pre-expand include size: 88784341815 bytes
Post-expand include size: 33105521015 bytes
Template argument size: 2446142340 bytes
Maximum: 2048000 bytes
--&gt;
</pre>
 
カウンターの仕様により、ここに表示されるサイズは常に制限値よりも小さくなります。もしこの数値が制限値に近ければ、読み込まれなかったテンプレートがある可能性があります。呼び込まれなかったテンプレートがある場合、この旨を伝える「<tt>&lt;!-- WARNING: template omitted, pre-expand include size too large--&gt;</tt>」などといったエラーメッセージがHTMLソース中に表示されます(例:[http://ja.wikipedia.org/w/index.php?title=皇室の系図一覧&oldid=15529665 皇室の系図一覧 2007年10月15日 (月) 16:25の版])。
Because of the way the counters are increased, these sizes will always be less than the limits. If either of these sizes is close to the limit, then it is likely that some 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.
 
== 制限内でやりくりするために ==
=== Example ===
ページがテンプレートの制限に達した場合、もっとも一般的な解決法は、下記の方法を用いてテンプレートを短くすることです。これでも解決しない場合、テンプレート呼び出しではなく、ページ本体に直接記述するデータを増やすことを考えてみてください。
For example, assume that template <code><nowiki>{{A}}</nowiki></code> contains <code><nowiki>{{B}}{{B}}{{B}}{{B}}{{B}}</nowiki></code> and the source of template
<code><nowiki>{{B}}</nowiki></code> is 100 bytes of plain text with no inclusions. Then:
# Any inclusion of template <code><nowiki>{{A}}</nowiki></code> will add 25 to the pre-expand counter of the page. If there are under 25 bytes left between the pre-expand counter and its limit when template <code><nowiki>{{A}}</nowiki></code> is encountered, this template will not be expanded.
# Suppose there are 250 bytes left between the pre-expand counter and its limit when template <code><nowiki>{{A}}</nowiki></code> is encountered. Then template <code><nowiki>{{A}}</nowiki></code> will be expanded, leaving 225 bytes. The first two instances of template <code><nowiki>{{B}}</nowiki></code> will be expanded, leaving 25 bytes. The remaining three instances of template <code><nowiki>{{B}}</nowiki></code> will not be expanded, because there are not enough pre-expand bytes left.
# The previous two points ignore the post-expand counter. Suppose also that there are only 150 bytes left between the post-expand counter and its limit, then after the parser has expanded two of the occurrences of template <code><nowiki>{{B}}</nowiki></code>, the result the expansion of <code><nowiki>{{A}}</nowiki></code> produces more than 200 bytes of code. Since this exceeds the remaining post-expand space, <code><nowiki>{{A}}</nowiki></code> will not be replaced.
 
=== noinclude と onlyinclude タグの使用 ===
The length of HTML comments is included in the pre-expand counter but not the post-expand counter.
テンプレートの展開時には、テンプレートのウィキソースの全体量が展開前カウンターに計上され、この時、データが&lt;noinclude&gt; や &lt;includeonly&gt; 、 &lt;onlyinclude&gt; タグに囲まれているかどうかは無関係です。しかし、&lt;noinclude&gt; タグに囲まれている部分、もしくは &lt;onlyinclude&gt; タグの外にある部分は呼び出し先に展開されませんから、これらの部分が「展開前カウンター」に計上される時には展開前のデータ量分だけが計上され、また「展開後カウンター」の数値には一切影響を与えません。
 
例えば、<code><nowiki>{{C}}</nowiki></code> には <code><nowiki><noinclude>{{D}}</noinclude></nowiki></code> が含まれ、 <code><nowiki>{{D}}</nowiki></code> には500バイトのデータが含まれており、呼び出し先のページの「展開前カウンター」に250バイトの余裕がある時、テンプレート <code><nowiki>{{C}}</nowiki></code> は問題なく読み込まれ、ページの「展開前カウンター」には28バイトしか計上されません。
=== Using noinclude and onlyinclude ===
When a template is expanded, the pre-expand counter is incremented by the total length of the template's wiki source, irrespective of whether the data is inside or outside &lt;noinclude&gt;, &lt;includeonly&gt; or &lt;onlyinclude&gt; sections of the source. However, code which is either inside a &lt;noinclude&gt; section or outside an &lt;onlyinclude&gt; section does not get expanded, and so only the ''unexpanded'' length of these sections contributes to the pre-expand size, and these sections do not contribute at all to the post-expand size.
 
=== テンプレートの説明文の切り離し ===
For example, if template
[[Help:テンプレートの説明文|テンプレートの説明文]]は、多くの場合、&lt;noinclude&gt; タグで囲んで提供されます。テンプレート呼び出しの際には、これらの部分の展開前のウィキテキストのデータ量しか展開前カウンターには計上されませんから、テンプレートの説明文を /doc というサブページに切り離し、テンプレート本体に読み込むようにすることで、テンプレートの読み込みサイズを小さくすることができます。詳しくは[[Help:テンプレートの説明文]]を参照してください。
<code><nowiki>{{C}}</nowiki></code> contains <code><nowiki><noinclude>{{D}}</noinclude></nowiki></code>,
<code><nowiki>{{D}}</nowiki></code> contains 500 bytes of data, and there are 250 bytes remaining between the the pre-expand counter and its limit, then template
<code><nowiki>{{C}}</nowiki></code> will be successfully expanded and its raw length of 28 bytes will be added to the pre-expand counter.
 
=== Documentation of templates条件文の使用 ===
<nowiki>{{#ifexpr}}</nowiki> などの[[Help:条件文]]を用いて、テンプレートの読み込みを制限することが可能です。この時、条件文の書き方によっては、条件文の結果によってテンプレートが読み込まれなくても、テンプレートのソースのデータ量は呼び出し先のページのカウンターに計上されます。これは、条件文を展開する前に、条件文の内容が読み込まれるためです。例えば、
&lt;noinclude&gt; sections in templates are frequently used to provide documentation on the usage of the template. Because only the raw length of such sections (the length of the unexpanded wikitext) contributes to the pre-expand size when the template is included on another page, the effective size of the template can be reduced by transcluding the documentation of the template from a /doc subpage, as described in [[Wikipedia:Template doc page pattern]] (see also {{tim|documentation}} and [http://en.wikipedia.org/w/index.php?title=Wikipedia:Village_pump_%28technical%29&diff=prev&oldid=69888944]).
<nowiki>{{#ifexpr:0|{{:123}}}}</nowiki>
では、結果は自明に偽なので、ページ [[123]]は読み込まれませんが、ページ[[123]]のデータ量は、「展開前カウンター」に計上されます。
 
この問題を解決するためには、呼び出しタグを条件文の外に出します。
One example of this is the {{tl|user}} template (on [[May 8]] [[2007]]), which contains:
<nowiki>{{ {{#ifexpr:0|:123|x0}} }}</nowiki>
<pre>
この場合も、ページ[[123]]は読み込まれませんが、条件文中に呼び出しタグがないため、条件文の計算前に[[123]]が読み込まれることはなく、中身が空のテンプレート<nowiki>{{</nowiki>[[:en:Template:x0|x0]]}}が呼び出されるだけのため、結果としてカウンターにはなにも計上されません。
<nowiki>
[[User:{{{User|{{{1|Example}}}}}}|{{{User|{{{1|''Example''}}}}}}]]
([[User talk:{{{User|{{{1|Example}}}}}}|talk]] <small>•</small>
[[Special:Contributions/{{{User|{{{1|Example}}}}}}|contribs]])<noinclude>
{{/doc}}
</noinclude>
</nowiki></pre>
The length of the source code of this template is 228 bytes, and this length is added to the pre-expand counter each time this template is included. The /doc subpage is only transcluded on the template page itself: when the template is included on another page, the {{t1|/doc}} template is not expanded, and so it only contributes 33 bytes to the pre-expand counter: 8 for the template tag itself, 23 for the noinclude tags, and 2 for the newlines (actually, the latter could be avoided).
 
=== Conditional inclusion ===
It is possible for the inclusion of a template to depend on testing a condition using a [[Help:Parser function|parser function]] such as <nowiki>{{#ifexpr}}</nowiki>. One might imagine that if the test is false then the inclusion will not count towards the pre-expand size. For example, the test
: <nowiki>{{#ifexpr:0|{{:123}}}}</nowiki>
is vacuously false and so the article [[123]] will not be included. However, the content of article [[123]] ''does'' count towards the pre-expand size in this case, because the arguments of parser functions are expanded before the parser function is executed.
 
The solution to this problem is to move the transclusion outside the parser function as follows:
: <nowiki>{{ {{#ifexpr:0|:123|x0}} }}.</nowiki>
Again article [[123]] will not be included, but now the arguments of the parser function are not transclusions, and only the template {{t1|x0}} contributes to the pre-expand size. Since this template is empty, it contributes nothing.
 
The two expressions have the same effect as regards content: the first expression expands to "{{#ifexpr:0|{{:123}}}}" and the second does as well: "{{ {{#ifexpr:0|:123|x0}} }}". However, the difference between the two can easily be checked using "What links here" and "edit this page". In the case of this page, it is the first conditional inclusion, not the second, which causes [http://en.wikipedia.org/w/index.php?title=Special:Whatlinkshere/123&limit=500 What links to 123] and [http://en.wikipedia.org/w/index.php?title=Wikipedia:Template_limits&action=edit edit this page] to report that the page [[123]] has been transcluded here.
 
=== A template for each array element ===
In the case of using a "large" [[m:help:array|array]] (say 100 or more elements) it is better to use a separate template for each array element, for example {{tim|eln de}}: in that case the pre-expand include size of using all array elements once depends only linearly of the array size. The alternative, putting the whole array in one template with #switch, for example {{tim|n en}}, causes the pre-expand include size of using all array elements once to be proportial to the square of the array size; this way the limit is quickly reached.
 
An intermediate solution between, for example, using 1 template with 100 elements and 100 templates with 1 element, would be using 10 templates with 10 elements each, giving a corresponding intermediate pre-expand include size.
 
=== 配列の各要素にテンプレートを使う ===
On a page of 100k one can afford that the content comes from templates which are a factor 20 larger than the result. This could be a switch with a list of 10 elements (the indexes, braces and the word "#switch:" also count), but not much more. If there are multiple layers of templates each layer counts.
巨大な[[配列]](例えば要素が100以上のもの)を用いる時には、各要素に別のテンプレートを用意した方がよいでしょう(例:[[:meta:Template:Eln de]])。このようにしておけば、配列に含まれている要素を1回ずつ呼び出しても、その展開前読み込みサイズは配列全体のサイズの一次に留まります。しかし、もし全ての要素を #switch を用いて1つのテンプレートに収めると(例えば[[:meta:Template:N en]])、各要素を呼び出した時の展開前読み込みサイズは配列全体のサイズの倍数になってしまい、あっというまに制限値に達してしまうでしょう。
 
ただし、100の要素を含む1つのテンプレートのかわりに、1つの要素を持つ100のテンプレートを作るのも大変ですので、例えば10の要素を持つテンプレートを10作る、というような方策もあるでしょう。
=== Avoiding identical template calls ===
Identical calls of template A can sometimes be avoided by calling template B with a parameter value depending on A, where B is a template which makes multiple use of this parameter value.
 
=== 同じテンプレートの呼び出しを避ける ===
== Special:ExpandTemplates ==
テンプレートAを何度も呼び出す代りに、Aを引数にとるテンプレートBを呼び出すということが可能な場合があります。
Tim Starling also created a related new special page [[mw:Extension:ExpandTemplates|ExpandTemplates]] at [[Special:ExpandTemplates]]. It is used to manually expand wikitext containing template calls. The calls are recursively expanded to their plain wiki-text. Special:ExpandTemplates also recursively expands all [[m:ParserFunctions|ParserFunction]] calls — something that cannot be achieved with [[WP:SUBST|substitution]] (see [[bugzilla:2777|bug 2777]]). In some situations, it may be necessary to completely expand a template using the ExpandTemplates page and then manually copy the resulting source code into an article or template. This is most useful when expanding the template reduces its length by removing many parser function calls.
 
== References参考文献 ==
* [http://lists.wikimedia.org/pipermail/wikipedia-l/2006-August/027271.html 開発者による wikipedia-l への制限値導入のアナウンス]
* [http://en.wikipedia.org/w/index.php?title=Wikipedia:Village_pump_%28technical%29&oldid=70023682#New_template_limits.2C_Special:ExpandTemplates Village pump technical] (discussion now moved to [[Wikipedia talk:Template limits]])
* [http://en.wikipedia.org/w/index.php?title=Wikipedia:Village_pump_%28technical%29&oldid=70023682#New_template_limits.2C_Special:ExpandTemplates Village pump technical] 英語版における制限値などを巡っての議論
* [http://lists.wikimedia.org/pipermail/wikipedia-l/2006-August/027271.html Tim's posting on wikipedia-l]
* [[:en:Wikipedia talk:Template limits]] 英語版における制限値などを巡っての議論
 
[[Category:ウィキペディアのテンプレート|* せいけん]]
[[Category:Wikipedia templates|{{PAGENAME}}]]
 
[[en:Wikipedia:Template_limits]]