class PageRestriction extends AbstractRestriction {
- const TYPE = 'page';
- const TYPE_ID = 1;
-
/**
- * @var \Title
+ * @inheritDoc
*/
- protected $title;
+ const TYPE = 'page';
/**
- * {@inheritdoc}
+ * @inheritDoc
*/
- public function matches( \Title $title ) {
- return $title->equals( $this->getTitle() );
- }
+ const TYPE_ID = 1;
/**
- * {@inheritdoc}
+ * @var \Title|bool
*/
- public function getType() {
- return self::TYPE;
- }
+ protected $title;
/**
- * {@inheritdoc}
+ * @inheritDoc
*/
- public function getTypeId() {
- return self::TYPE_ID;
+ 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;
}
/**
- * {@inheritdoc}
+ * @inheritDoc
*/
public static function newFromRow( \stdClass $row ) {
$restriction = parent::newFromRow( $row );