getMain(), $method); $this->mParent = $main; $this->services = MediaWikiServices::getInstance(); } public function execute() { $userAction = strtolower($this->getParameter('ataction')); $user = $this->getUser(); if (!$user->isRegistered()) { $this->addError('apierror-isekai-ai-toolbox-nopermission', 'nopermission'); return false; } $result = $this->getResult(); $permissionMap = [ 'embeddingpage' => 'ccembeddingpage', 'chatcomplete' => 'chatcomplete', ]; $permissionKey = $permissionMap[$userAction] ?? null; if ($permissionKey && !$user->isAllowed($permissionKey)) { $this->addError('apierror-isekai-ai-toolbox-nopermission', 'nopermission'); $result->addValue(['aitoolbox', $this->getModuleName()], 'available', false); return false; } $noCost = false; if ($userAction === 'chatcomplete' && $user->isAllowed('aitoolbox-unlimited')) { $noCost = true; } $isAvailable = true; $result->addValue(['aitoolbox', $this->getModuleName()], 'available', $isAvailable); $result->addValue(['aitoolbox', $this->getModuleName()], 'nocost', $noCost); return true; } public function getAllowedParams($flags = 0) { return [ 'ataction' => [ ParamValidator::PARAM_TYPE => [ 'embeddingpage', 'chatcomplete', ], ParamValidator::PARAM_DEFAULT => null, ParamValidator::PARAM_REQUIRED => true, ], ]; } public function getCacheMode($params) { return 'private'; } public function getParent() { return $this->mParent; } }