r79201 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79200‎ | r79201 | r79202 >
Date:21:00, 29 December 2010
Author:jeroendedauw
Status:deferred (Comments)
Tags:
Comment:
Added parameter type and description stuff to the describe parser hook
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
@@ -59,9 +59,11 @@
6060
6161 $params['hooks'] = new ListParameter( 'hooks' );
6262 $params['hooks']->setDefault( array_keys( ParserHook::getRegisteredParserHooks() ) );
 63+ $params['hooks']->setDescription( wfMsg( 'validator-describe-par-hooks' ) );
6364
6465 $params['pre'] = new Parameter( 'pre', Parameter::TYPE_BOOLEAN );
6566 $params['pre']->setDefault( 'off' );
 67+ $params['pre']->setDescription( wfMsg( 'validator-describe-par-pre' ) );
6668
6769 return $params;
6870 }
@@ -162,11 +164,12 @@
163165 $tableRows[] = $this->getDescriptionRow( $parameter );
164166 }
165167
166 - if ( count( $tableRows ) > 0 ) {
 168+ if ( count( $tableRows ) > 0 ) { // i18n
167169 $tableRows = array_merge( array( '! Parameter
168170 ! Aliases
 171+! Type
169172 ! Default
170 -! Usage' ), $tableRows );
 173+! Description' ), $tableRows );
171174
172175 $table = implode( "\n|-\n", $tableRows );
173176
@@ -174,11 +177,10 @@
175178 {| class="wikitable sortable"
176179 {$table}
177180 |}
178 -<pre!>..</pre!>
179181 EOT;
180182 }
181183
182 - return $table; // TODO
 184+ return $table;
183185 }
184186
185187 /**
@@ -198,13 +200,19 @@
199201 if ( is_array( $default ) ) $default = implode( ', ', $default );
200202 if ( $default === '' ) $default = "''empty''";
201203
202 - // TODO
 204+ $description = $parameter->getDescription();
 205+ if ( $description === false ) $description = '-';
203206
 207+ // TODO: some mapping to make the type names more user-friendly
 208+ $type = $parameter->getType();
 209+ if ( $parameter->isList() ) $type = wfMsgExt( 'validator-describe-listtype', 'parsemag', $type );
 210+
204211 return <<<EOT
205212 | {$parameter->getName()}
206213 | {$aliases}
 214+| {$type}
207215 | {$default}
208 -| Description be here.
 216+| {$description}
209217 EOT;
210218 }
211219
Index: trunk/extensions/Validator/includes/Parameter.php
@@ -178,6 +178,16 @@
179179 protected $defaulted = false;
180180
181181 /**
 182+ * A description for the parameter or false when there is none.
 183+ * Can be obtained via getDescription and set via setDescription.
 184+ *
 185+ * @since 0.4.3
 186+ *
 187+ * @var mixed string or false
 188+ */
 189+ protected $description = false;
 190+
 191+ /**
182192 * Constructor.
183193 *
184194 * @since 0.4
@@ -449,6 +459,17 @@
450460 }
451461
452462 /**
 463+ * Returns the type of the parameter.
 464+ *
 465+ * @since 0.4.3
 466+ *
 467+ * @return string element of the Parameter::TYPE_ enum
 468+ */
 469+ public function getType() {
 470+ return $this->type;
 471+ }
 472+
 473+ /**
453474 * Returns a list of dependencies the parameter has, in the form of
454475 * other parameter names.
455476 *
@@ -722,6 +743,29 @@
723744 }
724745
725746 return false;
726 - }
 747+ }
 748+
 749+ /**
 750+ * Returns a description message for the parameter, or false when there is none.
 751+ * Override in deriving classes to add a message.
 752+ *
 753+ * @since 0.4.3
 754+ *
 755+ * @return mixed string or false
 756+ */
 757+ public function getDescription() {
 758+ return $this->description;
 759+ }
727760
 761+ /**
 762+ * Sets a description message for the parameter.
 763+ *
 764+ * @since 0.4.3
 765+ *
 766+ * @param string $descriptionMessage
 767+ */
 768+ public function setDescription( $descriptionMessage ) {
 769+ $this->description = $descriptionMessage;
 770+ }
 771+
728772 }
\ No newline at end of file
Index: trunk/extensions/Validator/Validator.i18n.php
@@ -45,6 +45,9 @@
4646 'validator-describe-description' => 'Generates documentation for one or more parser hooks defined via Validator.',
4747 'validator-describe-notfound' => 'There is no parser hook that handles "$1".',
4848 'validator-describe-descriptionmsg' => "'''Description''': $1", // Because it's 1360 < 3
 49+ 'validator-describe-par-hooks' => 'The parser hooks for which to display documentation.',
 50+ 'validator-describe-par-pre' => 'Allows you to get the actual wikitext for the documentation, without it being rendered on the page.',
 51+ 'validator-describe-listtype' => 'List of $1 items',
4952
5053 // Criteria errors for single values
5154 'validator_error_empty_argument' => 'Parameter $1 can not have an empty value.',

Follow-up revisions

RevisionCommit summaryAuthorDate
r79251Fixed hardoced messages, follow up to r79201jeroendedauw13:18, 30 December 2010

Comments

#Comment by Raymond (talk | contribs)   12:39, 30 December 2010

+ 'validator-describe-listtype' => 'List of $1 items',

Needs PLURAL but I hesitate to add it by myself because I do not fully understand this extension. getDescriptionRow() looks a bit hackish with hardcoded words like "required", "empty" and the usage of implode( ', ', $default ) instead $wgLang->listToText. But maybe I am wrong and it is not possible.

#Comment by Jeroen De Dauw (talk | contribs)   12:51, 30 December 2010

$1 is a type, not a number, so I don't think PLURAL applies here. I'll fix the hardcoded stuff later.

Status & tagging log