Replace deprecated User::newFromId on Special:Redirect
Change-Id: I3a4f995e4cfb4dfe68b50662aebf795e3bb78b4a
This commit is contained in:
parent
ef0e5d4825
commit
237ef2a624
3 changed files with 18 additions and 7 deletions
|
|
@ -915,7 +915,8 @@ class SpecialPageFactory {
|
|||
'Redirect' => [
|
||||
'class' => \SpecialRedirect::class,
|
||||
'services' => [
|
||||
'RepoGroup'
|
||||
'RepoGroup',
|
||||
'UserFactory',
|
||||
]
|
||||
],
|
||||
'Revisiondelete' => [
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@
|
|||
* @ingroup SpecialPage
|
||||
*/
|
||||
|
||||
use MediaWiki\User\UserFactory;
|
||||
|
||||
/**
|
||||
* A special page that redirects to: the user for a numeric user id,
|
||||
* the file for a given filename, or the page for a given revision id.
|
||||
|
|
@ -51,15 +53,23 @@ class SpecialRedirect extends FormSpecialPage {
|
|||
/** @var RepoGroup */
|
||||
private $repoGroup;
|
||||
|
||||
/** @var UserFactory */
|
||||
private $userFactory;
|
||||
|
||||
/**
|
||||
* @param RepoGroup $repoGroup
|
||||
* @param UserFactory $userFactory
|
||||
*/
|
||||
public function __construct( RepoGroup $repoGroup ) {
|
||||
public function __construct(
|
||||
RepoGroup $repoGroup,
|
||||
UserFactory $userFactory
|
||||
) {
|
||||
parent::__construct( 'Redirect' );
|
||||
$this->mType = null;
|
||||
$this->mValue = null;
|
||||
|
||||
$this->repoGroup = $repoGroup;
|
||||
$this->userFactory = $userFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -83,7 +93,7 @@ class SpecialRedirect extends FormSpecialPage {
|
|||
// Message: redirect-not-numeric
|
||||
return Status::newFatal( $this->getMessagePrefix() . '-not-numeric' );
|
||||
}
|
||||
$user = User::newFromId( (int)$this->mValue );
|
||||
$user = $this->userFactory->newFromId( (int)$this->mValue );
|
||||
$user->load(); // Make sure the id is validated by loading the user
|
||||
if ( $user->isAnon() ) {
|
||||
// Message: redirect-not-exists
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
/**
|
||||
* Test class for SpecialRedirect class
|
||||
*
|
||||
|
|
@ -25,13 +23,15 @@ class SpecialRedirectTest extends MediaWikiIntegrationTestCase {
|
|||
* @covers SpecialRedirect::dispatchLog()
|
||||
*/
|
||||
public function testDispatch( $method, $type, $value, $expectedStatus ) {
|
||||
$userFactory = $this->getServiceContainer()->getUserFactory();
|
||||
$page = new SpecialRedirect(
|
||||
MediaWikiServices::getInstance()->getRepoGroup()
|
||||
$this->getServiceContainer()->getRepoGroup(),
|
||||
$userFactory
|
||||
);
|
||||
|
||||
// setup the user object
|
||||
if ( $value === self::CREATE_USER ) {
|
||||
$user = User::newFromName( __CLASS__ );
|
||||
$user = $userFactory->newFromName( __CLASS__ );
|
||||
$user->addToDatabase();
|
||||
$value = $user->getId();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue