2015-08-11 22:31:43 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Sets the VisualEditor autodisable preference on appropriate users.
|
|
|
|
*
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
|
2018-03-28 19:47:04 +00:00
|
|
|
* @license MIT
|
2015-08-11 22:31:43 +00:00
|
|
|
* @author Alex Monk <amonk@wikimedia.org>
|
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
|
|
|
* @ingroup Maintenance
|
|
|
|
*/
|
|
|
|
|
2020-06-06 16:40:04 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
2017-05-04 22:07:10 +00:00
|
|
|
$maintenancePath = getenv( 'MW_INSTALL_PATH' ) !== false
|
2015-08-11 22:31:43 +00:00
|
|
|
? getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php'
|
2018-02-05 18:59:37 +00:00
|
|
|
: __DIR__ . '/../../../../maintenance/Maintenance.php';
|
2017-05-04 22:07:10 +00:00
|
|
|
|
|
|
|
require_once $maintenancePath;
|
2015-08-11 22:31:43 +00:00
|
|
|
|
2018-03-28 19:47:04 +00:00
|
|
|
class AutodisableVisualEditorPref extends Maintenance {
|
2021-11-08 12:34:29 +00:00
|
|
|
|
2018-03-28 19:47:04 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2015-08-11 22:31:43 +00:00
|
|
|
public function __construct() {
|
|
|
|
parent::__construct();
|
2016-12-17 04:24:41 +00:00
|
|
|
$this->requireExtension( 'VisualEditor' );
|
2019-06-15 00:52:36 +00:00
|
|
|
$this->addDescription( "Sets the VisualEditor autodisable preference on appropriate users." );
|
2015-08-11 22:31:43 +00:00
|
|
|
$this->setBatchSize( 500 );
|
|
|
|
}
|
|
|
|
|
2018-03-28 19:47:04 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2015-08-11 22:31:43 +00:00
|
|
|
public function execute() {
|
2016-09-07 19:14:07 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2021-03-30 21:34:26 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
$lbFactory = $services->getDBLoadBalancerFactory();
|
|
|
|
$userOptionsManager = $services->getUserOptionsManager();
|
2015-08-11 22:31:43 +00:00
|
|
|
|
|
|
|
$lastUserId = -1;
|
|
|
|
do {
|
2022-08-12 21:58:14 +00:00
|
|
|
$results = $dbr->newSelectQueryBuilder()
|
|
|
|
->from( 'user' )
|
|
|
|
->leftJoin( 'user_properties', null, [
|
|
|
|
'user_id = up_user',
|
|
|
|
'up_property' => "visualeditor-enable"
|
|
|
|
] )
|
|
|
|
->field( 'user_id' )
|
|
|
|
->where( [
|
2015-08-11 22:31:43 +00:00
|
|
|
'user_id > ' . $dbr->addQuotes( $lastUserId ),
|
2017-05-04 22:27:27 +00:00
|
|
|
// only select users with no entry in user_properties
|
|
|
|
'up_value IS NULL',
|
2015-08-11 22:31:43 +00:00
|
|
|
'user_editcount > 0'
|
2022-08-12 21:58:14 +00:00
|
|
|
] )
|
|
|
|
->limit( $this->mBatchSize )
|
|
|
|
->orderBy( 'user_id' )
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
->fetchResultSet();
|
2015-08-11 22:31:43 +00:00
|
|
|
foreach ( $results as $userRow ) {
|
|
|
|
$user = User::newFromId( $userRow->user_id );
|
2015-09-30 21:02:56 +00:00
|
|
|
$user->load( User::READ_LATEST );
|
2021-03-30 21:34:26 +00:00
|
|
|
$userOptionsManager->setOption( $user, 'visualeditor-autodisable', true );
|
2015-08-11 22:31:43 +00:00
|
|
|
$user->saveSettings();
|
|
|
|
$lastUserId = $userRow->user_id;
|
|
|
|
}
|
2015-09-30 19:56:28 +00:00
|
|
|
$this->output( "Added preference for " . $results->numRows() . " users.\n" );
|
2020-06-06 16:40:04 +00:00
|
|
|
$lbFactory->waitForReplication();
|
2015-09-30 21:02:56 +00:00
|
|
|
} while ( $results->numRows() == $this->mBatchSize );
|
2015-08-11 22:31:43 +00:00
|
|
|
$this->output( "done.\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-02 22:46:12 +00:00
|
|
|
$maintClass = AutodisableVisualEditorPref::class;
|
2015-08-11 22:31:43 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|