Update for MW 1.42.0

main
落雨楓 1 month ago
parent 9b8aaa1d31
commit 55fbe29860

@ -2,7 +2,8 @@
namespace Isekai\AIToolbox; namespace Isekai\AIToolbox;
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
use Config; use MediaWiki\Config\Config;
use MediaWiki\Output\OutputPage;
use Isekai\AIToolbox\Job\UpdateTitleIndexJob; use Isekai\AIToolbox\Job\UpdateTitleIndexJob;
class Hooks { class Hooks {
@ -17,7 +18,7 @@ class Hooks {
$updater->addExtensionTable('aitoolbox_usage', $dir . $type . '/aitoolbox_usage.sql'); $updater->addExtensionTable('aitoolbox_usage', $dir . $type . '/aitoolbox_usage.sql');
} }
public static function onLoad(\OutputPage $outputPage) { public static function onLoad(OutputPage $outputPage) {
$user = $outputPage->getUser(); $user = $outputPage->getUser();
$permissionManager = MediaWikiServices::getInstance()->getPermissionManager(); $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
if ($user->isRegistered() && $permissionManager->userHasRight($user, 'chatcomplete')) { if ($user->isRegistered() && $permissionManager->userHasRight($user, 'chatcomplete')) {

@ -3,7 +3,9 @@ namespace Isekai\AIToolbox\Job;
use Job; use Job;
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
use Title; use MediaWiki\Context\RequestContext;
use MediaWiki\Title\Title;
use MediaWiki\Status\Status;
class UpdateTitleIndexJob extends Job { class UpdateTitleIndexJob extends Job {
public function __construct(Title $title) { public function __construct(Title $title) {
@ -16,6 +18,7 @@ class UpdateTitleIndexJob extends Job {
public function run() { public function run() {
$services = MediaWikiServices::getInstance(); $services = MediaWikiServices::getInstance();
$config = $services->getMainConfig(); $config = $services->getMainConfig();
$context = RequestContext::getMain();
$endpoint = $config->get('IsekaiAIBackendEndpoint'); $endpoint = $config->get('IsekaiAIBackendEndpoint');
$authToken = $config->get('IsekaiAIToolboxToken'); $authToken = $config->get('IsekaiAIToolboxToken');
@ -34,9 +37,11 @@ class UpdateTitleIndexJob extends Job {
$req->setHeader('Authorization', 'Bearer ' . $authToken); $req->setHeader('Authorization', 'Bearer ' . $authToken);
$status = \Status::wrap($req->execute()); $status = Status::wrap($req->execute());
if (!$status->isOK()) { if (!$status->isOK()) {
$this->setLastError($status->getMessage()); $formatterFactory = MediaWikiServices::getInstance()->getFormatterFactory();
$formatter = $formatterFactory->getStatusFormatter($context);
$this->setLastError($formatter->getMessage($status));
return false; return false;
} }

Loading…
Cancel
Save