19 private $ttmServerFactory;
23 private const CONSTRUCTOR_OPTIONS = [
25 'TranslateTranslationDefaultService',
26 'TranslateTranslationServices',
29 public function __construct(
35 parent::__construct( $main, $moduleName );
36 $this->options =
new ServiceOptions( self::CONSTRUCTOR_OPTIONS, $config );
37 $this->ttmServerFactory = $ttmServerFactory;
40 public function execute():
void {
41 if ( !$this->getSearchableTtmServers() ) {
42 $this->dieWithError(
'apierror-translate-notranslationservices' );
45 $params = $this->extractRequestParams();
47 $server = $this->ttmServerFactory->create( $params[
'service' ] );
49 $this->dieWithError(
'apierror-translate-notranslationservices' );
52 $result = $this->getResult();
54 if ( $params[
'filter'] !==
'' ) {
56 $documents = $translationSearch->getDocuments();
57 $total = $translationSearch->getTotalHits();
59 $searchResults = $server->search(
64 $documents = $server->getDocuments( $searchResults );
65 $total = $server->getTotalHits( $searchResults );
67 $result->addValue( [
'search',
'metadata' ],
'total', $total );
68 $result->addValue(
'search',
'translations', $documents );
72 private function getSearchableTtmServers(): array {
73 $ttmServiceIds = $this->ttmServerFactory->getNames();
76 foreach ( $ttmServiceIds as $serviceId ) {
77 $ttmServer = $this->ttmServerFactory->create( $serviceId );
86 protected function getAllowedFilters(): array {
95 protected function getAllowedParams(): array {
96 $available = $this->getSearchableTtmServers();
98 $filters = $this->getAllowedFilters();
102 ParamValidator::PARAM_TYPE => $available,
105 ParamValidator::PARAM_TYPE =>
'string',
106 ParamValidator::PARAM_REQUIRED =>
true,
108 'sourcelanguage' => [
109 ParamValidator::PARAM_TYPE =>
'string',
110 ParamValidator::PARAM_DEFAULT => $this->options->get(
'LanguageCode' ),
113 ParamValidator::PARAM_TYPE =>
'string',
114 ParamValidator::PARAM_DEFAULT =>
'',
117 ParamValidator::PARAM_TYPE =>
'string',
118 ParamValidator::PARAM_DEFAULT =>
'',
121 ParamValidator::PARAM_TYPE => $filters,
122 ParamValidator::PARAM_DEFAULT =>
'',
125 ParamValidator::PARAM_TYPE =>
'string',
126 ParamValidator::PARAM_DEFAULT =>
'',
129 ParamValidator::PARAM_TYPE =>
'string',
130 ParamValidator::PARAM_DEFAULT =>
'0',
133 ParamValidator::PARAM_TYPE =>
'integer',
134 ParamValidator::PARAM_DEFAULT => 0,
137 ParamValidator::PARAM_DEFAULT => 25,
138 ParamValidator::PARAM_TYPE =>
'limit',
139 IntegerDef::PARAM_MIN => 1,
140 IntegerDef::PARAM_MAX => ApiBase::LIMIT_SML1,
141 IntegerDef::PARAM_MAX2 => ApiBase::LIMIT_SML2
148 $ret[
'service'][ParamValidator::PARAM_DEFAULT] =
149 $this->options->get(
'TranslateTranslationDefaultService' );
155 protected function getExamplesMessages(): array {
157 'action=searchtranslations&language=fr&query=aide'
158 =>
'apihelp-searchtranslations-example-1',
159 'action=searchtranslations&language=fr&query=edit&filter=untranslated'
160 =>
'apihelp-searchtranslations-example-2',