* (bug 28719) Do not call mLinkHolders __destruct explicitly
[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 * @param $parser Parser
15 * @return void
16 */
17 static function register( $parser ) {
18 global $wgRawHtml;
19 $parser->setHook( 'pre', array( __CLASS__, 'pre' ) );
20 $parser->setHook( 'nowiki', array( __CLASS__, 'nowiki' ) );
21 $parser->setHook( 'gallery', array( __CLASS__, 'gallery' ) );
22 if ( $wgRawHtml ) {
23 $parser->setHook( 'html', array( __CLASS__, 'html' ) );
24 }
25 }
26
27 /**
28 * Core parser tag hook function for 'pre'.
29 * Text is treated roughly as 'nowiki' wrapped in an HTML 'pre' tag;
30 * valid HTML attributes are passed on.
31 *
32 * @param string $text
33 * @param array $attribs
34 * @param Parser $parser
35 * @return string HTML
36 */
37 static function pre( $text, $attribs, $parser ) {
38 // Backwards-compatibility hack
39 $content = StringUtils::delimiterReplace( '<nowiki>', '</nowiki>', '$1', $text, 'i' );
40
41 $attribs = Sanitizer::validateTagAttributes( $attribs, 'pre' );
42 return Xml::openElement( 'pre', $attribs ) .
43 Xml::escapeTagsOnly( $content ) .
44 '</pre>';
45 }
46
47 /**
48 * Core parser tag hook function for 'html', used only when
49 * $wgRawHtml is enabled.
50 *
51 * This is potentially unsafe and should be used only in very careful
52 * circumstances, as the contents are emitted as raw HTML.
53 *
54 * Uses undocumented extended tag hook return values, introduced in r61913.
55 *
56 * @param string $content
57 * @param array $attribs
58 * @param Parser $parser
59 * @return array
60 */
61 static function html( $content, $attributes, $parser ) {
62 global $wgRawHtml;
63 if( $wgRawHtml ) {
64 return array( $content, 'markerType' => 'nowiki' );
65 } else {
66 throw new MWException( '<html> extension tag encountered unexpectedly' );
67 }
68 }
69
70 /**
71 * Core parser tag hook function for 'nowiki'. Text within this section
72 * gets interpreted as a string of text with HTML-compatible character
73 * references, and wiki markup within it will not be expanded.
74 *
75 * Uses undocumented extended tag hook return values, introduced in r61913.
76 *
77 * @param string $content
78 * @param array $attribs
79 * @param Parser $parser
80 * @return array
81 */
82 static function nowiki( $content, $attributes, $parser ) {
83 $content = strtr( $content, array( '-{' => '-&#123;', '}-' => '&#125;-' ) );
84 return array( Xml::escapeTagsOnly( $content ), 'markerType' => 'nowiki' );
85 }
86
87 /**
88 * Core parser tag hook function for 'gallery'.
89 *
90 * Renders a thumbnail list of the given images, with optional captions.
91 * Full syntax documented on the wiki:
92 *
93 * http://www.mediawiki.org/wiki/Help:Images#Gallery_syntax
94 *
95 * @todo break Parser::renderImageGallery out here too.
96 *
97 * @param string $content
98 * @param array $attributes
99 * @param Parser $parser
100 * @return string HTML
101 */
102 static function gallery( $content, $attributes, $parser ) {
103 return $parser->renderImageGallery( $content, $attributes );
104 }
105 }