重新排版

master
落雨楓 4 days ago
parent 0b899e24c3
commit 81da7050f7

@ -15,7 +15,7 @@ class AIReviewJob extends Job {
/** /**
* 运行job开始进行AI审核 * 运行job开始进行AI审核
*/ */
public function run(){ public function run() {
$services = MediaWikiServices::getInstance(); $services = MediaWikiServices::getInstance();
$config = $services->getMainConfig(); $config = $services->getMainConfig();
$wgAIReviewRobotUID = $config->get('AIReviewRobotUID'); $wgAIReviewRobotUID = $config->get('AIReviewRobotUID');

@ -7,7 +7,7 @@ use AlibabaCloud\Green\Green;
class AliyunAIReview { class AliyunAIReview {
private const MAX_LENGTH = 10000; private const MAX_LENGTH = 10000;
public function __construct(){ public function __construct() {
global $wgAIReviewEndpoint, $wgAIReviewAccessKeyId, $wgAIReviewAccessKeySecret; global $wgAIReviewEndpoint, $wgAIReviewAccessKeyId, $wgAIReviewAccessKeySecret;
AlibabaCloud::accessKeyClient($wgAIReviewAccessKeyId, $wgAIReviewAccessKeySecret) AlibabaCloud::accessKeyClient($wgAIReviewAccessKeyId, $wgAIReviewAccessKeySecret)
->connectTimeout(3) ->connectTimeout(3)
@ -21,7 +21,7 @@ class AliyunAIReview {
return $response; return $response;
} }
public function buildRequestData($text){ public function buildRequestData($text) {
global $wgAIReviewBizType; global $wgAIReviewBizType;
$reqData = [ $reqData = [
@ -33,7 +33,7 @@ class AliyunAIReview {
return $reqData; return $reqData;
} }
public function buildTasks($text){ public function buildTasks($text) {
$splitter = new SectionSplitter($text, self::MAX_LENGTH); $splitter = new SectionSplitter($text, self::MAX_LENGTH);
$chunkList = $splitter->getChunkList(); $chunkList = $splitter->getChunkList();
$taskList = []; $taskList = [];
@ -67,7 +67,7 @@ class AliyunAIReview {
} }
} }
public function parseResponse($response){ public function parseResponse($response) {
if($response['code'] !== 200) if($response['code'] !== 200)
return ['pass' => false, 'reason' => wfMessage('isekai-aireview-aliyun-server-error', $response['code'])->escaped()]; return ['pass' => false, 'reason' => wfMessage('isekai-aireview-aliyun-server-error', $response['code'])->escaped()];

@ -5,7 +5,7 @@ use MediaWiki\MediaWikiServices;
use MediaWiki\Title\Title; use MediaWiki\Title\Title;
class Hooks { class Hooks {
public static function onModerationPending($fields, $mod_id){ public static function onModerationPending($fields, $mod_id) {
//加入审核队列 //加入审核队列
$title = Title::newFromText($fields['mod_title']); $title = Title::newFromText($fields['mod_title']);
$job = new AIReviewJob($title, ['mod_id' => $mod_id]); $job = new AIReviewJob($title, ['mod_id' => $mod_id]);

@ -34,7 +34,7 @@ class LogFormatter extends GlobalLogFormatter {
return $params; return $params;
} }
public function getMessageParameters(){ public function getMessageParameters() {
$params = parent::getMessageParameters(); $params = parent::getMessageParameters();
$entryParams = $this->entry->getParameters(); $entryParams = $this->entry->getParameters();
$type = $this->entry->getSubtype(); $type = $this->entry->getSubtype();

@ -7,7 +7,7 @@ class SectionSplitter {
private $bufferLength = 0; private $bufferLength = 0;
private $maxLength; private $maxLength;
public function __construct($text, $maxLength = 10000){ public function __construct($text, $maxLength = 10000) {
$this->maxLength = $maxLength; $this->maxLength = $maxLength;
$this->splitLine($text); $this->splitLine($text);
} }
@ -28,7 +28,7 @@ class SectionSplitter {
/** /**
* 按照行来拆分 * 按照行来拆分
*/ */
public function splitLine($text){ public function splitLine($text) {
$text = str_replace("\r\n", "\n", $text); $text = str_replace("\r\n", "\n", $text);
$lines = explode("\n", $text); $lines = explode("\n", $text);
foreach($lines as $line){ foreach($lines as $line){
@ -46,7 +46,7 @@ class SectionSplitter {
/** /**
* 按照句子来拆分 * 按照句子来拆分
*/ */
public function splitSentence($text){ //我就不信一句话能一万字 public function splitSentence($text) { //我就不信一句话能一万字
$sentences = explode("\0", preg_replace('/(。|\\.)/', "$1\0", $text)); $sentences = explode("\0", preg_replace('/(。|\\.)/', "$1\0", $text));
foreach($sentences as $sentence){ foreach($sentences as $sentence){
if(mb_strlen($sentence, 'UTF-8') > $this->maxLength){ //一句话能说一万字吗? if(mb_strlen($sentence, 'UTF-8') > $this->maxLength){ //一句话能说一万字吗?
@ -60,7 +60,7 @@ class SectionSplitter {
/** /**
* 强制拆分 * 强制拆分
*/ */
public function forceSplit($text){ public function forceSplit($text) {
$len = mb_strlen($text, 'UTF-8'); $len = mb_strlen($text, 'UTF-8');
$times = ceil($len / $this->maxLength); $times = ceil($len / $this->maxLength);
for($i = 0; $i < $times; $i ++){ for($i = 0; $i < $times; $i ++){
@ -72,7 +72,7 @@ class SectionSplitter {
} }
} }
public function getChunkList(){ public function getChunkList() {
return $this->chunkList; return $this->chunkList;
} }
} }

@ -27,7 +27,7 @@ class Utils {
return trim(implode("\n", $lines)); return trim(implode("\n", $lines));
} }
public static function getReadableReason($reasons){ public static function getReadableReason($reasons) {
$allowedReasons = ['spam', 'ad', 'politics', 'terrorism', 'abuse', 'porn', 'flood', 'contraband', 'meaningless', 'customized', 'normal']; $allowedReasons = ['spam', 'ad', 'politics', 'terrorism', 'abuse', 'porn', 'flood', 'contraband', 'meaningless', 'customized', 'normal'];
if(is_string($reasons)) return $reasons; if(is_string($reasons)) return $reasons;
@ -47,7 +47,7 @@ class Utils {
/** /**
* @throws \MWException * @throws \MWException
*/ */
public static function addAIReviewLog($event, $robotUser, $modUser, $title, $modid, $reason = null){ public static function addAIReviewLog($event, $robotUser, $modUser, $title, $modid, $reason = null) {
$entry = new ManualLogEntry('aireview', $event); $entry = new ManualLogEntry('aireview', $event);
$entry->setPerformer($robotUser); $entry->setPerformer($robotUser);
$entry->setTarget($title); $entry->setTarget($title);

Loading…
Cancel
Save