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