Index: trunk/extensions/Validator/includes/parserHooks/Validator_Describe.php |
— | — | @@ -227,9 +227,11 @@ |
228 | 228 | |
229 | 229 | $params = array(); |
230 | 230 | $requiredParams = array(); |
| 231 | + $plainParams = array(); |
231 | 232 | |
232 | 233 | foreach ( $parameters as $parameter ) { |
233 | 234 | $params[$parameter->getName()] = '{' . $parameter->getTypeMessage() . '}'; |
| 235 | + $plainParams[$parameter->getName()] = $parameter->getTypeMessage(); |
234 | 236 | |
235 | 237 | if ( $parameter->isRequired() ) { |
236 | 238 | $requiredParams[$parameter->getName()] = '{' . $parameter->getTypeMessage() . '}'; |
— | — | @@ -251,7 +253,20 @@ |
252 | 254 | $params |
253 | 255 | ) . "</nowiki></pre!>"; |
254 | 256 | |
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 | + } |
256 | 271 | } |
257 | 272 | |
258 | 273 | if ( $parserHook->forParserFunctions ) { |
— | — | @@ -265,7 +280,15 @@ |
266 | 281 | |
267 | 282 | $result .= "<pre!><nowiki>\n" . |
268 | 283 | $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 | + } |
270 | 293 | } |
271 | 294 | |
272 | 295 | return $result; |
— | — | @@ -278,14 +301,20 @@ |
279 | 302 | * |
280 | 303 | * @param string $functionName |
281 | 304 | * @param array $parameters Parameters (keys) and their type (values) |
| 305 | + * @param array $defaults |
282 | 306 | * |
283 | 307 | * @return string |
284 | 308 | */ |
285 | | - protected function buildParserFunctionSyntax( $functionName, array $parameters ) { |
| 309 | + protected function buildParserFunctionSyntax( $functionName, array $parameters, array $defaults = array() ) { |
286 | 310 | $arguments = array(); |
287 | 311 | |
288 | 312 | 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 | + } |
290 | 319 | } |
291 | 320 | |
292 | 321 | $singleLine = count( $arguments ) <= 3; |
Index: trunk/extensions/Validator/Validator.i18n.php |
— | — | @@ -71,8 +71,10 @@ |
72 | 72 | 'validator-describe-syntax' => 'Syntax', |
73 | 73 | 'validator-describe-tagmin' => 'Tag extension with only the required parameters.', |
74 | 74 | 'validator-describe-tagmax' => 'Tag extension with all parameters.', |
| 75 | + 'validator-describe-tagdefault' => 'Tag extension with all parameters using the default parameter notation.', |
75 | 76 | 'validator-describe-pfmin' => 'Parser function with only the required parameters.', |
76 | 77 | 'validator-describe-pfmax' => 'Parser function with all parameters.', |
| 78 | + 'validator-describe-pfdefault' => 'Parser function with all parameters using the default parameter notation.', |
77 | 79 | |
78 | 80 | // Criteria errors for single values |
79 | 81 | 'validator_error_empty_argument' => 'Parameter $1 can not have an empty value.', |