增加1.39支持

master
落雨楓 2 years ago
parent e0be90e676
commit 9d26636e82

@ -7,7 +7,7 @@
},
"authors": [
{
"name": "量子复合态",
"name": "Hyperzlib",
"email": "hyperzlib@outlook.com"
}
]

@ -1,13 +1,14 @@
{
"name": "IsekaiAIReview",
"author": "hyperzlib",
"namemsg": "isekai-aireview-name",
"author": "Hyperzlib",
"url": "https://github.com/Isekai-Project/mediawiki-extension-IsekaiAIReview",
"descriptionmsg": "isekai-aireview-desc",
"version": "1.0.0",
"version": "1.0.1",
"license-name": "MIT",
"type": "other",
"requires": {
"MediaWiki": ">= 1.31.0",
"MediaWiki": ">= 1.35.0",
"extensions": {
"Moderation": ">= 1.5.0"
}
@ -52,6 +53,5 @@
"AIReviewBizType": null,
"AIReviewRobotUID": 1
},
"load_composer_autoloader": true,
"manifest_version": 1
}

@ -1,4 +1,5 @@
{
"isekai-aireview-name": "异世界百科 AI自动审核",
"isekai-aireview-desc": "通过AI实现自动审核",
"log-name-aireview": "机器审核记录",
"log-description-aireview": "这里会显示经过机器审核的记录",

@ -3,7 +3,6 @@ namespace Isekai\AIReview;
use Job;
use MediaWiki\MediaWikiServices;
use MediaWiki\Moderation\AddLogEntryConsequence;
use Title;
use User;
use RequestContext;
@ -20,19 +19,20 @@ class AIReviewJob extends Job {
public function run(){
global $wgAIReviewRobotUID;
$dbr = wfGetDB(DB_REPLICA);
$services = MediaWikiServices::getInstance();
$robotUser = User::newFromId($wgAIReviewRobotUID);
$dbr = $services->getDBLoadBalancer()->getMaintenanceConnectionRef(DB_REPLICA);
$modid = $this->params['mod_id'];
$modUser = $dbr->selectField('moderation', 'mod_user', ['mod_id' => $modid], __METHOD__);
$robotUser = $services->getUserFactory()->newFromId($wgAIReviewRobotUID);
$mod_id = $this->params['mod_id'];
$modUser = $dbr->selectField('moderation', 'mod_user', ['mod_id' => $mod_id], __METHOD__);
$services = MediaWikiServices::getInstance();
$entryFactory = $services->getService('Moderation.EntryFactory');
$consequenceManager = $services->getService('Moderation.ConsequenceManager');
/** @var ModerationViewableEntry $contentEntry */
$contentEntry = $entryFactory->findViewableEntry($modid);
$contentEntry = $entryFactory->findViewableEntry($mod_id);
$title = $contentEntry->getTitle();
$context = RequestContext::getMain();
@ -50,7 +50,9 @@ class AIReviewJob extends Job {
'isekai-aireview',
'Reject revision on: ' . $title->getText() . ', reason: ' . Utils::getReadableReason($result['reason'])
);
Utils::addAIReviewLog('reject', $robotUser, $modUser, $title, $modid, $result['reason']);
Utils::addAIReviewLog('reject', $robotUser, $modUser, $title, $mod_id, $result['reason']);
$services->getHookContainer()->run("IsekaiAIReviewResult",
[ false, $title, $mod_id, $modUser, $result['reason'] ]);
return true;
}
}
@ -60,9 +62,11 @@ class AIReviewJob extends Job {
'isekai-aireview',
'Approve revision on: ' . $title->getText()
);
Utils::addAIReviewLog('approve', $robotUser, $modUser, $title, $modid);
$approveEntry = $entryFactory->findApprovableEntry($modid);
$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;
}
}

