|
|
|
<?php
|
|
|
|
namespace Isekai\AIToolbox;
|
|
|
|
|
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
use Config;
|
|
|
|
use Isekai\AIToolbox\Job\UpdateTitleIndexJob;
|
|
|
|
|
|
|
|
class Hooks {
|
|
|
|
/**
|
|
|
|
* Implements LoadExtensionSchemaUpdates hook.
|
|
|
|
*
|
|
|
|
* @param \DatabaseUpdater $updater
|
|
|
|
*/
|
|
|
|
public static function onLoadExtensionSchemaUpdates($updater) {
|
|
|
|
$dir = dirname(__DIR__) . '/sql/';
|
|
|
|
$type = $updater->getDB()->getType();
|
|
|
|
$updater->addExtensionTable('aitoolbox_usage', $dir . $type . '/aitoolbox_usage.sql');
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function onLoad(\OutputPage $outputPage) {
|
|
|
|
$user = $outputPage->getUser();
|
|
|
|
$permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
|
|
|
|
if ($user->isRegistered() && $permissionManager->userHasRight($user, 'chatcomplete')) {
|
|
|
|
$outputPage->addModules(["ext.isekai.ai-toolbox.launcher"]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function onResourceLoaderGetConfigVars(array &$vars, string $skin, Config $config){
|
|
|
|
$vars['wgIsekaiAIToolboxFrontendUrl'] = $config->get('IsekaiAIToolboxFrontendUrl');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \WikiPage $wikiPage
|
|
|
|
* @param \MediaWiki\User\UserIdentity $user
|
|
|
|
* @param string $summary
|
|
|
|
* @param int $flags
|
|
|
|
* @param \MediaWiki\Revision\RevisionRecord $revisionRecord
|
|
|
|
* @param \MediaWiki\Storage\EditResult $editResult
|
|
|
|
*/
|
|
|
|
public static function onPageSaveComplete($wikiPage, $user, $summary, $flags, $revisionRecord, $editResult) {
|
|
|
|
$title = $wikiPage->getTitle();
|
|
|
|
if ($title && $title->exists() && $title->getNamespace() === NS_MAIN) {
|
|
|
|
$job = new UpdateTitleIndexJob($wikiPage->getTitle(), []);
|
|
|
|
MediaWikiServices::getInstance()->getJobQueueGroup()->push($job);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|