Merge "Show revdel links instead of checkboxes on pages where there is no multiple...
[lhc/web/wiklou.git] / includes / Revision.php
index ba28999..d47c9b4 100644 (file)
@@ -1,4 +1,24 @@
 <?php
+/**
+ * Representation of a page version.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
 
 /**
  * @todo document
@@ -321,6 +341,7 @@ class Revision {
        /**
         * Return the list of revision fields that should be selected to create
         * a new revision.
+        * @return array
         */
        public static function selectFields() {
                return array(
@@ -342,6 +363,7 @@ class Revision {
        /**
         * Return the list of text fields that should be selected to read the
         * revision text
+        * @return array
         */
        public static function selectTextFields() {
                return array(
@@ -352,17 +374,20 @@ class Revision {
 
        /**
         * Return the list of page fields that should be selected from page table
+        * @return array
         */
        public static function selectPageFields() {
                return array(
                        'page_namespace',
                        'page_title',
+                       'page_id',
                        'page_latest'
                );
        }
 
        /**
         * Return the list of user fields that should be selected from user table
+        * @return array
         */
        public static function selectUserFields() {
                return array( 'user_name' );
@@ -468,7 +493,7 @@ class Revision {
        /**
         * Get revision ID
         *
-        * @return Integer
+        * @return Integer|null
         */
        public function getId() {
                return $this->mId;
@@ -487,7 +512,7 @@ class Revision {
        /**
         * Get text row ID
         *
-        * @return Integer
+        * @return Integer|null
         */
        public function getTextId() {
                return $this->mTextId;
@@ -496,7 +521,7 @@ class Revision {
        /**
         * Get parent revision ID (the original previous page revision)
         *
-        * @return Integer
+        * @return Integer|null
         */
        public function getParentId() {
                return $this->mParentId;
@@ -505,7 +530,7 @@ class Revision {
        /**
         * Returns the length of the text in this revision, or null if unknown.
         *
-        * @return Integer
+        * @return Integer|null
         */
        public function getSize() {
                return $this->mSize;
@@ -514,30 +539,34 @@ class Revision {
        /**
         * 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' ),
-                       array( 'page_namespace', 'page_title' ),
-                       array( 'page_id=rev_page',
-                                  'rev_id' => $this->mId ),
-                       'Revision::getTitle' );
-               if( $row ) {
-                       $this->mTitle = Title::makeTitle( $row->page_namespace, $row->page_title );
+               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;
        }
@@ -554,7 +583,7 @@ class Revision {
        /**
         * Get the page ID
         *
-        * @return Integer
+        * @return Integer|null
         */
        public function getPage() {
                return $this->mPage;
@@ -1095,7 +1124,8 @@ class Revision {
 
                $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',
@@ -1112,6 +1142,7 @@ class Revision {
                                'len'        => $current->rev_len,
                                'sha1'       => $current->rev_sha1
                                ) );
+                       $revision->setTitle( Title::makeTitle( $current->page_namespace, $current->page_title ) );
                } else {
                        $revision = null;
                }
@@ -1180,7 +1211,7 @@ class Revision {
                        $id = 0;
                }
                $conds = array( 'rev_id' => $id );
-               $conds['rev_page'] = $title->getArticleId();
+               $conds['rev_page'] = $title->getArticleID();
                $timestamp = $dbr->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__ );
                if ( $timestamp === false && wfGetLB()->getServerCount() > 1 ) {
                        # Not in slave, try master
@@ -1214,7 +1245,7 @@ class Revision {
         * @return Integer
         */
        static function countByTitle( $db, $title ) {
-               $id = $title->getArticleId();
+               $id = $title->getArticleID();
                if( $id ) {
                        return Revision::countByPageId( $db, $id );
                }