@ -48,9 +48,13 @@ class AliyunAIReview {
return $taskList;
}
/**
* @throws \AlibabaCloud\Client\Exception\ServerException
* @throws \AlibabaCloud\Client\Exception\ClientException
*/
public function doRequest($requestData){
$textScan = Green::v20180509()->textScan();
$response = $textScan->setMethod('POST')->setAcceptFormat('JSON')->setContent(json_encode($requestData))->request();
$response = $textScan->method('POST')->accept('JSON')->body(json_encode($requestData))->request();
if($response->getReasonPhrase() === 'OK'){
return $this->parseResponse($response->toArray());

@ -2,12 +2,14 @@
namespace Isekai\AIReview;
use JobQueueGroup;
use MediaWiki\MediaWikiServices;
use Title;
class Hooks {
public static function onModerationPending($fields, $modid){
public static function onModerationPending($fields, $mod_id){
//加入审核队列
$job = new AIReviewJob(Title::newFromText($fields['mod_title']), ['mod_id' => $modid]);
JobQueueGroup::singleton()->push($job);
$title = Title::newFromText($fields['mod_title']);
$job = new AIReviewJob($title, ['mod_id' => $mod_id]);
MediaWikiServices::getInstance()->getJobQueueGroup()->push($job);
}
}

@ -2,6 +2,7 @@
namespace Isekai\AIReview;
use LogFormatter as GlobalLogFormatter;
use MediaWiki\MediaWikiServices;
use SpecialPage;
use Message;
use Linker;
@ -9,44 +10,43 @@ use Title;
use User;
class LogFormatter extends GlobalLogFormatter {
/**
* @param array $params
* @return array
* @throws \MWException
*/
public function buildBaseParams(array $params): array {
$services = MediaWikiServices::getInstance();
$linkRenderer = $this->getLinkRenderer();
$entryParams = $this->entry->getParameters();
$modId = $entryParams['modid'];
$user = $services->getUserFactory()->newFromId($entryParams['moduser']);
$userLink = Linker::userLink($user->getId(), $user->getName());
$params[3] = Message::rawParam($userLink);
$link = $linkRenderer->makeKnownLink(
SpecialPage::getTitleFor('Moderation'),
$this->msg('moderation-log-change')->params($modId)->text(),
['title' => $this->msg('tooltip-moderation-rejected-change')->plain()],
['modaction' => 'show', 'modid' => $modId]
);
$params[4] = Message::rawParam($link);
return $params;
}
public function getMessageParameters(){
$params = parent::getMessageParameters();
$type = $this->entry->getSubtype();
$entryParams = $this->entry->getParameters();
$linkRenderer = $this->getLinkRenderer();
$type = $this->entry->getSubtype();
switch($type){
case 'approve':
$modId = $entryParams['modid'];
$user = User::newFromId($entryParams['moduser']);
$userLink = Linker::userLink( $user->getId(), $user->getName() );
$params[3] = Message::rawParam( $userLink );
$link = $linkRenderer->makeKnownLink(
SpecialPage::getTitleFor( 'Moderation' ),
$this->msg( 'moderation-log-change' )->params( $modId )->text(),
[ 'title' => $this->msg( 'tooltip-moderation-rejected-change' )->plain() ],
[ 'modaction' => 'show', 'modid' => $modId ]
);
$params[4] = Message::rawParam( $link );
$params = $this->buildBaseParams($params);
break;
case 'reject':
$modId = $entryParams['modid'];
$user = User::newFromId($entryParams['moduser']);
$userLink = Linker::userLink( $user->getId(), $user->getName() );
$params[3] = Message::rawParam( $userLink );
$link = $linkRenderer->makeKnownLink(
SpecialPage::getTitleFor( 'Moderation' ),
$this->msg( 'moderation-log-change' )->params( $modId )->text(),
[ 'title' => $this->msg( 'tooltip-moderation-rejected-change' )->plain() ],
[ 'modaction' => 'show', 'modid' => $modId ]
);
$params[4] = Message::rawParam( $link );
$params = $this->buildBaseParams($params);
$params[5] = Utils::getReadableReason($entryParams['reason']);
break;
@ -55,13 +55,14 @@ class LogFormatter extends GlobalLogFormatter {
}
public function getPreloadTitles() {
$services = MediaWikiServices::getInstance();
$type = $this->entry->getSubtype();
$params = $this->entry->getParameters();
$titles = [];
if ( $params['moduser'] ) { # Not anonymous
$user = User::newFromId($params['moduser']);
$user = $services->getUserFactory()->newFromId($params['moduser']);
$titles[] = Title::makeTitle( NS_USER, $user->getName() );
}

@ -5,7 +5,14 @@ use ManualLogEntry;
use PHPHtmlParser\Dom;
class Utils {
public static function getDiffAddedLines($diffHtml){
/**
* @throws \PHPHtmlParser\Exceptions\CurlException
* @throws \PHPHtmlParser\Exceptions\ChildNotFoundException
* @throws \PHPHtmlParser\Exceptions\NotLoadedException
* @throws \PHPHtmlParser\Exceptions\CircularException
* @throws \PHPHtmlParser\Exceptions\StrictException
*/
public static function getDiffAddedLines($diffHtml) {
$dom = new Dom();
$dom->load($diffHtml);
$lines = [];
@ -37,6 +44,9 @@ class Utils {
return implode(', ', $readableReasons);
}
/**
* @throws \MWException
*/
public static function addAIReviewLog($event, $robotUser, $modUser, $title, $modid, $reason = null){
$entry = new ManualLogEntry('aireview', $event);
$entry->setPerformer($robotUser);

Loading…
Cancel
Save