Index: trunk/extensions/Validator/includes/parserHooks/Validator_Describe.php |
— | — | @@ -196,26 +196,76 @@ |
197 | 197 | $result = '<h3>' . wfMsg( 'validator-describe-syntax' ) . "</h3>\n\n"; |
198 | 198 | |
199 | 199 | $params = array(); |
| 200 | + $requiredParams = array(); |
200 | 201 | |
201 | 202 | foreach ( $parameters as $parameter ) { |
202 | | - $params[$parameter->getName()] = '{' . $parameter->getType() . '}'; |
| 203 | + $params[$parameter->getName()] = '{' . $parameter->getTypeMessage() . '}'; |
| 204 | + |
| 205 | + if ( $parameter->isRequired() ) { |
| 206 | + $requiredParams[$parameter->getName()] = '{' . $parameter->getTypeMessage() . '}'; |
| 207 | + } |
203 | 208 | } |
204 | 209 | |
205 | 210 | if ( $parserHook->forTagExtensions ) { |
| 211 | + $result .= "'''" . wfMsg( 'validator-describe-tagmin' ) . "'''\n\n"; |
| 212 | + |
206 | 213 | $result .= "<pre!><nowiki>\n" . Xml::element( |
207 | 214 | $hookName, |
| 215 | + $requiredParams |
| 216 | + ) . "</nowiki></pre!>"; |
| 217 | + |
| 218 | + $result .= "'''" . wfMsg( 'validator-describe-tagmax' ) . "'''\n\n"; |
| 219 | + |
| 220 | + $result .= "<pre!><nowiki>\n" . Xml::element( |
| 221 | + $hookName, |
208 | 222 | $params |
209 | | - ) . "\n</nowiki></pre!>"; |
| 223 | + ) . "</nowiki></pre!>"; |
| 224 | + |
| 225 | + // TODO: example using the default if relevant |
210 | 226 | } |
211 | 227 | |
212 | 228 | if ( $parserHook->forParserFunctions ) { |
213 | | - // TODO |
| 229 | + $result .= "'''" . wfMsg( 'validator-describe-pfmin' ) . "'''\n\n"; |
| 230 | + |
| 231 | + $result .= "<pre!><nowiki>\n" . |
| 232 | + $this->buildParserFunctionSyntax( $hookName, $requiredParams ) |
| 233 | + . "</nowiki></pre!>"; |
| 234 | + |
| 235 | + $result .= "'''" . wfMsg( 'validator-describe-pfmax' ) . "'''\n\n"; |
| 236 | + |
| 237 | + $result .= "<pre!><nowiki>\n" . |
| 238 | + $this->buildParserFunctionSyntax( $hookName, $params ) |
| 239 | + . "</nowiki></pre!>"; |
214 | 240 | } |
215 | 241 | |
216 | 242 | return $result; |
217 | 243 | } |
218 | 244 | |
219 | 245 | /** |
| 246 | + * Builds the wikitext syntax for a parser function. |
| 247 | + * |
| 248 | + * @since 0.4.3 |
| 249 | + * |
| 250 | + * @param string $functionName |
| 251 | + * @param array $parameters Parameters (keys) and their type (values) |
| 252 | + * |
| 253 | + * @return string |
| 254 | + */ |
| 255 | + protected function buildParserFunctionSyntax( $functionName, array $parameters ) { |
| 256 | + $arguments = array(); |
| 257 | + |
| 258 | + foreach ( $parameters as $name => $type ) { |
| 259 | + $arguments[] = "$name=$type"; |
| 260 | + } |
| 261 | + |
| 262 | + $singleLine = count( $arguments ) <= 3; |
| 263 | + $delimiter = $singleLine ? '|' : "\n| "; |
| 264 | + $wrapper = $singleLine ? '' : "\n"; |
| 265 | + |
| 266 | + return "{{#$functionName:$wrapper" . implode( $delimiter, $arguments ) . $wrapper . '}}'; |
| 267 | + } |
| 268 | + |
| 269 | + /** |
220 | 270 | * Returns the wikitext for a table listing the provided parameters. |
221 | 271 | * |
222 | 272 | * @since 0.4.3 |
— | — | @@ -274,9 +324,7 @@ |
275 | 325 | $description = $parameter->getDescription(); |
276 | 326 | if ( $description === false ) $description = '-'; |
277 | 327 | |
278 | | - // TODO: some mapping to make the type names more user-friendly |
279 | | - $type = $parameter->getType(); |
280 | | - if ( $parameter->isList() ) $type = wfMsgExt( 'validator-describe-listtype', 'parsemag', $type ); |
| 328 | + $type = $parameter->getTypeMessage(); |
281 | 329 | |
282 | 330 | $number = 0; |
283 | 331 | $isDefault = false; |
Index: trunk/extensions/Validator/includes/Parameter.php |
— | — | @@ -470,6 +470,20 @@ |
471 | 471 | } |
472 | 472 | |
473 | 473 | /** |
| 474 | + * Returns an internationalized message indicating the parameter type suited for display to users. |
| 475 | + * |
| 476 | + * @since 0.4.3 |
| 477 | + * |
| 478 | + * @return string |
| 479 | + */ |
| 480 | + public function getTypeMessage() { |
| 481 | + $message = wfMsg( 'validator-type-' . $this->type ); |
| 482 | + return $this->isList() ? |
| 483 | + wfMsgExt( 'validator-describe-listtype', 'parsemag', $message ) |
| 484 | + : Language::ucfirst( $message ); |
| 485 | + } |
| 486 | + |
| 487 | + /** |
474 | 488 | * Returns a list of dependencies the parameter has, in the form of |
475 | 489 | * other parameter names. |
476 | 490 | * |
Index: trunk/extensions/Validator/Validator.i18n.php |
— | — | @@ -41,6 +41,14 @@ |
42 | 42 | 'validator-listerrors-high' => 'High', |
43 | 43 | 'validator-listerrors-fatal' => 'Fatal', |
44 | 44 | |
| 45 | + // Parameter types |
| 46 | + 'validator-type-string' => 'text', |
| 47 | + 'validator-type-number' => 'number', |
| 48 | + 'validator-type-integer' => 'whole number', |
| 49 | + 'validator-type-float' => 'number', |
| 50 | + 'validator-type-boolean' => 'yes/no', |
| 51 | + 'validator-type-char' => 'character', |
| 52 | + |
45 | 53 | // Describe |
46 | 54 | 'validator-describe-description' => 'Generates documentation for one or more parser hooks defined via Validator.', |
47 | 55 | 'validator-describe-notfound' => 'There is no parser hook that handles "$1".', |
— | — | @@ -61,6 +69,10 @@ |
62 | 70 | 'validator-describe-header-description' => 'Description', |
63 | 71 | 'validator-describe-parameters' => 'Parameters', |
64 | 72 | 'validator-describe-syntax' => 'Syntax', |
| 73 | + 'validator-describe-tagmin' => 'Tag extension with only the required parameters.', |
| 74 | + 'validator-describe-tagmax' => 'Tag extension with all parameters.', |
| 75 | + 'validator-describe-pfmin' => 'Parser function with only the required parameters.', |
| 76 | + 'validator-describe-pfmax' => 'Parser function with all parameters.', |
65 | 77 | |
66 | 78 | // Criteria errors for single values |
67 | 79 | 'validator_error_empty_argument' => 'Parameter $1 can not have an empty value.', |