Use UserFactory::newFromId() and ::newFromName() instead of User::newFromId() and ::newFromName()

User: :newFromId() and ::newFromName() has been deprecated in 1.36.

Bug: T294128
Change-Id: Id872c28c7d20dc3d27a74cfac608aeb911c87c3d
This commit is contained in:
RazeSoldier 2021-10-22 22:50:16 +08:00
parent bfc5d28789
commit 61ac0b0e7c
3 changed files with 9 additions and 10 deletions

View file

@ -34,7 +34,6 @@ use Maintenance;
use MediaWiki\MediaWikiServices;
use MWException;
use TitleArrayFromResult;
use User;
$IP = getenv( "MW_INSTALL_PATH" ) ?: __DIR__ . "/../../..";
if ( !is_readable( "$IP/maintenance/Maintenance.php" ) ) {
@ -104,9 +103,10 @@ class ReplaceAll extends Maintenance {
private function getUser() {
$userReplacing = $this->getOption( "user", 1 );
$userFactory = MediaWikiServices::getInstance()->getUserFactory();
$user = is_numeric( $userReplacing ) ?
User::newFromId( $userReplacing ) :
User::newFromName( $userReplacing );
$userFactory->newFromId( $userReplacing ) :
$userFactory->newFromName( $userReplacing );
if ( get_class( $user ) !== 'User' ) {
$this->fatalError(

View file

@ -27,7 +27,6 @@ use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\SlotRecord;
use RequestContext;
use Title;
use User;
use WatchAction;
use Wikimedia\ScopedCallback;
use WikiPage;
@ -52,9 +51,10 @@ class Job extends JobParent {
* @return bool success
*/
function run() {
$services = MediaWikiServices::getInstance();
// T279090
$current_user = User::newFromId( $this->params['user_id'] );
$permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
$current_user = $services->getUserFactory()->newFromId( $this->params['user_id'] );
$permissionManager = $services->getPermissionManager();
if ( !$permissionManager->userCan(
'replacetext', $current_user, $this->title
) ) {
@ -90,7 +90,7 @@ class Job extends JobParent {
$reason = $this->params['edit_summary'];
$create_redirect = $this->params['create_redirect'];
$mvPage = MediaWikiServices::getInstance()->getMovePageFactory()->newMovePage( $this->title, $new_title );
$mvPage = $services->getMovePageFactory()->newMovePage( $this->title, $new_title );
$mvStatus = $mvPage->move( $current_user, $reason, $create_redirect );
if ( !$mvStatus->isOK() ) {
$this->error = "replaceText: error while moving: " . $this->title->getPrefixedDBkey() .
@ -101,7 +101,7 @@ class Job extends JobParent {
if ( $this->params['watch_page'] ) {
if ( method_exists( \MediaWiki\Watchlist\WatchlistManager::class, 'addWatch' ) ) {
// MW 1.37+
MediaWikiServices::getInstance()->getWatchlistManager()->addWatch( $current_user, $new_title );
$services->getWatchlistManager()->addWatch( $current_user, $new_title );
} else {
// Method was removed, but we only invoke it in versions its
// still available, suppress phan error

View file

@ -27,7 +27,6 @@ use OOUI;
use PermissionsError;
use SpecialPage;
use Title;
use User;
use Xml;
class SpecialReplaceText extends SpecialPage {
@ -249,7 +248,7 @@ class SpecialReplaceText extends SpecialPage {
$replacement_params = [];
if ( $wgReplaceTextUser != null ) {
$user = User::newFromName( $wgReplaceTextUser );
$user = MediaWikiServices::getInstance()->getUserFactory()->newFromName( $wgReplaceTextUser );
} else {
$user = $this->getUser();
}