Lockal has uploaded a new change for review. https://gerrit.wikimedia.org/r/74853
Change subject: (Bug 50861) Debug Yandex translation service failures ...................................................................... (Bug 50861) Debug Yandex translation service failures Migrate to Yandex Translate API v1.5. The previous version 1.0 was deprecated on July 1, 2013. Starting from version 1.5, all API methods must be accessed using a key. Also all API methods must be accessed only via HTTPS protocol. Change-Id: Id5377b9a189be17e182c54df9e8138e9b44fbccc --- M Translate.php M webservices/YandexWebService.php 2 files changed, 23 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate refs/changes/53/74853/1 diff --git a/Translate.php b/Translate.php index b186e70..41f5d7c 100644 --- a/Translate.php +++ b/Translate.php @@ -291,8 +291,9 @@ 'type' => 'apertium', ); $wgTranslateTranslationServices['Yandex'] = array( - 'url' => 'http://translate.yandex.net/api/v1/tr.json/translate', - 'pairs' => 'http://translate.yandex.net/api/v1/tr.json/getLangs', + 'url' => 'https://translate.yandex.net/api/v1.5/tr.json/translate', + 'key' => null, + 'pairs' => 'https://translate.yandex.net/api/v1.5/tr.json/getLangs', 'timeout' => 3, 'langorder' => array( 'en', 'ru', 'uk', 'de', 'fr', 'pl', 'it', 'es', 'tr' ), 'langlimit' => 1, diff --git a/webservices/YandexWebService.php b/webservices/YandexWebService.php index 58e8c65..ea24348 100644 --- a/webservices/YandexWebService.php +++ b/webservices/YandexWebService.php @@ -20,8 +20,19 @@ } protected function doPairs() { + if ( !isset( $this->config['key'] ) ) { + throw new TranslationWebServiceException( 'API key is not set' ); + } + + $service = $this->service; $pairs = array(); - $json = Http::get( $this->config['pairs'], $this->config['timeout'] ); + + $params = array( + 'key' => $this->config['key'], + ); + + $url = $this->config['pairs'] . '?' . wfArrayToCgi( $params ); + $json = Http::get( $url, $this->config['timeout'] ); $response = FormatJson::decode( $json ); if ( !is_object( $response ) ) { @@ -38,6 +49,10 @@ } protected function doRequest( $text, $from, $to ) { + if ( !isset( $this->config['key'] ) ) { + throw new TranslationWebServiceException( 'API key is not set' ); + } + $service = $this->service; $text = trim( $text ); @@ -47,16 +62,16 @@ $options['timeout'] = $this->config['timeout']; $options['method'] = 'POST'; $options['postData'] = array( + 'key' => $this->config['key'], 'text' => $text, 'lang' => "$from-$to", - 'x-application' => "Translate " . TRANSLATE_VERSION . ")", ); $url = $this->config['url']; $req = MWHttpRequest::factory( $url, $options ); - wfProfileIn( 'TranslateWebServiceRequest-' . $this->service ); + wfProfileIn( 'TranslateWebServiceRequest-' . $service ); $status = $req->execute(); - wfProfileOut( 'TranslateWebServiceRequest-' . $this->service ); + wfProfileOut( 'TranslateWebServiceRequest-' . $service ); if ( !$status->isOK() ) { $error = $req->getContent(); @@ -72,7 +87,7 @@ throw new TranslationWebServiceException( serialize( $req->getContent() ) ); } elseif ( $response->code !== 200 ) { $exception = "(HTTP {$response->code}) with ($service ($from|$to)): " . - $req->getContent(); + $response->message; throw new TranslationWebServiceException( $exception ); } -- To view, visit https://gerrit.wikimedia.org/r/74853 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id5377b9a189be17e182c54df9e8138e9b44fbccc Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Translate Gerrit-Branch: master Gerrit-Owner: Lockal <lockals...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits