From 0b899e24c3358f3be13537067a05334d0faee71a Mon Sep 17 00:00:00 2001 From: Lex Lim Date: Sun, 26 Jan 2025 11:40:39 +0000 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8DMW=201.43?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 4 +-- extension.json | 35 +++++++++++++----------- includes/AIReviewJob.php | 6 ++--- includes/Hooks.php | 3 ++- maintenance/TryApprove.php | 54 ++++++++++++++++++++++++++++++++++++++ maintenance/test.txt | 1 + 6 files changed, 82 insertions(+), 21 deletions(-) create mode 100644 maintenance/TryApprove.php diff --git a/composer.json b/composer.json index bb0f96e..99b4743 100644 --- a/composer.json +++ b/composer.json @@ -2,8 +2,8 @@ "name": "hyperzlib/isekai-ai-review", "type": "mediawiki-extension", "require": { - "alibabacloud/sdk": "^1.8", - "paquettg/php-html-parser": "^2.2" + "paquettg/php-html-parser": "^2.2", + "alibabacloud/green": "^1.8" }, "authors": [ { diff --git a/extension.json b/extension.json index 095bf4a..4289cf4 100644 --- a/extension.json +++ b/extension.json @@ -21,13 +21,8 @@ "i18n" ] }, - "AutoloadClasses": { - "Isekai\\AIReview\\Hooks": "includes/Hooks.php", - "Isekai\\AIReview\\SectionSplitter": "includes/SectionSplitter.php", - "Isekai\\AIReview\\Utils": "includes/Utils.php", - "Isekai\\AIReview\\AliyunAIReview": "includes/AliyunAIReview.php", - "Isekai\\AIReview\\AIReviewJob": "includes/AIReviewJob.php", - "Isekai\\AIReview\\LogFormatter": "includes/LogFormatter.php" + "AutoloadNamespaces": { + "Isekai\\AIReview\\": "includes/" }, "Hooks": { "ModerationPending": [ @@ -47,11 +42,21 @@ "aireview": "moderation" }, "config": { - "AIReviewEndpoint": "cn-shanghai", - "AIReviewAccessKeyId": "", - "AIReviewAccessKeySecret": "", - "AIReviewBizType": null, - "AIReviewRobotUID": 1 - }, - "manifest_version": 1 -} \ No newline at end of file + "AIReviewEndpoint": { + "value": "cn-shanghai" + }, + "AIReviewAccessKeyId": { + "value": "" + }, + "AIReviewAccessKeySecret": { + "value": "" + }, + "AIReviewBizType": { + "value": null + }, + "AIReviewRobotUID": { + "value": 1 + } + }, + "manifest_version": 2 +} diff --git a/includes/AIReviewJob.php b/includes/AIReviewJob.php index eb7b734..a682aad 100644 --- a/includes/AIReviewJob.php +++ b/includes/AIReviewJob.php @@ -16,9 +16,9 @@ class AIReviewJob extends Job { * 运行job,开始进行AI审核 */ public function run(){ - global $wgAIReviewRobotUID; - $services = MediaWikiServices::getInstance(); + $config = $services->getMainConfig(); + $wgAIReviewRobotUID = $config->get('AIReviewRobotUID'); $dbr = $services->getDBLoadBalancer()->getMaintenanceConnectionRef(DB_REPLICA); @@ -61,9 +61,9 @@ class AIReviewJob extends Job { 'isekai-aireview', 'Approve revision on: ' . $title->getText() ); + Utils::addAIReviewLog('approve', $robotUser, $modUser, $title, $mod_id); $approveEntry = $entryFactory->findApprovableEntry($mod_id); $approveEntry->approve($robotUser); - Utils::addAIReviewLog('approve', $robotUser, $modUser, $title, $mod_id); $services->getHookContainer()->run("IsekaiAIReviewResult", [ true, $title, $mod_id, $modUser, '' ]); return true; diff --git a/includes/Hooks.php b/includes/Hooks.php index 0e5a8fd..277059c 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -9,6 +9,7 @@ class Hooks { //加入审核队列 $title = Title::newFromText($fields['mod_title']); $job = new AIReviewJob($title, ['mod_id' => $mod_id]); - MediaWikiServices::getInstance()->getJobQueueGroup()->push($job); + $jobQueue = MediaWikiServices::getInstance()->getJobQueueGroup(); + $jobQueue->push($job); } } \ No newline at end of file diff --git a/maintenance/TryApprove.php b/maintenance/TryApprove.php new file mode 100644 index 0000000..b7a7016 --- /dev/null +++ b/maintenance/TryApprove.php @@ -0,0 +1,54 @@ +addDescription('Test AI Review'); + } + + public function execute() { + $services = MediaWikiServices::getInstance(); + $entryFactory = $services->getService('Moderation.EntryFactory'); + + $robotUser = $services->getUserFactory()->newFromId(1); + + $approveEntry = $entryFactory->findApprovableEntry(1228); + $approveEntry->approve($robotUser); + + return true; + } +} + +$maintClass = TryAIReview::class; +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/maintenance/test.txt b/maintenance/test.txt index e69de29..a2788d7 100644 --- a/maintenance/test.txt +++ b/maintenance/test.txt @@ -0,0 +1 @@ +测试AI审核 \ No newline at end of file