Extension:ParserPhase2

From MediaWiki.org

Jump to: navigation, search

(($parserphase2off$))((%parserphase2off%))

         

Manual on MediaWiki Extensions
List of MediaWiki Extensions
Crystal Clear action run.png
ParserPhase2

Release status: stable

Implementation  Parser extension
Description This extension enables performing a 'second pass' through a 'parser cached' page replacing for 'dynamic' variables.
Author(s)  Jean-Lou Dupont
Last Version  1.1.1
MediaWiki  1.10, 1.11, 1.12
License No license specified
Download SVN
See SVN ($Id$)

check usage (experimental)

Contents

[edit] Purpose

This extension enables performing a 'second pass' through a 'parser cached' page replacing for 'dynamic' variables. In a word, once a page is normally processed (i.e. 'first pass') Mediawiki 'fixes' all templates & variables in a 'parser cached' page. This extension enables substituting selected variables upon page view whilst still preserving the valuable job performed by the parser/parser cache.

Additionally, the extension enables the execution of 'parser functions' and 'magic words' *after* the page's 'tidy' process is executed. This functionality is referred to as 'parser after tidy'. This capability allows for the inclusion of text that would otherwise upset MediaWiki's parser e.g. execution of a parser functions that replaces text in an 'html' tagged section.

Finally, the extension enables the execution of 'parser functions' and 'magic words' *before* the page's 'strip' process is executed i.e. before the MediaWiki begins parsing the page. This functionality is referred to as 'parser before strip'.

[edit] Theory of operation

In the standard MW processing flow, when a page is viewed it is retrieved (either from the cache or 'raw' from the database) and sent to the 'output page' object. What this extension does is intercept the flow process through the 'OutputPageBeforeHTML' hook and:

  • Extracts the (($ magic word| ... $)) tags (and other supported invocation formats)
  • Looks for 'magic word' in the dictionary and retrieve the value if found
  • Looks for 'magic word' in the 'parser function' dictionary and execute the function if found

This same process is performed for both 'parser phase 2' and 'parser after tidy' functionalities. See Extension:ParserPhase2/Flow Summary for more details.

[edit] Features

  • Enable/disable keywords for 'sectional execution' support
    • By default, replacement is 'enabled' until a 'disable' magic word is encountered
    • Execution is stopped (i.e. no replacement occurs) until an 'enable' magic word is next encountered
  • Integrates with the standard Mediawiki Parser Cache
  • Provides a simple 'magic word' based interface to standard Mediawiki variables & parser functions
  • Handles two invocation forms for the 'parser phase 2' functionality:
    • (($...$))
    • (( ... ))
  • Handles one invocation for the 'parser after tidy' functionality:
    • ((% ... %))
  • Handles one invocation for the 'parser before strip' functionality:
    • ((@ ... @))
  • Master Off functionality
    • ((% parserphase2off %)) for turning off all 'parser after tidy' processing on the page
    • ((@ parserphase2off @)) for turning off all 'parser before strip' processing on the page
    • (($ parserphase2off $)) for turning off all 'output before HTML' processing on the page
    • Remove the space between the keyword 'parserphase2off' and the enclosing delimiters for proper usage.

[edit] Usage

[edit] ParserPhase2 functionality

(($magic word|...parameters...$)) or (( ))

Where 'variable' is a standard Mediawiki magic word e.g. CURRENTTIME, REVISIONID etc.

[edit] Parser After Tidy functionality

((%magic word|...parameters...%))

[edit] Parser Before Strip functionality

((@magic word|...parameters...@))

[edit] Nesting

Recursive invocation is supported; example:

  • (($#f1 | (($#f2$)) | (($#f3$)) $))

[edit] Issues with Wikitext tables

There are some limitations in the usage of this extension with wikitext based tables since parameters are separated through the pipe | character.

[edit] Dependancy



[edit] Installation

See the Mediawiki Extension table entry "download" above.[1]

[edit] LocalSettings.php

Extension:ExtensionManager: See footnote[2]

require_once( "$IP/extensions/ParserPhase2/ParserPhase2.php" );

[edit] PEAR

PEAR is a repository of en:PHP software code.

pear channel-discover mediawiki.googlecode.com/svn
  • Install extension through PEAR:
pear install mediawiki/ParserPhase2
  • Add the following to LocalSettings.php[2][3]:
require 'MediaWiki/ParserPhase2/ParserPhase2.php';
  • Note that the required version of PEAR must be respected. Currently, the minimum version of PEAR usable with this channel is v1.6.2. Perform the following command to upgrade to the latest version of PEAR:
pear upgrade pear

[edit] Upgrades through PEAR

Sometimes, it is necessary to clear PEAR's cache in order to perform upgrades.

pear clear-cache

or use the force method:

pear upgrade --force mediawiki/ParserPhase2

[edit] PEAR Web Frontend

For easier remote package management, PEAR Frontend WEB can be installed. Installation notes can be found here. An example of the WEB frontend is available here.

[edit] RSS feed

To keep kept up-to-date with this channel, use the following RSS feed__Rss2.jpg.

[edit] Notes

[edit] Other Extensions From the same author

Consult User Jldupont's page.


  1. The most recent release is always available through the extension's PEAR and SVN repositories. This page is not necessarily up-to-date.
  2. 2.0 2.1 2.2 Extension:ExtensionManager does not require any modification to LocalSettings.php because ExtensionManager includes the extension.
    Note that if PHP code caching is in place (e.g. APC, eAccelerator), then to successfully complete the installation a cache flush might be needed.
  3. Modifications to LocalSettings.php is only necessary if not using Extension:ExtensionManager

[edit] History

  • fixed client side caching logic due to a bug in PHP's preg_match_all function
  • fixed issue with $wgParser not having a valid 'mTitle' property set
  • added 'disable' command
  • Removed dependency on 'ExtensionClass'
  • Added 'stub' capability
  • Added 'EndParserPhase2' hook
  • Added pattern: ((magic word|... )) which more closely maps to standard MW parser function calling
    • DO NOT MIX PATTERNS ON THE SAME PAGE i.e. no (($...$)) mixing up with ((...))
  • Added functionality to execute parser functions/magic words just after the 'tidy' process
  • Added functionality to execute parser functions/magic words just BEFORE the 'strip' process i.e. before the parser really begins.
  • Added 'enable' magic word
  • Added support for 'sectional execution' i.e. replacement between 'enable' and 'disable' magic words
  • Added 'recursive' (aka 'nesting') processing functionality
  • Changed calls to $this->execute in order to remove PHP warning.

[edit] 1.0.0

  • Moved to PEAR repository

[edit] 1.0.1

  • Removed unused variable in order to avoid unecessary PHP notice

[edit] 1.1.0

  • Added 'master off' functionality
Release Notes
1.1.1 Fixed for MediaWiki 1.12 compatiblity


[edit] TODO

  • possibly fix to allow mixing up (($..$)) and ((..)) patterns on the same page (TBD)