Index: trunk/extensions/Validator/INSTALL |
— | — | @@ -1,4 +1,4 @@ |
2 | | -[[Validator 0.4.9]] |
| 2 | +[[Validator 0.4.10]] |
3 | 3 | |
4 | 4 | Once you have downloaded the code, place the 'Validator' directory within |
5 | 5 | your MediaWiki 'extensions' directory. Then add the following code to your |
Index: trunk/extensions/Validator/RELEASE-NOTES |
— | — | @@ -4,6 +4,13 @@ |
5 | 5 | This change log contains a list of completed to-do's (new features, bug fixes, refactoring) for every version of Validator. |
6 | 6 | |
7 | 7 | |
| 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 | + |
8 | 15 | === Validator 0.4.9 === |
9 | 16 | (2011-07-30) |
10 | 17 | |
Index: trunk/extensions/Validator/includes/parserHooks/Validator_Describe.php |
— | — | @@ -15,6 +15,15 @@ |
16 | 16 | class ValidatorDescribe extends ParserHook { |
17 | 17 | |
18 | 18 | /** |
| 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 | + /** |
19 | 28 | * No LSB in pre-5.3 PHP *sigh*. |
20 | 29 | * This is to be refactored as soon as php >=5.3 becomes acceptable. |
21 | 30 | */ |
— | — | @@ -59,12 +68,16 @@ |
60 | 69 | |
61 | 70 | $params['hooks'] = new ListParameter( 'hooks' ); |
62 | 71 | $params['hooks']->setDefault( array_keys( ParserHook::getRegisteredParserHooks() ) ); |
63 | | - $params['hooks']->setDescription( wfMsg( 'validator-describe-par-hooks' ) ); |
| 72 | + $params['hooks']->setMessage( 'validator-describe-par-hooks' ); |
64 | 73 | $params['hooks']->addAliases( 'hook' ); |
65 | 74 | |
66 | 75 | $params['pre'] = new Parameter( 'pre', Parameter::TYPE_BOOLEAN ); |
67 | 76 | $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' ); |
69 | 82 | |
70 | 83 | return $params; |
71 | 84 | } |
— | — | @@ -92,6 +105,8 @@ |
93 | 106 | * @return string |
94 | 107 | */ |
95 | 108 | public function render( array $parameters ) { |
| 109 | + $this->language = $parameters['language']; |
| 110 | + |
96 | 111 | $parts = array(); |
97 | 112 | |
98 | 113 | // Loop over the hooks for which the docs should be added. |
— | — | @@ -132,12 +147,16 @@ |
133 | 148 | ( $parameters['pre'] ? ' ==' : '</h2>' ); |
134 | 149 | |
135 | 150 | if ( $parameters['pre'] ) { |
136 | | - $description .= "\n<!-- " . wfMsg( 'validator-describe-autogen' ) . ' -->'; |
| 151 | + $description .= "\n<!-- " . $this->msg( 'validator-describe-autogen' ) . ' -->'; |
137 | 152 | } |
138 | 153 | |
139 | 154 | $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 ) { |
142 | 161 | $description .= wfMsgExt( 'validator-describe-descriptionmsg', 'parsemag', $descriptionData['description'] ); |
143 | 162 | $description .= "\n\n"; |
144 | 163 | } |
— | — | @@ -151,19 +170,19 @@ |
152 | 171 | } |
153 | 172 | } |
154 | 173 | |
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 ) ); |
156 | 175 | $description .= "\n\n"; |
157 | 176 | } |
158 | 177 | |
159 | 178 | if ( $parserHook->forTagExtensions || $parserHook->forParserFunctions ) { |
160 | 179 | if ( $parserHook->forTagExtensions && $parserHook->forParserFunctions ) { |
161 | | - $description .= wfMsg( 'validator-describe-bothhooks' ); |
| 180 | + $description .= $this->msg( 'validator-describe-bothhooks' ); |
162 | 181 | } |
163 | 182 | elseif ( $parserHook->forTagExtensions ) { |
164 | | - $description .= wfMsg( 'validator-describe-tagextension' ); |
| 183 | + $description .= $this->msg( 'validator-describe-tagextension' ); |
165 | 184 | } |
166 | 185 | else { // if $parserHook->forParserFunctions |
167 | | - $description .= wfMsg( 'validator-describe-parserfunction' ); |
| 186 | + $description .= $this->msg( 'validator-describe-parserfunction' ); |
168 | 187 | } |
169 | 188 | |
170 | 189 | $description .= "\n\n"; |
— | — | @@ -246,14 +265,14 @@ |
247 | 266 | $preClose = $pre ? '</pre>' : '</pre>'; |
248 | 267 | |
249 | 268 | if ( $parserHook->forTagExtensions ) { |
250 | | - $result .= "\n\n'''" . wfMsg( 'validator-describe-tagmin' ) . "'''\n\n"; |
| 269 | + $result .= "\n\n'''" . $this->msg( 'validator-describe-tagmin' ) . "'''\n\n"; |
251 | 270 | |
252 | 271 | $result .= "$preOpen<nowiki>\n" . Xml::element( |
253 | 272 | $hookName, |
254 | 273 | $requiredParams |
255 | 274 | ) . "\n</nowiki>$preClose"; |
256 | 275 | |
257 | | - $result .= "\n\n'''" . wfMsg( 'validator-describe-tagmax' ) . "'''\n\n"; |
| 276 | + $result .= "\n\n'''" . $this->msg( 'validator-describe-tagmax' ) . "'''\n\n"; |
258 | 277 | |
259 | 278 | // TODO: multiline when long |
260 | 279 | $result .= "$preOpen<nowiki>\n" . Xml::element( |
— | — | @@ -262,7 +281,7 @@ |
263 | 282 | ) . "\n</nowiki>$preClose"; |
264 | 283 | |
265 | 284 | 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"; |
267 | 286 | $contents = ''; |
268 | 287 | foreach ( $plainParams as $name => $type ) { |
269 | 288 | $contents = '{' . $name . ', ' . $type . '}'; |
— | — | @@ -278,20 +297,20 @@ |
279 | 298 | } |
280 | 299 | |
281 | 300 | if ( $parserHook->forParserFunctions ) { |
282 | | - $result .= "\n\n'''" . wfMsg( 'validator-describe-pfmin' ) . "'''\n\n"; |
| 301 | + $result .= "\n\n'''" . $this->msg( 'validator-describe-pfmin' ) . "'''\n\n"; |
283 | 302 | |
284 | 303 | $result .= "$preOpen<nowiki>\n" . |
285 | 304 | $this->buildParserFunctionSyntax( $hookName, $requiredParams ) |
286 | 305 | . "\n</nowiki>$preClose"; |
287 | 306 | |
288 | | - $result .= "\n\n'''" . wfMsg( 'validator-describe-pfmax' ) . "'''\n\n"; |
| 307 | + $result .= "\n\n'''" . $this->msg( 'validator-describe-pfmax' ) . "'''\n\n"; |
289 | 308 | |
290 | 309 | $result .= "$preOpen<nowiki>\n" . |
291 | 310 | $this->buildParserFunctionSyntax( $hookName, $params ) |
292 | 311 | . "\n</nowiki>$preClose"; |
293 | 312 | |
294 | 313 | 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"; |
296 | 315 | |
297 | 316 | $result .= "$preOpen<nowiki>\n" . |
298 | 317 | $this->buildParserFunctionSyntax( $hookName, $plainParams, $defaults ) |
— | — | @@ -355,18 +374,18 @@ |
356 | 375 | if ( count( $tableRows ) > 0 ) { |
357 | 376 | $tableRows = array_merge( array( |
358 | 377 | "! #\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' ) |
364 | 383 | ), $tableRows ); |
365 | 384 | |
366 | 385 | $table = implode( "\n|-\n", $tableRows ); |
367 | 386 | |
368 | 387 | $h3 = |
369 | 388 | ( $pre ? '=== ' : '<h3>' ) . |
370 | | - wfMsg( 'validator-describe-parameters' ) . |
| 389 | + $this->msg( 'validator-describe-parameters' ) . |
371 | 390 | ( $pre ? ' ===' : '</h3>' ); |
372 | 391 | |
373 | 392 | $table = "$h3\n\n" . |
— | — | @@ -392,8 +411,15 @@ |
393 | 412 | $aliases = $parameter->getAliases(); |
394 | 413 | $aliases = count( $aliases ) > 0 ? implode( ', ', $aliases ) : '-'; |
395 | 414 | |
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 | + } |
398 | 424 | |
399 | 425 | $type = $parameter->getTypeMessage(); |
400 | 426 | |
— | — | @@ -409,7 +435,7 @@ |
410 | 436 | } |
411 | 437 | } |
412 | 438 | |
413 | | - $default = $parameter->isRequired() ? "''" . wfMsg( 'validator-describe-required' ) . "''" : $parameter->getDefault(); |
| 439 | + $default = $parameter->isRequired() ? "''" . $this->msg( 'validator-describe-required' ) . "''" : $parameter->getDefault(); |
414 | 440 | |
415 | 441 | if ( is_array( $default ) ) { |
416 | 442 | $default = implode( ', ', $default ); |
— | — | @@ -418,7 +444,7 @@ |
419 | 445 | $default = $default ? 'yes' : 'no'; |
420 | 446 | } |
421 | 447 | |
422 | | - if ( $default === '' ) $default = "''" . wfMsg( 'validator-describe-empty' ) . "''"; |
| 448 | + if ( $default === '' ) $default = "''" . $this->msg( 'validator-describe-empty' ) . "''"; |
423 | 449 | |
424 | 450 | if ( !$isDefault ) { |
425 | 451 | $number = '-'; |
— | — | @@ -455,5 +481,21 @@ |
456 | 482 | public function getDescription() { |
457 | 483 | return wfMsg( 'validator-describe-description' ); |
458 | 484 | } |
| 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 | + } |
459 | 501 | |
460 | 502 | } |
Index: trunk/extensions/Validator/includes/ParserHook.php |
— | — | @@ -413,13 +413,14 @@ |
414 | 414 | return array( |
415 | 415 | 'names' => $this->getNames(), |
416 | 416 | 'description' => $this->getDescription(), |
| 417 | + 'message' => $this->getMessage(), |
417 | 418 | 'parameters' => $this->getParameterInfo( $type ), |
418 | 419 | 'defaults' => $this->getDefaultParameters( $type ), |
419 | 420 | ); |
420 | 421 | } |
421 | 422 | |
422 | 423 | /** |
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. |
424 | 425 | * Override in deriving classes to add a message. |
425 | 426 | * |
426 | 427 | * @since 0.4.3 |
— | — | @@ -427,6 +428,19 @@ |
428 | 429 | * @return mixed string or false |
429 | 430 | */ |
430 | 431 | 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() { |
431 | 445 | return false; |
432 | 446 | } |
433 | 447 | |
Index: trunk/extensions/Validator/Validator.i18n.php |
— | — | @@ -64,6 +64,7 @@ |
65 | 65 | 'validator-describe-bothhooks' => 'Implemented as both parser function and as tag extension.', |
66 | 66 | 'validator-describe-par-hooks' => 'The parser hooks for which to display documentation.', |
67 | 67 | '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', |
68 | 69 | 'validator-describe-listtype' => 'List of $1 items', |
69 | 70 | 'validator-describe-empty' => 'empty', |
70 | 71 | 'validator-describe-required' => 'required', |
Index: trunk/extensions/Validator/Validator.php |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | die( 'Not an entry point.' ); |
27 | 27 | } |
28 | 28 | |
29 | | -define( 'Validator_VERSION', '0.4.9' ); |
| 29 | +define( 'Validator_VERSION', '0.4.10 alpha' ); |
30 | 30 | |
31 | 31 | // Register the internationalization file. |
32 | 32 | $wgExtensionMessagesFiles['Validator'] = dirname( __FILE__ ) . '/Validator.i18n.php'; |