r79249 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79248‎ | r79249 | r79250 >
Date:12:48, 30 December 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added parameter number column and some work on syntax examples
Modified paths:
  • /trunk/extensions/Validator/includes/parserHooks/Validator_Describe.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Validator/includes/parserHooks/Validator_Describe.php
@@ -168,8 +168,12 @@
169169 $description .= "\n\n";
170170 }
171171
172 - $description .= $this->getParameterTable( $descriptionData['parameters'] );
 172+ $description .= $this->getParameterTable( $descriptionData['parameters'], $descriptionData['defaults'] );
173173
 174+ if ( $parserHook->forTagExtensions || $parserHook->forParserFunctions ) {
 175+ $description .= $this->getSyntaxExamples( $hookName, $descriptionData['parameters'], $parserHook );
 176+ }
 177+
174178 if ( $parameters['pre'] ) {
175179 $description = '<pre>' . $description . '</pre>';
176180 }
@@ -178,23 +182,59 @@
179183 }
180184
181185 /**
 186+ * Returns the wikitext for some syntax examples.
 187+ *
 188+ * @since 0.4.3
 189+ *
 190+ * @param string $hookName
 191+ * @param array $parameters
 192+ * @param ParserHook $parserHook
 193+ *
 194+ * @return string
 195+ */
 196+ protected function getSyntaxExamples( $hookName, array $parameters, ParserHook $parserHook ) {
 197+ $result = "<h3>Syntax</h3>\n\n"; // TODO: i18n
 198+
 199+ $params = array();
 200+
 201+ foreach ( $parameters as $parameter ) {
 202+ $params[$parameter->getName()] = '{' . $parameter->getType() . '}';
 203+ }
 204+
 205+ if ( $parserHook->forTagExtensions ) {
 206+ $result .= "<pre!><nowiki>\n" . Xml::element(
 207+ $hookName,
 208+ $params
 209+ ) . "\n</nowiki></pre!>";
 210+ }
 211+
 212+ if ( $parserHook->forParserFunctions ) {
 213+ // TODO
 214+ }
 215+
 216+ return $result;
 217+ }
 218+
 219+ /**
182220 * Returns the wikitext for a table listing the provided parameters.
183221 *
184222 * @since 0.4.3
185223 *
186224 * @param array $parameters
 225+ * @param array $defaults
187226 *
188227 * @return string
189228 */
190 - protected function getParameterTable( array $parameters ) {
 229+ protected function getParameterTable( array $parameters, array $defaults ) {
191230 $tableRows = array();
192231
193232 foreach ( $parameters as $parameter ) {
194 - $tableRows[] = $this->getDescriptionRow( $parameter );
 233+ $tableRows[] = $this->getDescriptionRow( $parameter, $defaults );
195234 }
196235
197236 if ( count( $tableRows ) > 0 ) { // i18n
198 - $tableRows = array_merge( array( '! Parameter
 237+ $tableRows = array_merge( array( '! #
 238+! Parameter
199239 ! Aliases
200240 ! Type
201241 ! Default
@@ -203,6 +243,8 @@
204244 $table = implode( "\n|-\n", $tableRows );
205245
206246 $table = <<<EOT
 247+<h3>Parameters</h3>
 248+
207249 {| class="wikitable sortable"
208250 {$table}
209251 |}
@@ -218,10 +260,11 @@
219261 * @since 0.4.3
220262 *
221263 * @param Parameter $parameter
 264+ * @param array $defaults
222265 *
223266 * @return string
224267 */
225 - protected function getDescriptionRow( Parameter $parameter ) {
 268+ protected function getDescriptionRow( Parameter $parameter, array $defaults ) {
226269 $aliases = $parameter->getAliases();
227270 $aliases = count( $aliases ) > 0 ? implode( ', ', $aliases ) : '-';
228271
@@ -236,7 +279,24 @@
237280 $type = $parameter->getType();
238281 if ( $parameter->isList() ) $type = wfMsgExt( 'validator-describe-listtype', 'parsemag', $type );
239282
 283+ $number = 0;
 284+ $isDefault = false;
 285+
 286+ foreach ( $defaults as $default ) {
 287+ $number++;
 288+
 289+ if ( $default == $parameter->getName() ) {
 290+ $isDefault = true;
 291+ break;
 292+ }
 293+ }
 294+
 295+ if ( !$isDefault ) {
 296+ $number = '-';
 297+ }
 298+
240299 return <<<EOT
 300+| {$number}
241301 | {$parameter->getName()}
242302 | {$aliases}
243303 | {$type}

Status & tagging log