r93639 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93638‎ | r93639 | r93640 >
Date:19:46, 1 August 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added language parameter to describe that allows setting the lang for the generated docs
Modified paths:
  • /trunk/extensions/Validator/INSTALL (modified) (history)
  • /trunk/extensions/Validator/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/Validator/Validator.i18n.php (modified) (history)
  • /trunk/extensions/Validator/Validator.php (modified) (history)
  • /trunk/extensions/Validator/includes/ParserHook.php (modified) (history)
  • /trunk/extensions/Validator/includes/parserHooks/Validator_Describe.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Validator/INSTALL
@@ -1,4 +1,4 @@
2 -[[Validator 0.4.9]]
 2+[[Validator 0.4.10]]
33
44 Once you have downloaded the code, place the 'Validator' directory within
55 your MediaWiki 'extensions' directory. Then add the following code to your
Index: trunk/extensions/Validator/RELEASE-NOTES
@@ -4,6 +4,13 @@
55 This change log contains a list of completed to-do's (new features, bug fixes, refactoring) for every version of Validator.
66
77
 8+=== Validator 0.4.10 ===
 9+(2011-08-xx)
 10+
 11+* Added language parameter to describe that allows setting the lang for the generated docs.
 12+
 13+* Added getMessage method to ParserHook class for better i18n.
 14+
815 === Validator 0.4.9 ===
916 (2011-07-30)
1017
Index: trunk/extensions/Validator/includes/parserHooks/Validator_Describe.php
@@ -15,6 +15,15 @@
1616 class ValidatorDescribe extends ParserHook {
1717
1818 /**
 19+ * Field to store the value of the language parameter.
 20+ *
 21+ * @since 0.4.10
 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 */
@@ -59,12 +68,16 @@
6069
6170 $params['hooks'] = new ListParameter( 'hooks' );
6271 $params['hooks']->setDefault( array_keys( ParserHook::getRegisteredParserHooks() ) );
63 - $params['hooks']->setDescription( wfMsg( 'validator-describe-par-hooks' ) );
 72+ $params['hooks']->setMessage( 'validator-describe-par-hooks' );
6473 $params['hooks']->addAliases( 'hook' );
6574
6675 $params['pre'] = new Parameter( 'pre', Parameter::TYPE_BOOLEAN );
6776 $params['pre']->setDefault( 'off' );
68 - $params['pre']->setDescription( wfMsg( 'validator-describe-par-pre' ) );
 77+ $params['pre']->setMessage( 'validator-describe-par-pre' );
 78+
 79+ $params['language'] = new Parameter( 'language' );
 80+ $params['language']->setDefault( $GLOBALS['wgLanguageCode'] );
 81+ $params['language']->setMessage( 'validator-describe-par-language' );
6982
7083 return $params;
7184 }
@@ -92,6 +105,8 @@
93106 * @return string
94107 */
95108 public function render( array $parameters ) {
 109+ $this->language = $parameters['language'];
 110+
96111 $parts = array();
97112
98113 // Loop over the hooks for which the docs should be added.
@@ -132,12 +147,16 @@
133148 ( $parameters['pre'] ? ' ==' : '</h2>' );
134149
135150 if ( $parameters['pre'] ) {
136 - $description .= "\n<!-- " . wfMsg( 'validator-describe-autogen' ) . ' -->';
 151+ $description .= "\n<!-- " . $this->msg( 'validator-describe-autogen' ) . ' -->';
137152 }
138153
139154 $description .= "\n\n";
140 -
141 - if ( $descriptionData['description'] !== false ) {
 155+
 156+ if ( $descriptionData['message'] !== false ) {
 157+ $description .= $this->msg( 'validator-describe-descriptionmsg', 'parsemag', $this->msg( $descriptionData['message'] ) );
 158+ $description .= "\n\n";
 159+ }
 160+ else if ( $descriptionData['description'] !== false ) {
142161 $description .= wfMsgExt( 'validator-describe-descriptionmsg', 'parsemag', $descriptionData['description'] );
143162 $description .= "\n\n";
144163 }
@@ -151,19 +170,19 @@
152171 }
153172 }
154173
155 - $description .= wfMsgExt( 'validator-describe-aliases', 'parsemag', $wgLang->listToText( $aliases ), count( $aliases ) );
 174+ $description .= $this->msg( 'validator-describe-aliases', 'parsemag', $wgLang->listToText( $aliases ), count( $aliases ) );
