config = MediaWikiServices::getInstance()->getMainConfig(); $this->cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); } /** * @throws \ApiUsageException */ public function execute() { $this->checkUserRightsAny('queryuserpoints'); $params = $this->extractRequestParams(); $this->requireMaxOneParameter( $params, 'userids', 'users' ); $users = (array)$params['users']; $userids = (array)$params['userids']; $services = MediaWikiServices::getInstance(); $pointConfig = $this->config->get('IsekaiUserPointConfig'); $pointTypes = array_keys($pointConfig); $pointInfos = []; foreach ($pointTypes as $pointType) { $pointInfos[$pointType] = [ 'name' => Utils::getPointName($pointType), 'icon' => Utils::getPointIcon($pointType), ]; } /** @var IsekaiUserPointsFactory */ $userPointsFactory = $services->getService('IsekaiUserPoints'); $userFactory = $services->getUserFactory(); $userInstances = []; foreach ( $users as $u ) { $user = $userFactory->newFromName( $u ); $userInstances[] = $user; } foreach ( $userids as $u ) { $user = $userFactory->newFromId( $u ); $userInstances[] = $user; } $userPointsInstances = $userPointsFactory->newFromUsers($userInstances, $pointTypes); $result = $this->getResult(); foreach ($userPointsInstances as $userPointsTuple) { if ( !$userPointsTuple ) { continue; } list($user, $type, $userPoint) = $userPointsTuple; $result->addValue( [ 'query', $this->getModuleName(), "pointdata", $user->getId() ], $type, [ 'point_type' => $type, 'points' => $userPoint->points, 'timed_points_data' => $userPoint->timedPointsData, 'locked_points' => $userPoint->lockedPoints, 'locked_points_data' => $userPoint->lockedPointsData, ] ); } $result->addValue( [ 'query', $this->getModuleName() ], 'pointinfo', $pointInfos ); } /** * @param array $params Ignored parameters * @return string */ public function getCacheMode($params) { return 'public'; } public function getAllowedParams() { return [ 'users' => [ ParamValidator::PARAM_ISMULTI => true ], 'userids' => [ ParamValidator::PARAM_ISMULTI => true, ParamValidator::PARAM_TYPE => 'integer' ], ]; } }