r79273 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79272‎ | r79273 | r79274 >
Date:17:31, 30 December 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added user friendly translation of parameter types
Modified paths:
  • /trunk/extensions/Validator/Validator.i18n.php (modified) (history)
  • /trunk/extensions/Validator/includes/Parameter.php (modified) (history)
  • /trunk/extensions/Validator/includes/parserHooks/Validator_Describe.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Validator/includes/parserHooks/Validator_Describe.php
@@ -196,26 +196,76 @@
197197 $result = '<h3>' . wfMsg( 'validator-describe-syntax' ) . "</h3>\n\n";
198198
199199 $params = array();
 200+ $requiredParams = array();
200201
201202 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+ }
203208 }
204209
205210 if ( $parserHook->forTagExtensions ) {
 211+ $result .= "'''" . wfMsg( 'validator-describe-tagmin' ) . "'''\n\n";
 212+
206213 $result .= "<pre!><nowiki>\n" . Xml::element(
207214 $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,
208222 $params
209 - ) . "\n</nowiki></pre!>";
 223+ ) . "</nowiki></pre!>";
 224+
 225+ // TODO: example using the default if relevant
210226 }
211227
212228 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!>";
214240 }
215241
216242 return $result;
217243 }
218244
219245 /**
 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+ /**
220270 * Returns the wikitext for a table listing the provided parameters.
221271 *
222272 * @since 0.4.3
@@ -274,9 +324,7 @@
275325 $description = $parameter->getDescription();
276326 if ( $description === false ) $description = '-';
277327
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();
281329
282330 $number = 0;
283331 $isDefault = false;
Index: trunk/extensions/Validator/includes/Parameter.php
@@ -470,6 +470,20 @@
471471 }
472472
473473 /**
 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+ /**
474488 * Returns a list of dependencies the parameter has, in the form of
475489 * other parameter names.
476490 *
Index: trunk/extensions/Validator/Validator.i18n.php
@@ -41,6 +41,14 @@
4242 'validator-listerrors-high' => 'High',
4343 'validator-listerrors-fatal' => 'Fatal',
4444
 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+
4553 // Describe
4654 'validator-describe-description' => 'Generates documentation for one or more parser hooks defined via Validator.',
4755 'validator-describe-notfound' => 'There is no parser hook that handles "$1".',
@@ -61,6 +69,10 @@
6270 'validator-describe-header-description' => 'Description',
6371 'validator-describe-parameters' => 'Parameters',
6472 '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.',
6577
6678 // Criteria errors for single values
6779 'validator_error_empty_argument' => 'Parameter $1 can not have an empty value.',

Status & tagging log