18 private const GROUPS =
'groups';
19 private const MESSAGES =
'messages';
21 public function __construct( ApiMain $mainModule, $moduleName,
EntitySearch $entitySearch ) {
22 parent::__construct( $mainModule, $moduleName );
23 $this->entitySearch = $entitySearch;
26 public function execute() {
27 $query = $this->getParameter(
'query' );
28 $maxResults = $this->getParameter(
'limit' );
29 $entityTypes = $this->getParameter(
'entitytype' );
30 $groupTypeFilter = $this->getParameter(
'grouptypes' );
33 $remainingResults = $maxResults;
35 if ( in_array( self::GROUPS, $entityTypes ) ) {
36 $searchResults[ self::GROUPS ] = $this->entitySearch
37 ->searchStaticMessageGroups( $query, $maxResults, $groupTypeFilter );
38 $remainingResults = $maxResults - count( $searchResults[ self::GROUPS ] );
41 if ( in_array( self::MESSAGES, $entityTypes ) && $remainingResults > 0 ) {
42 $searchResults[ self::MESSAGES ] = $this->entitySearch
43 ->searchMessages( $query, $remainingResults );
46 $this->getResult()->addValue(
null, $this->getModuleName(), $searchResults );
49 protected function getAllowedParams(): array {
52 ParamValidator::PARAM_TYPE => [ self::GROUPS, self::MESSAGES ],
53 ParamValidator::PARAM_ISMULTI =>
true,
54 ParamValidator::PARAM_DEFAULT => implode(
'|', [ self::GROUPS, self::MESSAGES ] )
57 ParamValidator::PARAM_TYPE =>
'string',
58 ParamValidator::PARAM_DEFAULT =>
''
61 ParamValidator::PARAM_TYPE =>
'limit',
62 ParamValidator::PARAM_DEFAULT => 10,
63 NumericDef::PARAM_MAX => ApiBase::LIMIT_SML1
66 ParamValidator::PARAM_ISMULTI =>
true,
67 ParamValidator::PARAM_DEFAULT => [],
68 ParamValidator::PARAM_TYPE => array_keys( $this->entitySearch->getGroupTypes() )
73 public function isInternal():
bool {