Anomie has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/321427

Change subject: Update for API error i18n
......................................................................

Update for API error i18n

See Iae0e2ce3.

Change-Id: If9d08a244ece2a14bfc546695d606ef857308a2f
---
M i18n/en.json
M i18n/qqq.json
M includes/api/ApiQueryCoordinates.php
M includes/api/ApiQueryGeoSearch.php
M tests/phpunit/GeoSearchTest.php
5 files changed, 77 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GeoData 
refs/changes/27/321427/1

diff --git a/i18n/en.json b/i18n/en.json
index 352823b..60ddb13 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -42,5 +42,11 @@
        "apihelp-query+geosearch-param-primary": "Whether to return only 
primary coordinates (\"primary\"), secondary (\"secondary\") or both 
(\"all\").",
        "apihelp-query+geosearch-param-debug": "Whether debug information 
should be returned.",
        "apihelp-query+geosearch-example-1": "Search around the point with 
coordinates 37° 47′ 13.1″ N, 122° 23′ 58.84″ W",
-       "apihelp-query+geosearch-example-2": "Search in a bounding box"
+       "apihelp-query+geosearch-example-2": "Search in a bounding box",
+       "apierror-geodata-nocoord": "Page coordinates unknown.",
+       "apierror-geodata-noprimarycoord": "Page $1 has no primary 
coordinates.",
+       "apierror-geodata-notonearth": "This page's coordinates are not on 
Earth.",
+       "apierror-geodata-invalidbox": "Invalid bounding box.",
+       "apierror-geodata-boxtoobig": "Bounding box is too big",
+       "apierror-geodata-badcoord": "Invalid coordinate provided"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 9bbc85e..de8ef3f 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -46,5 +46,11 @@
        "apihelp-query+geosearch-param-primary": 
"{{doc-apihelp-param|query+geosearch|primary}}",
        "apihelp-query+geosearch-param-debug": 
"{{doc-apihelp-param|query+geosearch|debug}}",
        "apihelp-query+geosearch-example-1": "Do not alter \"37° 47′ 13.1″ N, 
122° 23′ 58.84″ W\".\n{{doc-apihelp-example|query+geosearch}}",
-       "apihelp-query+geosearch-example-2": 
"{{doc-apihelp-example|query+geosearch}}"
+       "apihelp-query+geosearch-example-2": 
"{{doc-apihelp-example|query+geosearch}}",
+       "apierror-geodata-badcoord": "{{doc-apierror}}",
+       "apierror-geodata-boxtoobig": "{{doc-apierror}}",
+       "apierror-geodata-invalidbox": "{{doc-apierror}}",
+       "apierror-geodata-nocoord": "{{doc-apierror}}",
+       "apierror-geodata-noprimarycoord": "{{doc-apierror}}\n\nParameters:\n* 
$1 - ",
+       "apierror-geodata-notonearth": "{{doc-apierror}}"
 }
diff --git a/includes/api/ApiQueryCoordinates.php 
b/includes/api/ApiQueryCoordinates.php
index 8b799da..99f358e 100644
--- a/includes/api/ApiQueryCoordinates.php
+++ b/includes/api/ApiQueryCoordinates.php
@@ -38,10 +38,9 @@
 
                if ( isset( $params['continue'] ) ) {
                        $parts = explode( '|', $params['continue'] );
-                       if ( count( $parts ) != 2 || !is_numeric( $parts[0] ) 
|| !is_numeric( $parts[0] ) ) {
-                               $this->dieUsage( "Invalid continue parameter. 
You should pass the " .
-                                       "original value returned by the 
previous query", "_badcontinue" );
-                       }
+                       $this->dieContinueUsageIf( count( $parts ) != 2 );
+                       $this->dieContinueUsageIf( !is_numeric( $parts[0] ) );
+                       $this->dieContinueUsageIf( !is_numeric( $parts[1] ) );
                        $parts[0] = intval( $parts[0] );
                        $parts[1] = intval( $parts[1] );
                        $this->addWhere(
@@ -99,21 +98,41 @@
                if ( $params['distancefrompoint'] !== null ) {
                        $arr = explode( '|', $params['distancefrompoint'] );
                        if ( count( $arr ) != 2 || 
!$globe->coordinatesAreValid( $arr[0], $arr[1] ) ) {
-                               $this->dieUsage( 'Invalid coordinate provided', 
'_invalid-coord' );
+                               if ( is_callable( [ $this, 'dieWithError' ] ) ) 
{
+                                       $this->dieWithError( 
'apierror-geodata-badcoord', 'invalid-coord' );
+                               } else {
+                                       $this->dieUsage( 'Invalid coordinate 
provided', '_invalid-coord' );
+                               }
                        }
                        return new Coord( $arr[0], $arr[1], 'earth' );
                }
                if ( $params['distancefrompage'] !== null ) {
                        $title = Title::newFromText( 
$params['distancefrompage'] );
                        if ( !$title ) {
-                               $this->dieUsage( "Page 
``{$params['distancefrompage']}'' does not exist", '_invalid-page' );
+                               if ( is_callable( [ $this, 'dieWithError' ] ) ) 
{
+                                       $this->dieWithError(
+                                               [ 'apierror-invalidtitle', 
wfEscapeWikiText( $params['distancefrompage'] ) ]
+                                       );
+                               } else {
+                                       $this->dieUsage( "Page 
``{$params['distancefrompage']}'' does not exist", '_invalid-page' );
+                               }
                        }
                        $coord = GeoData::getPageCoordinates( $title );
                        if ( !$coord ) {
-                               $this->dieUsage( "Page 
``{$params['distancefrompage']}'' has no primary coordinates", 
'_no-coordinates' );
+                               if ( is_callable( [ $this, 'dieWithError' ] ) ) 
{
+                                       $this->dieWithError(
+                                               [ 
'apierror-geodata-noprimarycoord', $title->getPrefixedText() ], 'no-coordinates'
+                                       );
+                               } else {
+                                       $this->dieUsage( "Page 
``{$params['distancefrompage']}'' has no primary coordinates", 
'_no-coordinates' );
+                               }
                        }
                        if ( $coord->globe != 'earth' ) {
-                               $this->dieUsage( "This page's coordinates are 
not on Earth", '_notonearth' );
+                               if ( is_callable( [ $this, 'dieWithError' ] ) ) 
{
+                                       $this->dieWithError( 
'apierror-geodata-notonearth', 'notonearth' );
+                               } else {
+                                       $this->dieUsage( "This page's 
coordinates are not on Earth", '_notonearth' );
+                               }
                        }
                        return $coord;
                }
diff --git a/includes/api/ApiQueryGeoSearch.php 
b/includes/api/ApiQueryGeoSearch.php
index e698080..4a7290c 100644
--- a/includes/api/ApiQueryGeoSearch.php
+++ b/includes/api/ApiQueryGeoSearch.php
@@ -59,14 +59,22 @@
                        || !$globe->coordinatesAreValid( $parts[2], $parts[3] )
                        || $vals[0] <= $vals[2]
                ) {
-                       $this->dieUsage( 'Invalid bounding box', 
'_invalid-bbox' );
+                       if ( is_callable( [ $this, 'dieWithError' ] ) ) {
+                               $this->dieWithError( 
'apierror-geodata-invalidbox', 'invalid-bbox' );
+                       } else {
+                               $this->dieUsage( 'Invalid bounding box', 
'_invalid-bbox' );
+                       }
                }
                $bbox = new BoundingBox( $vals[0], $vals[1], $vals[2], $vals[3] 
);
                $area = $bbox->area();
                if ( $area > $wgMaxGeoSearchRadius * $wgMaxGeoSearchRadius * 4
                        || $area < 100
                ) {
-                       $this->dieUsage( 'Bounding box is too big', '_toobig' );
+                       if ( is_callable( [ $this, 'dieWithError' ] ) ) {
+                               $this->dieWithError( 
'apierror-geodata-boxtoobig', 'toobig' );
+                       } else {
+                               $this->dieUsage( 'Bounding box is too big', 
'_toobig' );
+                       }
                }
 
                return $bbox;
@@ -83,20 +91,38 @@
                if ( isset( $params['coord'] ) ) {
                        $arr = explode( '|', $params['coord'] );
                        if ( count( $arr ) != 2 || 
!$globe->coordinatesAreValid( $arr[0], $arr[1] ) ) {
-                               $this->dieUsage( 'Invalid coordinate provided', 
'_invalid-coord' );
+                               if ( is_callable( [ $this, 'dieWithError' ] ) ) 
{
+                                       $this->dieWithError( 
'apierror-geodata-badcoord', 'invalid-coord' );
+                               } else {
+                                       $this->dieUsage( 'Invalid coordinate 
provided', '_invalid-coord' );
+                               }
                        }
                        $this->coord = new Coord( floatval( $arr[0] ), 
floatval( $arr[1] ), $params['globe'] );
                } elseif ( isset( $params['page'] ) ) {
                        $t = Title::newFromText( $params['page'] );
                        if ( !$t || !$t->canExist() ) {
-                               $this->dieUsage( "Invalid page title 
``{$params['page']}'' provided", '_invalid-page' );
+                               if ( is_callable( [ $this, 'dieWithError' ] ) ) 
{
+                                       $this->dieWithError( [ 
'apierror-invalidtitle', wfEscapeWikiText( $params['page'] ) ] );
+                               } else {
+                                       $this->dieUsage( "Invalid page title 
``{$params['page']}'' provided", '_invalid-page' );
+                               }
                        }
                        if ( !$t->exists() ) {
-                               $this->dieUsage( "Page ``{$params['page']}'' 
does not exist", '_nonexistent-page' );
+                               if ( is_callable( [ $this, 'dieWithError' ] ) ) 
{
+                                       $this->dieWithError(
+                                               [ 
'apierror-missingtitle-byname', $t->getPrefixedText() ], 'missingtitle'
+                                       );
+                               } else {
+                                       $this->dieUsage( "Page 
``{$params['page']}'' does not exist", '_nonexistent-page' );
+                               }
                        }
                        $this->coord = GeoData::getPageCoordinates( $t );
                        if ( !$this->coord ) {
-                               $this->dieUsage( 'Page coordinates unknown', 
'_no-coordinates' );
+                               if ( is_callable( [ $this, 'dieWithError' ] ) ) 
{
+                                       $this->dieWithError( 
'apierror-geodata-nocoord', 'no-coordinates' );
+                               } else {
+                                       $this->dieUsage( 'Page coordinates 
unknown', '_no-coordinates' );
+                               }
                        }
                        $this->idToExclude = $t->getArticleID();
                } elseif ( isset( $params['bbox'] ) ) {
diff --git a/tests/phpunit/GeoSearchTest.php b/tests/phpunit/GeoSearchTest.php
index 53f228a..331e7ef 100644
--- a/tests/phpunit/GeoSearchTest.php
+++ b/tests/phpunit/GeoSearchTest.php
@@ -6,6 +6,7 @@
 use FauxRequest;
 use GeoData\ApiQueryGeoSearch;
 use MediaWikiTestCase;
+use ApiUsageException;
 use UsageException;
 
 /**
@@ -26,10 +27,12 @@
        }
 
        /**
-        * @expectedException UsageException
         * @dataProvider provideRequiredParams
         */
        public function testRequiredParams( array $params ) {
+               $this->setExpectedException(
+                       class_exists( ApiUsageException::class ) ? 
ApiUsageException::class : UsageException::class
+               );
                $this->request( $params );
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/321427
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If9d08a244ece2a14bfc546695d606ef857308a2f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/GeoData
Gerrit-Branch: master
Gerrit-Owner: Anomie <bjor...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to