You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.7 KiB
PHTML

2 years ago
<?php
namespace Isekai\AIToolbox;
2 years ago
use MediaWiki\MediaWikiServices;
use Config;
use Isekai\AIToolbox\Job\UpdateTitleIndexJob;
2 years ago
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');
}
2 years ago
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"]);
2 years ago
}
}
public static function onResourceLoaderGetConfigVars(array &$vars, string $skin, Config $config){
$vars['wgIsekaiAIToolboxFrontendUrl'] = $config->get('IsekaiAIToolboxFrontendUrl');
2 years ago
}
/**
* @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);
}
}
2 years ago
}