Merge "Title: Make getOtherPage() check canHaveTalkPage()"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 7 Sep 2017 09:38:24 +0000 (09:38 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 7 Sep 2017 09:38:24 +0000 (09:38 +0000)
1  2 
includes/Title.php

diff --combined includes/Title.php
@@@ -1036,7 -1036,6 +1036,7 @@@ class Title implements LinkTarget 
         * Can this title have a corresponding talk page?
         *
         * @see MWNamespace::hasTalkNamespace
 +       * @since 1.30
         *
         * @return bool True if this title either is a talk page or can have a talk page associated.
         */
         * get the talk page, if it is a subject page get the talk page
         *
         * @since 1.25
-        * @throws MWException
+        * @throws MWException If the page doesn't have an other page
         * @return Title
         */
        public function getOtherPage() {
                if ( $this->isTalkPage() ) {
                        return $this->getSubjectPage();
                } else {
+                       if ( !$this->canHaveTalkPage() ) {
+                               throw new MWException( "{$this->getPrefixedText()} does not have an other page" );
+                       }
                        return $this->getTalkPage();
                }
        }
  
                if ( $this->mTitleProtection === null ) {
                        $dbr = wfGetDB( DB_REPLICA );
 +                      $commentStore = new CommentStore( 'pt_reason' );
 +                      $commentQuery = $commentStore->getJoin();
                        $res = $dbr->select(
 -                              'protected_titles',
 +                              [ 'protected_titles' ] + $commentQuery['tables'],
                                [
                                        'user' => 'pt_user',
 -                                      'reason' => 'pt_reason',
                                        'expiry' => 'pt_expiry',
                                        'permission' => 'pt_create_perm'
 -                              ],
 +                              ] + $commentQuery['fields'],
                                [ 'pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey() ],
 -                              __METHOD__
 +                              __METHOD__,
 +                              [],
 +                              $commentQuery['joins']
                        );
  
                        // fetchRow returns false if there are no rows.
                        $row = $dbr->fetchRow( $res );
                        if ( $row ) {
 -                              $row['expiry'] = $dbr->decodeExpiry( $row['expiry'] );
 +                              $this->mTitleProtection = [
 +                                      'user' => $row['user'],
 +                                      'expiry' => $dbr->decodeExpiry( $row['expiry'] ),
 +                                      'permission' => $row['permission'],
 +                                      'reason' => $commentStore->getComment( $row )->text,
 +                              ];
 +                      } else {
 +                              $this->mTitleProtection = false;
                        }
 -                      $this->mTitleProtection = $row;
                }
                return $this->mTitleProtection;
        }