Index: trunk/extensions/examples/Parser_hook.php |
— | — | @@ -20,22 +20,39 @@ |
21 | 21 | 'author' => 'Ævar Arnfjörð Bjarmason' |
22 | 22 | ); |
23 | 23 | |
| 24 | +/* Register the registration function */ |
24 | 25 | $wgHooks['ParserFirstCallInit'][] = 'wfParserHook'; |
25 | 26 | |
| 27 | +/** |
| 28 | + * The registration function. |
| 29 | + */ |
26 | 30 | function wfParserHook( $parser ) { |
27 | 31 | $parser->setHook( 'hook' , 'wfParserHookParse' ); |
| 32 | + // Always return true. |
28 | 33 | return true; |
29 | 34 | } |
30 | 35 | |
31 | 36 | /** |
32 | | - * @param string $in The input passed to <hook> |
33 | | - * @param array $argv The attributes of the <hook> element in array form |
| 37 | + * @param String $data The input passed to <hook> |
| 38 | + * @param Array $params The attributes of the <hook> element in array form |
| 39 | + * @param Parser $parser Not used in this extension, but can be used to |
| 40 | + * turn wikitext into html or do some other "advanced" stuff |
| 41 | + * @param PPFrame $frame Not used in this extension, but can be used |
| 42 | + * to see what template arguments ({{{1}}}) this hook was used with. |
| 43 | + * |
| 44 | + * @return String HTML to put in page at spot where <hook> tag is. |
34 | 45 | */ |
35 | | -function wfParserHookParse( $data, $params, $parser ) { |
| 46 | +function wfParserHookParse( $data, $params, $parser, $frame ) { |
| 47 | + // Very important to escape user data to prevent an XSS |
| 48 | + // security vulnerability. |
| 49 | + // print_r just turns an array into something readable. |
| 50 | + $paramsEscaped = htmlspecialchars( print_r( $params, true ) ); |
| 51 | + $dataEscaped = htmlspecialchars( $data ); |
| 52 | + |
36 | 53 | if ( !count( $params ) ) { |
37 | | - return $data; |
| 54 | + return $dataEscaped; |
38 | 55 | } else { |
39 | | - return '<pre>' . $data . "\n" . print_r( $params, true ) . '</pre>'; |
| 56 | + return '<pre>' . $dataEscaped . "\n" . $paramsEscaped . '</pre>'; |
40 | 57 | } |
41 | 58 | } |
42 | 59 | |