Jump to content

Help:Wikifunctions/Rich Outputs

From mediawiki.org

Z89 / HTML fragment is the output type Wikifunctions functions use to produce content for display on-wiki — most notably the content rendered in Abstract Wikipedia articles.

A Z89 value is a small, sanitised piece of HTML. Most of it is rendered as-is, but certain markers inside it are recognised by the system and transformed into something richer — a numbered citation marker that opens a popover, a thumbnail fetched from Commons, and so on. We call these transformed elements rich outputs.

Depending on the marker, the transform happens either server-side (by the Wikifunctions PHP renderer, before the page is sent to the browser) or client-side (by JavaScript, after the page loads).

This page introduces the mechanism. For the concrete features built on top, see:

  • Citations — reference markers with popovers
  • Images — Commons thumbnails rendered as <figure> elements

How rich outputs work

[edit]
Example function output containing a citation marker.
Example function output containing a Commons thumbnail.

A function that produces a rich output returns Z89 content containing specific markers — either custom HTML elements (e.g. <ext-wikilambda-image>) or elements with specific CSS classes (e.g. class="ext-wikilambda-reference"). The system recognises these markers and transforms them:

  • Server-side transforms run before the HTML reaches the browser. The Wikifunctions PHP renderer scans the function output, finds known custom elements, fetches whatever data they need (for example, image metadata from Commons), and replaces them with trusted, fully-rendered HTML. The reader sees the result with no extra JavaScript.
  • Client-side transforms run in the browser after the page loads. A small ResourceLoader module scans for known CSS classes and enhances those elements (for example, by wiring up popovers, drawers, or interactive behaviour).

Both transforms operate on Z89 output regardless of whether it is being displayed in Abstract Wikipedia, on a Wikifunctions function-result, or in an embedded function-call result.

Why rich outputs exist

[edit]

Function outputs go through the MediaWiki HTML sanitiser before display, which by default disallows tags like <figure> and <img>. Adding those tags to the sanitiser's allow-list everywhere would weaken its safety guarantees. Instead, the rich-output mechanism uses opaque placeholders or class-based markers that do a custom pass through the sanitiser, and is then expanded into trusted HTML by extension code that knows the rules of each output type.

This keeps the sanitiser strict, while still letting function authors return outputs that visually and behaviourally match the rest of Wikipedia content.

Future rich outputs

[edit]

The mechanism is extensible, and more rich-output types may be added over time. Some possibilities that have come up: infoboxes, quote boxes — the kinds of structured content that today rely on Wikipedia templates. Adding a new type requires changes to the WikiLambda MediaWiki extension itself — it is not something function authors can do from inside Wikifunctions — but ideas and use cases from function authors and contributors are very welcome.

See also

[edit]