Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1428861
TranslationEntitySearchActionApi.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
TranslationEntitySearchActionApi.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Extension\Translate\TranslatorInterface
;
use
ApiBase
;
use
ApiMain
;
use
Wikimedia\ParamValidator\ParamValidator
;
use
Wikimedia\ParamValidator\TypeDef\NumericDef
;
/**
* Action API module for searching message groups and message keys.
* @author Niklas Laxström
* @license GPL-2.0-or-later
*/
class
TranslationEntitySearchActionApi
extends
ApiBase
{
private
EntitySearch
$entitySearch
;
private
const
GROUPS
=
'groups'
;
private
const
MESSAGES
=
'messages'
;
public
function
__construct
(
ApiMain
$mainModule
,
$moduleName
,
EntitySearch
$entitySearch
)
{
parent
::
__construct
(
$mainModule
,
$moduleName
);
$this
->
entitySearch
=
$entitySearch
;
}
public
function
execute
()
{
$query
=
$this
->
getParameter
(
'query'
);
$maxResults
=
$this
->
getParameter
(
'limit'
);
$entityTypes
=
$this
->
getParameter
(
'entitytype'
);
$groupTypeFilter
=
$this
->
getParameter
(
'grouptypes'
);
$searchResults
=
[];
$remainingResults
=
$maxResults
;
if
(
in_array
(
self
::
GROUPS
,
$entityTypes
)
)
{
$searchResults
[
self
::
GROUPS
]
=
$this
->
entitySearch
->
searchStaticMessageGroups
(
$query
,
$maxResults
,
$groupTypeFilter
);
$remainingResults
=
$maxResults
-
count
(
$searchResults
[
self
::
GROUPS
]
);
}
if
(
in_array
(
self
::
MESSAGES
,
$entityTypes
)
&&
$remainingResults
>
0
)
{
$searchResults
[
self
::
MESSAGES
]
=
$this
->
entitySearch
->
searchMessages
(
$query
,
$remainingResults
);
}
$this
->
getResult
()->
addValue
(
null
,
$this
->
getModuleName
(),
$searchResults
);
}
protected
function
getAllowedParams
():
array
{
return
[
'entitytype'
=>
[
ParamValidator
::
PARAM_TYPE
=>
[
self
::
GROUPS
,
self
::
MESSAGES
],
ParamValidator
::
PARAM_ISMULTI
=>
true
,
ParamValidator
::
PARAM_DEFAULT
=>
implode
(
'|'
,
[
self
::
GROUPS
,
self
::
MESSAGES
]
)
],
'query'
=>
[
ParamValidator
::
PARAM_TYPE
=>
'string'
,
ParamValidator
::
PARAM_DEFAULT
=>
''
],
'limit'
=>
[
ParamValidator
::
PARAM_TYPE
=>
'limit'
,
ParamValidator
::
PARAM_DEFAULT
=>
10
,
NumericDef
::
PARAM_MAX
=>
ApiBase
::
LIMIT_SML1
],
'grouptypes'
=>
[
ParamValidator
::
PARAM_ISMULTI
=>
true
,
ParamValidator
::
PARAM_DEFAULT
=>
[],
ParamValidator
::
PARAM_TYPE
=>
array_keys
(
$this
->
entitySearch
->
getGroupTypes
()
)
]
];
}
public
function
isInternal
():
bool
{
// Temporarily until stable
return
true
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 16, 16:46 (11 h, 55 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
4d/ee/4f81d0d8eaa053941966d2b78318
Default Alt Text
TranslationEntitySearchActionApi.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment