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.

98 lines
2.0 KiB
PHP

<?php
namespace Isekai\Maintenance;
use Maintenance;
use Config;
use ApiMain;
use FauxRequest;
use Isekai\MiscUtills;
use Isekai\MiscUtils;
use MediaWiki\MediaWikiServices;
use Title;
use Wikimedia\Rdbms\IDatabase;
$IP = getenv( 'MW_INSTALL_PATH' );
if ( $IP === false ) {
$IP = __DIR__ . '/../../..';
}
require_once "$IP/maintenance/Maintenance.php";
class UpdateActivatedEditor extends Maintenance {
/**
* MediaWiki Sservices
*
* @var MediaWikiServices
*/
public $services;
/**
* A database replica DB object
*
* @var IDatabase
*/
public $dbr;
/**
* Config
*
* @var Config
*/
public $config;
public function __construct() {
parent::__construct();
$this->addDescription( 'Update activated-editor users by editor history.' );
$this->setBatchSize( 300 );
$this->requireExtension( 'IsekaiMisc' );
}
/**
* Return all users
* @return IResultWrapper
*/
private function getUserRes() {
return $this->dbr->select(
[ 'user' ],
[
'user_id',
'user_name',
],
[ 'user_editcount > 0' ],
__METHOD__
);
}
public function execute() {
$this->services = MediaWikiServices::getInstance();
$this->dbr = $this->services->getDBLoadBalancer()->getConnection(DB_REPLICA);
$this->config = $this->services->getMainConfig();
$userFactory = $this->services->getUserFactory();
$userGroupManager = $this->services->getUserGroupManager();
$requiredWords = $this->config->get('IsekaiActivateEditorRequiredWords');
$groupedUserIds = [];
$res = $this->getUserRes(NS_MAIN);
foreach ($res as $row) {
$continueKey = null;
$userCreditSize = 0;
$user = $userFactory->newFromId($row->user_id);
$this->output('Checking user "' . $user->getName() . '"...' . PHP_EOL);
if (MiscUtils::checkUserIsActivatedEditor($user)) {
$this->output(' Adding user "' . $user->getName() . '" to activated-editor group' . PHP_EOL);
$userGroupManager->addUserToGroup($user, 'activated-editor');
}
}
}
}
$maintClass = UpdateActivatedEditor::class;
require_once RUN_MAINTENANCE_IF_MAIN;