r113019 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113018‎ | r113019 | r113020 >
Date:11:53, 5 March 2012
Author:nikerabbit
Status:ok
Tags:i18nreview 
Comment:
Exception in one tm/mt module should not prevent other services from running
Modified paths:
  • /trunk/extensions/Translate/utils/TranslationHelpers.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/utils/TranslationHelpers.php
@@ -225,7 +225,7 @@
226226 try {
227227 return call_user_func_array( $cb, $params );
228228 } catch ( TranslationHelperExpection $e ) {
229 - return"<!-- Box $type not available: {$e->getMessage()} -->";
 229+ return "<!-- Box $type not available: {$e->getMessage()} -->";
230230 }
231231 }
232232
@@ -313,6 +313,13 @@
314314 public function getSuggestionBox( $async = false ) {
315315 global $wgTranslateTranslationServices;
316316
 317+ $handlers = array(
 318+ 'ttmserver' => 'getTTMServerBox',
 319+ 'microsoft' => 'getMicrosoftSuggestion',
 320+ 'apertium' => 'getApertiumSuggestion',
 321+ );
 322+
 323+ $errors = '';
317324 $boxes = array();
318325 foreach ( $wgTranslateTranslationServices as $name => $config ) {
319326 if ( $async === 'async' ) {
@@ -321,12 +328,13 @@
322329 $config['timeout'] = $config['timeout-sync'];
323330 }
324331
325 - if ( $config['type'] === 'ttmserver' ) {
326 - $boxes[] = $this->getTTMServerBox( $name, $config );
327 - } elseif ( $config['type'] === 'microsoft' ) {
328 - $boxes[] = $this->getMicrosoftSuggestion( $name, $config );
329 - } elseif ( $config['type'] === 'apertium' ) {
330 - $boxes[] = $this->getApertiumSuggestion( $name, $config );
 332+ if ( isset( $handlers[$config['type']] ) ) {
 333+ $method = $handlers[$config['type']];
 334+ try {
 335+ $boxes[] = $this->$method( $name, $config );
 336+ } catch ( TranslationHelperExpection $e ) {
 337+ $errors .= "<!-- Box $name not available: {$e->getMessage()} -->\n";
 338+ }
331339 } else {
332340 throw new MWException( __METHOD__ . ": Unsupported type {$config['type']}" );
333341 }
@@ -338,10 +346,10 @@
339347 // Enclose if there is more than one box
340348 if ( count( $boxes ) ) {
341349 $sep = Html::element( 'hr', array( 'class' => 'mw-translate-sep' ) );
342 - return TranslateUtils::fieldset( wfMsgHtml( 'translate-edit-tmsugs' ),
 350+ return $errors . TranslateUtils::fieldset( wfMsgHtml( 'translate-edit-tmsugs' ),
343351 implode( "$sep\n", $boxes ), array( 'class' => 'mw-translate-edit-tmsugs' ) );
344352 } else {
345 - return null;
 353+ return $errors;
346354 }
347355 }
348356

Status & tagging log