diff options
Diffstat (limited to 'www/wiki/extensions/Translate/api/ApiQueryTranslationAids.php')
-rw-r--r-- | www/wiki/extensions/Translate/api/ApiQueryTranslationAids.php | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/www/wiki/extensions/Translate/api/ApiQueryTranslationAids.php b/www/wiki/extensions/Translate/api/ApiQueryTranslationAids.php index 8fa06d11..67560df1 100644 --- a/www/wiki/extensions/Translate/api/ApiQueryTranslationAids.php +++ b/www/wiki/extensions/Translate/api/ApiQueryTranslationAids.php @@ -4,7 +4,7 @@ * * @file * @author Niklas Laxström - * @license GPL-2.0+ + * @license GPL-2.0-or-later */ /** @@ -18,15 +18,12 @@ class ApiTranslationAids extends ApiBase { $title = Title::newFromText( $params['title'] ); if ( !$title ) { - $this->dieUsage( 'Invalid title', 'invalidtitle' ); + $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['title'] ) ] ); } $handle = new MessageHandle( $title ); if ( !$handle->isValid() ) { - $this->dieUsage( - 'Title does not correspond to a translatable message', - 'nomessagefortitle' - ); + $this->dieWithError( 'apierror-translate-nomessagefortitle', 'nomessagefortitle' ); } if ( (string)$params['group'] !== '' ) { @@ -36,11 +33,11 @@ class ApiTranslationAids extends ApiBase { } if ( !$group ) { - $this->dieUsage( 'Invalid group', 'invalidgroup' ); + $this->dieWithError( 'apierror-translate-invalidgroup', 'invalidgroup' ); } - $data = array(); - $times = array(); + $data = []; + $times = []; $props = $params['prop']; $aggregator = new QueryAggregator(); @@ -52,7 +49,9 @@ class ApiTranslationAids extends ApiBase { $result = $this->getResult(); // Create list of aids, populate web services queries - $aids = array(); + $aids = []; + + $dataProvider = new TranslationAidDataProvider( $handle ); foreach ( $props as $type ) { // Do not proceed if translation aid is not supported for this message group if ( !isset( $types[$type] ) ) { @@ -60,11 +59,17 @@ class ApiTranslationAids extends ApiBase { } $class = $types[$type]; - $obj = new $class( $group, $handle, $this ); + $obj = new $class( $group, $handle, $this, $dataProvider ); if ( $obj instanceof QueryAggregatorAware ) { $obj->setQueryAggregator( $aggregator ); - $obj->populateQueries(); + try { + $obj->populateQueries(); + } catch ( TranslationHelperException $e ) { + $data[$type] = [ 'error' => $e->getMessage() ]; + // Prevent processing this aids and thus overwriting our error + continue; + } } $aids[$type] = $obj; @@ -82,7 +87,7 @@ class ApiTranslationAids extends ApiBase { try { $aid = $obj->getData(); } catch ( TranslationHelperException $e ) { - $aid = array( 'error' => $e->getMessage() ); + $aid = [ 'error' => $e->getMessage() ]; } if ( isset( $aid['**'] ) ) { @@ -100,28 +105,28 @@ class ApiTranslationAids extends ApiBase { public function getAllowedParams() { $props = array_keys( TranslationAid::getTypes() ); - Hooks::run( 'TranslateTranslationAids', array( &$props ) ); + Hooks::run( 'TranslateTranslationAids', [ &$props ] ); - return array( - 'title' => array( + return [ + 'title' => [ ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_REQUIRED => true, - ), - 'group' => array( + ], + 'group' => [ ApiBase::PARAM_TYPE => 'string', - ), - 'prop' => array( + ], + 'prop' => [ ApiBase::PARAM_DFLT => implode( '|', $props ), ApiBase::PARAM_TYPE => $props, ApiBase::PARAM_ISMULTI => true, - ), - ); + ], + ]; } protected function getExamplesMessages() { - return array( + return [ 'action=translationaids&title=MediaWiki:January/fi' => 'apihelp-translationaids-example-1', - ); + ]; } } |