ApiComparePages: Throw an error if getDiffBody returns false, instead of blank output
authorMatthew Britton <gurch@users.mediawiki.org>
Mon, 6 Jun 2011 09:22:52 +0000 (09:22 +0000)
committerMatthew Britton <gurch@users.mediawiki.org>
Mon, 6 Jun 2011 09:22:52 +0000 (09:22 +0000)
This lets the client distinguish a legitimately blank diff (identical revisions) from one that does not exist or which they do not have permission to view.

getDiffBody doesn't tell the caller why it failed, so there may be a better way to do this.

includes/api/ApiComparePages.php

index 43d3d1f..38fce50 100644 (file)
@@ -53,7 +53,13 @@ class ApiComparePages extends ApiBase {
                $vals['torevid'] = $rev2;
 
                $difftext = $de->getDiffBody();
-               ApiResult::setContent( $vals, $difftext );
+               
+               if ( $difftext === false ) {
+                       $this->dieUsage( 'The diff cannot be retrieved. ' . 
+                               'Maybe one or both revisions do not exist or you do not have permission to view them.', 'baddiff' );
+               } else {
+                       ApiResult::setContent( $vals, $difftext );
+               }
 
                $this->getResult()->addValue( null, $this->getModuleName(), $vals );
        }