diff --git a/includes/Hooks.php b/includes/Hooks.php index 7609d06..d1d5c0b 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -2,7 +2,8 @@ namespace Isekai\AIToolbox; use MediaWiki\MediaWikiServices; -use Config; +use MediaWiki\Config\Config; +use MediaWiki\Output\OutputPage; use Isekai\AIToolbox\Job\UpdateTitleIndexJob; class Hooks { @@ -17,7 +18,7 @@ class Hooks { $updater->addExtensionTable('aitoolbox_usage', $dir . $type . '/aitoolbox_usage.sql'); } - public static function onLoad(\OutputPage $outputPage) { + public static function onLoad(OutputPage $outputPage) { $user = $outputPage->getUser(); $permissionManager = MediaWikiServices::getInstance()->getPermissionManager(); if ($user->isRegistered() && $permissionManager->userHasRight($user, 'chatcomplete')) { diff --git a/includes/Job/UpdateTitleIndexJob.php b/includes/Job/UpdateTitleIndexJob.php index 2e0eca1..4491939 100644 --- a/includes/Job/UpdateTitleIndexJob.php +++ b/includes/Job/UpdateTitleIndexJob.php @@ -3,7 +3,9 @@ namespace Isekai\AIToolbox\Job; use Job; use MediaWiki\MediaWikiServices; -use Title; +use MediaWiki\Context\RequestContext; +use MediaWiki\Title\Title; +use MediaWiki\Status\Status; class UpdateTitleIndexJob extends Job { public function __construct(Title $title) { @@ -16,6 +18,7 @@ class UpdateTitleIndexJob extends Job { public function run() { $services = MediaWikiServices::getInstance(); $config = $services->getMainConfig(); + $context = RequestContext::getMain(); $endpoint = $config->get('IsekaiAIBackendEndpoint'); $authToken = $config->get('IsekaiAIToolboxToken'); @@ -34,9 +37,11 @@ class UpdateTitleIndexJob extends Job { $req->setHeader('Authorization', 'Bearer ' . $authToken); - $status = \Status::wrap($req->execute()); - if(!$status->isOK()){ - $this->setLastError($status->getMessage()); + $status = Status::wrap($req->execute()); + if (!$status->isOK()) { + $formatterFactory = MediaWikiServices::getInstance()->getFormatterFactory(); + $formatter = $formatterFactory->getStatusFormatter($context); + $this->setLastError($formatter->getMessage($status)); return false; }