Transkluze

From mediawiki.org
This page is a translated version of the page Transclusion and the translation is 44% complete.

"Transkluze" je proces, při které se kód stránky zahrne do kódu stránky jiné, tím že se zavolá prostřednictvím odkazu. V kontextu wiki to znamená, že lze úpravou kódu šablony, vytvořené v rámci MediaWiki a natahované do wiki kódu mnoha dalších stránek, měnit jejich obsah, aniž by bylo nutné každou z nich editovat zvlášť.

Jak funguje transkluze

To transclude any source page (within a single MediaWiki project, such as Wikipedia) within another target page, include the following code: {{SOMEPAGE}}

Whenever the target page A is rendered, the entire content of the source page B (in this case, SOMEPAGE), will be rendered at the location where the transclusion tag was placed.

For example, you might decide to place a welcome message on every newcomer's talk page. Transclusion creates a "live" link between the template-page and the target-page(s) upon which the message should appear. When the template is edited, all the target-pages are edited too.

You might also decide to create a (template) page with your mailing address and include that template on not only your page, but all your friends' pages as well. When you move your television and couch to another apartment, you can change your address template, and that new information will automatically update on all your friends' pages.

Transclusion Markup & Syntax

If the source is in the Template namespace (e.g. "Template:Welcome"), just use the name itself, alone: {{Welcome}}

If the source is in the Main article namespace (e.g. "VisualEditor"), a colon (:) must be added in front of the name: {{:VisualEditor}}

If the source is in any other namespace (e.g. "User:Example"), you must use the full name, including the namespace: {{User:Example}}

If the source is a subpage of the target page, (e.g. "Transclusion/ja"), you can simply specify the name of the subpage regardless of namespace: {{/ja}}

Etymologie

Výraz „transkluze” se poprvé objevil roku 1981 v knize Literary Machines (Literární stroje) Teda Nelsona, stejně jako výrazy „hypertext” a „hypermédia”.

Částečná transkluze

Transkluze umožňuje sestavit do jedné stránky obsah z mnoha dalších stránek a podstránek, ale není nutné aby se při tom natahoval pokaždé celý wiki kód volané stránky. Značky „noinclude“, „onlyinclude“ a „includeonly“ umožňují ovlivnit proces zpracování kódu při transkluzi. V některých případech je dokonce vložení kompletního kódu nežádoucí, typicky u šablon je potřeba kromě dokumentace odfiltrovat i kategorizační odkazy.

Efekt částečné a plné transkluze na konkrétních příkladech

Úplnou transkluzi použijte, pokud chcete do cílové stránky zahrnout celý obsah zdrojové stránky. Například obsah stránky o jabloních můžete zahrnout do stránky věnované ovocným stromům. Ale tam, kde chcete zahrnout jen část zdrojové stránky, se vám bude hodit částečná transkluze. Například chcete-li zahrnout do stránky, která pojednává o pečení jablečného štrůdlu, informace ze stránky věnované odrůdě Granny Smith.

Značky, jimiž se dá proces transkluze ovlivnit

  • noinclude - Značka ‎<noinclude>...‎</noinclude> znamená, že text, umístěný mezi značkami má být viditelný jen na zdrojové stránce a do jiné stránky se vložit nesmí. Tato značka se obvykle využívá k odfiltrování kategorizace šablony a její dokumentace.
  • includeonly - Značka ‎<includeonly>...‎</includeonly> signalizuje, že text který je mezi značkami se má zobrazovat jen pokud je obsah vložen do jiné stránky, ale na zdrojové stránce ne. To se hodí například v situaci, kdy používáte šablonu, která má kategorizovat do určité kategorie všechny stránky kde je použitá. Pokud byste ji nepoužili, spadla by do stejné kategorie i ta šablona.
  • onlyinclude - Značka ‎<onlyinclude>...‎</onlyinclude> signalizuje, že kód mezi značkami bude viditelný na výchozí stránce, i na všech stránkách do kterých bude vložena. This is the most subtle of the partial transclusion tags because it often overrules the others. If there is at least one pair of "onlyinclude" tags on a page, then whenever this page is transcluded, it is only the material within the "onlyinclude" tags that is transcluded. There can be several such "onlyinclude" sections on a page. This can be useful, for example, to repeat a small part of one page on a second one: just surround the small part by onlyinclude tags, and transclude it onto the second page.
Značky ‎<noinclude>, ‎<includeonly>, a ‎<onlyinclude> se chovají jinak, pokud jsou uzavřeny do tagu ‎<nowiki> tags. Značka nowiki tags umožňuje vypnout u značek ‎<noinclude> a ‎<includeonly> jejich zpracování během první transkluze. A u značky ‎<onlyinclude>, má ‎<nowiki> ten efekt, že odfiltruje během první transkluze značku ‎<onlyinclude>.
Kód Výsledný efekt při transkluzi
<nowiki><noinclude> My content </noinclude></nowiki> <noinclude> My content </noinclude>
<nowiki><includeonly> My content </includeonly></nowiki> <includeonly> My content </includeonly>
<nowiki><onlyinclude>My content</onlyinclude></nowiki> My content

Tyto značky můžete zahnízdit do sebe dle libosti a tak, ovlivnit nejenom to co se bude zobrazovat na aktuální stránce, ale i to, co se bude zobrazovat na stránkách sestavených s využitím transkluze.

Podstránky

You can cut and paste the text to be transcluded into a subpage, then use the name of the subpage in the transclusion template. This approach can be used only where subpages are enabled; for example, on the English Wikipedia, subpages can be used only from User, Talk or Wikipedia pages; currently, subpages cannot be created from main article pages.

Example: you want to discuss the deletion and redirecting of Pussycat to Cat. First, create the subpage Talk:Pussycat/Let's delete Pussycat!, write your comment into it, then transclude it in Talk:Pussycat and Talk:Cat using the template {{Talk:Pussycat/Let's delete Pussycat!}}. Comments posted in either talk page will be shown in both.

Speciální stránky

Sample: {{Special:Newpages/3}} gives 3 new pages.

URL parameters can be given like template parameters, e. g.

{{Special:RecentChanges|namespace=10|limit=5}}.

Alternatives to transclusion by template

Occasionally you may want to use a template, but for one reason or another may not want to use transclusion. The automatic one-time copying of a template's code/text to the location of a template tag is called Template substitution or subclusion (substitution + transclusion). To subclude a template's code/text, the template tag is modified from the standard transclusion tag to a substitution tag, simply by adding subst:, creating a tag with the form: {{subst:template name}}.

Labeled Section Transclusion

An extension called Labeled Section Transclusion enables marked sections of text to be transcluded.

Scribunto

You can transclude page content, or even parts of it, using Lua with the Scribunto extension. See Module:Transcluder for an example on this wiki.

Semantic MediaWiki

The Semantic MediaWiki extension uses inline queries to query and display semantic data. There are currently two ways to perform transclusion or something similar:

  1. Transclusion proper. The display format "embedded" ensures that selected pages (mainspace articles, templates, etc.) are transcluded. As with templates, sections placed between noinclude tags will be omitted.
  2. Selected passages in a page can be assigned a property of type 'Text'. These selections can be requested by running an inline query for this type of property.

See inline queries for further information.

Pages related to MediaWiki transclusion


Templates

See also