r100382 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100381‎ | r100382 | r100383 >
Date:21:29, 20 October 2011
Author:jeroendedauw
Status:deferred (Comments)
Tags:
Comment:
applied patch by Van de Bugger from bug 31830
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_Info.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/languages/SMW_Messages.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php
@@ -86,6 +86,8 @@
8787 $wgHooks['PageSchemasRegisterHandlers'][] = 'SMWPageSchemas::registerClass';
8888 $wgHooks['ParserFirstCallInit'][] = 'SMWSMWDoc::staticInit';
8989 $wgHooks['LanguageGetMagic'][] = 'SMWSMWDoc::staticMagic';
 90+ $wgHooks['ParserFirstCallInit'][] = 'SMWInfo::staticInit';
 91+ $wgHooks['LanguageGetMagic'][] = 'SMWInfo::staticMagic';
9092
9193 if ( version_compare( $wgVersion, '1.17alpha', '>=' ) ) {
9294 // For MediaWiki 1.17 alpha and later.
@@ -606,7 +608,6 @@
607609 function smwfAddMagicWords( &$magicWords, $langCode ) {
608610 $magicWords['ask'] = array( 0, 'ask' );
609611 $magicWords['show'] = array( 0, 'show' );
610 - $magicWords['info'] = array( 0, 'info' );
611612 $magicWords['subobject'] = array( 0, 'subobject' );
612613 $magicWords['concept'] = array( 0, 'concept' );
613614 $magicWords['set'] = array( 0, 'set' );
@@ -659,7 +660,6 @@
660661 function smwfRegisterParserFunctions( Parser &$parser ) {
661662 $parser->setFunctionHook( 'ask', array( 'SMWAsk', 'render' ) );
662663 $parser->setFunctionHook( 'show', array( 'SMWShow', 'render' ) );
663 - $parser->setFunctionHook( 'info', array( 'SMWInfo', 'render' ) );
664664 $parser->setFunctionHook( 'subobject', array( 'SMWSubobject', 'render' ) );
665665 $parser->setFunctionHook( 'concept', array( 'SMWConcept', 'render' ) );
666666 $parser->setFunctionHook( 'set', array( 'SMWSet', 'render' ) );
Index: trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_Info.php
@@ -13,38 +13,102 @@
1414 * @author Markus Krötzsch
1515 * @author Jeroen De Dauw
1616 */
17 -class SMWInfo {
 17+class SMWInfo extends ParserHook {
1818
1919 /**
20 - * Method for handling the info parser function.
 20+ * Renders and returns the output.
 21+ * @see ParserHook::render
2122 *
22 - * @since 1.5.3
 23+ * @since 1.7
2324 *
24 - * @param Parser $parser
 25+ * @param array $parameters
 26+ *
 27+ * @return string
2528 */
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+ );
2940
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() ) {
4142 global $wgOut;
4243 SMWOutputs::commitToOutputPage( $wgOut );
4344 }
4445 else {
45 - SMWOutputs::commitToParser( $parser );
 46+ SMWOutputs::commitToParser( $this->parser );
4647 }
4748
4849 return $result;
4950 }
5051
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 @@
381381 'smw-paramdesc-category-delim' => 'The delimiter',
382382 'smw-paramdesc-category-template' => 'A template to format the items with',
383383 '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".',
384388 );
385389
386390 /** Message documentation (Message documentation)

Follow-up revisions

RevisionCommit summaryAuthorDate
r100400Follow up to r100382;jeroendedauw00:43, 21 October 2011

Comments

#Comment by Siebrand (talk | contribs)   22:05, 20 October 2011

Please add message documentation for the newly added messages. Thanks.

#Comment by Nikerabbit (talk | contribs)   06:28, 21 October 2011

Why some have since 1.6 and some since 1.7?

#Comment by P858snake (talk | contribs)   06:31, 21 October 2011

Semantic have their own versioning scheme

#Comment by Nikerabbit (talk | contribs)   06:52, 21 October 2011

I know that, but surely code added in one commit should all be "since the same version". Is it just copying tags from the base class or what?

#Comment by Jeroen De Dauw (talk | contribs)   16:08, 21 October 2011

This is a copy paste error, it should be 1.7.

Status & tagging log