[MediaWiki-commits] [Gerrit] mediawiki...GeoData[master]: Update for API error i18n
jenkins-bot has submitted this change and it was merged. ( 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, 78 insertions(+), 17 deletions(-) Approvals: Gergő Tisza: Looks good to me, approved jenkins-bot: Verified 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..b9ab5e6 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 - Page name", + "apierror-geodata-notonearth": "{{doc-apierror}}" } diff --git a/includes/api/ApiQueryCoordinates.php b/includes/api/ApiQueryCoordinates.php index 8b799da..ebdcca1 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,42 @@ 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' ); +
[MediaWiki-commits] [Gerrit] mediawiki...GeoData[master]: Update for API error i18n
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