Merge "Rename getCopyWarn() to getCopyrightWarning() and make it public and static"
[lhc/web/wiklou.git] / includes / WikiPage.php
index b5318c0..76a9828 100644 (file)
@@ -243,11 +243,20 @@ class WikiPage extends Page {
 
        /**
         * Clear the object
+        * @return void
         */
        public function clear() {
                $this->mDataLoaded = false;
                $this->mDataLoadedFrom = self::DATA_NOT_LOADED;
 
+               $this->clearCacheFields();
+       }
+
+       /**
+        * Clear the object cache fields
+        * @return void
+        */
+       protected function clearCacheFields() {
                $this->mCounter = null;
                $this->mRedirectTarget = null; # Title object if set
                $this->mLastRevision = null; # Latest revision
@@ -396,10 +405,18 @@ class WikiPage extends Page {
                        $this->mTouched     = wfTimestamp( TS_MW, $data->page_touched );
                        $this->mIsRedirect  = intval( $data->page_is_redirect );
                        $this->mLatest      = intval( $data->page_latest );
+                       // Bug 37225: $latest may no longer match the cached latest Revision object.
+                       // Double-check the ID of any cached latest Revision object for consistency.
+                       if ( $this->mLastRevision && $this->mLastRevision->getId() != $this->mLatest ) {
+                               $this->mLastRevision = null;
+                               $this->mTimestamp = '';
+                       }
                } else {
                        $lc->addBadLinkObj( $this->mTitle );
 
                        $this->mTitle->loadFromRow( false );
+
+                       $this->clearCacheFields();
                }
 
                $this->mDataLoaded = true;
@@ -611,7 +628,7 @@ class WikiPage extends Page {
                if ( !$this->mTimestamp ) {
                        $this->loadLastEdit();
                }
-               
+
                return wfTimestamp( TS_MW, $this->mTimestamp );
        }
 
@@ -1428,7 +1445,7 @@ class WikiPage extends Page {
         *  Compatibility note: this function previously returned a boolean value indicating success/failure
         */
        public function doEdit( $text, $summary, $flags = 0, $baseRevId = false, $user = null ) {
-               global $wgUser, $wgDBtransactions, $wgUseAutomaticEditSummaries;
+               global $wgUser, $wgUseAutomaticEditSummaries;
 
                # Low-level sanity check
                if ( $this->mTitle->getText() === '' ) {
@@ -1496,11 +1513,6 @@ class WikiPage extends Page {
                                return $status;
                        }
 
-                       # Make sure the revision is either completely inserted or not inserted at all
-                       if ( !$wgDBtransactions ) {
-                               $userAbort = ignore_user_abort( true );
-                       }
-
                        $revision = new Revision( array(
                                'page'       => $this->getId(),
                                'comment'    => $summary,
@@ -1511,6 +1523,9 @@ class WikiPage extends Page {
                                'user_text'  => $user->getName(),
                                'timestamp'  => $now
                        ) );
+                       # Bug 37225: use accessor to get the text as Revision may trim it.
+                       # After trimming, the text may be a duplicate of the current text.
+                       $text = $revision->getText(); // sanity; EditPage should trim already
 
                        $changed = ( strcmp( $text, $oldtext ) != 0 );
 
@@ -1531,11 +1546,6 @@ class WikiPage extends Page {
                                        /* Belated edit conflict! Run away!! */
                                        $status->fatal( 'edit-conflict' );
 
-                                       # Delete the invalid revision if the DB is not transactional
-                                       if ( !$wgDBtransactions ) {
-                                               $dbw->delete( 'revision', array( 'rev_id' => $revisionId ), __METHOD__ );
-                                       }
-
                                        $revisionId = 0;
                                        $dbw->rollback( __METHOD__ );
                                } else {
@@ -1566,10 +1576,6 @@ class WikiPage extends Page {
                                $revision->setId( $this->getLatest() );
                        }
 
-                       if ( !$wgDBtransactions ) {
-                               ignore_user_abort( $userAbort );
-                       }
-
                        // Now that ignore_user_abort is restored, we can respond to fatal errors
                        if ( !$status->isOK() ) {
                                wfProfileOut( __METHOD__ );
@@ -1617,6 +1623,9 @@ class WikiPage extends Page {
                        ) );
                        $revisionId = $revision->insertOn( $dbw );
 
+                       # Bug 37225: use accessor to get the text as Revision may trim it
+                       $text = $revision->getText(); // sanity; EditPage should trim already
+
                        # Update the page record with revision data
                        $this->updateRevisionOn( $dbw, $revision, 0 );
 
@@ -2264,13 +2273,23 @@ class WikiPage extends Page {
                $this->mTitle->resetArticleID( 0 );
        }
 
+       public function getDeletionUpdates() {
+               $updates = array(
+                       new LinksDeletionUpdate( $this ),
+               );
+
+               //@todo: make a hook to add update objects
+               //NOTE: deletion updates will be determined by the ContentHandler in the future
+               return $updates;
+       }
+
        /**
         * Roll back the most recent consecutive set of edits to a page
         * from the same user; fails if there are no eligible edits to
         * roll back to, e.g. user is the sole contributor. This function
         * performs permissions checks on $user, then calls commitRollback()
         * to do the dirty work
-        * 
+        *
         * @todo: seperate the business/permission stuff out from backend code
         *
         * @param $fromP String: Name of the user whose edits to rollback.
@@ -2940,7 +2959,7 @@ class WikiPage extends Page {
        public function quickEdit( $text, $comment = '', $minor = 0 ) {
                wfDeprecated( __METHOD__, '1.18' );
                global $wgUser;
-               return $this->doQuickEdit( $text, $wgUser, $comment, $minor );
+               $this->doQuickEdit( $text, $wgUser, $comment, $minor );
        }
 
        /**
@@ -2961,16 +2980,6 @@ class WikiPage extends Page {
                global $wgUser;
                return $this->isParserCacheUsed( ParserOptions::newFromUser( $wgUser ), $oldid );
        }
-
-       public function getDeletionUpdates() {
-               $updates = array(
-                       new LinksDeletionUpdate( $this ),
-               );
-
-               //@todo: make a hook to add update objects
-               //NOTE: deletion updates will be determined by the ContentHandler in the future
-               return $updates;
-       }
 }
 
 class PoolWorkArticleView extends PoolCounterWork {