Update usages of PageRestriction::getTitle() to handle a null response.
Bug: T214763
Change-Id: Ied33e2c3c9442c47ae8084a97bb0921869fb9d49
switch ( $restriction->getType() ) {
case 'page':
$value = [ 'id' => $restriction->getValue() ];
- self::addTitleInfo( $value, $restriction->getTitle() );
+ if ( $restriction->getTitle() ) {
+ self::addTitleInfo( $value, $restriction->getTitle() );
+ }
break;
default:
$value = $restriction->getValue();
const TYPE_ID = 1;
/**
- * @var \Title
+ * @var \Title|bool
*/
protected $title;
* {@inheritdoc}
*/
public function matches( \Title $title ) {
+ if ( !$this->getTitle() ) {
+ return false;
+ }
+
return $title->equals( $this->getTitle() );
}
* @return \Title|null
*/
public function getTitle() {
- if ( !$this->title ) {
+ if ( $this->title === null ) {
$this->title = \Title::newFromID( $this->value );
+
+ // If the title does not exist, set to false to prevent multiple database
+ // queries.
+ if ( $this->title === null ) {
+ $this->title = false;
+ }
}
- return $this->title;
+ return $this->title ?? null;
}
/**
foreach ( $block->getRestrictions() as $restriction ) {
switch ( $restriction->getType() ) {
case PageRestriction::TYPE:
- $pageRestrictions[] = $restriction->getTitle()->getPrefixedText();
+ if ( $restriction->getTitle() ) {
+ $pageRestrictions[] = $restriction->getTitle()->getPrefixedText();
+ }
break;
case NamespaceRestriction::TYPE:
$namespaceRestrictions[] = $restriction->getValue();
switch ( $restriction->getType() ) {
case PageRestriction::TYPE:
- $items[$restriction->getType()][] = HTML::rawElement(
- 'li',
- [],
- Linker::link( $restriction->getTitle() )
- );
+ if ( $restriction->getTitle() ) {
+ $items[$restriction->getType()][] = HTML::rawElement(
+ 'li',
+ [],
+ Linker::link( $restriction->getTitle() )
+ );
+ }
break;
case NamespaceRestriction::TYPE:
$text = $restriction->getValue() === NS_MAIN
'ir_type' => PageRestriction::TYPE_ID,
'ir_value' => $pageId,
] );
+ // Page that has been deleted.
+ $this->db->insert( 'ipblocks_restrictions', [
+ 'ir_ipb_id' => $block->getId(),
+ 'ir_type' => PageRestriction::TYPE_ID,
+ 'ir_value' => 999999,
+ ] );
$this->db->insert( 'ipblocks_restrictions', [
'ir_ipb_id' => $block->getId(),
'ir_type' => NamespaceRestriction::TYPE_ID,
$page = $this->getExistingTestPage( 'Mars' );
$this->assertFalse( $restriction->matches( $page->getTitle() ) );
+
+ // Deleted page.
+ $restriction = new $class( 2, 99999 );
+ $page = $this->getExistingTestPage( 'Saturn' );
+ $this->assertFalse( $restriction->matches( $page->getTitle() ) );
}
public function testGetType() {
new PageRestriction( 0, $pageSaturn->getId() ),
new PageRestriction( 0, $pageMars->getId() ),
new NamespaceRestriction( 0, NS_TALK ),
+ // Deleted page.
+ new PageRestriction( 0, 999999 ),
] );
$block->insert();
$restrictions = [
( new PageRestriction( 0, $pageId ) )->setTitle( $title ),
- new NamespaceRestriction( 0, NS_MAIN )
+ new NamespaceRestriction( 0, NS_MAIN ),
+ // Deleted page.
+ new PageRestriction( 0, 999999 ),
];
$wrappedPager = TestingAccessWrapper::newFromObject( $pager );