Index: trunk/extensions/Validator/includes/parserHooks/Validator_Describe.php |
— | — | @@ -168,8 +168,12 @@ |
169 | 169 | $description .= "\n\n"; |
170 | 170 | } |
171 | 171 | |
172 | | - $description .= $this->getParameterTable( $descriptionData['parameters'] ); |
| 172 | + $description .= $this->getParameterTable( $descriptionData['parameters'], $descriptionData['defaults'] ); |
173 | 173 | |
| 174 | + if ( $parserHook->forTagExtensions || $parserHook->forParserFunctions ) { |
| 175 | + $description .= $this->getSyntaxExamples( $hookName, $descriptionData['parameters'], $parserHook ); |
| 176 | + } |
| 177 | + |
174 | 178 | if ( $parameters['pre'] ) { |
175 | 179 | $description = '<pre>' . $description . '</pre>'; |
176 | 180 | } |
— | — | @@ -178,23 +182,59 @@ |
179 | 183 | } |
180 | 184 | |
181 | 185 | /** |
| 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 | + /** |
182 | 220 | * Returns the wikitext for a table listing the provided parameters. |
183 | 221 | * |
184 | 222 | * @since 0.4.3 |
185 | 223 | * |
186 | 224 | * @param array $parameters |
| 225 | + * @param array $defaults |
187 | 226 | * |
188 | 227 | * @return string |
189 | 228 | */ |
190 | | - protected function getParameterTable( array $parameters ) { |
| 229 | + protected function getParameterTable( array $parameters, array $defaults ) { |
191 | 230 | $tableRows = array(); |
192 | 231 | |
193 | 232 | foreach ( $parameters as $parameter ) { |
194 | | - $tableRows[] = $this->getDescriptionRow( $parameter ); |
| 233 | + $tableRows[] = $this->getDescriptionRow( $parameter, $defaults ); |
195 | 234 | } |
196 | 235 | |
197 | 236 | if ( count( $tableRows ) > 0 ) { // i18n |
198 | | - $tableRows = array_merge( array( '! Parameter |
| 237 | + $tableRows = array_merge( array( '! # |
| 238 | +! Parameter |
199 | 239 | ! Aliases |
200 | 240 | ! Type |
201 | 241 | ! Default |
— | — | @@ -203,6 +243,8 @@ |
204 | 244 | $table = implode( "\n|-\n", $tableRows ); |
205 | 245 | |
206 | 246 | $table = <<<EOT |
| 247 | +<h3>Parameters</h3> |
| 248 | + |
207 | 249 | {| class="wikitable sortable" |
208 | 250 | {$table} |
209 | 251 | |} |
— | — | @@ -218,10 +260,11 @@ |
219 | 261 | * @since 0.4.3 |
220 | 262 | * |
221 | 263 | * @param Parameter $parameter |
| 264 | + * @param array $defaults |
222 | 265 | * |
223 | 266 | * @return string |
224 | 267 | */ |
225 | | - protected function getDescriptionRow( Parameter $parameter ) { |
| 268 | + protected function getDescriptionRow( Parameter $parameter, array $defaults ) { |
226 | 269 | $aliases = $parameter->getAliases(); |
227 | 270 | $aliases = count( $aliases ) > 0 ? implode( ', ', $aliases ) : '-'; |
228 | 271 | |
— | — | @@ -236,7 +279,24 @@ |
237 | 280 | $type = $parameter->getType(); |
238 | 281 | if ( $parameter->isList() ) $type = wfMsgExt( 'validator-describe-listtype', 'parsemag', $type ); |
239 | 282 | |
| 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 | + |
240 | 299 | return <<<EOT |
| 300 | +| {$number} |
241 | 301 | | {$parameter->getName()} |
242 | 302 | | {$aliases} |
243 | 303 | | {$type} |