18 private $entitySearch;
19 private const GROUPS =
'groups';
20 private const MESSAGES =
'messages';
22 public function __construct( ApiMain $mainModule, $moduleName,
EntitySearch $entitySearch ) {
23 parent::__construct( $mainModule, $moduleName );
24 $this->entitySearch = $entitySearch;
27 public function execute() {
28 $query = $this->getParameter(
'query' );
29 $maxResults = $this->getParameter(
'limit' );
30 $entityTypes = $this->getParameter(
'entitytype' );
33 $remainingResults = $maxResults;
35 if ( in_array( self::GROUPS, $entityTypes ) ) {
36 $searchResults[ self::GROUPS ] = $this->entitySearch
37 ->searchStaticMessageGroups( $query, $maxResults );
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_REQUIRED => true
61 ParamValidator::PARAM_TYPE =>
'limit',
62 ParamValidator::PARAM_DEFAULT => 10,
63 NumericDef::PARAM_MAX => ApiBase::LIMIT_SML1
68 public function isInternal():
bool {