Merge "Revision::getTitle produce rev_id IS NULL query"
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 31 May 2012 17:06:50 +0000 (17:06 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 31 May 2012 17:06:50 +0000 (17:06 +0000)
1  2 
includes/Revision.php

diff --combined includes/Revision.php
@@@ -493,7 -493,7 +493,7 @@@ class Revision 
        /**
         * Get revision ID
         *
-        * @return Integer
+        * @return Integer|null
         */
        public function getId() {
                return $this->mId;
        /**
         * Get text row ID
         *
-        * @return Integer
+        * @return Integer|null
         */
        public function getTextId() {
                return $this->mTextId;
        /**
         * Returns the length of the text in this revision, or null if unknown.
         *
-        * @return Integer
+        * @return Integer|null
         */
        public function getSize() {
                return $this->mSize;
        /**
         * Returns the base36 sha1 of the text in this revision, or null if unknown.
         *
-        * @return String
+        * @return String|null
         */
        public function getSha1() {
                return $this->mSha1;
        }
  
        /**
-        * Returns the title of the page associated with this entry.
+        * Returns the title of the page associated with this entry or null.
+        *
+        * Will do a query, when title is not set and id is given.
         *
-        * @return Title
+        * @return Title|null
         */
        public function getTitle() {
                if( isset( $this->mTitle ) ) {
                        return $this->mTitle;
                }
-               $dbr = wfGetDB( DB_SLAVE );
-               $row = $dbr->selectRow(
-                       array( 'page', 'revision' ),
-                       self::selectPageFields(),
-                       array( 'page_id=rev_page',
-                                  'rev_id' => $this->mId ),
-                       __METHOD__ );
-               if ( $row ) {
-                       $this->mTitle = Title::newFromRow( $row );
+               if( !is_null( $this->mId ) ) { //rev_id is defined as NOT NULL
+                       $dbr = wfGetDB( DB_SLAVE );
+                       $row = $dbr->selectRow(
+                               array( 'page', 'revision' ),
+                               self::selectPageFields(),
+                               array( 'page_id=rev_page',
+                                          'rev_id' => $this->mId ),
+                               __METHOD__ );
+                       if ( $row ) {
+                               $this->mTitle = Title::newFromRow( $row );
+                       }
                }
                return $this->mTitle;
        }
        /**
         * Get the page ID
         *
-        * @return Integer
+        * @return Integer|null
         */
        public function getPage() {
                return $this->mPage;
  
                $current = $dbw->selectRow(
                        array( 'page', 'revision' ),
 -                      array( 'page_latest', 'rev_text_id', 'rev_len', 'rev_sha1' ),
 +                      array( 'page_latest', 'page_namespace', 'page_title',
 +                              'rev_text_id', 'rev_len', 'rev_sha1' ),
                        array(
                                'page_id' => $pageId,
                                'page_latest=rev_id',
                                'len'        => $current->rev_len,
                                'sha1'       => $current->rev_sha1
                                ) );
 +                      $revision->setTitle( Title::makeTitle( $current->page_namespace, $current->page_title ) );
                } else {
                        $revision = null;
                }