Extension:Labeled Section Transclusion

This extension allows selective transclusion of marked-off sections of text. Its functionality is similar to the tag with normal wiki transclusion.

While normal transclusion is primarily intended to transclude large portions of small templates, while labeled section transclusion is intended for small portions of large pages, there are some differences. In the native template transclusion, sections are marked by behavior; thus you can have only (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.

Mark off sections
First, mark off sections in the text using tags like this:

this is a chapter

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.

Transclude with a parser function
Then, call the parser function to transclude it, i.e. to transclude a section called chapter1 from a page called article:

The target article defines the location of the section; its behavior is determined by the parser function. To transclude a document, but exclude a specified section, use the #lstx function. Optionally, replacement text can be specified.

or

Discontiguous sections
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
These functions have an additional, optional argument to specify a section range; i.e. , 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
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, etc. Then create an archive page with the text, using archive , which copies archived sections. Lastly, replace the contents of talk_page with archive to remove those sections.

Transcluding visual headings
There is experimental support for transcluding sections of text marked with the normal headings, i.e. .  If installed, this is done with the lsth function.

To transclude the introduction (up to the first heading) of a page, use

You can also transclude from the first occurrence of heading until the next heading of the same or lower level. Note that this comparison is case insensitive, to prevent links from breaking due to case changes.

You can also transclude from the first occurrence of heading to the next occurrence of other heading (regardless of level) with

Skipped headings
Since the traditional transclusion in MediaWiki isn't intented 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, 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.

Localisation
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.

Installation
Copy the files of the extension from Subversion, and put it in your extensions directory. Then, include it from LocalSettings.php:

require_once ( 'extensions/LabeledSectionTransclusion/lst.php' );

To enable transcluding visual sections, also add

require_once ( 'extensions/LabeledSectionTransclusion/lsth.php' );

Since the code is still undergoing some restructuring in preparation for deployment on the official projects, the internal functions may change from time to time. Although there is currently no public API to call these functions, DynamicPageList2 calls some of the internal functions directly. To make this more stable, the file compat.php has been added, in order to provide a more consistent API. This file is not used by LST, and is only provided for compatibility with DPL2.

If you are using DPL2, you should also add

require_once ( 'extensions/LabeledSectionTransclusion/compat.php' );

Requirements
This extension requires a MediaWiki installation with support for parser functions. This support was mature in the 1.7 series, although some 1.6 versions may also be made to work.

optional enhancements
Support for regression testing parser functions was added in MediaWiki 1.9alpha (r17410) in order to test this extension; if you want to run the regression tests in an older installation, you'll need to apply the patch for maintenance/ParserTests.inc from 7801

Support for offsetting edit section links (so that it can detect sections that aren't transcluded, and skip them) was added in MediaWiki 1.9alpha (r18218).