Year of the Dragon: Through April 23rd, claim the adventure pack Slice of Life for free! Speak to Xatheral in the Hall of Heroes.

Game mechanicsNewbie guideIn developmentDDO StoreSocial Media


ChallengesClassesCollectablesCraftingEnhancementsEpic DestiniesFavorFeats

GlossaryItemsMapsMonstersPlacesQuestsRacesReincarnationSkillsSpells


Please create an account or log in to build a reputation and unlock more editing privileges, and then visit DDO wiki's IRC Chat/Discord if you need any help!

Help:Extension:Labeled Section Transclusion

From DDO wiki
Jump to navigation Jump to search

As taken directly from the extension page on MediaWiki:


This extension allows selective transclusion of marked-off sections of text. Its functionality is similar to an enhanced version of the <onlyinclude> tag with normal wiki transclusion, which selects sections for inclusion. It is currently enabled on meta.wikimedia.org, *.wikisource.org, en.wiktionary.org, it.wikibooks.org, and mediawiki.org.

While normal transclusion is primarily intended to transclude large portions of small templates, labeled section transclusion is intended for small portions of large pages.

However, there are some differences. In the native template transclusion, sections are marked by behavior; thus you can have only one (possibly non-contiguous) section to be included or skipped.

Here, sections are marked by name, and behavior is chosen by the caller, which can include or skip sections as needed. Different pages can include or exclude selected sections; there can be arbitrary numbers of sections, which can also overlap arbitrarily.

Marking sections by name rather than behavior allows edit section links to be rendered more appropriately for getting excerpts from larger texts, since the extension can now account for sections that are skipped in the beginning of the page, allowing transcluded sections to be offset appropriately.

How it works[edit]

Step 1: Mark off sections[edit]

Mark off sections in the text using <section> tags like this:

<section begin=chapter1 />this is a chapter<section end=chapter1 />

Note that this uses two individual markers, rather than normal XML open/close tags, which simplifies nested or overlapping sections. This allows you to insert section tags without worrying about interfering with other sections.

Step 2a: Transclude the section[edit]

Call the parser function #lst to transclude it, i.e. to transclude a section called chapter1 from a page called articleX:

 {{#lst:articleX|chapter1}}

The target article defines the location of the section; its behavior is determined by the parser function.

Step 2b: Transclude the page but excluding the section[edit]

To transclude a page, but exclude a specified section, use the #lstx function:

{{#lstx:articleX|chapter1}}

Optionally, you may add replacement text to the excluded section.

{{#lstx:articleX|chapter1|replacement_text}}

Example:

{{#lstx:articleX|chapter1|See chapter 1 in [[articleX]].}}

The replacement text will appear in the area where the section is skipped (excluded).

Other functions[edit]

Discontiguous sections[edit]

It is possible to have multiple sections with the same name; in this case, every section with that name will be included/excluded. This is especially useful to mark various discussions.

Section ranges[edit]

These functions have an additional, optional argument to specify a section range; i.e. {{#lst:articleX|chapter1|chapter3}}, to include everything from the beginning of chapter 1 to the end of chapter 3. This allows using empty marker pairs to mark one end of the section, possibly in a template. A similar mechanism is currently used at the French Wikisource.

Substitution[edit]

This also works with substitution; it's even possible for an article to substitute a section of itself. One use of this provides a neat way to archive talk pages: Mark the text to be archived using <section begin=archive />, etc. Then create an archive page with the text, using {{subst:#lst:talk_page|archive}}, which copies archived sections. Lastly, replace the contents of talk_page with {{subst:#lstx:talk_page|archive}} to remove those sections.

Transcluding sections by headings[edit]

[[#ref_{{{1}}}|^]] This is not currently enabled on wikisource, Meta or mediawiki.org.

There is optional support for transcluding sections of text marked with the normal headings, i.e. ==this section==. If installed, this is done with the lsth function.

Transclude the introduction[edit]

To transclude the introduction of a page (i.e. the content before the first heading), use

{{#lsth:pagename}}

Transclude a specific section[edit]

You can also transclude the whole content of the sectionX (which includes all its sub-sections but excludes the heading of sectionX itself).

{{#lsth:pagename|sectionX}}

Things to note:

  1. Only the first occurrence of the sectionX is transcluded if you have more than one section with the same name.
  2. Make sure you type what the heading of sectionX is in wiki code, not how it is displayed. For example if the heading of the section is ==List of [[Extension]]==, you should type "List of [[Extension]]" not "List of Extension".
  3. The matching is case insensitive, to prevent links from breaking due to case changes.

Transclude multiple sections[edit]

You can also transclude from the first occurrence of sectionX (excluding the heading of sectionX itself) until it reaches the next occurrence of sectionY. Note that sectionY acts as a stop point so the transclusion doesn't contain the content of sectionY.

{{#lsth:pagename|sectionX|sectionY}}

Notes about skipped headings[edit]

Since the traditional transclusion in MediaWiki isn't intended to transclude sections, it doesn't account for skipped headings. As a result, if you were to transclude a template with multiple headings, and skip the first heading, then all of the edit sections links would point to the wrong section in the template.

When this extension is used (with MediaWiki 1.9 or later), the #lst and #lsth functions count headings in the "skipped" beginning part, and offset transcluded headings appropriately. This will allow these links to point to the correct section in the simple case.

Note that #lstx does not count skipped headings, and that skipped headings within discontiguous sections are not offset. But it seems it has been fixed now (likely when ported to MediaWiki's new preprocessor). The transcluded headings can be linked to the correct sections.

Localisation[edit]

Internally, the parser functions all use the lst prefix, for consistency with the name of the extension. Since this acronym may be confusing to non-developers, readable English variants have been introduced, so the functions can currently be called from either name.

function English German Hebrew (RTL) Portuguese
#lst #section #Abschnitt
#קטע
#trecho
#lstx #section-x #Abschnitt-x
#בלי קטע
#trecho-x
#lsth #section-h

Additionally, the tag can now be localised (currently English, German, and Hebrew), i.e.:

English
<section begin=x/> ... <section end=x/>
German
<Abschnitt Anfang=x/> ... <Abschnitt Ende=x/>
Hebrew (RTL)
<קטע התחלה=א> ... <קטע סוף=א> ("start" code to the right and "end" code to the left)
Portuguese
<trecho começo=x/> ... <trecho fim=x/>

Limitations[edit]

  • While it is possible to use this extension across namespaces, interwiki references are not resolved. It is not yet possible, for example, to include part of a Wikisource page into a remote MediaWiki installation.
  • Section tags cannot themselves be transcluded in order to work on other pages. This means, for instance, that these tags cannot be embedded in a template using template parameters and parser functions.