Extension:WhiteSpace

Category:Unmaintained extensions#WhiteSpace Category:Extensions without an imageCategory:Extensions without a compatibility policyCategory:AGPL licensed extensions
MediaWiki extensions manual
WhiteSpace
Release status: unmaintainedCategory:Unmaintained extensions
Implementation Tag Category:Tag extensions
Description Provides tags to control whitespace
Author(s) Van de Buggertalk
Latest version 0.1.0 (2012-03-19)
MediaWiki 1.35+Category:Extensions with manual MediaWiki version
License GNU Affero General Public License 3.0
Download Category:Extensions in Wikimedia version control
  • <dws />
  • <nl />
Quarterly downloads 1 (Ranked 97th)
Translate the WhiteSpace extension if it is available at translatewiki.net
Category:All extensions

The WhiteSpace extension provides two tags to control whitespace in templates: <dws /> discards itself and all whitespace (including newlines) after the tag, <nl /> replaces itself with a newline.

Rationale

In wikitext spaces and newlines do matter. Leading space causes a paragraph to be verbatim, newline terminates a list item, etc. This means that template code cannot be formatted freely. For example, two subsequent template calls:

{{ Template1 }}{{ Template2 }}

being reformatted as:

{{ Template1 }}
{{ Template2 }}

may produce different result (e. g. two list items instead of one). This is not a big deal for a simple template, but it quickly become a real issue for complicated templates. Let us consider a real example, a small part of Template:Extension:

   {{#if: {{{username|}}} |<!--
   -->{{#ifeq: {{{username}}}|{{{author|{{{username}}}<!-- -->}}}|<!--
      nothing
   -->|<!--else--><!--
      -->{{{author}}} (<!--
   -->}}<!--
   -->[[User:{{{username}}}|{{{username}}}]]<!--
   --><sup><small>[[User talk:{{{username}}}|{{int:talkpagelinktext}}]]</small></sup><!--
   -->{{#ifeq: {{{username}}}|{{{author|{{{username}}}<!-- -->}}}|<!--
      nothing
   -->|<!--else--><!--
      -->)<!--
   -->}}<!--
-->|<!--else--><!--
   -->{{{author}}}<!--
-->}}

HTML comments (<!-- -->) allows splitting template code to lines but it pollutes template code so the overall result is not so good. Using <dws/> the code can be reformatted as:

{{  #if: {{{ username | }}} 
    |   {{  #ifeq: {{{ username }}} | {{{ author | {{{ username }}} }}}
            |   nothing
            |   {{{ author }}}<dws/>
                (
        }}<dws/>
        [[User:{{{ username }}}|{{{ username }}}]]<dws/>
        <sup><small>[[User talk:{{{ username }}}|{{ int: talkpagelinktext }}]]</small></sup><dws/>
        {{  #ifeq: {{{ username }}} | {{{ author | {{{ username }}} }}}
            |   nothing
            |   )
        }}
    |   {{{ author }}}
}}

Of course, it is just another style of formatting, but <dws/> allows using this style regularly and uniformly.

Installation

  • Download and move the extracted WhiteSpace 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/WhiteSpace
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'WhiteSpace' );
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.
Category:AGPL licensed extensions Category:All extensions Category:Extensions in Wikimedia version control Category:Extensions with manual MediaWiki version Category:Extensions without a compatibility policy Category:Extensions without an image Category:ParserBeforeInternalParse extensions Category:ParserBeforePreprocess extensions Category:Tag extensions Category:Unmaintained extensions