Jump to content

Extension:Pipe Escape

From mediawiki.org
(Redirected from Extension:PipeEscape)
MediaWiki extensions manual
Pipe Escape
Release status: unmaintained
Implementation Parser function
Description Allows to escape pipe characters in parser function and template arguments
Author(s)
Latest version 3.0.0
MediaWiki >= 1.35.0
Database changes No
License GNU General Public License 2.0 or later
Download
Example sandbox.semantic-mediawiki.org
Translate the Pipe Escape extension if it is available at translatewiki.net

The Pipe Escape extension allows pipe characters in parser function arguments (and template argument calls) to avoid being interpreted as an argument delimiter. This is primarily for using wiki tables (or parts thereof) inside parser function calls or templates.

Use cases

[edit]

For example, suppose you have the following wikitable in a template:

{|
|-
!       || Heading 1 || Heading 2
|-
| Row a || a1        || a2
|-
| Row b || b1        || b2
|}

but you only want the table to show up when a non-whitespace value is supplied for template argument targ. One possible solution is to use HTML instead of wiki syntax.

{{#if: {{{targ|}}}|<table>
<tr>
<th> <th> Heading 1 <th> Heading 2
<tr>
<td> Row a <td> a1 <td> a2
<tr>
<td> Row b <td> b1 <td> b2
</table>
}}

but this is less intuitive and, therefore, more error-prone, and, in part, defeats the purpose of a wiki. Another solution is to hide the pipe characters from the parser function in a template. (Common practice is to use the "!" template (MW ≤ 1.23) or the {{!}} magic word (MW ≥ 1.24) with its includable contents being only a raw pipe character.)

{{#if: {{{targ|}}}
|{{(!}}
{{!}}-
!           {{!}}{{!}} Heading 1 {{!}}{{!}} Heading 2
{{!}}-
{{!}} Row a {{!}}{{!}} a1        {{!}}{{!}} a2
{{!}}-
{{!}} Row b {{!}}{{!}} b1        {{!}}{{!}} b2
{{!)}}
}}

This is a better solution, but things can get messy when you hide multiple pipes in an argument. This is where this simple parser function comes in handy.

Usage

[edit]
{{#!: ''wiki text'' }}

This hides the pipe characters in wiki text so that outer parser functions and outer templates do not interpret them as argument delimiters. With this extension, the above example can be rewritten as

{{#if: {{{targ|}}}
| {{#!:
{|
|-
!       || Heading 1 || Heading 2
|-
| Row a || a1        || a2
|-
| Row b || b1        || b2
|}
}}
}}

In reality, the pipe characters are still treated as argument delimiters in this parser function. Still, it concatenates the arguments using a pipe character as a separator, which outer parser functions do not register as delimiters.

Unlike most parser functions, pipe escape preserves the leading and trailing whitespace around its arguments except the first argument (due to the way MediaWiki handles the first argument in parser functions; See task 14842), and the trailing whitespace in the last argument.

Pipe escape only affects top-level pipe characters. It does not affect pipe characters in other parser functions nested within the pipe escape parser function call. The same is true for pipe characters in template calls, template arguments, intrawiki links, tag extensions, etc...

Installation

[edit]
  • Download and move the extracted PipeEscape folder to your extensions/ directory.
    Developers and code contributors should install the extension from Git instead, using:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/PipeEscape
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'PipeEscape' );
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.