3 * Tag hooks provided by MediaWiki core
9 * Various tag hooks, registered in Parser::firstCallInit()
14 * @param $parser Parser
16 static function register( $parser ) {
18 $parser->setHook( 'pre', array( __CLASS__
, 'pre' ) );
19 $parser->setHook( 'nowiki', array( __CLASS__
, 'nowiki' ) );
20 $parser->setHook( 'gallery', array( __CLASS__
, 'gallery' ) );
22 $parser->setHook( 'html', array( __CLASS__
, 'html' ) );
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.
32 * @param array $attribs
33 * @param Parser $parser
36 static function pre( $text, $attribs, $parser ) {
37 // Backwards-compatibility hack
38 $content = StringUtils
::delimiterReplace( '<nowiki>', '</nowiki>', '$1', $text, 'i' );
40 $attribs = Sanitizer
::validateTagAttributes( $attribs, 'pre' );
41 return Xml
::openElement( 'pre', $attribs ) .
42 Xml
::escapeTagsOnly( $content ) .
47 * Core parser tag hook function for 'html', used only when
48 * $wgRawHtml is enabled.
50 * This is potentially unsafe and should be used only in very careful
51 * circumstances, as the contents are emitted as raw HTML.
53 * Uses undocumented extended tag hook return values, introduced in r61913.
55 * @param $content string
56 * @param $attributes array
57 * @param $parser Parser
60 static function html( $content, $attributes, $parser ) {
63 return array( $content, 'markerType' => 'nowiki' );
65 throw new MWException( '<html> extension tag encountered unexpectedly' );
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.
74 * Uses undocumented extended tag hook return values, introduced in r61913.
76 * @param $content string
77 * @param $attributes array
78 * @param $parser Parser
81 static function nowiki( $content, $attributes, $parser ) {
82 $content = strtr( $content, array( '-{' => '-{', '}-' => '}-' ) );
83 return array( Xml
::escapeTagsOnly( $content ), 'markerType' => 'nowiki' );
87 * Core parser tag hook function for 'gallery'.
89 * Renders a thumbnail list of the given images, with optional captions.
90 * Full syntax documented on the wiki:
92 * http://www.mediawiki.org/wiki/Help:Images#Gallery_syntax
94 * @todo break Parser::renderImageGallery out here too.
96 * @param string $content
97 * @param array $attributes
98 * @param Parser $parser
101 static function gallery( $content, $attributes, $parser ) {
102 return $parser->renderImageGallery( $content, $attributes );