More function and variable documentation
[lhc/web/wiklou.git] / includes / parser / CoreTagHooks.php
1 <?php
2 /**
3 * Tag hooks provided by MediaWiki core
4 *
5 * @file
6 */
7
8 /**
9 * Various tag hooks, registered in Parser::firstCallInit()
10 * @ingroup Parser
11 */
12 class CoreTagHooks {
13 /**
14 * @static
15 * @param $parser Parser
16 * @return void
17 */
18 static function register( $parser ) {
19 global $wgRawHtml, $wgUseTeX;
20 $parser->setHook( 'pre', array( __CLASS__, 'pre' ) );
21 $parser->setHook( 'nowiki', array( __CLASS__, 'nowiki' ) );
22 $parser->setHook( 'gallery', array( __CLASS__, 'gallery' ) );
23 if ( $wgRawHtml ) {
24 $parser->setHook( 'html', array( __CLASS__, 'html' ) );
25 }
26 if ( $wgUseTeX ) {
27 $parser->setHook( 'math', array( __CLASS__, 'math' ) );
28 }
29 }
30
31 static function pre( $text, $attribs, $parser ) {
32 // Backwards-compatibility hack
33 $content = StringUtils::delimiterReplace( '<nowiki>', '</nowiki>', '$1', $text, 'i' );
34
35 $attribs = Sanitizer::validateTagAttributes( $attribs, 'pre' );
36 return Xml::openElement( 'pre', $attribs ) .
37 Xml::escapeTagsOnly( $content ) .
38 '</pre>';
39 }
40
41 static function html( $content, $attributes, $parser ) {
42 global $wgRawHtml;
43 if( $wgRawHtml ) {
44 return array( $content, 'markerType' => 'nowiki' );
45 } else {
46 throw new MWException( '<html> extension tag encountered unexpectedly' );
47 }
48 }
49
50 static function nowiki( $content, $attributes, $parser ) {
51 $content = strtr( $content, array( '-{' => '-&#123;', '}-' => '&#125;-' ) );
52 return array( Xml::escapeTagsOnly( $content ), 'markerType' => 'nowiki' );
53 }
54
55 /**
56 * @static
57 * @param $content
58 * @param $attributes
59 * @param $parser Parser
60 * @return
61 */
62 static function math( $content, $attributes, $parser ) {
63 global $wgContLang;
64 return $wgContLang->armourMath( MathRenderer::renderMath( $content, $attributes, $parser->getOptions() ) );
65 }
66
67 /**
68 * @static
69 * @param $content
70 * @param $attributes
71 * @param $parser Parser
72 * @return
73 */
74 static function gallery( $content, $attributes, $parser ) {
75 return $parser->renderImageGallery( $content, $attributes );
76 }
77 }