Sandbox:Temp: Difference between revisions

From Wikibase
Jump to navigation Jump to search
Sandbox demo: semantic content model demonstration (entities, dynamic rendering, citations, embeds, sitelink) (via update-page on MediaWiki MCP Server)
Tag: Reverted
Demonstrate multi-line content end-to-end: Q1129 (Bernoulli numbers in Python), storage encoding vs decoded rendering, citations + bibliography (via update-page on MediaWiki MCP Server)
Tag: Reverted
Line 3: Line 3:
== Freedom begins under this line ==
== Freedom begins under this line ==


This page is a demonstration of ronzz-wikibase's semantic content model: '''items''' (persons, sources, quotations, mathematical expressions, code), '''dynamic rendering''' of their statements, '''citations''', '''embeds''', and the '''page ↔ item sitelink'''. Everything shown below is live data: edit an item and this page updates by itself — no page editing required.
This page demonstrates the instance's '''multi-line content''' capability: content items (quotations, math, code) can now hold genuinely multi-line payloads. Multi-line payloads are stored '''backslash-escaped''' — the wiki's string values reject raw line breaks — and '''decoded at render time'''. Everything below is live data: edit the item and this page updates by itself.


The page is sitelinked to [[Item:Q1080|Charles Babbage]], so the short parser-function forms in the Dynamic rendering section resolve to that item automatically.
=== 1. The multi-line item ===


=== 1. The items behind this page ===
[[Item:Q1129|Bernoulli numbers in Python]] is a code-snippet item whose payload is a real 12-line Python program — an Akiyama–Tanigawa computation of the Bernoulli numbers, echoing the algorithm Ada Lovelace sketched in her 1843 note. Earlier code items (e.g. [[Item:Q99|Factorial in Python]]) were single-line only, squeezed onto one line; this one keeps its real shape.


{| class="wikitable"
{| class="wikitable"
! Kind !! Item !! Live data rendered from statements
! Kind !! Item !! Live data rendered from statements
|-
|-
| Person || [[Item:Q1080|Charles Babbage]] || instance of: {{#statements:P1|from=Q1080}} · born {{#statements:P50|from=Q1080}} · died {{#statements:P52|from=Q1080}}
| Code snippet || [[Item:Q1129|Bernoulli numbers in Python]] || instance of: {{#statements:P1|from=Q1129}} · language: {{#statements:P5|from=Q1129}} · attributed to: {{#statements:P6|from=Q1129}} · source: {{#statements:P28|from=Q1129}}
|-
|-
| Collective (publisher) || [[Item:Q1081|Longman]] || instance of: {{#statements:P1|from=Q1081}}
| Person || [[Item:Q94|Ada Lovelace]] || instance of: {{#statements:P1|from=Q94}}
|-
|-
| Book (citable source) || [[Item:Q1082|Passages from the Life of a Philosopher]] || instance of: {{#statements:P1|from=Q1082}} · author: {{#statements:P6|from=Q1082}} · publisher: {{#statements:P54|from=Q1082}} · year: {{#statements:P8|from=Q1082}}
| Book (citable source) || [[Item:Q95|Notes by the Translator]] || author: {{#statements:P6|from=Q95}} · publisher: {{#statements:P54|from=Q95}} · year: {{#statements:P8|from=Q95}}
|-
| Mathematical expression || [[Item:Q1083|Euler's identity]] || instance of: {{#statements:instance of|from=Q1083}} (property by label) · LaTeX: {{#statements:P4|from=Q1083}}
|-
| Code snippet || [[Item:Q1085|Finite differences in Python]] || instance of: {{#statements:P1|from=Q1085}} · language: {{#statements:P5|from=Q1085}}
|-
| Quotation || [[Item:Q1086|Pray, Mr. Babbage, …]] || instance of: {{#statements:P1|from=Q1086}} · attributed to: {{#statements:P6|from=Q1086}} · source: {{#statements:P28|from=Q1086}}
|}
|}


=== 2. Embedded content ===
=== 2. How the payload is stored ===


Item content renders standalone at its embed URL — the same fragment the '''Copy embed code''' button on each item page points to. On this wiki the Sanitizer keeps raw <code>iframe</code> tags out of pages (the iframe snippet is meant for third-party sites), so the reliable on-wiki surface is the bare embed URL — which also feeds the citation auto-collect:
The stored statement escapes each line break as a two-character <code>\n</code> sequence (and <code>\t</code> for tabs, <code>\r</code> for carriage returns, <code>\\</code> for backslashes — backslashes first, so a literal <code>\n</code> inside the code survives the round trip). The <nowiki>{{#statements:}}</nowiki> parser function shows the raw, escaped value — one long line, exactly what storage holds:


* '''Quotation''' — [https://wikibase.ronzz.org/wiki/Special:Embed/Q1086 rendered embed]
<code>{{#statements:P3|from=Q1129}}</code>
* '''Mathematical expression''' — [https://wikibase.ronzz.org/wiki/Special:Embed/Q1083 rendered embed]
* '''Code snippet''' — [https://wikibase.ronzz.org/wiki/Special:Embed/Q1085 rendered embed]


The content itself is rendered inline below, straight from the items' statements:
=== 3. How it renders ===


==== Quotation ====
==== The embed surface ====
<blockquote>{{#statements:P2|from=Q1086}}</blockquote>


==== Mathematical expression ====
The standalone embed decodes the payload — real line breaks, no escape sequences: [https://wikibase.ronzz.org/wiki/Special:Embed/Q1129 rendered embed]. (The sanitizer strips <code>iframe</code> tags from wiki pages, so on-wiki the reliable surface is this URL — which also feeds the citation auto-collect in § 4.)
<code>{{#statements:P4|from=Q1083}}</code> — rendered with KaTeX at the embed URL above.


==== Code snippet ====
==== On this page ====
{{#statements:P3|from=Q1085}}


=== 3. Dynamic rendering ===
The <nowiki>{{#content:}}</nowiki> parser function is the on-wiki decoder — it returns the same payload with the escapes undone:


The values in the table above come from the <code>#statements</code> parser function. Because this page is sitelinked to [[Item:Q1080]], the short form — no <code>from=</code> — resolves to that item:
<div style="border:1px solid #c8ccd1; border-left:4px solid #36c; padding:0.75em 1em; background:#f8f9fa;">{{#content:Q1129}}</div>


* {{#statements:P1}} — instance of (short form, via the sitelink)
That is the decoded payload rendered live: each line of the program is on its own line, indentation preserved, no <code>\n</code> in sight.
* Born {{#statements:P50}} · died {{#statements:P52}} (short form, via the sitelink)
* {{#statements:P6|from=Q1082}} wrote ''Passages from the Life of a Philosopher'' (explicit <code>from=</code> form)


=== 4. Citations ===
=== 4. Citations and bibliography ===


The citable source [[Item:Q1082]] is cited inline with the custom citation mechanism and collected in the bibliography below:<ref>{{#cite:Q1082}}</ref>
The snippet's source, [[Item:Q95|Notes by the Translator]] (Ada Lovelace, 1843), is cited inline:<ref>{{#cite:Q95}}</ref> Lovelace's note described the computation of Bernoulli numbers on the Analytical Engine — widely regarded as the first published computer program, and the direct inspiration for this snippet.<ref>{{#cite:Q95}}</ref>


Babbage recounts the reactions his Difference Engine provoked in his autobiography, and the quotation embedded above comes from the same work.<ref>{{#cite:Q1082}}</ref>
The Babbage quotation [[Item:Q1086|Pray, Mr. Babbage, …]] embeds the same way: [https://wikibase.ronzz.org/wiki/Special:Embed/Q1086 rendered embed] — its source is collected automatically too.


==== Bibliography ====
==== Bibliography ====
<references/>
<references/>


==== Sources collected automatically ====
==== Sources collected automatically ====


The <nowiki>{{#citations:}}</nowiki> collector gathers the same book here automatically — deduplicated across the footnote citations above and the embed URLs in § 2:
The <nowiki>{{#citations:}}</nowiki> collector gathers the same sources here — deduplicated across the inline citations above and the embed URLs in § 3:


{{#citations:}}
{{#citations:}}
Line 69: Line 57:
=== 5. Try it yourself ===
=== 5. Try it yourself ===


* Open [[Item:Q1080]] and use '''Update basic information''' to change a date — the Dynamic rendering section updates immediately.
* Open [[Item:Q1129]] and edit its <code>code source</code> statement — § 3 updates immediately.
* Use the '''Sitelink''' tab on this page to link it to another item and see the short forms change.
* See the help pages: [[Help:Contributing/code]], [[Help:Contributing/citations]], [[Help:Contributing/semanticDynamicContent]], [[Help:Contributing/quotation]], [[Help:Contributing/math]].
* See the help pages: [[Help:Contributing/semanticDynamicContent]], [[Help:Contributing/citations]], [[Help:Contributing/quotation]], [[Help:Contributing/math]], [[Help:Contributing/code]], [[Help:Contributing/entities]].

Revision as of 11:33, 30 August 2026

Languages: English · français · Esperanto

This is a scratch page. You can do whatever to it below this line

Freedom begins under this line

This page demonstrates the instance's multi-line content capability: content items (quotations, math, code) can now hold genuinely multi-line payloads. Multi-line payloads are stored backslash-escaped — the wiki's string values reject raw line breaks — and decoded at render time. Everything below is live data: edit the item and this page updates by itself.

1. The multi-line item

Bernoulli numbers in Python is a code-snippet item whose payload is a real 12-line Python program — an Akiyama–Tanigawa computation of the Bernoulli numbers, echoing the algorithm Ada Lovelace sketched in her 1843 note. Earlier code items (e.g. Factorial in Python) were single-line only, squeezed onto one line; this one keeps its real shape.

Kind Item Live data rendered from statements
Code snippet Bernoulli numbers in Python instance of: code snippet · language: Python · attributed to: Ada Lovelace · source: Notes by the Translator
Person Ada Lovelace instance of: person
Book (citable source) Notes by the Translator author: Ada Lovelace · publisher: R. & J. E. Taylor · year: 1843

2. How the payload is stored

The stored statement escapes each line break as a two-character \n sequence (and \t for tabs, \r for carriage returns, \\ for backslashes — backslashes first, so a literal \n inside the code survives the round trip). The {{#statements:}} parser function shows the raw, escaped value — one long line, exactly what storage holds:

from fractions import Fraction\n\ndef bernoulli(n):\n """Return the nth Bernoulli number (Akiyama-Tanigawa algorithm)."""\n A = [Fraction(0)] * (n + 1)\n for m in range(n + 1):\n A[m] = Fraction(1, m + 1)\n for j in range(m, 0, -1):\n A[j - 1] = j * (A[j - 1] - A[j])\n return A[0]\n\nprint([str(bernoulli(n)) for n in range(8)])

3. How it renders

The embed surface

The standalone embed decodes the payload — real line breaks, no escape sequences: rendered embed. (The sanitizer strips iframe tags from wiki pages, so on-wiki the reliable surface is this URL — which also feeds the citation auto-collect in § 4.)

On this page

The {{#content:}} parser function is the on-wiki decoder — it returns the same payload with the escapes undone:

from fractions import Fraction

def bernoulli(n):
    """Return the nth Bernoulli number (Akiyama-Tanigawa algorithm)."""
    A = [Fraction(0)] * (n + 1)
    for m in range(n + 1):
        A[m] = Fraction(1, m + 1)
        for j in range(m, 0, -1):
            A[j - 1] = j * (A[j - 1] - A[j])
    return A[0]

print([str(bernoulli(n)) for n in range(8)])

That is the decoded payload rendered live: each line of the program is on its own line, indentation preserved, no \n in sight.

4. Citations and bibliography

The snippet's source, Notes by the Translator (Ada Lovelace, 1843), is cited inline:[1] Lovelace's note described the computation of Bernoulli numbers on the Analytical Engine — widely regarded as the first published computer program, and the direct inspiration for this snippet.[1]

The Babbage quotation Pray, Mr. Babbage, … embeds the same way: rendered embed — its source is collected automatically too.

Bibliography

  1. ↑ ↑ Lovelace, A. (1843). Notes by the Translator. In Notes by the Translator. R. & J. E. Taylor. https://doi.org/10.1000/notes

Sources collected automatically

The {{#citations:}} collector gathers the same sources here — deduplicated across the inline citations above and the embed URLs in § 3:

  1. Lovelace, A. (1843). Notes by the Translator. In Notes by the Translator. R. & J. E. Taylor. https://doi.org/10.1000/notes
  2. Babbage, C. (1864). Passages from the Life of a Philosopher. In Passages from the Life of a Philosopher. Longman.

5. Try it yourself