MediaWiki
REL1_22
|
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 return "<pre>\n" . 00038 var_export( $in, true ) . "\n" . 00039 var_export( $argv, true ) . "\n" . 00040 "</pre>"; 00041 } 00042 00043 static function staticTagHook( $in, $argv, $parser ) { 00044 if ( !count( $argv ) ) { 00045 $parser->static_tag_buf = $in; 00046 return ''; 00047 } elseif ( count( $argv ) === 1 && isset( $argv['action'] ) 00048 && $argv['action'] === 'flush' && $in === null 00049 ) { 00050 // Clear the buffer, we probably don't need to 00051 if ( isset( $parser->static_tag_buf ) ) { 00052 $tmp = $parser->static_tag_buf; 00053 } else { 00054 $tmp = ''; 00055 } 00056 $parser->static_tag_buf = null; 00057 return $tmp; 00058 } else { // wtf? 00059 return 00060 "\nCall this extension as <statictag>string</statictag> or as" . 00061 " <statictag action=flush/>, not in any other way.\n" . 00062 "text: " . var_export( $in, true ) . "\n" . 00063 "argv: " . var_export( $argv, true ) . "\n"; 00064 } 00065 } 00066 }