summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Translate/api/ApiStatsQuery.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/Translate/api/ApiStatsQuery.php')
-rw-r--r--www/wiki/extensions/Translate/api/ApiStatsQuery.php54
1 files changed, 40 insertions, 14 deletions
diff --git a/www/wiki/extensions/Translate/api/ApiStatsQuery.php b/www/wiki/extensions/Translate/api/ApiStatsQuery.php
index a65c982a..51244e0e 100644
--- a/www/wiki/extensions/Translate/api/ApiStatsQuery.php
+++ b/www/wiki/extensions/Translate/api/ApiStatsQuery.php
@@ -4,7 +4,7 @@
*
* @file
* @author Niklas Laxström
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
*/
/**
@@ -18,12 +18,30 @@ abstract class ApiStatsQuery extends ApiQueryBase {
return 'public';
}
+ /**
+ * Implement this to implement input validation and return the name of the target that
+ * is then given to loadStats.
+ * @param array $params
+ * @return string
+ */
+ abstract protected function validateTargetParamater( array $params );
+
+ /**
+ * Implement this to load stats.
+ * @param string $target
+ * @param int $flags See MessageGroupStats for possible flags
+ * @return array[]
+ */
+ abstract protected function loadStatistics( $target, $flags = 0 );
+
public function execute() {
$params = $this->extractRequestParams();
- MessageGroupStats::setTimeLimit( $params['timelimit'] );
- $cache = $this->getData();
+ $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'] ) {
@@ -31,39 +49,47 @@ abstract class ApiStatsQuery extends ApiQueryBase {
}
if ( $stats[MessageGroupStats::TOTAL] === null ) {
+ $incomplete = true;
$this->setContinueEnumParameter( 'offset', $item );
break;
}
$data = $this->makeItem( $item, $stats );
- $result->addValue( array( 'query', $this->getModuleName() ), null, $data );
+ $result->addValue( [ 'query', $this->getModuleName() ], null, $data );
}
- $result->addIndexedTagName( array( 'query', $this->getModuleName() ), 'stats' );
+ $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'stats' );
+
+ if ( $incomplete ) {
+ DeferredUpdates::addCallableUpdate( function () use ( $target ) {
+ $this->loadStatistics( $target );
+ } );
+ }
}
protected function makeItem( $item, $stats ) {
- return array(
+ return [
'total' => $stats[MessageGroupStats::TOTAL],
'translated' => $stats[MessageGroupStats::TRANSLATED],
'fuzzy' => $stats[MessageGroupStats::FUZZY],
'proofread' => $stats[MessageGroupStats::PROOFREAD],
- );
+ ];
}
public function getAllowedParams() {
- return array(
- 'offset' => array(
- ApiBase::PARAM_DFLT => 0,
+ return [
+ 'offset' => [
+ ApiBase::PARAM_DFLT => '0',
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
- ),
- 'timelimit' => array(
+ ],
+ 'timelimit' => [
ApiBase::PARAM_DFLT => 8,
ApiBase::PARAM_TYPE => 'integer',
ApiBase::PARAM_MAX => 10,
ApiBase::PARAM_MIN => 0,
- ),
- );
+ ApiBase::PARAM_DEPRECATED => true, // Since 2018.10
+ ],
+ ];
}
}