getMain(), $method); $this->mParent = $main; $this->services = MediaWikiServices::getInstance(); $this->config = $this->services->getMainConfig(); } public function requireParameter(array $paramKeys) { $missing = []; foreach ($paramKeys as $paramKey) { if ($this->getParameter($paramKey) === null) { $missing[] = $paramKey; } } if (count($missing) > 0) { $this->dieWithError( [ 'apierror-missingparam', Message::listParam( array_map( function ( $p ) { return '' . $this->encodeParamName( $p ) . ''; }, $missing ) ), count( $missing ), ], 'missingparam' ); } } public function execute() { // Check permission $this->checkUserRightsAny('aitoolboxbot'); $userFactory = $this->services->getUserFactory(); $userOptionsLookup = $this->services->getUserOptionsLookup(); $userId = $this->getParameter('userid'); $user = $userFactory->newFromId($userId); if (!$user->isRegistered()) { $this->dieWithError('apierror-ai-toolbox-user-not-found', 'user-not-found'); } $userInfo = [ 'userid' => $user->getId(), 'username' => $user->getName(), 'realname' => $user->getRealName(), // 'nickname' => $userOptionsLookup->getOption($user, 'nickname'), 'email' => $user->getEmail(), 'unlimitedusage' => false ]; // Get user points from IsekaiUserPoints $pointType = $this->config->get('IsekaiAIToolboxPointType'); if ($pointType) { /** @var \Isekai\UserPoints\Service\IsekaiUserPointsFactory */ $pointFactory = $this->services->getService('IsekaiUserPoints'); $pointService = $pointFactory->newFromUserId($userId, $pointType); if ($pointService) { $userInfo['points'] = $pointService->points; } } if ($user->isAllowed('aitoolbox-unlimited')) { $userInfo['unlimitedusage'] = true; } // Get user avatar $avatarTpl = $this->config->get('IsekaiAIToolboxUserAvatar'); $avatarUrl = null; if (is_array($avatarTpl) && isset($avatarTpl['type'])) { if ($avatarTpl['type'] === 'gravatar') { $gravatarUrl = $avatarTpl['mirror'] ?? 'https://secure.gravatar.com/avatar/'; $gravatarUrl .= md5(strtolower(trim($user->getEmail()))) . '?s=256'; $avatarUrl = $gravatarUrl; } elseif ($avatarTpl['type'] === 'local') { $avatarUrl = $avatarTpl['url'] ?? ''; $avatarUrl = str_replace(['{username}', '{userid}'], [$user->getName(), $user->getId()], $avatarUrl); } } if ($avatarUrl) { if (strpos($avatarUrl, 'http://') === false && strpos($avatarUrl, 'https://') === false) { $avatarUrl = $this->config->get(MainConfigNames::Server) . $avatarUrl; } $userInfo['avatar'] = $avatarUrl; } $result = $this->getResult(); $result->addValue(['aitoolboxbot'], $this->getModuleName(), $userInfo); } public function getAllowedParams($flags = 0) { return [ 'userid' => [ ParamValidator::PARAM_TYPE => 'integer', ParamValidator::PARAM_DEFAULT => null, ParamValidator::PARAM_REQUIRED => true, ], ]; } public function getCacheMode($params) { return 'private'; } public function getParent() { return $this->mParent; } }