From 4275a4dc886d0a0ac9cd1d5eccdd95cdb673561c Mon Sep 17 00:00:00 2001
From: =?utf8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?=
Date: Mon, 27 Feb 2006 02:53:03 +0000
Subject: [PATCH] * 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:
---
maintenance/parserTests.inc | 1 +
maintenance/parserTests.txt | 24 ++++++++++++
maintenance/parserTestsStaticParserHook.php | 41 +++++++++++++++++++++
3 files changed, 66 insertions(+)
create mode 100644 maintenance/parserTestsStaticParserHook.php
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"
+ );
+}
--
2.20.1