Extension:ForeachFunction

From MediaWiki.org

Jump to: navigation, search
Manual on MediaWiki Extensions
List of MediaWiki Extensions
ForeachFunction

Release status: beta

Implementation Parser extension
Description
Author(s) Jean-Lou Dupont
Last Version 1.0.0
MediaWiki 1.10, 1.11
License No license specified
Download SVN
See SVN ($Id: ForeachFunction.doc.wikitext 492 2007-10-10 16:27:42Z jeanlou.dupont $)

Contents

[edit] Purpose

This extension provides 'looping' functionality (e.g. 'foreach') for iterating through arrays.

[edit] Feature

  • Security: only pages with protection on 'edit' can use the keywords provided by this extension

[edit] Usage

[edit] Simple Array

  • {{#foreachx:global object name|property|pattern}}
    • The global object's property will be retrieved; the property should be an 'array'
  • {{#foreachx:global object name|method|pattern}}
    • The global object's method will be called: an array is expected as return value
  • {{#foreachx:global array variable|key|pattern}}
    • The global array variable will be referenced using 'key' as key
  • {{#foreachx:global array variable||pattern}}
    • The global array variable will be referenced (as a whole)
  • {{#foreachx:class name|static property|pattern}}
    • The static property of class name will be referenced (as a whole)

[edit] Simple Array with Conditional

  • {{#foreachc: X | Y |pattern|match value|match value replacement}} where {X:Y} can be:
    • { Global Object Name: Property }
    • { Global Object Name: Method }
    • { Global Array Variable: Key }
    • { Class Name: Static Property }

'match value' is represented by $match$ in the pattern field. When the 'value' of the current array entry matches the 'match' variable provided, then $match$ is replaced with 'match value'.

[edit] Array of Arrays

  • {{#foreachy:global object name|property|pattern}}
    • The global object's property will be retrieved; the property should be an 'array'
  • {{#foreachy:global object name|method|pattern}}
    • The global object's method will be called: an array is expected as return value
  • {{#foreachy:global array variable|key|pattern}}
    • The global array variable will be referenced using 'key' as key
  • {{#foreachy:global array variable||pattern}}
    • The global array variable will be referenced (as a whole)

[edit] Dependancies



[edit] Installation

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

[edit] LocalSettings.php

Extension:ExtensionManager: See footnote[2]

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

[edit] PEAR

PEAR is a repository of software code.

pear channel-discover mediawiki.googlecode.com/svn
  • Install extension through PEAR:
pear install mediawiki/ParserExt
  • Add the following to LocalSettings.php[2][3]:
require 'MediaWiki/ParserExt/ParserExt.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/ParserExt

[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 feedImage:Rss2.jpg.

[edit] Notes

[edit] Sandbox

You are invited in the author's sandbox to try-out some of his extensions.

[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

  • Added 'CLASS NAME::STATIC PROPERTY' support
  • Added 'addExemptNamespaces' function
  • Added '#foreachc' parser function
Personal tools
In other languages