You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.7 KiB
PHP

<?php
namespace Isekai\UserPoints\Api;
use ApiQueryBase;
use ApiQuery;
use Config;
use MediaWiki\MediaWikiServices;
use WANObjectCache;
use Isekai\UserPoints\Utils;
class ApiQueryPointInfo extends ApiQueryBase {
private const CACHE_VERSION = 2;
private const PREFIX = 'pi';
private $params;
/**
* @var Config
*/
private $config;
/**
* @var WANObjectCache
*/
private $cache;
/**
* @param ApiQuery $query API query module object
* @param string $moduleName Name of this query module
*/
public function __construct($query, $moduleName) {
parent::__construct($query, $moduleName, self::PREFIX);
$this->config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'textextracts' );
$this->cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
}
/**
* @throws \ApiUsageException
*/
public function execute() {
$pointConfig = $this->config->get('IsekaiUserPointConfig');
$pointTypes = array_keys($pointConfig);
$pointInfos = [];
foreach ($pointTypes as $pointType) {
$pointInfos[$pointType] = [
'name' => Utils::getPointName($pointType),
'icon' => Utils::getPointIcon($pointType),
];
}
$result = $this->getResult();
$result->addValue(
[ 'query', $this->getModuleName() ],
'pointinfo',
$pointInfos
);
}
/**
* @param array $params Ignored parameters
* @return string
*/
public function getCacheMode($params) {
return 'public';
}
public function getAllowedParams() {
return [
];
}
}