diff --git a/extension.json b/extension.json index 5ac1b73..eb52af4 100644 --- a/extension.json +++ b/extension.json @@ -55,6 +55,9 @@ ], "ResourceLoaderGetConfigVars": [ "Isekai\\AIToolbox\\Hooks::onResourceLoaderGetConfigVars" + ], + "onPageSaveComplete": [ + "Isekai\\AIToolbox\\Hooks::onPageSaveComplete" ] }, "APIModules": { @@ -100,6 +103,9 @@ "type": "gravatar" } }, + "wgIsekaiAIBackendEndpoint": { + "value": "http://localhost:8144" + }, "IsekaiAIToolboxFrontendUrl": { "value": "/ai-toolbox/toolbox/{title}?token={token}" } diff --git a/includes/Hooks.php b/includes/Hooks.php index 576a263..25203aa 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -3,6 +3,7 @@ namespace Isekai\AIToolbox; use MediaWiki\MediaWikiServices; use Config; +use Isekai\AIToolbox\Job\UpdateTitleIndexJob; class Hooks { /** @@ -27,4 +28,20 @@ class Hooks { 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); + } + } } \ No newline at end of file diff --git a/includes/Job/UpdateTitleIndexJob.php b/includes/Job/UpdateTitleIndexJob.php new file mode 100644 index 0000000..b9815a1 --- /dev/null +++ b/includes/Job/UpdateTitleIndexJob.php @@ -0,0 +1,36 @@ +getMainConfig(); + + $endpoint = $config->get('wgIsekaiAIBackendEndpoint'); + + $title = $this->title; + $pageTitle = $title->getText(); + + $factory = MediaWikiServices::getInstance()->getHttpRequestFactory(); + $req = $factory->create($endpoint + '/sys/embedding_search/title/update', [ + 'method' => 'POST', + 'postData' => [ + 'title' => $pageTitle + ], + 'timeout' => 10 + ], __METHOD__); + + return true; + } +} \ No newline at end of file