Attached below is a test case that demonstrates the "always evaluate" behavior I was describing in vanilla MediaWiki 1.12.0 and ParserFunctions. The custom parser function #bugtest does two things:
1. Displays a simple message, "Here I Am!" 2. Appends a timestamp to the file C:\Temp\sideeffect.txt (you can change this in the code)
When you call it like this:
{{#if: foo | {{#bugtest:}} }}
it displays "Here I Am!" and writes a timestamp to the file, as you'd expect. However, if you call it like this:
{{#if: | {{#bugtest:}} }}
it does not display any message, but it STILL writes the timestamp, demonstrating that the #bugtest code is being run.
This is on Windows 2003 Server with PHP 5.2.5.
Brion, any comments?
DanB
====
<?php
$vpIgnoreConditional = new IgnoreConditional; $wgExtensionFunctions[] = array($vpIgnoreConditional, 'setup'); $wgHooks['LanguageGetMagic'][] = array($vpIgnoreConditional, 'magic');
class IgnoreConditional { const NAME = 'bugtest'; const OUTFILE = "c:\temp\sideeffect.txt";
// The entry point. Associates the parser function with a PHP function. function setup() { global $wgParser; $wgParser->setFunctionHook(self::NAME, array($this, 'renderParserFunction')); }
function magic(&$magicWords, $langCode) { $magicWords[self::NAME] = array(0, self::NAME); return true; }
// The function that does the work. function renderParserFunction(&$parser) { // Do a side-effect $handle = fopen(self::OUTFILE, "a") or die("Cannot open"); fwrite($handle, date('r') . "\r\n") or die("Cannot write"); fclose($handle);
// Return some text return 'Here I am!'; } }