Introduce Title::getTalkPageIfDefined.
[lhc/web/wiklou.git] / includes / Title.php
index 6538538..0a2f868 100644 (file)
@@ -1316,6 +1316,21 @@ class Title implements LinkTarget {
                return self::makeTitle( MWNamespace::getTalk( $this->getNamespace() ), $this->getDBkey() );
        }
 
+       /**
+        * Get a Title object associated with the talk page of this article,
+        * if such a talk page can exist.
+        *
+        * @return Title The object for the talk page,
+        *         or null if no associated talk page can exist, according to canHaveTalkPage().
+        */
+       public function getTalkPageIfDefined() {
+               if ( !$this->canHaveTalkPage() ) {
+                       return null;
+               }
+
+               return $this->getTalkPage();
+       }
+
        /**
         * Get a title object associated with the subject page of this
         * talk page
@@ -3172,7 +3187,7 @@ class Title implements LinkTarget {
                if ( $limit > -1 ) {
                        $options['LIMIT'] = $limit;
                }
-               $this->mSubpages = TitleArray::newFromResult(
+               return TitleArray::newFromResult(
                        $dbr->select( 'page',
                                [ 'page_id', 'page_namespace', 'page_title', 'page_is_redirect' ],
                                $conds,
@@ -3180,7 +3195,6 @@ class Title implements LinkTarget {
                                $options
                        )
                );
-               return $this->mSubpages;
        }
 
        /**