Rename WikiPage::isParserCacheUsed to WikiPage::shouldCheckParserCache
[lhc/web/wiklou.git] / includes / page / WikiPage.php
index 5e4438a..f7f2528 100644 (file)
@@ -1082,16 +1082,13 @@ class WikiPage implements Page, IDBAccessObject {
         * Should the parser cache be used?
         *
         * @param ParserOptions $parserOptions ParserOptions to check
-        * @param int $oldid
+        * @param int $oldId
         * @return bool
         */
-       public function isParserCacheUsed( ParserOptions $parserOptions, $oldid ) {
-               global $wgEnableParserCache;
-
-               return $wgEnableParserCache
-                       && $parserOptions->getStubThreshold() == 0
+       public function shouldCheckParserCache( ParserOptions $parserOptions, $oldId ) {
+               return $parserOptions->getStubThreshold() == 0
                        && $this->exists()
-                       && ( $oldid === null || $oldid === 0 || $oldid === $this->getLatest() )
+                       && ( $oldId === null || $oldId === 0 || $oldId === $this->getLatest() )
                        && $this->getContentHandler()->isParserCacheSupported();
        }
 
@@ -1108,10 +1105,10 @@ class WikiPage implements Page, IDBAccessObject {
         */
        public function getParserOutput( ParserOptions $parserOptions, $oldid = null ) {
 
-               $useParserCache = $this->isParserCacheUsed( $parserOptions, $oldid );
+               $useParserCache = $this->shouldCheckParserCache( $parserOptions, $oldid );
                wfDebug( __METHOD__ . ': using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
                if ( $parserOptions->getStubThreshold() ) {
-                       wfIncrStats( 'pcache_miss_stub' );
+                       wfIncrStats( 'pcache.miss.stub' );
                }
 
                if ( $useParserCache ) {
@@ -1267,10 +1264,9 @@ class WikiPage implements Page, IDBAccessObject {
                        $conditions['page_latest'] = $lastRevision;
                }
 
-               $now = wfTimestampNow();
                $row = array( /* SET */
                        'page_latest'      => $revision->getId(),
-                       'page_touched'     => $dbw->timestamp( $now ),
+                       'page_touched'     => $dbw->timestamp( $revision->getTimestamp() ),
                        'page_is_new'      => ( $lastRevision === 0 ) ? 1 : 0,
                        'page_is_redirect' => $rt !== null ? 1 : 0,
                        'page_len'         => $len,
@@ -1868,7 +1864,7 @@ class WikiPage implements Page, IDBAccessObject {
                                $revision = null;
                                // Update page_touched, this is usually implicit in the page update
                                // Other cache updates are done in onArticleEdit()
-                               $this->mTitle->invalidateCache();
+                               $this->mTitle->invalidateCache( $now );
                        }
                } else {
                        // Create new article
@@ -1961,13 +1957,13 @@ class WikiPage implements Page, IDBAccessObject {
                $status->value['revision'] = $revision;
 
                $hook_args = array( &$this, &$user, $content, $summary,
-                                                       $flags & EDIT_MINOR, null, null, &$flags, $revision, &$status, $baseRevId );
+                       $flags & EDIT_MINOR, null, null, &$flags, $revision, &$status, $baseRevId );
 
                ContentHandler::runLegacyHooks( 'ArticleSaveComplete', $hook_args );
                Hooks::run( 'PageContentSaveComplete', $hook_args );
 
                // Promote user to any groups they meet the criteria for
-               $dbw->onTransactionIdle( function () use ( $user ) {
+               DeferredUpdates::addCallableUpdate( function () use ( $user ) {
                        $user->addAutopromoteOnceGroups( 'onEdit' );
                        $user->addAutopromoteOnceGroups( 'onView' ); // b/c
                } );
@@ -2152,8 +2148,6 @@ class WikiPage implements Page, IDBAccessObject {
         *   - 'no-change': don't update the article count, ever
         */
        public function doEditUpdates( Revision $revision, User $user, array $options = array() ) {
-               global $wgEnableParserCache;
-
                $options += array(
                        'changed' => true,
                        'created' => false,
@@ -2173,13 +2167,12 @@ class WikiPage implements Page, IDBAccessObject {
                        $editInfo = $this->mPreparedEdit;
                }
 
-               // Save it to the parser cache
-               if ( $wgEnableParserCache ) {
-                       $parserCache = ParserCache::singleton();
-                       $parserCache->save(
-                               $editInfo->output, $this, $editInfo->popts, $editInfo->timestamp, $editInfo->revid
-                       );
-               }
+               // Save it to the parser cache.
+               // Make sure the cache time matches page_touched to avoid double parsing.
+               ParserCache::singleton()->save(
+                       $editInfo->output, $this, $editInfo->popts,
+                       $revision->getTimestamp(), $editInfo->revid
+               );
 
                // Update the links tables and other secondary data
                if ( $content ) {
@@ -2769,9 +2762,16 @@ class WikiPage implements Page, IDBAccessObject {
                $dbw->begin( __METHOD__ );
 
                if ( $id == 0 ) {
-                       $this->loadPageData( 'forupdate' );
+                       // T98706: lock the page from various other updates but avoid using
+                       // WikiPage::READ_LOCKING as that will carry over the FOR UPDATE to
+                       // the revisions queries (which also JOIN on user). Only lock the page
+                       // row and CAS check on page_latest to see if the trx snapshot matches.
+                       $latest = $this->lock();
+
+                       $this->loadPageData( WikiPage::READ_LATEST );
                        $id = $this->getID();
-                       if ( $id == 0 ) {
+                       if ( $id == 0 || $this->getLatest() != $latest ) {
+                               // Page not there or trx snapshot is stale
                                $dbw->rollback( __METHOD__ );
                                $status->error( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) );
                                return $status;
@@ -2878,6 +2878,24 @@ class WikiPage implements Page, IDBAccessObject {
                return $status;
        }
 
+       /**
+        * Lock the page row for this title and return page_latest (or 0)
+        *
+        * @return integer
+        */
+       protected function lock() {
+               return (int)wfGetDB( DB_MASTER )->selectField(
+                       'page',
+                       'page_latest',
+                       array(
+                               'page_namespace' => $this->getTitle()->getNamespace(),
+                               'page_title' => $this->getTitle()->getDBkey()
+                       ),
+                       __METHOD__,
+                       array( 'FOR UPDATE' )
+               );
+       }
+
        /**
         * Do some database updates after deletion
         *
@@ -3006,7 +3024,7 @@ class WikiPage implements Page, IDBAccessObject {
                        ) );
                }
 
-               // Get the last edit not by this guy...
+               // Get the last edit not by this person...
                // Note: these may not be public values
                $user = intval( $current->getUser( Revision::RAW ) );
                $user_text = $dbw->addQuotes( $current->getUserText( Revision::RAW ) );
@@ -3028,29 +3046,6 @@ class WikiPage implements Page, IDBAccessObject {
                        return array( array( 'notvisiblerev' ) );
                }
 
-               // Set patrolling and bot flag on the edits, which gets rollbacked.
-               // This is done before the rollback edit to have patrolling also on failure (bug 62157).
-               $set = array();
-               if ( $bot && $guser->isAllowed( 'markbotedits' ) ) {
-                       // Mark all reverted edits as bot
-                       $set['rc_bot'] = 1;
-               }
-
-               if ( $wgUseRCPatrol ) {
-                       // Mark all reverted edits as patrolled
-                       $set['rc_patrolled'] = 1;
-               }
-
-               if ( count( $set ) ) {
-                       $dbw->update( 'recentchanges', $set,
-                               array( /* WHERE */
-                                       'rc_cur_id' => $current->getPage(),
-                                       'rc_user_text' => $current->getUserText(),
-                                       'rc_timestamp > ' . $dbw->addQuotes( $s->rev_timestamp ),
-                               ), __METHOD__
-                       );
-               }
-
                // Generate the edit summary if necessary
                $target = Revision::newFromId( $s->rev_id, Revision::READ_LATEST );
                if ( empty( $summary ) ) {
@@ -3099,6 +3094,30 @@ class WikiPage implements Page, IDBAccessObject {
                        $guser
                );
 
+               // Set patrolling and bot flag on the edits, which gets rollbacked.
+               // This is done even on edit failure to have patrolling in that case (bug 62157).
+               $set = array();
+               if ( $bot && $guser->isAllowed( 'markbotedits' ) ) {
+                       // Mark all reverted edits as bot
+                       $set['rc_bot'] = 1;
+               }
+
+               if ( $wgUseRCPatrol ) {
+                       // Mark all reverted edits as patrolled
+                       $set['rc_patrolled'] = 1;
+               }
+
+               if ( count( $set ) ) {
+                       $dbw->update( 'recentchanges', $set,
+                               array( /* WHERE */
+                                       'rc_cur_id' => $current->getPage(),
+                                       'rc_user_text' => $current->getUserText(),
+                                       'rc_timestamp > ' . $dbw->addQuotes( $s->rev_timestamp ),
+                               ),
+                               __METHOD__
+                       );
+               }
+
                if ( !$status->isOK() ) {
                        return $status->getErrorsArray();
                }
@@ -3142,7 +3161,6 @@ class WikiPage implements Page, IDBAccessObject {
                // Update existence markers on article/talk tabs...
                $other = $title->getOtherPage();
 
-               $other->invalidateCache();
                $other->purgeSquid();
 
                $title->touchLinks();
@@ -3159,7 +3177,6 @@ class WikiPage implements Page, IDBAccessObject {
                // Update existence markers on article/talk tabs...
                $other = $title->getOtherPage();
 
-               $other->invalidateCache();
                $other->purgeSquid();
 
                $title->touchLinks();