Jump to content

Module:Section sizes/doc: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
size: +example;
Line 16: Line 16:
{{section sizes|Klingon language}}
{{section sizes|Klingon language}}


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


: Use entry point <code>section_length_get</code> to return an article or section length statistic:
<code>section_size_get</code> return an article or section size statistic:
<code>{{((}}#invoke:{{BASEPAGENAME}}|section_length_get|&lt;{{var|page name}}>|&lt;{{var|section name}}>}}</code>{{br}}
:<code>{{((}}#invoke:{{BASEPAGENAME}}|section_size_get|&lt;{{var|page name}}>|[&lt;{{var|section name}}{{!}}{{var|token}}>]|_all|_pct=yes |_nosep=yes}}</code>
<code>{{((}}#invoke:{{BASEPAGENAME}}|section_length_get|&lt;{{var|page name}}>|&lt;{{var|section name}}> |_all}}</code>{{br}}
<code>{{((}}#invoke:{{BASEPAGENAME}}|section_length_get|&lt;{{var|page name}}>|&lt;{{var|section name}}> |_all |_pct=yes |_nosep=yes}}</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 to three positional arguments from <code>frame</code>, and two named arguments:
<code>section_size_get</code> takes one to three positional parameters and two named parameters from <code>frame</code>:
:<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}}{{!}}{{var|token}}></code> (optional) – the second positional parameter is either the section name, or one of three tokens (if param 2 is absent, the default is the article's lead section)
:: <code>&lt;{{var|sectionName}}></code> – returns the length of the given section
*: <code>&lt;{{var|section name}}></code> – returns the size of the named section
:: <code>_lead</code> – returns the length of the lead section (this is the default, if param 2 is absent)
*: <code>_lead</code> – returns the size of the lead section; default when second positional parameter is empty or omitted
:: <code>_max</code> – returns the length of the longest section
*: <code>_max</code> – returns the size of the longest individual section
:: <code>_total</code> – returns the length of the article (should = {{tl|PAGESIZE}} )
*: <code>_total</code> – returns the size of the article (should equal [[Help:Magic_words#Metadata|PAGESIZE]])
:<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>_all</code> (optional) – the third positional parameter is the scope of the size measure; requires <code>&lt;{{var|section name}}></code>; not supported for keywords; returns size of the named section plus the sizes of its subsections

'''Named parameters'''
====Named parameters====
: <code>_nosep=yes</code> (optional) – if present, length is emitted without a thousands separator (default: with separator)
*{{para|_nosep}} (optional) – no separator; accepts one value: <code>yes</code>; section size emitted without thousands separators; ignored when {{para|_pct}} is set (default: with separator)
: <code>_pct=yes</code> (optional) – if present, length is emitted as a percentage of page length, rounded to 2 decimals, with a % symbol appended (default: length is given in bytes)
*{{para|_pct}} (optional) – percent; accepts one value: <code>yes</code>; emits size of <code>&lt;{{var|section name}}></code>, <code>_lead</code>, <code>_max</code>, or <code>_total</code> as a percentage of <code>_total</code> rounded to 2 decimals with a '%' symbol

==== Examples ====
These examples refer to the same article as shown in the <code>size</code> example.

Sizes of a named section with and without its subsections (<code>_all</code>):
*<syntaxhighlight lang="wikitext" inline="1">{{#invoke:Section sizes|section_size_get| Klingon language | Phonology }}</syntaxhighlight> → {{#invoke:Section sizes|section_size_get| Klingon language | Phonology }}
*<syntaxhighlight lang="wikitext" inline="1">{{#invoke:Section sizes|section_size_get| Klingon language | Phonology | _all }}</syntaxhighlight> → {{#invoke:Section sizes|section_size_get| Klingon language | Phonology | _all }}

Keywords:
*<syntaxhighlight lang="wikitext" inline="1">{{#invoke:Section sizes|section_size_get| Klingon language | _lead }}</syntaxhighlight> → {{#invoke:Section sizes|section_size_get| Klingon language | _lead }}
*<syntaxhighlight lang="wikitext" inline="1">{{#invoke:Section sizes|section_size_get| Klingon language | _max }}</syntaxhighlight> → {{#invoke:Section sizes|section_size_get| Klingon language | _max }}
*<syntaxhighlight lang="wikitext" inline="1">{{#invoke:Section sizes|section_size_get| Klingon language | _total }}</syntaxhighlight> → {{#invoke:Section sizes|section_size_get| Klingon language | _total }}

Section sizes without thousands separator:
*<syntaxhighlight lang="wikitext" inline="1">{{#invoke:Section sizes|section_size_get| Klingon language | Phonology | _nosep=yes }}</syntaxhighlight> → {{#invoke:Section sizes|section_size_get| Klingon language | Phonology | _nosep=yes }}
*<syntaxhighlight lang="wikitext" inline="1">{{#invoke:Section sizes|section_size_get| Klingon language | _total | _nosep=yes }}</syntaxhighlight> → {{#invoke:Section sizes|section_size_get| Klingon language | _total | _nosep=yes }}

Section sizes as a percentage of <code>_total</code>:
*<syntaxhighlight lang="wikitext" inline="1">{{#invoke:Section sizes|section_size_get| Klingon language | Phonology | _pct=yes }}</syntaxhighlight> → {{#invoke:Section sizes|section_size_get| Klingon language | Phonology | _pct=yes }}
*<syntaxhighlight lang="wikitext" inline="1">{{#invoke:Section sizes|section_size_get| Klingon language | _lead | _pct=yes }}</syntaxhighlight> → {{#invoke:Section sizes|section_size_get| Klingon language | _lead | _pct=yes }}
*<syntaxhighlight lang="wikitext" inline="1">{{#invoke:Section sizes|section_size_get| Klingon language | _max | _pct=yes }}</syntaxhighlight> → {{#invoke:Section sizes|section_size_get| Klingon language | _max | _pct=yes }}
*<syntaxhighlight lang="wikitext" inline="1">{{#invoke:Section sizes|section_size_get| Klingon language | _total | _pct=yes }}</syntaxhighlight> → {{#invoke:Section sizes|section_size_get| Klingon language | _total | _pct=yes }}


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

Revision as of 19:58, 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 wikitable:

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

Entry point size() takes two arguments from frame, one positional and one named:

  • <page name> (required) – the first positional parameter is the page name; may include namespace
  • |style= (optional) – css string suitable for use in the wikitable'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}}

Example

{{#invoke:Section sizes|size|Klingon language}}

section_size_get

section_size_get return an article or section size statistic:

{{#invoke:Section sizes|section_size_get|<page name>|[<section name|token>]|_all|_pct=yes |_nosep=yes}}

section_size_get takes one to three positional parameters and two named parameters from frame:

  • <page name> (required) – the first positional parameter is the page name; may include namespace
  • <section name|token> (optional) – the second positional parameter is either the section name, or one of three tokens (if param 2 is absent, the default is the article's lead section)
    <section name> – returns the size of the named section
    _lead – returns the size of the lead section; default when second positional parameter is empty or omitted
    _max – returns the size of the longest individual section
    _total – returns the size of the article (should equal PAGESIZE)
  • _all (optional) – the third positional parameter is the scope of the size measure; requires <section name>; not supported for keywords; returns size of the named section plus the sizes of its subsections

Named parameters

  • |_nosep= (optional) – no separator; accepts one value: yes; section size emitted without thousands separators; ignored when |_pct= is set (default: with separator)
  • |_pct= (optional) – percent; accepts one value: yes; emits size of <section name>, _lead, _max, or _total as a percentage of _total rounded to 2 decimals with a '%' symbol

Examples

These examples refer to the same article as shown in the size example.

Sizes of a named section with and without its subsections (_all):

  • {{#invoke:Section sizes|section_size_get| Klingon language | Phonology }} → 4,931
  • {{#invoke:Section sizes|section_size_get| Klingon language | Phonology | _all }} → 12,081

Keywords:

  • {{#invoke:Section sizes|section_size_get| Klingon language | _lead }} → 5,542
  • {{#invoke:Section sizes|section_size_get| Klingon language | _max }} → 8,298
  • {{#invoke:Section sizes|section_size_get| Klingon language | _total }} → 66,227

Section sizes without thousands separator:

  • {{#invoke:Section sizes|section_size_get| Klingon language | Phonology | _nosep=yes }} → 4931
  • {{#invoke:Section sizes|section_size_get| Klingon language | _total | _nosep=yes }} → 66227

Section sizes as a percentage of _total:

  • {{#invoke:Section sizes|section_size_get| Klingon language | Phonology | _pct=yes }} → 7.45%
  • {{#invoke:Section sizes|section_size_get| Klingon language | _lead | _pct=yes }} → 8.37%
  • {{#invoke:Section sizes|section_size_get| Klingon language | _max | _pct=yes }} → 12.53%
  • {{#invoke:Section sizes|section_size_get| Klingon language | _total | _pct=yes }} → 100.00%

See also