MediaWiki
REL1_19
|
00001 <?php 00028 class ParserTestParserHook { 00029 00030 static function setup( &$parser ) { 00031 $parser->setHook( 'tag', array( __CLASS__, 'dumpHook' ) ); 00032 $parser->setHook( 'statictag', array( __CLASS__, 'staticTagHook' ) ); 00033 return true; 00034 } 00035 00036 static function dumpHook( $in, $argv ) { 00037 ob_start(); 00038 var_dump( 00039 $in, 00040 $argv 00041 ); 00042 $ret = ob_get_clean(); 00043 00044 return "<pre>\n$ret</pre>"; 00045 } 00046 00047 static function staticTagHook( $in, $argv, $parser ) { 00048 if ( ! count( $argv ) ) { 00049 $parser->static_tag_buf = $in; 00050 return ''; 00051 } elseif ( count( $argv ) === 1 && isset( $argv['action'] ) 00052 && $argv['action'] === 'flush' && $in === null ) 00053 { 00054 // Clear the buffer, we probably don't need to 00055 if ( isset( $parser->static_tag_buf ) ) { 00056 $tmp = $parser->static_tag_buf; 00057 } else { 00058 $tmp = ''; 00059 } 00060 $parser->static_tag_buf = null; 00061 return $tmp; 00062 } else 00063 // wtf? 00064 return 00065 "\nCall this extension as <statictag>string</statictag> or as" . 00066 " <statictag action=flush/>, not in any other way.\n" . 00067 "text: " . var_export( $in, true ) . "\n" . 00068 "argv: " . var_export( $argv, true ) . "\n"; 00069 } 00070 }