20 private $ttmServerFactory;
24 private const CONSTRUCTOR_OPTIONS = [
26 'TranslateTranslationDefaultService',
27 'TranslateTranslationServices',
30 public function __construct(
36 parent::__construct( $main, $moduleName );
37 $this->options =
new ServiceOptions( self::CONSTRUCTOR_OPTIONS, $config );
38 $this->ttmServerFactory = $ttmServerFactory;
41 public function execute():
void {
42 if ( !$this->getSearchableTtmServers() ) {
43 $this->dieWithError(
'apierror-translate-notranslationservices' );
46 $params = $this->extractRequestParams();
48 $server = $this->ttmServerFactory->create( $params[
'service' ] );
50 $this->dieWithError(
'apierror-translate-notranslationservices' );
53 $result = $this->getResult();
55 if ( $params[
'filter'] !==
'' ) {
57 $documents = $translationSearch->getDocuments();
58 $total = $translationSearch->getTotalHits();
60 $searchResults = $server->search(
65 $documents = $server->getDocuments( $searchResults );
66 $total = $server->getTotalHits( $searchResults );
68 $result->addValue( [
'search',
'metadata' ],
'total', $total );
69 $result->addValue(
'search',
'translations', $documents );
73 private function getSearchableTtmServers(): array {
74 $ttmServiceIds = $this->ttmServerFactory->getNames();
77 foreach ( $ttmServiceIds as $serviceId ) {
78 $ttmServer = $this->ttmServerFactory->create( $serviceId );
87 protected function getAllowedFilters(): array {
96 protected function getAllowedParams(): array {
97 $available = $this->getSearchableTtmServers();
99 $filters = $this->getAllowedFilters();
103 ParamValidator::PARAM_TYPE => $available,
106 ParamValidator::PARAM_TYPE =>
'string',
107 ParamValidator::PARAM_REQUIRED =>
true,
109 'sourcelanguage' => [
110 ParamValidator::PARAM_TYPE =>
'string',
111 ParamValidator::PARAM_DEFAULT => $this->options->get(
'LanguageCode' ),
114 ParamValidator::PARAM_TYPE =>
'string',
115 ParamValidator::PARAM_DEFAULT =>
'',
118 ParamValidator::PARAM_TYPE =>
'string',
119 ParamValidator::PARAM_DEFAULT =>
'',
122 ParamValidator::PARAM_TYPE => $filters,
123 ParamValidator::PARAM_DEFAULT =>
'',
126 ParamValidator::PARAM_TYPE =>
'string',
127 ParamValidator::PARAM_DEFAULT =>
'',
130 ParamValidator::PARAM_TYPE =>
'string',
131 ParamValidator::PARAM_DEFAULT =>
'0',
134 ParamValidator::PARAM_TYPE =>
'integer',
135 ParamValidator::PARAM_DEFAULT => 0,
138 ParamValidator::PARAM_DEFAULT => 25,
139 ParamValidator::PARAM_TYPE =>
'limit',
140 IntegerDef::PARAM_MIN => 1,
141 IntegerDef::PARAM_MAX => ApiBase::LIMIT_SML1,
142 IntegerDef::PARAM_MAX2 => ApiBase::LIMIT_SML2
149 $ret[
'service'][ParamValidator::PARAM_DEFAULT] =
150 $this->options->get(
'TranslateTranslationDefaultService' );
156 protected function getExamplesMessages(): array {
158 'action=searchtranslations&language=fr&query=aide'
159 =>
'apihelp-searchtranslations-example-1',
160 'action=searchtranslations&language=fr&query=edit&filter=untranslated'
161 =>
'apihelp-searchtranslations-example-2',