You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.9 KiB
PHP

<?php
namespace Isekai;
use ApiMain;
use MediaWiki\Request\FauxRequest;
use MediaWiki\User\User;
use MediaWiki\MediaWikiServices;
class MiscUtils {
/**
* @param User $user
*/
public static function checkUserIsActivatedEditor($user) {
$services = MediaWikiServices::getInstance();
$config = $services->getMainConfig();
$userGroupManager = $services->getUserGroupManager();
$userGroups = $userGroupManager->getUserGroups($user);
if (in_array('activated-editor', $userGroups)) {
return true;
}
$requiredWords = $config->get('IsekaiActivateEditorRequiredWords');
$continueKey = null;
$userCreditSize = 0;
do {
$apiParams = [
'action' => 'query',
'list' => 'usercontribs',
'ucprop' => 'sizediff',
'uclimit' => 20,
'ucuserids' => $user->getId(),
];
if ($continueKey) {
$apiParams['uccontinue'] = $continueKey;
}
$api = new ApiMain( new FauxRequest( $apiParams ) );
$api->execute();
$result = $api->getResult();
$continueKey = $result->getResultData( [ 'continue', 'uccontinue' ] );
if ($continueKey === '||') {
$continueKey = null;
}
$userCredits = $result->getResultData( [ 'query', 'usercontribs' ] );
foreach ($userCredits as $userCreditData) {
if (is_array($userCreditData) && isset($userCreditData['sizediff'])) {
if ($userCreditData['sizediff'] > 0) {
$userCreditSize += $userCreditData['sizediff'];
}
}
}
if ($userCreditSize > $requiredWords) {
return true;
}
} while($continueKey);
return false;
}
}