r92600 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92599‎ | r92600 | r92601 >
Date:23:18, 19 July 2011
Author:jeroendedauw
Status:deferred (Comments)
Tags:
Comment:
added language parameter to mapsdoc hook
Modified paths:
  • /trunk/extensions/Maps/Maps.i18n.php (modified) (history)
  • /trunk/extensions/Maps/includes/parserHooks/Maps_MapsDoc.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/Maps.i18n.php
@@ -46,6 +46,7 @@
4747
4848 // Mapsdoc parser hook
4949 'maps-mapsdoc-par-service' => 'The mapping service to display parameter documentation for.',
 50+ 'maps-mapsdoc-par-language' => 'The language in which to display the documentation. If no such translation is available, English will be used instead.',
5051
5152 // Coordinates parser hook
5253 'maps-coordinates-par-location' => 'The coordinates you want to format.',
Index: trunk/extensions/Maps/includes/parserHooks/Maps_MapsDoc.php
@@ -15,6 +15,15 @@
1616 class MapsMapsDoc extends ParserHook {
1717
1818 /**
 19+ * Field to store the value of the language parameter.
 20+ *
 21+ * @since 1.0.1
 22+ *
 23+ * @var string
 24+ */
 25+ protected $language;
 26+
 27+ /**
1928 * No LSB in pre-5.3 PHP *sigh*.
2029 * This is to be refactored as soon as php >=5.3 becomes acceptable.
2130 */
@@ -57,8 +66,13 @@
5867
5968 $params['service'] = new Parameter( 'service' );
6069 $params['service']->addCriteria( new CriterionInArray( $GLOBALS['egMapsAvailableServices'] ) );
61 - $params['service']->setDescription( wfMsg( 'maps-mapsdoc-par-service' ) );
 70+ $params['service']->setDescription( wfMsgForContent( 'maps-mapsdoc-par-service' ) );
6271
 72+ $params['language'] = new Parameter( 'language' );
 73+ $params['language']->setDefault( $GLOBALS['wgLanguageCode'] );
 74+ //$params['language']->addCriteria( new CriterionInArray( ) );
 75+ $params['language']->setDescription( wfMsgForContent( 'maps-mapsdoc-par-language' ) );
 76+
6377 return $params;
6478 }
6579
@@ -71,7 +85,7 @@
7286 * @return array
7387 */
7488 protected function getDefaultParameters( $type ) {
75 - return array( 'service' );
 89+ return array( 'service', 'language' );
7690 }
7791
7892 /**
@@ -85,12 +99,27 @@
86100 * @return string
87101 */
88102 public function render( array $parameters ) {
 103+ $this->language = $parameters['language'];
 104+
89105 $params = $this->getServiceParameters( $parameters['service'] );
90106
91107 return $this->getParameterTable( $params );
92108 }
93109
94110 /**
 111+ * Message function that takes into account the language parameter.
 112+ *
 113+ * @since 1.0.1
 114+ *
 115+ * @param string $key
 116+ *
 117+ * @return string
 118+ */
 119+ protected function msg( $key ) {
 120+ return wfMsgReal( $key, array(), true, $this->language );
 121+ }
 122+
 123+ /**
95124 * Returns the wikitext for a table listing the provided parameters.
96125 *
97126 * @since 1.0
@@ -110,11 +139,11 @@
111140
112141 if ( count( $tableRows ) > 0 ) {
113142 $tableRows = array_merge( array(
114 - '!' . wfMsg( 'validator-describe-header-parameter' ) ."\n" .
115 - '!' . wfMsg( 'validator-describe-header-aliases' ) ."\n" .
116 - '!' . wfMsg( 'validator-describe-header-type' ) ."\n" .
117 - '!' . wfMsg( 'validator-describe-header-default' ) ."\n" .
118 - '!' . wfMsg( 'validator-describe-header-description' )
 143+ '!' . $this->msg( 'validator-describe-header-parameter' ) ."\n" .
 144+ '!' . $this->msg( 'validator-describe-header-aliases' ) ."\n" .
 145+ '!' . $this->msg( 'validator-describe-header-type' ) ."\n" .
 146+ '!' . $this->msg( 'validator-describe-header-default' ) ."\n" .
 147+ '!' . $this->msg( 'validator-describe-header-description' )
119148 ), $tableRows );
120149
121150 $table = implode( "\n|-\n", $tableRows );
@@ -146,7 +175,7 @@
147176
148177 $type = $parameter->getTypeMessage();
149178
150 - $default = $parameter->isRequired() ? "''" . wfMsg( 'validator-describe-required' ) . "''" : $parameter->getDefault();
 179+ $default = $parameter->isRequired() ? "''" . $this->msg( 'validator-describe-required' ) . "''" : $parameter->getDefault();
151180 if ( is_array( $default ) ) {
152181 $default = implode( ', ', $default );
153182 }
@@ -154,7 +183,7 @@
155184 $default = $default ? 'yes' : 'no';
156185 }
157186
158 - if ( $default === '' ) $default = "''" . wfMsg( 'validator-describe-empty' ) . "''";
 187+ if ( $default === '' ) $default = "''" . $this->msg( 'validator-describe-empty' ) . "''";
159188
160189 return <<<EOT
161190 | {$parameter->getName()}

Sign-offs

UserFlagDate
Nikerabbitinspected09:23, 20 July 2011

Comments

#Comment by Nikerabbit (talk | contribs)   09:23, 20 July 2011

Actually it goes through the language fallback chain, which ends in English.

#Comment by Jeroen De Dauw (talk | contribs)   11:45, 20 July 2011

What do you mean? $this->msg() seems to work just fine.

#Comment by Nikerabbit (talk | contribs)   12:04, 20 July 2011

Yes it does, but I was commenting this message:

+'maps-mapsdoc-par-language' => 'The language in which to display the documentation. If no such translation is available, English will be used instead.',
#Comment by Jeroen De Dauw (talk | contribs)   12:11, 20 July 2011

What message would you suggest instead?