Hygiene: SkinUserPageHelper should support Title = null
In some edge cases the RequestContext::getTitle() can return null instead of Title object. Similar situations already happened in the past (see T179833). The RequestContext::getTitle() documentation says it can return null, therefore code should be resilient and support such situations, even if there are not common. Bug: T221792 Change-Id: I842f8c49f20e511fda3b081e59a06586810bc748
This commit is contained in:
parent
7af32bc309
commit
047618c24d
|
@ -25,7 +25,7 @@ use User;
|
||||||
|
|
||||||
class SkinUserPageHelper {
|
class SkinUserPageHelper {
|
||||||
/**
|
/**
|
||||||
* @var Title
|
* @var Title|null
|
||||||
*/
|
*/
|
||||||
private $title;
|
private $title;
|
||||||
/**
|
/**
|
||||||
|
@ -39,9 +39,9 @@ class SkinUserPageHelper {
|
||||||
private $pageUser;
|
private $pageUser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Title $title
|
* @param Title|null $title
|
||||||
*/
|
*/
|
||||||
public function __construct( Title $title ) {
|
public function __construct( Title $title = null ) {
|
||||||
$this->title = $title;
|
$this->title = $title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,8 @@ class SkinUserPageHelper {
|
||||||
*/
|
*/
|
||||||
private function fetchData() {
|
private function fetchData() {
|
||||||
if ( $this->fetchedData === false ) {
|
if ( $this->fetchedData === false ) {
|
||||||
if ( $this->title->inNamespace( NS_USER ) && !$this->title->isSubpage() ) {
|
if ( $this->title && $this->title->inNamespace( NS_USER ) && !$this->title->isSubpage()
|
||||||
|
) {
|
||||||
$this->pageUser = $this->buildPageUserObject( $this->title );
|
$this->pageUser = $this->buildPageUserObject( $this->title );
|
||||||
}
|
}
|
||||||
$this->fetchedData = true;
|
$this->fetchedData = true;
|
||||||
|
|
|
@ -24,6 +24,19 @@ class SkinUserPageHelperTest extends MediaWikiTestCase {
|
||||||
$this->assertEquals( false, $helper->isUserPage() );
|
$this->assertEquals( false, $helper->isUserPage() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::isUserPage
|
||||||
|
* @covers ::fetchData
|
||||||
|
* @covers ::__construct
|
||||||
|
*/
|
||||||
|
public function testTitleIsNull() {
|
||||||
|
$title = null;
|
||||||
|
|
||||||
|
$helper = new SkinUserPageHelper( $title );
|
||||||
|
$this->assertEquals( null, $helper->getPageUser() );
|
||||||
|
$this->assertEquals( false, $helper->isUserPage() );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::isUserPage
|
* @covers ::isUserPage
|
||||||
* @covers ::fetchData
|
* @covers ::fetchData
|
||||||
|
|
Loading…
Reference in New Issue