Jump to content

Module:Section sizes/doc: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Add second entry point section_length_get; add usage examples and param descriptions.
Usage: Add _nosep and _pct, and redo positional param 3 as scoping arg.
Line 4: Line 4:
This module has two entry points: <code>size</code>, and <code>section_length_get</code>.
This module has two entry points: <code>size</code>, and <code>section_length_get</code>.


: Use <code>size</code> to emit the section table:
=== <code>size</code> ===
: Use entry point <code>size</code> to emit the section table:
<code>{{((}}#invoke:{{BASEPAGENAME}}|size|&lt;{{var|page name}}>|style=&lt;{{var|style string}}>}}</code>{{br}}
<code>{{((}}#invoke:{{BASEPAGENAME}}|size|&lt;{{var|page name}}>|style=&lt;{{var|style string}}>}}</code>{{br}}


Line 11: Line 12:
:{{para|style}} (optional) – css string suitable for use in the table's <code>style=</code> attribute; for example to render the table at the right side of the page:
:{{para|style}} (optional) – css string suitable for use in the table's <code>style=</code> attribute; for example to render the table at the right side of the page:
::<code><nowiki>{{</nowiki>#invoke:{{BASEPAGENAME}}|size|&lt;{{var|page name}}>|style=float:right; margin-left:.5em}}</code>
::<code><nowiki>{{</nowiki>#invoke:{{BASEPAGENAME}}|size|&lt;{{var|page name}}>|style=float:right; margin-left:.5em}}</code>

=== <code>section_length_get</code> ===


: Use entry point <code>section_length_get</code> to return an article or section length statistic:
: Use entry point <code>section_length_get</code> to return an article or section length statistic:
Line 17: Line 20:
<code>{{((}}#invoke:{{BASEPAGENAME}}|section_length_get|&lt;{{var|page name}}>|&lt;{{var|token}}>}}</code>{{br}}
<code>{{((}}#invoke:{{BASEPAGENAME}}|section_length_get|&lt;{{var|page name}}>|&lt;{{var|token}}>}}</code>{{br}}


Entry point <code>section_length_get()</code> takes one, two, or three arguments from <code>frame</code>:
Entry point <code>section_length_get()</code> takes one to three positional arguments from <code>frame</code>, and two named arguments:
:<code>&lt;{{var|page name}}></code> (required) – the first positional parameter is the page name; may include namespace
:<code>&lt;{{var|page name}}></code> (required) – the first positional parameter is the page name; may include namespace
:<code>&lt;{{var|section name}}></code> (optional) – the second positional parameter is either the section name, or one of three tokens (if param 2 is absent, the default is _lead)
:<code>&lt;{{var|section name}}></code> (optional) – the second positional parameter is either the section name, or one of three tokens (if param 2 is absent, the default is _lead)
Line 24: Line 27:
:: <code>_max</code> – returns the length of the longest section
:: <code>_max</code> – returns the length of the longest section
:: <code>_total</code> – returns the length of the article (should = {{tl|PAGESIZE}} )
:: <code>_total</code> – returns the length of the article (should = {{tl|PAGESIZE}} )
:<code>_all</code> (optional) – the third positional parameter is the string <code>_all</code>; this includes the total length of the section whose name is given in parameter 2, including all its subsections.
:<code>&lt;{{var|scope}}></code> (optional) – the third positional parameter is the scope of the length measure; if the value <code>_all</code> is passed, all subsections of the section whose name is given in parameter 2 are included in the length (optional; default: subsections excluded)
: <code>_nosep=yes</code> (optional) – if present, length is emitted without a thousands separator (default: with separator)
: <code>_pct=yes</code> (optional) – if present, length is emitted in percent of page length, rounded to 2 decimals, with a % symbol appended (default: length is given in bytes)


== See also ==
== See also ==

Revision as of 06:04, 22 September 2024

This module creates a wikitable that lists each section in a page along with that section's size in bytes. Each section is wikilinked to its target in the page; subsections are indented. Cells for section sizes are shaded according to the size; the smallest section's background is white, and the largest section's background is red.

Usage

This module has two entry points: size, and section_length_get.

size

Use entry point size to emit the section table:

{{#invoke:Section sizes|size|<page name>|style=<style string>}}

Entry point size() takes two arguments from frame:

<page name> (required) – the first positional parameter is the page name; may include namespace
|style= (optional) – css string suitable for use in the table's style= attribute; for example to render the table at the right side of the page:
{{#invoke:Section sizes|size|<page name>|style=float:right; margin-left:.5em}}

section_length_get

Use entry point section_length_get to return an article or section length statistic:

{{#invoke:Section sizes|section_length_get|<page name>|<section name>}}
{{#invoke:Section sizes|section_length_get|<page name>|<section name> |_all}}
{{#invoke:Section sizes|section_length_get|<page name>|<token>}}

Entry point section_length_get() takes one to three positional arguments from frame, and two named arguments:

<page name> (required) – the first positional parameter is the page name; may include namespace
<section name> (optional) – the second positional parameter is either the section name, or one of three tokens (if param 2 is absent, the default is _lead)
<sectionName> – returns the length of the given section
_lead – returns the length of the lead section (this is the default, if param 2 is absent)
_max – returns the length of the longest section
_total – returns the length of the article (should = {{PAGESIZE}} )
<scope> (optional) – the third positional parameter is the scope of the length measure; if the value _all is passed, all subsections of the section whose name is given in parameter 2 are included in the length (optional; default: subsections excluded)
_nosep=yes (optional) – if present, length is emitted without a thousands separator (default: with separator)
_pct=yes (optional) – if present, length is emitted in percent of page length, rounded to 2 decimals, with a % symbol appended (default: length is given in bytes)

See also