Help:Contributing/semanticDynamicContent: Difference between revisions
Sitelink tab: red/blue tab + popup on every content page (deployed 2026-08-23) (via update-page on MediaWiki MCP Server) |
Standardize: add copy button to block code snippets |
||
| Line 37: | Line 37: | ||
|- | |- | ||
| Instance | | Instance | ||
| <syntaxhighlight lang="wikitext">{{#statements:P1|from=Q99}}</syntaxhighlight> | | <syntaxhighlight lang="wikitext" copy>{{#statements:P1|from=Q99}}</syntaxhighlight> | ||
| {{#statements:P1|from=Q99}} | | {{#statements:P1|from=Q99}} | ||
|- | |- | ||
| Programming language | | Programming language | ||
| <syntaxhighlight lang="wikitext">{{#statements:P5|from=Q99}}</syntaxhighlight> | | <syntaxhighlight lang="wikitext" copy>{{#statements:P5|from=Q99}}</syntaxhighlight> | ||
| {{#statements:P5|from=Q99}} | | {{#statements:P5|from=Q99}} | ||
|- | |- | ||
| Code source | | Code source | ||
| <syntaxhighlight lang="wikitext">{{#statements:P3|from=Q99}}</syntaxhighlight> | | <syntaxhighlight lang="wikitext" copy>{{#statements:P3|from=Q99}}</syntaxhighlight> | ||
| {{#statements:P3|from=Q99}} | | {{#statements:P3|from=Q99}} | ||
|- | |- | ||
| Attributed to | | Attributed to | ||
| <syntaxhighlight lang="wikitext">{{#statements:P6|from=Q99}}</syntaxhighlight> | | <syntaxhighlight lang="wikitext" copy>{{#statements:P6|from=Q99}}</syntaxhighlight> | ||
| {{#statements:P6|from=Q99}} | | {{#statements:P6|from=Q99}} | ||
|- | |- | ||
| By label instead of P-number | | By label instead of P-number | ||
| <syntaxhighlight lang="wikitext">{{#statements:instance of|from=Q99}}</syntaxhighlight> | | <syntaxhighlight lang="wikitext" copy>{{#statements:instance of|from=Q99}}</syntaxhighlight> | ||
| {{#statements:instance of|from=Q99}} | | {{#statements:instance of|from=Q99}} | ||
|- | |- | ||
| Another entity — Q55 (Markdown) | | Another entity — Q55 (Markdown) | ||
| <syntaxhighlight lang="wikitext">{{#statements:P1|from=Q55}}</syntaxhighlight> | | <syntaxhighlight lang="wikitext" copy>{{#statements:P1|from=Q55}}</syntaxhighlight> | ||
| {{#statements:P1|from=Q55}} | | {{#statements:P1|from=Q55}} | ||
|} | |} | ||
| Line 67: | Line 67: | ||
! You type !! You get | ! You type !! You get | ||
|- | |- | ||
| <syntaxhighlight lang="wikitext">{{#statements:P1|from=Q94}}</syntaxhighlight> | | <syntaxhighlight lang="wikitext" copy>{{#statements:P1|from=Q94}}</syntaxhighlight> | ||
| {{#statements:P1|from=Q94}} | | {{#statements:P1|from=Q94}} | ||
|} | |} | ||
| Line 78: | Line 78: | ||
! You type !! You get | ! You type !! You get | ||
|- | |- | ||
| <syntaxhighlight lang="wikitext">{{#statements:P999|from=Q55}}</syntaxhighlight> | | <syntaxhighlight lang="wikitext" copy>{{#statements:P999|from=Q55}}</syntaxhighlight> | ||
| {{#statements:P999|from=Q55}} | | {{#statements:P999|from=Q55}} | ||
|} | |} | ||
| Line 121: | Line 121: | ||
|- | |- | ||
| Official website | | Official website | ||
| <syntaxhighlight lang="wikitext">{{#statements:official website}}</syntaxhighlight> | | <syntaxhighlight lang="wikitext" copy>{{#statements:official website}}</syntaxhighlight> | ||
| {{#statements:official website|from=Q180}} | | {{#statements:official website|from=Q180}} | ||
|- | |- | ||
| Source code repository | | Source code repository | ||
| <syntaxhighlight lang="wikitext">{{#statements:source code repository}}</syntaxhighlight> | | <syntaxhighlight lang="wikitext" copy>{{#statements:source code repository}}</syntaxhighlight> | ||
| {{#statements:source code repository|from=Q180}} | | {{#statements:source code repository|from=Q180}} | ||
|- | |- | ||
| Category (instance of) | | Category (instance of) | ||
| <syntaxhighlight lang="wikitext">{{#statements:instance of}}</syntaxhighlight> | | <syntaxhighlight lang="wikitext" copy>{{#statements:instance of}}</syntaxhighlight> | ||
| {{#statements:instance of|from=Q180}} | | {{#statements:instance of|from=Q180}} | ||
|} | |} | ||
Create new software pages with [[Special:AddSoftware]] — it creates the item, the <code>FOSS:<Name></code> page and the page↔item sitelink in one flow. | Create new software pages with [[Special:AddSoftware]] — it creates the item, the <code>FOSS:<Name></code> page and the page↔item sitelink in one flow. | ||
Revision as of 09:45, 23 August 2026
Semantic dynamic content renders item data on a wiki page at view time. Edit the item once; every page that renders its statements updates. Every example below is live against real items.
The two parser functions
Two of the Wikibase client's parser functions are enabled on this wiki. Both take a property — a P-number or its label — and render its statements. They differ in output form:
| Function | Output form | Use it when |
|---|---|---|
#statements
|
Rich wikitext: each value keeps its markup (language attributes, list structure). | Default for page content — values stay marked up for styling and screen readers. |
#property
|
Escaped plain text: no markup survives. | Inside templates or table cells, where markup would interfere. |
Same call, both forms — Q96 (quotation, one statement per language):
#property |
#statements
|
|---|---|
| The Analytical Engine has no pretensions whatever to originate anything. It can do whatever we know how to order it to perform., La machine analytique ne prétend nullement être à l'origine de quoi que ce soit. Elle peut faire tout ce que nous savons lui ordonner d'exécuter., La analiza maŝino tute ne pretendas origini ion ajn. Ĝi povas fari ĉion, kion ni scias ordoni al ĝi plenumi. | The Analytical Engine has no pretensions whatever to originate anything. It can do whatever we know how to order it to perform., La machine analytique ne prétend nullement être à l'origine de quoi que ce soit. Elle peut faire tout ce que nous savons lui ordonner d'exécuter., La analiza maŝino tute ne pretendas origini ion ajn. Ĝi povas fari ĉion, kion ni scias ordoni al ĝi plenumi. |
The visible text is identical. The difference is in the page source: #statements wraps each value in language markup, #property emits plain text. Item values render as labels, not links, on this wiki.
Examples
Running example: Q99 (Factorial in Python). The from= argument names the entity. The property can be a P-number or a label.
| What you want | You type | You get |
|---|---|---|
| Instance | {{#statements:P1|from=Q99}}
|
code snippet |
| Programming language | {{#statements:P5|from=Q99}}
|
Python |
| Code source | {{#statements:P3|from=Q99}}
|
factorial = lambda n: 1 if n <= 1 else n * factorial(n - 1) |
| Attributed to | {{#statements:P6|from=Q99}}
|
Ada Lovelace |
| By label instead of P-number | {{#statements:instance of|from=Q99}}
|
code snippet |
| Another entity — Q55 (Markdown) | {{#statements:P1|from=Q55}}
|
programming language |
An item with no statements renders nothing — empty output is not an error. Q94 (Ada Lovelace) has no statements:
You type You get {{#statements:P1|from=Q94}}person
An unknown property is an explicit error, not empty output — P999 does not exist:
You type You get {{#statements:P999|from=Q55}}Failed to render property P999: P999 property not found.
Sitelinks: pages ↔ items
A sitelink links an item to a page title on the wikibase site. It maps the page to the item; the item page shows the link in its Sitelinks section. Without from=, a parser function uses the item sitelinked to the current page.
Live pairs on this wiki: Q55 (Markdown) ↔ Cheatsheets:Markdown, Q77 (SPARQL) ↔ Cheatsheets:SPARQL.
The Sitelink tab
Every content page has a Sitelink tab next to Page/Discussion:
- Red (not linked): click it to open a small dialog — type a label to search for an item (or enter a Q-id directly), then click Link. The page is linked immediately.
- Blue (linked): the tab links straight to the item page.
You can also link a page the classic way: open the item, add the page title in the Sitelinks section (site wikibase), or use the API: action=wbsetsitelink with linksite=wikibase.
Without
from=the page must be sitelinked to an item. This page is not linked, so{{#statements:P1}}on it renders nothing. Link the page to an item (via the tab) to use the short form.
Limits
Lua modules ({{#invoke:Wikibase}}) are not available — the Scribunto extension is not installed. Use the parser functions above.
See also
- Wikibase Client (official extension docs)
- Wikidata introduction — what a Wikibase is for
- Cheatsheets:SPARQL — query items the other way
- Help:Contributing — contributing to this wiki
FOSS software pages (worked example)
FOSS software pages (FOSS:Main) are thin templates over their items: the page transcludes Template:Tl, whose infobox reads the item's statements at view time — so when a project moves its website or repository, you edit the item once and every page updates. Because the page is sitelinked to its item (see above), the short form works. Live example — FOSS:Flameshot ↔ Item Q180:
| What you want | You type | You get |
|---|---|---|
| Official website | {{#statements:official website}}
|
|
| Source code repository | {{#statements:source code repository}}
|
|
| Category (instance of) | {{#statements:instance of}}
|
Create new software pages with Special:AddSoftware — it creates the item, the FOSS:<Name> page and the page↔item sitelink in one flow.