More return type 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 static function math( $content, $attributes, $parser ) {
56 global $wgContLang;
57 return $wgContLang->armourMath( MathRenderer::renderMath( $content, $attributes, $parser->getOptions() ) );
58 }
59
60 /**
61 * @static
62 * @param $content
63 * @param $attributes
64 * @param $parser Parser
65 * @return
66 */
67 static function gallery( $content, $attributes, $parser ) {
68 return $parser->renderImageGallery( $content, $attributes );
69 }
70 }