diff --git a/includes/Hooks.php b/includes/Hooks.php index 12065b2a9b..7e6d3792db 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -10,7 +10,6 @@ namespace MediaWiki\Extension\VisualEditor; -use ActorMigration; use Article; use Config; use DeferredUpdates; @@ -519,28 +518,21 @@ class Hooks { !$userOptionsLookup->getOption( $user, 'visualeditor-hidetabdialog' ) && $userOptionsLookup->getOption( $user, 'visualeditor-tabs' ) === 'remember-last' ) { + // Check if the user has made any edits before the SET switch time $dbr = wfGetDB( DB_REPLICA ); - $revWhere = ActorMigration::newMigration()->getWhere( $dbr, 'rev_user', $user ); - foreach ( $revWhere['orconds'] as $key => $cond ) { - $tsField = $key === 'actor' ? 'revactor_timestamp' : 'rev_timestamp'; - if ( - $dbr->select( - [ 'revision' ] + $revWhere['tables'], - '1', - [ - $cond, - $tsField . ' < ' . $dbr->addQuotes( $dbr->timestamp( - $config->get( 'VisualEditorSingleEditTabSwitchTime' ) - ) ) - ], - __METHOD__, - [ 'LIMIT' => 1 ], - $revWhere['joins'] - )->numRows() === 1 - ) { - $links['views']['edit']['class'] .= ' visualeditor-showtabdialog'; - break; - } + $revExists = $dbr->newSelectQueryBuilder() + ->from( 'revision' ) + ->field( '1' ) + ->where( [ + 'rev_actor' => $user->getActorId(), + 'rev_timestamp < ' . $dbr->addQuotes( $dbr->timestamp( + $config->get( 'VisualEditorSingleEditTabSwitchTime' ) + ) ) + ] ) + ->caller( __METHOD__ ) + ->fetchField(); + if ( $revExists ) { + $links['views']['edit']['class'] .= ' visualeditor-showtabdialog'; } } diff --git a/maintenance/AutodisableVisualEditorPref.php b/maintenance/AutodisableVisualEditorPref.php index e2fb9b995c..b47c70bc03 100644 --- a/maintenance/AutodisableVisualEditorPref.php +++ b/maintenance/AutodisableVisualEditorPref.php @@ -41,27 +41,23 @@ class AutodisableVisualEditorPref extends Maintenance { $lastUserId = -1; do { - $results = $dbr->select( - [ 'user', 'user_properties' ], - 'user_id', - [ + $results = $dbr->newSelectQueryBuilder() + ->from( 'user' ) + ->leftJoin( 'user_properties', null, [ + 'user_id = up_user', + 'up_property' => "visualeditor-enable" + ] ) + ->field( 'user_id' ) + ->where( [ 'user_id > ' . $dbr->addQuotes( $lastUserId ), // only select users with no entry in user_properties 'up_value IS NULL', 'user_editcount > 0' - ], - __METHOD__, - [ - 'LIMIT' => $this->mBatchSize, - 'ORDER BY' => 'user_id' - ], - [ - 'user_properties' => [ - 'LEFT OUTER JOIN', - 'user_id = up_user and up_property = "visualeditor-enable"' - ] - ] - ); + ] ) + ->limit( $this->mBatchSize ) + ->orderBy( 'user_id' ) + ->caller( __METHOD__ ) + ->fetchResultSet(); foreach ( $results as $userRow ) { $user = User::newFromId( $userRow->user_id ); $user->load( User::READ_LATEST );