X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/tests/parser/ParserTestParserHook.php diff --git a/tests/parser/ParserTestParserHook.php b/tests/parser/ParserTestParserHook.php new file mode 100644 index 00000000..5bf50ead --- /dev/null +++ b/tests/parser/ParserTestParserHook.php @@ -0,0 +1,67 @@ + + */ + +class ParserTestParserHook { + + static function setup( &$parser ) { + $parser->setHook( 'tag', [ __CLASS__, 'dumpHook' ] ); + $parser->setHook( 'tåg', [ __CLASS__, 'dumpHook' ] ); + $parser->setHook( 'statictag', [ __CLASS__, 'staticTagHook' ] ); + return true; + } + + static function dumpHook( $in, $argv ) { + return "
\n" .
+			var_export( $in, true ) . "\n" .
+			var_export( $argv, true ) . "\n" .
+			"
"; + } + + static function staticTagHook( $in, $argv, $parser ) { + if ( !count( $argv ) ) { + $parser->static_tag_buf = $in; + return ''; + } elseif ( count( $argv ) === 1 && isset( $argv['action'] ) + && $argv['action'] === 'flush' && $in === null + ) { + // Clear the buffer, we probably don't need to + if ( isset( $parser->static_tag_buf ) ) { + $tmp = $parser->static_tag_buf; + } else { + $tmp = ''; + } + $parser->static_tag_buf = null; + return $tmp; + } else { // wtf? + return + "\nCall this extension as string or as" . + " , not in any other way.\n" . + "text: " . var_export( $in, true ) . "\n" . + "argv: " . var_export( $argv, true ) . "\n"; + } + } +}