重新排版

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

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

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

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

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

@ -7,7 +7,7 @@ class SectionSplitter {
private $bufferLength = 0;
private $maxLength;
public function __construct($text, $maxLength = 10000){
public function __construct($text, $maxLength = 10000) {
$this->maxLength = $maxLength;
$this->splitLine($text);
}
@ -28,7 +28,7 @@ class SectionSplitter {
/**
* 按照行来拆分
*/
public function splitLine($text){
public function splitLine($text) {
$text = str_replace("\r\n", "\n", $text);
$lines = explode("\n", $text);
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));
foreach($sentences as $sentence){
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');
$times = ceil($len / $this->maxLength);
for($i = 0; $i < $times; $i ++){
@ -72,7 +72,7 @@ class SectionSplitter {
}
}
public function getChunkList(){
public function getChunkList() {
return $this->chunkList;
}
}

@ -27,7 +27,7 @@ class Utils {
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'];
if(is_string($reasons)) return $reasons;
@ -47,7 +47,7 @@ class Utils {
/**
* @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->setPerformer($robotUser);
$entry->setTarget($title);

Loading…
Cancel
Save