Manual:Live preview

Jump to: navigation, search

Live preview is a feature of MediaWiki which allows showing a preview of an article or section on an edit form without reloading the remaining HTML code of the form.

It has some bugs, see live preview tracking bug for an up to date list.

Advantages[edit | edit source]

  • less incoming traffic: wikicode and all the menus are not received from the server again,
  • faster response time,
  • same cursor position in the editing window.

Disadvantages[edit | edit source]

Only preview area is updated, which means:

  • optional css files might be missing (e.g. if user adds <source> tag),
  • scripts are not executed if they do not use the wikipage.content hook.

Technical details[edit | edit source]

A live preview of an arbitrary MediaWiki markup string is returned if an appropriate flag is set when submitting a page via the "edit" action.

The following arguments to index.php should be passed via POST request:

  1. title=Page_Title
  2. wpPreview=true
  3. live=true
  4. wpTextbox1=String

The result is a preview of the string passed as the value of the wpTextbox1 field. This is similar to the result of action=render index.php parameter when viewing a page.

The title argument is actually used only if the string contains magic words such as {{PAGENAME}}.

Implementation[edit | edit source]

This feature should be exploited by JavaScript code with a "Live preview" button on the edit form. This button should submit the text with live flag and show resulting preview.

Live preview is currently disabled on Wikimedia projects, probably due to potential incompatibilities with some older browsers.

However, several userscripts are available, like qPreview and Quick Preview.

Also a script using built-in preview.js is possible.

Other uses[edit | edit source]

Live preview can be potentially used in a way other than in the edit form. For example, the current timestamp on the English Wikipedia is the 14-digit number within the result of the executing the following command:

curl -f -m 60 -d "" -g "{{CURRENTTIMESTAMP}}"

Alternatives[edit | edit source]

A similar preview functionality is now implemented in API, using the parse function. As an example, the current time stamp can be obtained by:

curl -f -m 60 -d "" -g "{{CURRENTTIMESTAMP}}"

Enabling live preview[edit | edit source]

Live preview is on or off depending on the $wgLivePreview variable of LocalSettings.php (MW ≤ 1.16.5). To activate it you must also enable it on a per-user basis in the "editing" tab of your user preferences page.

See also[edit | edit source]

Language: English  • 日本語 • 中文