Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php |
— | — | @@ -86,6 +86,8 @@ |
87 | 87 | $wgHooks['PageSchemasRegisterHandlers'][] = 'SMWPageSchemas::registerClass'; |
88 | 88 | $wgHooks['ParserFirstCallInit'][] = 'SMWSMWDoc::staticInit'; |
89 | 89 | $wgHooks['LanguageGetMagic'][] = 'SMWSMWDoc::staticMagic'; |
| 90 | + $wgHooks['ParserFirstCallInit'][] = 'SMWInfo::staticInit'; |
| 91 | + $wgHooks['LanguageGetMagic'][] = 'SMWInfo::staticMagic'; |
90 | 92 | |
91 | 93 | if ( version_compare( $wgVersion, '1.17alpha', '>=' ) ) { |
92 | 94 | // For MediaWiki 1.17 alpha and later. |
— | — | @@ -606,7 +608,6 @@ |
607 | 609 | function smwfAddMagicWords( &$magicWords, $langCode ) { |
608 | 610 | $magicWords['ask'] = array( 0, 'ask' ); |
609 | 611 | $magicWords['show'] = array( 0, 'show' ); |
610 | | - $magicWords['info'] = array( 0, 'info' ); |
611 | 612 | $magicWords['subobject'] = array( 0, 'subobject' ); |
612 | 613 | $magicWords['concept'] = array( 0, 'concept' ); |
613 | 614 | $magicWords['set'] = array( 0, 'set' ); |
— | — | @@ -659,7 +660,6 @@ |
660 | 661 | function smwfRegisterParserFunctions( Parser &$parser ) { |
661 | 662 | $parser->setFunctionHook( 'ask', array( 'SMWAsk', 'render' ) ); |
662 | 663 | $parser->setFunctionHook( 'show', array( 'SMWShow', 'render' ) ); |
663 | | - $parser->setFunctionHook( 'info', array( 'SMWInfo', 'render' ) ); |
664 | 664 | $parser->setFunctionHook( 'subobject', array( 'SMWSubobject', 'render' ) ); |
665 | 665 | $parser->setFunctionHook( 'concept', array( 'SMWConcept', 'render' ) ); |
666 | 666 | $parser->setFunctionHook( 'set', array( 'SMWSet', 'render' ) ); |
Index: trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_Info.php |
— | — | @@ -13,38 +13,102 @@ |
14 | 14 | * @author Markus Krötzsch |
15 | 15 | * @author Jeroen De Dauw |
16 | 16 | */ |
17 | | -class SMWInfo { |
| 17 | +class SMWInfo extends ParserHook { |
18 | 18 | |
19 | 19 | /** |
20 | | - * Method for handling the info parser function. |
| 20 | + * Renders and returns the output. |
| 21 | + * @see ParserHook::render |
21 | 22 | * |
22 | | - * @since 1.5.3 |
| 23 | + * @since 1.7 |
23 | 24 | * |
24 | | - * @param Parser $parser |
| 25 | + * @param array $parameters |
| 26 | + * |
| 27 | + * @return string |
25 | 28 | */ |
26 | | - public static function render( Parser &$parser ) { |
27 | | - $params = func_get_args(); |
28 | | - array_shift( $params ); // We already know the $parser ... |
| 29 | + public function render( array $parameters ) { |
| 30 | + /** |
| 31 | + * Non-escaping is safe bacause a user's message is passed through parser, which will |
| 32 | + * handle unsafe HTM elements. |
| 33 | + */ |
| 34 | + $result = smwfEncodeMessages( |
| 35 | + array( $parameters['message'] ), |
| 36 | + $parameters['icon'], |
| 37 | + ' <!--br-->', |
| 38 | + false // No escaping. |
| 39 | + ); |
29 | 40 | |
30 | | - $content = array_shift( $params ); // First parameter is the info message. |
31 | | - $icon = array_shift( $params ); // Second parameter is icon to use or null when not provided. |
32 | | - |
33 | | - if ( is_null( $icon ) || $icon === '' || !in_array( $icon, array( 'info', 'warning' ) ) ) { |
34 | | - $icon = 'info'; |
35 | | - } |
36 | | - |
37 | | - $result = smwfEncodeMessages( array( $content ), $icon ); |
38 | | - |
39 | | - global $wgTitle; |
40 | | - if ( !is_null( $wgTitle ) && $wgTitle->isSpecialPage() ) { |
| 41 | + if ( !is_null( $this->parser->getTitle() ) && $this->parser->getTitle()->isSpecialPage() ) { |
41 | 42 | global $wgOut; |
42 | 43 | SMWOutputs::commitToOutputPage( $wgOut ); |
43 | 44 | } |
44 | 45 | else { |
45 | | - SMWOutputs::commitToParser( $parser ); |
| 46 | + SMWOutputs::commitToParser( $this->parser ); |
46 | 47 | } |
47 | 48 | |
48 | 49 | return $result; |
49 | 50 | } |
50 | 51 | |
51 | | -} |
\ No newline at end of file |
| 52 | + /** |
| 53 | + * No LSB in pre-5.3 PHP *sigh*. |
| 54 | + * This is to be refactored as soon as php >=5.3 becomes acceptable. |
| 55 | + */ |
| 56 | + public static function staticMagic( array &$magicWords, $langCode ) { |
| 57 | + $instance = new self; |
| 58 | + return $instance->magic( $magicWords, $langCode ); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * No LSB in pre-5.3 PHP *sigh*. |
| 63 | + * This is to be refactored as soon as php >=5.3 becomes acceptable. |
| 64 | + */ |
| 65 | + public static function staticInit( Parser &$parser ) { |
| 66 | + $instance = new self; |
| 67 | + return $instance->init( $parser ); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Gets the name of the parser hook. |
| 72 | + * @see ParserHook::getName |
| 73 | + * |
| 74 | + * @since 1.7 |
| 75 | + * |
| 76 | + * @return string |
| 77 | + */ |
| 78 | + protected function getName() { |
| 79 | + return 'info'; |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * Returns the list of default parameters. |
| 84 | + * @see ParserHook::getDefaultParameters |
| 85 | + * |
| 86 | + * @since 1.6 |
| 87 | + * |
| 88 | + * @return array |
| 89 | + */ |
| 90 | + protected function getDefaultParameters( $type ) { |
| 91 | + return array( 'message', 'icon' ); |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * Returns an array containing the parameter info. |
| 96 | + * @see ParserHook::getParameterInfo |
| 97 | + * |
| 98 | + * @since 1.7 |
| 99 | + * |
| 100 | + * @return array |
| 101 | + */ |
| 102 | + protected function getParameterInfo( $type ) { |
| 103 | + $params = array(); |
| 104 | + |
| 105 | + $params['message'] = new Parameter( 'message' ); |
| 106 | + $params['message']->setMessage( 'smw-info-par-message' ); |
| 107 | + |
| 108 | + $params['icon'] = new Parameter( 'icon', Parameter::TYPE_STRING, 'info' ); |
| 109 | + $params['icon']->addCriteria( new CriterionInArray( 'info', 'warning' ) ); |
| 110 | + $params['icon']->setMessage( 'smw-info-par-icon' ); |
| 111 | + |
| 112 | + return $params; |
| 113 | + } |
| 114 | + |
| 115 | +} |
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_Messages.php |
— | — | @@ -380,6 +380,10 @@ |
381 | 381 | 'smw-paramdesc-category-delim' => 'The delimiter', |
382 | 382 | 'smw-paramdesc-category-template' => 'A template to format the items with', |
383 | 383 | 'smw-paramdesc-category-userparam' => 'A parameter to pass to the template', |
| 384 | + |
| 385 | + // Messages for info parser function. |
| 386 | + 'smw-info-par-message' => 'Message to display.', |
| 387 | + 'smw-info-par-icon' => 'Icon to show, either "info" or "warning".', |
384 | 388 | ); |
385 | 389 | |
386 | 390 | /** Message documentation (Message documentation) |