From cec2ca565dda289e1ad9e79b38c825658ce7a19c Mon Sep 17 00:00:00 2001 From: Lex Lim Date: Sun, 25 Jun 2023 09:41:09 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=BB=E5=8A=A8=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=A0=87=E9=A2=98=E7=B4=A2=E5=BC=95=E7=9A=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extension.json | 6 +++++ includes/Hooks.php | 17 +++++++++++++ includes/Job/UpdateTitleIndexJob.php | 36 ++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 includes/Job/UpdateTitleIndexJob.php 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