r79307 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79306‎ | r79307 | r79308 >
Date:00:25, 31 December 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added default parameter syntax examples
Modified paths:
  • /trunk/extensions/Validator/Validator.i18n.php (modified) (history)
  • /trunk/extensions/Validator/includes/parserHooks/Validator_Describe.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Validator/includes/parserHooks/Validator_Describe.php
@@ -227,9 +227,11 @@
228228
229229 $params = array();
230230 $requiredParams = array();
 231+ $plainParams = array();
231232
232233 foreach ( $parameters as $parameter ) {
233234 $params[$parameter->getName()] = '{' . $parameter->getTypeMessage() . '}';
 235+ $plainParams[$parameter->getName()] = $parameter->getTypeMessage();
234236
235237 if ( $parameter->isRequired() ) {
236238 $requiredParams[$parameter->getName()] = '{' . $parameter->getTypeMessage() . '}';
@@ -251,7 +253,20 @@
252254 $params
253255 ) . "</nowiki></pre!>";
254256
255 - // TODO: example using the default if relevant
 257+ if ( count( $defaults ) > 0 ) {
 258+ $result .= "'''" . wfMsg( 'validator-describe-tagdefault' ) . "'''\n\n";
 259+
 260+ foreach ( $plainParams as $name => $type ) {
 261+ $contents = '{' . $name . ', ' . $type . '}';
 262+ break;
 263+ }
 264+
 265+ $result .= "<pre!><nowiki>\n" . Xml::element(
 266+ $hookName,
 267+ array_slice( $params, 1 ),
 268+ $contents
 269+ ) . "</nowiki></pre!>";
 270+ }
256271 }
257272
258273 if ( $parserHook->forParserFunctions ) {
@@ -265,7 +280,15 @@
266281
267282 $result .= "<pre!><nowiki>\n" .
268283 $this->buildParserFunctionSyntax( $hookName, $params )
269 - . "</nowiki></pre!>";
 284+ . "</nowiki></pre!>";
 285+
 286+ if ( count( $defaults ) > 0 ) {
 287+ $result .= "'''" . wfMsg( 'validator-describe-pfdefault' ) . "'''\n\n";
 288+
 289+ $result .= "<pre!><nowiki>\n" .
 290+ $this->buildParserFunctionSyntax( $hookName, $plainParams, $defaults )
 291+ . "</nowiki></pre!>";
 292+ }
270293 }
271294
272295 return $result;
@@ -278,14 +301,20 @@
279302 *
280303 * @param string $functionName
281304 * @param array $parameters Parameters (keys) and their type (values)
 305+ * @param array $defaults
282306 *
283307 * @return string
284308 */
285 - protected function buildParserFunctionSyntax( $functionName, array $parameters ) {
 309+ protected function buildParserFunctionSyntax( $functionName, array $parameters, array $defaults = array() ) {
286310 $arguments = array();
287311
288312 foreach ( $parameters as $name => $type ) {
289 - $arguments[] = "$name=$type";
 313+ if ( in_array( $name, $defaults ) ) {
 314+ $arguments[] = '{' . $name . ', ' . $type . '}';
 315+ }
 316+ else {
 317+ $arguments[] = "$name=$type";
 318+ }
290319 }
291320
292321 $singleLine = count( $arguments ) <= 3;
Index: trunk/extensions/Validator/Validator.i18n.php
@@ -71,8 +71,10 @@
7272 'validator-describe-syntax' => 'Syntax',
7373 'validator-describe-tagmin' => 'Tag extension with only the required parameters.',
7474 'validator-describe-tagmax' => 'Tag extension with all parameters.',
 75+ 'validator-describe-tagdefault' => 'Tag extension with all parameters using the default parameter notation.',
7576 'validator-describe-pfmin' => 'Parser function with only the required parameters.',
7677 'validator-describe-pfmax' => 'Parser function with all parameters.',
 78+ 'validator-describe-pfdefault' => 'Parser function with all parameters using the default parameter notation.',
7779
7880 // Criteria errors for single values
7981 'validator_error_empty_argument' => 'Parameter $1 can not have an empty value.',

Status & tagging log