Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1428171
QueryLanguageStatsActionApi.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
QueryLanguageStatsActionApi.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Extension\Translate\Statistics
;
use
IJobSpecification
;
use
JobQueueGroup
;
use
MediaWiki\Api\ApiQuery
;
use
MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups
;
use
MediaWiki\Extension\Translate\Utilities\Utilities
;
use
Wikimedia\ParamValidator\ParamValidator
;
/**
* Api module for querying language stats.
* @ingroup API TranslateAPI
* @author Niklas Laxström
* @license GPL-2.0-or-later
*/
class
QueryLanguageStatsActionApi
extends
QueryStatsActionApi
{
public
function
__construct
(
ApiQuery
$query
,
string
$moduleName
,
JobQueueGroup
$jobQueueGroup
)
{
parent
::
__construct
(
$query
,
$moduleName
,
'ls'
,
$jobQueueGroup
);
}
// ApiStatsQuery methods
/** @inheritDoc */
protected
function
validateTargetParamater
(
array
$params
):
string
{
$requested
=
$params
[
'language'
];
if
(
!
Utilities
::
isSupportedLanguageCode
(
$requested
)
)
{
$this
->
dieWithError
(
[
'apierror-translate-invalidlanguage'
,
$requested
]
);
}
return
$requested
;
}
/** @inheritDoc */
protected
function
loadStatistics
(
string
$target
,
int
$flags
=
0
):
array
{
$groupId
=
$this
->
getParameter
(
'group'
);
$group
=
$groupId
!==
null
?
MessageGroups
::
getGroup
(
$groupId
)
:
null
;
if
(
$groupId
)
{
if
(
!
$group
)
{
$this
->
dieWithError
(
[
'apierror-badparameter'
,
'group'
]
);
}
return
[
$groupId
=>
MessageGroupStats
::
forItem
(
$group
->
getId
(),
$target
,
$flags
)
];
}
else
{
return
MessageGroupStats
::
forLanguage
(
$target
,
$flags
);
}
}
/** @inheritDoc */
protected
function
makeStatsItem
(
string
$item
,
array
$stats
):
array
{
$data
=
$this
->
makeItem
(
$stats
);
$data
[
'group'
]
=
$item
;
return
$data
;
}
/** @inheritDoc */
protected
function
getCacheRebuildJob
(
string
$target
):
IJobSpecification
{
return
RebuildMessageGroupStatsJob
::
newJob
(
[
'languagecode'
=>
$target
]
);
}
// Api methods
/** @inheritDoc */
protected
function
getAllowedParams
():
array
{
$params
=
parent
::
getAllowedParams
();
$params
[
'language'
]
=
[
ParamValidator
::
PARAM_TYPE
=>
'string'
,
ParamValidator
::
PARAM_REQUIRED
=>
true
,
];
$params
[
'group'
]
=
[
ParamValidator
::
PARAM_TYPE
=>
'string'
,
];
return
$params
;
}
/** @inheritDoc */
protected
function
getExamplesMessages
():
array
{
return
[
'action=query&meta=languagestats&lslanguage=fi'
=>
'apihelp-query+languagestats-example-1'
,
'action=query&meta=languagestats&lslanguage=fi&group=A'
=>
'apihelp-query+languagestats-example-2'
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 16, 15:45 (14 h, 47 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
25/77/1a7367eb8494271f2e7419f594fb
Default Alt Text
QueryLanguageStatsActionApi.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment