Extension:Labeled Section Transclusion

From MediaWiki.org
Jump to navigation Jump to search
This page is a translated version of the page Extension:Labeled Section Transclusion and the translation is 41% complete.

Other languages:
Deutsch • ‎English • ‎Lëtzebuergesch • ‎català • ‎dansk • ‎español • ‎français • ‎hrvatski • ‎italiano • ‎magyar • ‎polski • ‎português • ‎português do Brasil • ‎sicilianu • ‎suomi • ‎Ελληνικά • ‎български • ‎русский • ‎українська • ‎العربية • ‎فارسی • ‎मराठी • ‎हिन्दी • ‎বাংলা • ‎中文 • ‎日本語
MediaWiki 拡張機能マニュアル
Crystal Clear action run.svg
Labeled Section Transclusion
リリースの状態: 安定
実装 Tag, Parser function
説明 文章のマークされた節を埋め込み参照する
作者 Steve Sanbeg
最新バージョン continuous updates
MediaWiki 1.25+
PHP 5.4+
データベースの変更 いいえ
ライセンス GNU General Public License 2.0 or later
ダウンロード
translatewiki.net で翻訳を利用できる場合は、Labeled Section Transclusion 拡張機能の翻訳にご協力ください
使用状況とバージョン マトリクスを確認してください。
問題点 未解決のタスク · バグを報告

Labeled Section Transclusion(ラベル付き段落の参照読み込み)拡張機能は、通常のようにウィキテキストを構文解析して、マークされた節の選択的な参照読み込みを可能にします。その機能は、通常の参照読み込みを持つ<onlyinclude>タグの拡張バージョンと似ています。これは、包含する節を選択します。これはウィキメディアのすべてのウィキで有効になっています。

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.

動作の仕組み

ステップ 1: 節へのタグ付け

以下のように <section> タグを使用して節にタグ付けします:

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

これらのタグはHTML/XMLではなく、通常の属性構文を使用しないことに注意してください。 このため、beginend のマーカーは XML の通常の開く/閉じるタグではなく、個別であるため、節の入れ子やオーバーラップが許可されます。これにより、他の節との干渉を気にすることなく、section タグを挿入できるようになります。

ステップ 2a: 節の参照読み込み

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

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}}

例:

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

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

その他の機能

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.

節の範囲

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.

subst展開

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

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.

導入部の参照読み込み

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

{{#lsth:pagename}}

特定の節の参照読み込み

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.

複数の節の参照読み込み

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}}

スキップした見出しについての注記

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.

地域化

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.

関数 英語 ドイツ語 ヘブライ語 (RTL) ポルトガル語
#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.:

英語
<section begin=x/> ... <section end=x/>
ドイツ語
<Abschnitt Anfang=x/> ... <Abschnitt Ende=x/>
ヘブライ語 (RTL)
<קטע התחלה=א> ... <קטע סוף=א> (「開始」コードが右、「終了」コードが左です)
ポルトガル語
<trecho começo=x/> ... <trecho fim=x/>

制限

  • 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. {{#lst:}} and {{#lstx:}} work only if section tags appear directly in the wikitext of the transcluded page. This means, for instance, that these tags cannot be embedded in a template using template parameters and parser functions. The #tag magic word does not work with section tags. #tag produces balanced tags, while the section tags uses singular tags. See タスク T39256.
  • As of 2014, section tags don't have any effect when used inside a template parameter. If page A contains a text {{B|X}}, there's no way {{#lst:A|...}} can access X.

ダウンロード

拡張機能は、Git から直接取得できる場合があります [?]:

  • コードを参照
  • 一部の拡張機能には安定版リリースのタグがあります。
    • タグを参照
    • タグを選択します
    • 「スナップショット」をクリックします
  • 各ブランチは過去の MediaWiki リリースと関連付けられています。 最新のアルファ バージョンを含む「master」ブランチもあります (MediaWiki のアルファ バージョンが必要な場合用)。

スナップショットを展開して、MediaWiki インストレーション内の extensions/LabeledSectionTransclusion/ ディレクトリに配置します。

git に馴染みがあり、かつサーバーにシェルでアクセスできる場合は、拡張機能を以下のようにして取得することもできます:

cd extensions/
git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/LabeledSectionTransclusion.git

インストール

  • ダウンロードして、ファイルを extensions/ フォルダー内の LabeledSectionTransclusion という名前のディレクトリ内に配置します。
  • 以下のコードを LocalSettings.php の末尾に追加します:
    wfLoadExtension( 'LabeledSectionTransclusion' );
    
  • Yes 完了 – ウィキの「Special:Version」に移動して、拡張機能が正しくインストールされたことを確認します。

MediaWiki 1.27 以前を稼働させている利用者へ:

上記の手順では、wfLoadExtension() を使用してこの拡張機能をインストールする新しい方法を記載しています。 この拡張機能をこれらの過去のバージョン (MediaWiki 1.27 以前) にインストールする必要がある場合は、wfLoadExtension( 'LabeledSectionTransclusion' ); の代わりに以下を使用する必要があります:

require_once "$IP/extensions/LabeledSectionTransclusion/LabeledSectionTransclusion.php";

There is also a Gadget in use on various Wikisources that makes it possible to define sections with a simplified ## label ## syntax. Its code can be found at Wikisource:MediaWiki:Gadget-Easy_LST.js.

関連ページ