Committing today's work the LinkHooks' new parser.
[lhc/web/wiklou.git] / includes / Revision.php
index 3eaf50b..eba7be4 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 /**
  * @todo document
+ * @file
  */
 
 /**
@@ -34,10 +35,8 @@ class Revision {
         * @param Title $title
         * @param int $id
         * @return Revision
-        * @access public
-        * @static
         */
-       public static function newFromTitle( &$title, $id = 0 ) {
+       public static function newFromTitle( $title, $id = 0 ) {
                if( $id ) {
                        $matchId = intval( $id );
                } else {
@@ -59,7 +58,7 @@ class Revision {
         * @access public
         * @static
         */
-       public static function loadFromId( &$db, $id ) {
+       public static function loadFromId( $db, $id ) {
                return Revision::loadFromConds( $db,
                        array( 'page_id=rev_page',
                               'rev_id' => intval( $id ) ) );
@@ -99,7 +98,7 @@ class Revision {
         * @access public
         * @static
         */
-       public static function loadFromTitle( &$db, $title, $id = 0 ) {
+       public static function loadFromTitle( $db, $title, $id = 0 ) {
                if( $id ) {
                        $matchId = intval( $id );
                } else {
@@ -125,7 +124,7 @@ class Revision {
         * @access public
         * @static
         */
-       public static function loadFromTimestamp( &$db, &$title, $timestamp ) {
+       public static function loadFromTimestamp( $db, $title, $timestamp ) {
                return Revision::loadFromConds(
                        $db,
                        array( 'rev_timestamp'  => $db->timestamp( $timestamp ),
@@ -186,7 +185,7 @@ class Revision {
         * @access public
         * @static
         */
-       public static function fetchAllRevisions( &$title ) {
+       public static function fetchAllRevisions( $title ) {
                return Revision::fetchFromConds(
                        wfGetDB( DB_SLAVE ),
                        array( 'page_namespace' => $title->getNamespace(),
@@ -204,7 +203,7 @@ class Revision {
         * @access public
         * @static
         */
-       public static function fetchRevision( &$title ) {
+       public static function fetchRevision( $title ) {
                return Revision::fetchFromConds(
                        wfGetDB( DB_SLAVE ),
                        array( 'rev_id=page_latest',
@@ -258,6 +257,27 @@ class Revision {
                        'rev_parent_id'
                );
        }
+       
+       /**
+        * Return the list of text fields that should be selected to read the 
+        * revision text
+        */
+       static function selectTextFields() {
+               return array(
+                       'old_text',
+                       'old_flags'
+               );
+       }
+       /**
+        * Return the list of page fields that should be selected from page table
+        */
+       static function selectPageFields() {
+               return array(
+                       'page_namespace',
+                       'page_title',
+                       'page_latest'
+               );
+       }
 
        /**
         * @param object $row
@@ -385,7 +405,7 @@ class Revision {
                        'Revision::getTitle' );
                if( $row ) {
                        $this->mTitle = Title::makeTitle( $row->page_namespace,
-                                                          $row->page_title );
+                                                         $row->page_title );
                }
                return $this->mTitle;
        }
@@ -536,24 +556,26 @@ class Revision {
         * @return Revision
         */
        public function getPrevious() {
-               $prev = $this->mTitle->getPreviousRevisionID( $this->mId );
-               if( $prev ) {
-                       return Revision::newFromTitle( $this->mTitle, $prev );
-               } else {
-                       return null;
+               if( $this->getTitle() ) {
+                       $prev = $this->getTitle()->getPreviousRevisionID( $this->getId() );
+                       if( $prev ) {
+                               return Revision::newFromTitle( $this->getTitle(), $prev );
+                       }
                }
+               return null;
        }
 
        /**
         * @return Revision
         */
        public function getNext() {
-               $next = $this->mTitle->getNextRevisionID( $this->mId );
-               if ( $next ) {
-                       return Revision::newFromTitle( $this->mTitle, $next );
-               } else {
-                       return null;
+               if( $this->getTitle() ) {
+                       $next = $this->getTitle()->getNextRevisionID( $this->getId() );
+                       if ( $next ) {
+                               return Revision::newFromTitle( $this->getTitle(), $next );
+                       }
                }
+               return null;
        }
 
        /**
@@ -688,7 +710,7 @@ class Revision {
         * @param Database $dbw
         * @return int
         */
-       public function insertOn( &$dbw ) {
+       public function insertOn( $dbw ) {
                global $wgDefaultExternalStore;
 
                wfProfileIn( __METHOD__ );
@@ -750,6 +772,9 @@ class Revision {
                );
 
                $this->mId = !is_null($rev_id) ? $rev_id : $dbw->insertId();
+               
+               wfRunHooks( 'RevisionInsertComplete', array( &$this, $data, $flags ) );
+               
                wfProfileOut( __METHOD__ );
                return $this->mId;
        }
@@ -802,7 +827,8 @@ class Revision {
 
                $text = self::getRevisionText( $row );
 
-               if( $wgRevisionCacheExpiry ) {
+               # No negative caching -- negative hits on text rows may be due to corrupted slave servers
+               if( $wgRevisionCacheExpiry && $text !== false ) {
                        $wgMemc->set( $key, $text, $wgRevisionCacheExpiry );
                }
 
@@ -825,7 +851,7 @@ class Revision {
         * @param bool     $minor
         * @return Revision
         */
-       public static function newNullRevision( &$dbw, $pageId, $summary, $minor ) {
+       public static function newNullRevision( $dbw, $pageId, $summary, $minor ) {
                wfProfileIn( __METHOD__ );
 
                $current = $dbw->selectRow(
@@ -865,7 +891,7 @@ class Revision {
                if( ( $this->mDeleted & $field ) == $field ) {
                        global $wgUser;
                        $permission = ( $this->mDeleted & self::DELETED_RESTRICTED ) == self::DELETED_RESTRICTED
-                               ? 'hiderevision'
+                               ? 'suppressrevision'
                                : 'deleterevision';
                        wfDebug( "Checking for $permission due to $field match on $this->mDeleted\n" );
                        return $wgUser->isAllowed( $permission );
@@ -878,18 +904,21 @@ class Revision {
        /**
         * Get rev_timestamp from rev_id, without loading the rest of the row
         * @param integer $id
+        * @param integer $pageid, optional
         */
-       static function getTimestampFromID( $id ) {
+       static function getTimestampFromId( $id, $pageId = 0 ) {
                $dbr = wfGetDB( DB_SLAVE );
-               $timestamp = $dbr->selectField( 'revision', 'rev_timestamp',
-                       array( 'rev_id' => $id ), __METHOD__ );
+               $conds = array( 'rev_id' => $id );
+               if( $pageId ) {
+                       $conds['rev_page'] = $pageId;
+               }
+               $timestamp = $dbr->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__ );
                if ( $timestamp === false ) {
                        # Not in slave, try master
                        $dbw = wfGetDB( DB_MASTER );
-                       $timestamp = $dbw->selectField( 'revision', 'rev_timestamp',
-                               array( 'rev_id' => $id ), __METHOD__ );
+                       $timestamp = $dbw->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__ );
                }
-               return $timestamp;
+               return wfTimestamp( TS_MW, $timestamp );
        }
 
        /**