MediaWiki  master
parserTestsParserHook.php
Go to the documentation of this file.
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
00059                         // wtf?
00060                         return
00061                                 "\nCall this extension as <statictag>string</statictag> or as" .
00062                                 " <statictag action=flush/>, not in any other way.\n" .
00063                                 "text: " . var_export( $in, true ) . "\n" .
00064                                 "argv: " . var_export( $argv, true ) . "\n";
00065         }
00066 }