Localisation updates from http://translatewiki.net.
[T119942Repr.git] / Parser_hook.php
blobc751805661be5dc376eda80306f72fb364147985
1 <?php
2 if ( !defined( 'MEDIAWIKI' ) ) die();
3 /**
4 * A parser hook example, use it on a page like
5 * <hook arg1="foo" arg2="bar" ...>input</hook>
7 * @file
8 * @ingroup Extensions
10 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
11 * @author Niklas Laxström
12 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
13 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
16 $wgExtensionCredits['parserhook'][] = array(
17 'path' => __FILE__,
18 'name' => 'Parser hook',
19 'description' => 'a sample parser hook',
20 'author' => 'Ævar Arnfjörð Bjarmason'
23 /* Register the registration function */
24 $wgHooks['ParserFirstCallInit'][] = 'wfParserHook';
26 /**
27 * The registration function.
29 function wfParserHook( $parser ) {
30 $parser->setHook( 'hook' , 'wfParserHookParse' );
31 // Always return true.
32 return true;
35 /**
36 * @param String $data The input passed to <hook>
37 * @param Array $params The attributes of the <hook> element in array form
38 * @param Parser $parser Not used in this extension, but can be used to
39 * turn wikitext into html or do some other "advanced" stuff
40 * @param PPFrame $frame Not used in this extension, but can be used
41 * to see what template arguments ({{{1}}}) this hook was used with.
43 * @return String HTML to put in page at spot where <hook> tag is.
45 function wfParserHookParse( $data, $params, $parser, $frame ) {
46 // Very important to escape user data to prevent an XSS
47 // security vulnerability.
48 // print_r just turns an array into something readable.
49 $paramsEscaped = htmlspecialchars( print_r( $params, true ) );
50 $dataEscaped = htmlspecialchars( $data );
52 if ( !count( $params ) ) {
53 return $dataEscaped;
54 } else {
55 return '<pre>' . $dataEscaped . "\n" . $paramsEscaped . '</pre>';