r106439 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106438‎ | r106439 | r106440 >
Date:15:28, 16 December 2011
Author:reedy
Status:reverted (Comments)
Tags:
Comment:
Prep work for * (bug 33147) API examples should explain what they do

Now formatted in the autogenerated documentation

Format for paraminfo adds a description attribute to output


query allimages descriptions are tranformed, need to do/add to other ones
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/includes/api/ApiBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiParamInfo.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryAllimages.php (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -212,6 +212,7 @@
213213 * (bug 32415) Empty page get no size attribute in API output.
214214 * (bug 31759) Undefined property notice in querypages API.
215215 * (bug 32495) API should allow purge by pageids.
 216+* (bug 33147) API examples should explain what they do.
216217
217218 === Languages updated in 1.19 ===
218219
Index: trunk/phase3/includes/api/ApiQueryAllimages.php
@@ -246,12 +246,14 @@
247247
248248 public function getExamples() {
249249 return array(
250 - 'Simple Use',
251 - ' Show a list of images starting at the letter "B"',
252 - ' api.php?action=query&list=allimages&aifrom=B',
253 - 'Using as Generator',
254 - ' Show info about 4 images starting at the letter "T"',
255 - ' api.php?action=query&generator=allimages&gailimit=4&gaifrom=T&prop=imageinfo',
 250+ 'api.php?action=query&list=allimages&aifrom=B' => array(
 251+ 'Simple Use',
 252+ 'Show a list of images starting at the letter "B"',
 253+ ),
 254+ 'api.php?action=query&generator=allimages&gailimit=4&gaifrom=T&prop=imageinfo' => array(
 255+ 'Using as Generator',
 256+ 'Show info about 4 images starting at the letter "T"',
 257+ ),
256258 );
257259 }
258260
Index: trunk/phase3/includes/api/ApiBase.php
@@ -267,7 +267,29 @@
268268 $msg .= "Parameters:\n$paramsMsg";
269269 }
270270
271 - $msg .= $this->makeHelpArrayToString( $lnPrfx, "Example", $this->getExamples() );
 271+ $examples = $this->getExamples();
 272+ if ( $examples !== false ) {
 273+ if ( !is_array( $examples ) ) {
 274+ $examples = array(
 275+ $examples
 276+ );
 277+ }
 278+ $msg .= "Example" . ( count( $examples ) > 1 ? 's' : '' ) . ":\n";
 279+ foreach( $examples as $k => $v ) {
 280+ if ( is_numeric( $k ) ) {
 281+ $msg .= " $v\n";
 282+ } else {
 283+ if ( is_array( $v ) ) {
 284+ $msg .= implode( "\n", array_map( array( $this, 'indentExampleText' ), $v ) );
 285+ } else {
 286+ $msg .= " $v";
 287+ }
 288+ $msg .= "\n $k";
 289+ }
 290+ }
 291+ }
 292+
 293+ $msg .= "\n";
272294 $msg .= $this->makeHelpArrayToString( $lnPrfx, "Help page", $this->getHelpUrls() );
273295
274296 if ( $this->getMain()->getShowVersions() ) {
@@ -292,6 +314,14 @@
293315 }
294316
295317 /**
 318+ * @param $item string
 319+ * @return string
 320+ */
 321+ private function indentExampleText( $item ) {
 322+ return " " . $item;
 323+ }
 324+
 325+ /**
296326 * @param $prefix string Text to split output items
297327 * @param $title string What is being output
298328 * @param $input string|array
Index: trunk/phase3/includes/api/ApiParamInfo.php
@@ -114,8 +114,9 @@
115115 $result = $this->getResult();
116116 $retval['classname'] = get_class( $obj );
117117 $retval['description'] = implode( "\n", (array)$obj->getFinalDescription() );
118 - $examples = (array)$obj->getExamples();
119 - $retval['examples'] = implode( "\n", $examples );
 118+
 119+ $retval['examples'] = '';
 120+
120121 $retval['version'] = implode( "\n", (array)$obj->getVersion() );
121122 $retval['prefix'] = $obj->getModulePrefix();
122123
@@ -143,9 +144,28 @@
144145 }
145146 $result->setIndexedTagName( $retval['helpurls'], 'helpurl' );
146147
147 - $retval['allexamples'] = $examples;
148 - if ( isset( $retval['allexamples'][0] ) && $retval['allexamples'][0] === false ) {
149 - $retval['allexamples'] = array();
 148+ $examples = $obj->getExamples();
 149+ $retval['allexamples'] = array();
 150+ if ( $examples !== false ) {
 151+ foreach( $examples as $k => $v ) {
 152+ if ( strlen( $retval['examples'] ) ) {
 153+ $retval['examples'] .= ' ';
 154+ }
 155+ $item = array();
 156+ if ( is_numeric( $k ) ) {
 157+ $retval['examples'] .= $v;
 158+ $result->setContent( $item, $v );
 159+ } else {
 160+ if ( !is_array( $v ) ) {
 161+ $item['description'] = $v;
 162+ } else {
 163+ $item['description'] = implode( $v, "\n" );
 164+ }
 165+ $retval['examples'] .= $item['description'] . ' ' . $k;
 166+ $result->setContent( $item, $k );
 167+ }
 168+ $retval['allexamples'][] = $item;
 169+ }
150170 }
151171 $result->setIndexedTagName( $retval['allexamples'], 'example' );
152172

Follow-up revisions

RevisionCommit summaryAuthorDate
r106441Convert a few more descriptions...reedy15:45, 16 December 2011
r106521More example conversions/additions...reedy19:10, 17 December 2011
r106870For r106521/r106865, wrap long example description strings...reedy21:37, 20 December 2011
r106879Revert r106439, r106441 - bad formatting mushing separate lines togetherbrion22:11, 20 December 2011
r107393Re-instate most of the revisions for bug 33147 "API examples should explain w...reedy16:22, 27 December 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   22:08, 20 December 2011

This looks wrong:

Examples:
  Simple Use
  Show a list of images starting at the letter "B"
    api.php?action=query&list=allimages&aifrom=B  Using as Generator
  Show info about 4 images starting at the letter "T"
    api.php?action=query&generator=allimages&gailimit=4&gaifrom=T&prop=imageinfo

Status & tagging log