Add a version number and user-agent string to ForeignAPIRepo.
[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 static function register( $parser ) {
14 global $wgRawHtml, $wgUseTeX;
15 $parser->setHook( 'pre', array( __CLASS__, 'pre' ) );
16 $parser->setHook( 'nowiki', array( __CLASS__, 'nowiki' ) );
17 $parser->setHook( 'gallery', array( __CLASS__, 'gallery' ) );
18 if ( $wgRawHtml ) {
19 $parser->setHook( 'html', array( __CLASS__, 'html' ) );
20 }
21 if ( $wgUseTeX ) {
22 $parser->setHook( 'math', array( __CLASS__, 'math' ) );
23 }
24 }
25
26 static function pre( $text, $attribs, $parser ) {
27 // Backwards-compatibility hack
28 $content = StringUtils::delimiterReplace( '<nowiki>', '</nowiki>', '$1', $text, 'i' );
29
30 $attribs = Sanitizer::validateTagAttributes( $attribs, 'pre' );
31 return Xml::openElement( 'pre', $attribs ) .
32 Xml::escapeTagsOnly( $content ) .
33 '</pre>';
34 }
35
36 static function html( $content, $attributes, $parser ) {
37 global $wgRawHtml;
38 if( $wgRawHtml ) {
39 return array( $content, 'markerType' => 'nowiki' );
40 } else {
41 throw new MWException( '<html> extension tag encountered unexpectedly' );
42 }
43 }
44
45 static function nowiki( $content, $attributes, $parser ) {
46 $content = strtr( $content, array( '-{' => '-&#123;', '}-' => '&#125;-' ) );
47 return array( Xml::escapeTagsOnly( $content ), 'markerType' => 'nowiki' );
48 }
49
50 static function math( $content, $attributes, $parser ) {
51 global $wgContLang;
52 return $wgContLang->armourMath( MathRenderer::renderMath( $content, $attributes, $parser->getOptions() ) );
53 }
54
55 static function gallery( $content, $attributes, $parser ) {
56 return $parser->renderImageGallery( $content, $attributes );
57 }
58 }