Merge "Improve docs for Title::getInternalURL/getCanonicalURL"
[lhc/web/wiklou.git] / includes / block / Restriction / PageRestriction.php
index 209b148..ea73d19 100644 (file)
@@ -24,38 +24,36 @@ namespace MediaWiki\Block\Restriction;
 
 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() );
        }
 
        /**
         * Set the title.
         *
+        * @since 1.33
         * @param \Title $title
         * @return self
         */
@@ -68,18 +66,25 @@ class PageRestriction extends AbstractRestriction {
        /**
         * Get Title.
         *
+        * @since 1.33
         * @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 );