From: Ævar Arnfjörð Bjarmason Date: Mon, 27 Feb 2006 02:53:03 +0000 (+0000) Subject: * Add a parser test for parser hooks inside comments which are currently X-Git-Tag: 1.6.0~266 X-Git-Url: https://git.cyclocoop.org//%22?a=commitdiff_plain;h=4275a4dc886d0a0ac9cd1d5eccdd95cdb673561c;p=lhc%2Fweb%2Fwiklou.git * Add a parser test for parser hooks inside comments which are currently parsed (called) by the parser but shouldn't, the following will output "hello, world" in the hook: --- diff --git a/maintenance/parserTests.inc b/maintenance/parserTests.inc index 7de93eba30..e4610505bd 100644 --- a/maintenance/parserTests.inc +++ b/maintenance/parserTests.inc @@ -34,6 +34,7 @@ require_once( "$IP/includes/BagOStuff.php" ); require_once( "$IP/languages/LanguageUtf8.php" ); require_once( "$IP/includes/Hooks.php" ); require_once( "$IP/maintenance/parserTestsParserHook.php" ); +require_once( "$IP/maintenance/parserTestsStaticParserHook.php" ); require_once( "$IP/maintenance/parserTestsParserTime.php" ); /** diff --git a/maintenance/parserTests.txt b/maintenance/parserTests.txt index 5e90909cac..eeefcaa576 100644 --- a/maintenance/parserTests.txt +++ b/maintenance/parserTests.txt @@ -3456,6 +3456,30 @@ array(4) {

!! end +### +### (see maintenance/parserTestsStaticParserHook.php for the extension) +### + +!! test +Parser hook: static parser hook not inside a comment +!! input +hello, world + +!! result +

hello, world +

+!! end + + +!! test +Parser hook: static parser hook inside a comment +!! input + + +!! result +


+

+!! end # Nested template calls; this case was broken by Parser.php rev 1.506, # since reverted. diff --git a/maintenance/parserTestsStaticParserHook.php b/maintenance/parserTestsStaticParserHook.php new file mode 100644 index 0000000000..820a06f866 --- /dev/null +++ b/maintenance/parserTestsStaticParserHook.php @@ -0,0 +1,41 @@ + + * @copyright Copyright © 2005, 2006 Ævar Arnfjörð Bjarmason + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later + */ + +$wgHooks['ParserTestParser'][] = 'wfParserTestStaticParserHookSetup'; + +function wfParserTestStaticParserHookSetup( &$parser ) { + $parser->setHook( 'statictag', 'wfParserTestStaticParserHookHook' ); + + return true; +} + +function wfParserTestStaticParserHookHook( $in, $argv ) { + static $buf = null; + + if ( ! count( $argv ) ) { + $buf = $in; + return ''; + } else if ( count( $argv ) === 1 && $argv['action'] === 'flush' && $in === null ) { + // Clear the buffer, we probably don't need to + $tmp = $buf; + $buf = null; + return $tmp; + } else + // wtf? + die( + "\nCall this extension as string or as" . + " , not in any other way.\n" + ); +}