156175 $description .= "\n\n";
157176 }
158177
159178 if ( $parserHook->forTagExtensions || $parserHook->forParserFunctions ) {
160179 if ( $parserHook->forTagExtensions && $parserHook->forParserFunctions ) {
161 - $description .= wfMsg( 'validator-describe-bothhooks' );
 180+ $description .= $this->msg( 'validator-describe-bothhooks' );
162181 }
163182 elseif ( $parserHook->forTagExtensions ) {
164 - $description .= wfMsg( 'validator-describe-tagextension' );
 183+ $description .= $this->msg( 'validator-describe-tagextension' );
165184 }
166185 else { // if $parserHook->forParserFunctions
167 - $description .= wfMsg( 'validator-describe-parserfunction' );
 186+ $description .= $this->msg( 'validator-describe-parserfunction' );
168187 }
169188
170189 $description .= "\n\n";
@@ -246,14 +265,14 @@
247266 $preClose = $pre ? '&lt;/pre&gt;' : '</pre>';
248267
249268 if ( $parserHook->forTagExtensions ) {
250 - $result .= "\n\n'''" . wfMsg( 'validator-describe-tagmin' ) . "'''\n\n";
 269+ $result .= "\n\n'''" . $this->msg( 'validator-describe-tagmin' ) . "'''\n\n";
251270
252271 $result .= "$preOpen<nowiki>\n" . Xml::element(
253272 $hookName,
254273 $requiredParams
255274 ) . "\n</nowiki>$preClose";
256275
257 - $result .= "\n\n'''" . wfMsg( 'validator-describe-tagmax' ) . "'''\n\n";
 276+ $result .= "\n\n'''" . $this->msg( 'validator-describe-tagmax' ) . "'''\n\n";
258277
259278 // TODO: multiline when long
260279 $result .= "$preOpen<nowiki>\n" . Xml::element(
@@ -262,7 +281,7 @@
263282 ) . "\n</nowiki>$preClose";
264283
265284 if ( count( $defaults ) > 0 ) {
266 - $result .= "\n\n'''" . wfMsg( 'validator-describe-tagdefault' ) . "'''\n\n";
 285+ $result .= "\n\n'''" . $this->msg( 'validator-describe-tagdefault' ) . "'''\n\n";
267286 $contents = '';
268287 foreach ( $plainParams as $name => $type ) {
269288 $contents = '{' . $name . ', ' . $type . '}';
@@ -278,20 +297,20 @@
279298 }
280299
281300 if ( $parserHook->forParserFunctions ) {
282 - $result .= "\n\n'''" . wfMsg( 'validator-describe-pfmin' ) . "'''\n\n";
 301+ $result .= "\n\n'''" . $this->msg( 'validator-describe-pfmin' ) . "'''\n\n";
283302
284303 $result .= "$preOpen<nowiki>\n" .
285304 $this->buildParserFunctionSyntax( $hookName, $requiredParams )
286305 . "\n</nowiki>$preClose";
287306
288 - $result .= "\n\n'''" . wfMsg( 'validator-describe-pfmax' ) . "'''\n\n";
 307+ $result .= "\n\n'''" . $this->msg( 'validator-describe-pfmax' ) . "'''\n\n";
289308
290309 $result .= "$preOpen<nowiki>\n" .
291310 $this->buildParserFunctionSyntax( $hookName, $params )
292311 . "\n</nowiki>$preClose";
293312
294313 if ( count( $defaults ) > 0 ) {
295 - $result .= "\n\n'''" . wfMsg( 'validator-describe-pfdefault' ) . "'''\n\n";
 314+ $result .= "\n\n'''" . $this->msg( 'validator-describe-pfdefault' ) . "'''\n\n";
296315
297316 $result .= "$preOpen<nowiki>\n" .
298317 $this->buildParserFunctionSyntax( $hookName, $plainParams, $defaults )
@@ -355,18 +374,18 @@
356375 if ( count( $tableRows ) > 0 ) {
357376 $tableRows = array_merge( array(
358377 "! #\n" .
359 - '!' . wfMsg( 'validator-describe-header-parameter' ) ."\n" .
360 - '!' . wfMsg( 'validator-describe-header-aliases' ) ."\n" .
361 - '!' . wfMsg( 'validator-describe-header-type' ) ."\n" .
362 - '!' . wfMsg( 'validator-describe-header-default' ) ."\n" .
363 - '!' . wfMsg( 'validator-describe-header-description' )
 378+ '!' . $this->msg( 'validator-describe-header-parameter' ) ."\n" .
 379+ '!' . $this->msg( 'validator-describe-header-aliases' ) ."\n" .
 380+ '!' . $this->msg( 'validator-describe-header-type' ) ."\n" .
 381+ '!' . $this->msg( 'validator-describe-header-default' ) ."\n" .
 382+ '!' . $this->msg( 'validator-describe-header-description' )
364383 ), $tableRows );
365384
366385 $table = implode( "\n|-\n", $tableRows );
367386
368387 $h3 =
369388 ( $pre ? '=== ' : '<h3>' ) .
370 - wfMsg( 'validator-describe-parameters' ) .
 389+ $this->msg( 'validator-describe-parameters' ) .
371390 ( $pre ? ' ===' : '</h3>' );
372391
373392 $table = "$h3\n\n" .
@@ -392,8 +411,15 @@
393412 $aliases = $parameter->getAliases();
394413 $aliases = count( $aliases ) > 0 ? implode( ', ', $aliases ) : '-';
395414
396 - $description = $parameter->getDescription();
397 - if ( $description === false ) $description = '-';
 415+ $description = $parameter->getMessage();
 416+
 417+ if ( $description === false ) {
 418+ $description = $parameter->getDescription();
 419+ if ( $description === false ) $description = '-';
 420+ }
 421+ else {
 422+ $description = $this->msg( $description );
 423+ }
398424
399425 $type = $parameter->getTypeMessage();
400426
@@ -409,7 +435,7 @@
410436 }
411437 }
412438
413 - $default = $parameter->isRequired() ? "''" . wfMsg( 'validator-describe-required' ) . "''" : $parameter->getDefault();
 439+ $default = $parameter->isRequired() ? "''" . $this->msg( 'validator-describe-required' ) . "''" : $parameter->getDefault();
414440
415441 if ( is_array( $default ) ) {
416442 $default = implode( ', ', $default );
@@ -418,7 +444,7 @@
419445 $default = $default ? 'yes' : 'no';
420446 }
421447
422 - if ( $default === '' ) $default = "''" . wfMsg( 'validator-describe-empty' ) . "''";
 448+ if ( $default === '' ) $default = "''" . $this->msg( 'validator-describe-empty' ) . "''";
423449
424450 if ( !$isDefault ) {
425451 $number = '-';
@@ -455,5 +481,21 @@
456482 public function getDescription() {
457483 return wfMsg( 'validator-describe-description' );
458484 }
 485+
 486+ /**
 487+ * Message function that takes into account the language parameter.
 488+ *
 489+ * @since 0.4.10
 490+ *
 491+ * @param string $key
 492+ * @param array $args
 493+ *
 494+ * @return string
 495+ */
 496+ protected function msg() {
 497+ $args = func_get_args();
 498+ $key = array_shift( $args );
 499+ return wfMsgReal( $key, $args, true, $this->language );
 500+ }
459501
460502 }
Index: trunk/extensions/Validator/includes/ParserHook.php
@@ -413,13 +413,14 @@
414414 return array(
415415 'names' => $this->getNames(),
416416 'description' => $this->getDescription(),
 417+ 'message' => $this->getMessage(),
417418 'parameters' => $this->getParameterInfo( $type ),
418419 'defaults' => $this->getDefaultParameters( $type ),
419420 );
420421 }
421422
422423 /**
423 - * Returns a description message for the parser hook, or false when there is none.
 424+ * Returns a description for the parser hook, or false when there is none.
424425 * Override in deriving classes to add a message.
425426 *
426427 * @since 0.4.3
@@ -427,6 +428,19 @@
428429 * @return mixed string or false
429430 */
430431 public function getDescription() {
 432+ $msg = $this->getMessage();
 433+ return $msg === false ? false : wfMsg( $msg );
 434+ }
 435+
 436+ /**
 437+ * Returns a description message for the parser hook, or false when there is none.
 438+ * Override in deriving classes to add a message.
 439+ *
 440+ * @since 0.4.10
 441+ *
 442+ * @return mixed string or false
 443+ */
 444+ public function getMessage() {
431445 return false;
432446 }
433447
Index: trunk/extensions/Validator/Validator.i18n.php
@@ -64,6 +64,7 @@
6565 'validator-describe-bothhooks' => 'Implemented as both parser function and as tag extension.',
6666 'validator-describe-par-hooks' => 'The parser hooks for which to display documentation.',
6767 'validator-describe-par-pre' => 'Allows you to get the actual wikitext for the documentation, without it being rendered on the page.',
 68+ 'validator-describe-par-language' => 'The language to display the descriptions in',
6869 'validator-describe-listtype' => 'List of $1 items',
6970 'validator-describe-empty' => 'empty',
7071 'validator-describe-required' => 'required',
Index: trunk/extensions/Validator/Validator.php
@@ -25,7 +25,7 @@
2626 die( 'Not an entry point.' );
2727 }
2828
29 -define( 'Validator_VERSION', '0.4.9' );
 29+define( 'Validator_VERSION', '0.4.10 alpha' );
3030
3131 // Register the internationalization file.
3232 $wgExtensionMessagesFiles['Validator'] = dirname( __FILE__ ) . '/Validator.i18n.php';

Follow-up revisions

RevisionCommit summaryAuthorDate
r93641fu r93639jeroendedauw19:55, 1 August 2011