X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/8989532d3de45b196373107c7a812a68ac0ff2d9..d75ce11339b35963b5f8c3d53190819c1c025716:/includes/parser/CoreTagHooks.php diff --git a/includes/parser/CoreTagHooks.php b/includes/parser/CoreTagHooks.php new file mode 100644 index 00000000..7cc8260e --- /dev/null +++ b/includes/parser/CoreTagHooks.php @@ -0,0 +1,49 @@ +setHook( 'pre', array( __CLASS__, 'pre' ) ); + $parser->setHook( 'nowiki', array( __CLASS__, 'nowiki' ) ); + $parser->setHook( 'gallery', array( __CLASS__, 'gallery' ) ); + if ( $wgRawHtml ) { + $parser->setHook( 'html', array( __CLASS__, 'html' ) ); + } + if ( $wgUseTeX ) { + $parser->setHook( 'math', array( __CLASS__, 'math' ) ); + } + } + + static function pre( $text, $attribs, $parser ) { + // Backwards-compatibility hack + $content = StringUtils::delimiterReplace( '', '', '$1', $text, 'i' ); + + $attribs = Sanitizer::validateTagAttributes( $attribs, 'pre' ); + return Xml::openElement( 'pre', $attribs ) . + Xml::escapeTagsOnly( $content ) . + ''; + } + + static function html( $content, $attributes, $parser ) { + global $wgRawHtml; + if( $wgRawHtml ) { + return array( $content, 'markerType' => 'nowiki' ); + } else { + throw new MWException( ' extension tag encountered unexpectedly' ); + } + } + + static function nowiki( $content, $attributes, $parser ) { + $content = strtr( $content, array( '-{' => '-{', '}-' => '}-' ) ); + return array( Xml::escapeTagsOnly( $content ), 'markerType' => 'nowiki' ); + } + + static function math( $content, $attributes, $parser ) { + global $wgContLang; + return $wgContLang->armourMath( MathRenderer::renderMath( $content, $attributes ) ); + } + + static function gallery( $content, $attributes, $parser ) { + return $parser->renderImageGallery( $content, $attributes ); + } +}