r112690 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112689‎ | r112690 | r112691 >
Date:14:42, 29 February 2012
Author:nikerabbit
Status:ok
Tags:
Comment:
Google no more
Modified paths:
  • /trunk/extensions/Translate/utils/TranslationHelpers.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/utils/TranslationHelpers.php
@@ -405,8 +405,6 @@
406406 $boxes[] = $this->getTmBox( $name, $config );
407407 } elseif ( $config['type'] === 'ttmserver' ) {
408408 $boxes[] = $this->getTTMServerBox( $name, $config );
409 - } elseif ( $config['type'] === 'google' ) {
410 - $boxes[] = $this->getGoogleSuggestion( $name, $config );
411409 } elseif ( $config['type'] === 'microsoft' ) {
412410 $boxes[] = $this->getMicrosoftSuggestion( $name, $config );
413411 } elseif ( $config['type'] === 'apertium' ) {
@@ -429,60 +427,6 @@
430428 }
431429 }
432430
433 - protected function getGoogleSuggestion( $serviceName, $config ) {
434 - global $wgMemc;
435 -
436 - $this->mustHaveDefinition();
437 - self::checkTranslationServiceFailure( $serviceName );
438 -
439 - $code = $this->handle->getCode();
440 - $definition = trim( strval( $this->getDefinition() ) );
441 - $definition = self::wrapUntranslatable( $definition );
442 -
443 - $memckey = wfMemckey( 'translate-tmsug-badcodes-' . $serviceName );
444 - $unsupported = $wgMemc->get( $memckey );
445 -
446 - if ( isset( $unsupported[$code] ) ) {
447 - return null;
448 - }
449 -
450 - /* There is 5000 *character* limit, but encoding needs to be taken into
451 - * account. Not sure if this applies also to post method. */
452 - if ( strlen( rawurlencode( $definition ) ) > 4900 ) {
453 - return null;
454 - }
455 -
456 - $source = $this->group->getSourceLanguage();
457 - $options = self::makeGoogleQueryParams( $definition, "$source|$code", $config );
458 - $json = Http::post( $config['url'], $options );
459 - $response = FormatJson::decode( $json );
460 -
461 - if ( $json === false ) {
462 - // Most likely a timeout or other general error
463 - self::reportTranslationServiceFailure( $serviceName );
464 - } elseif ( !is_object( $response ) ) {
465 - error_log( __METHOD__ . ': Unable to parse reply: ' . strval( $json ) );
466 - return null;
467 - }
468 -
469 - if ( $response->responseStatus === 200 ) {
470 - $text = Sanitizer::decodeCharReferences( $response->responseData->translatedText );
471 - $text = self::unwrapUntranslatable( $text );
472 - $text = $this->suggestionField( $text );
473 - return Html::rawElement( 'div', null, self::legend( $serviceName ) . $text . self::clear() );
474 - } elseif ( $response->responseDetails === 'invalid translation language pair' ) {
475 - $unsupported[$code] = true;
476 - $wgMemc->set( $memckey, $unsupported, 60 * 60 * 8 );
477 - } else {
478 - // Unknown error, assume the worst
479 - wfWarn( __METHOD__ . "($serviceName): " . $response->responseDetails );
480 - error_log( __METHOD__ . "($serviceName): " . $response->responseDetails );
481 - self::reportTranslationServiceFailure( $serviceName );
482 - }
483 -
484 - return null;
485 - }
486 -
487431 protected static function makeGoogleQueryParams( $definition, $pair, $config ) {
488432 global $wgSitename, $wgVersion, $wgProxyKey, $wgUser;
489433 $options = array();

Status & tagging log