Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4147282
QueryStatsActionApi.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
QueryStatsActionApi.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Extension\Translate\Statistics
;
use
IJobSpecification
;
use
JobQueueGroup
;
use
MediaWiki\Api\ApiBase
;
use
MediaWiki\Api\ApiQuery
;
use
MediaWiki\Api\ApiQueryBase
;
use
MediaWiki\Deferred\DeferredUpdates
;
use
Wikimedia\ParamValidator\ParamValidator
;
/**
* A base module for querying message group related stats.
*
* @ingroup API TranslateAPI
* @author Niklas Laxström
* @license GPL-2.0-or-later
* @since 2012-11-30
*/
abstract
class
QueryStatsActionApi
extends
ApiQueryBase
{
private
JobQueueGroup
$jobQueueGroup
;
public
function
__construct
(
ApiQuery
$queryModule
,
string
$moduleName
,
string
$paramPrefix
,
JobQueueGroup
$jobQueueGroup
)
{
parent
::
__construct
(
$queryModule
,
$moduleName
,
$paramPrefix
);
$this
->
jobQueueGroup
=
$jobQueueGroup
;
}
/** @inheritDoc */
public
function
getCacheMode
(
$params
):
string
{
return
'public'
;
}
/**
* Implement this to implement input validation and return the name of the target that
* is then given to loadStats.
*/
abstract
protected
function
validateTargetParamater
(
array
$params
):
string
;
/**
* Implement this to load stats.
* @param string $target
* @param int $flags See MessageGroupStats for possible flags
* @return array[]
*/
abstract
protected
function
loadStatistics
(
string
$target
,
int
$flags
=
0
):
array
;
/** Implement this to load each individual stat item */
abstract
protected
function
makeStatsItem
(
string
$item
,
array
$stats
):
?
array
;
public
function
execute
()
{
$params
=
$this
->
extractRequestParams
();
$target
=
$this
->
validateTargetParamater
(
$params
);
$cache
=
$this
->
loadStatistics
(
$target
,
MessageGroupStats
::
FLAG_CACHE_ONLY
);
$result
=
$this
->
getResult
();
$incomplete
=
false
;
foreach
(
$cache
as
$item
=>
$stats
)
{
if
(
$item
<
$params
[
'offset'
]
)
{
continue
;
}
if
(
$stats
[
MessageGroupStats
::
TOTAL
]
===
null
)
{
$incomplete
=
true
;
$this
->
setContinueEnumParameter
(
'offset'
,
$item
);
break
;
}
$data
=
$this
->
makeStatsItem
(
$item
,
$stats
);
if
(
$data
===
null
)
{
continue
;
}
$result
->
addValue
(
[
'query'
,
$this
->
getModuleName
()
],
null
,
$data
);
}
$result
->
addIndexedTagName
(
[
'query'
,
$this
->
getModuleName
()
],
'stats'
);
if
(
$incomplete
)
{
DeferredUpdates
::
addCallableUpdate
(
function
()
use
(
$target
):
void
{
$this
->
jobQueueGroup
->
push
(
$this
->
getCacheRebuildJob
(
$target
)
);
}
);
}
}
protected
function
makeItem
(
array
$stats
):
array
{
return
[
'total'
=>
$stats
[
MessageGroupStats
::
TOTAL
],
'translated'
=>
$stats
[
MessageGroupStats
::
TRANSLATED
],
'fuzzy'
=>
$stats
[
MessageGroupStats
::
FUZZY
],
'proofread'
=>
$stats
[
MessageGroupStats
::
PROOFREAD
],
];
}
abstract
protected
function
getCacheRebuildJob
(
string
$target
):
IJobSpecification
;
protected
function
getAllowedParams
():
array
{
return
[
'offset'
=>
[
ParamValidator
::
PARAM_DEFAULT
=>
'0'
,
ParamValidator
::
PARAM_TYPE
=>
'string'
,
ApiBase
::
PARAM_HELP_MSG
=>
'api-help-param-continue'
,
],
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Aug 19 2026, 18:21 (6 w, 1 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
a4/da/892fe4561bb90ec5896974518714
Default Alt Text
QueryStatsActionApi.php (3 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment