00001 <?php
00002
00003 class CoreTagHooks {
00004 static function register( $parser ) {
00005 global $wgRawHtml, $wgUseTeX;
00006 $parser->setHook( 'pre', array( __CLASS__, 'pre' ) );
00007 $parser->setHook( 'nowiki', array( __CLASS__, 'nowiki' ) );
00008 $parser->setHook( 'gallery', array( __CLASS__, 'gallery' ) );
00009 if ( $wgRawHtml ) {
00010 $parser->setHook( 'html', array( __CLASS__, 'html' ) );
00011 }
00012 if ( $wgUseTeX ) {
00013 $parser->setHook( 'math', array( __CLASS__, 'math' ) );
00014 }
00015 }
00016
00017 static function pre( $text, $attribs, $parser ) {
00018
00019 $content = StringUtils::delimiterReplace( '<nowiki>', '</nowiki>', '$1', $text, 'i' );
00020
00021 $attribs = Sanitizer::validateTagAttributes( $attribs, 'pre' );
00022 return Xml::openElement( 'pre', $attribs ) .
00023 Xml::escapeTagsOnly( $content ) .
00024 '</pre>';
00025 }
00026
00027 static function html( $content, $attributes, $parser ) {
00028 global $wgRawHtml;
00029 if( $wgRawHtml ) {
00030 return array( $content, 'markerType' => 'nowiki' );
00031 } else {
00032 throw new MWException( '<html> extension tag encountered unexpectedly' );
00033 }
00034 }
00035
00036 static function nowiki( $content, $attributes, $parser ) {
00037 $content = strtr( $content, array( '-{' => '-{', '}-' => '}-' ) );
00038 return array( Xml::escapeTagsOnly( $content ), 'markerType' => 'nowiki' );
00039 }
00040
00041 static function math( $content, $attributes, $parser ) {
00042 global $wgContLang;
00043 return $wgContLang->armourMath( MathRenderer::renderMath( $content, $attributes ) );
00044 }
00045
00046 static function gallery( $content, $attributes, $parser ) {
00047 return $parser->renderImageGallery( $content, $attributes );
00048 }
00049 }