]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/parser/CoreTagHooks.php
MediaWiki 1.16.0
[autoinstalls/mediawiki.git] / includes / parser / CoreTagHooks.php
1 <?php
2
3 class CoreTagHooks {
4         static function register( $parser ) {
5                 global $wgRawHtml, $wgUseTeX;
6                 $parser->setHook( 'pre', array( __CLASS__, 'pre' ) );
7                 $parser->setHook( 'nowiki', array( __CLASS__, 'nowiki' ) );
8                 $parser->setHook( 'gallery', array( __CLASS__, 'gallery' ) );
9                 if ( $wgRawHtml ) {
10                         $parser->setHook( 'html', array( __CLASS__, 'html' ) );
11                 }
12                 if ( $wgUseTeX ) {
13                         $parser->setHook( 'math', array( __CLASS__, 'math' ) );
14                 }
15         }
16
17         static function pre( $text, $attribs, $parser ) {
18                 // Backwards-compatibility hack
19                 $content = StringUtils::delimiterReplace( '<nowiki>', '</nowiki>', '$1', $text, 'i' );
20
21                 $attribs = Sanitizer::validateTagAttributes( $attribs, 'pre' );
22                 return Xml::openElement( 'pre', $attribs ) .
23                         Xml::escapeTagsOnly( $content ) .
24                         '</pre>';
25         }
26
27         static function html( $content, $attributes, $parser ) {
28                 global $wgRawHtml;
29                 if( $wgRawHtml ) {
30                         return array( $content, 'markerType' => 'nowiki' );
31                 } else {
32                         throw new MWException( '<html> extension tag encountered unexpectedly' );
33                 }
34         }
35
36         static function nowiki( $content, $attributes, $parser ) {
37                 $content = strtr( $content, array( '-{' => '-&#123;', '}-' => '&#125;-' ) );
38                 return array( Xml::escapeTagsOnly( $content ), 'markerType' => 'nowiki' );
39         }
40
41         static function math( $content, $attributes, $parser ) {
42                 global $wgContLang;
43                 return $wgContLang->armourMath( MathRenderer::renderMath( $content, $attributes ) );
44         }
45
46         static function gallery( $content, $attributes, $parser ) {
47                 return $parser->renderImageGallery( $content, $attributes );
48         }
49 }