Add updateRevisionOn() sanity check for existing pages too
[lhc/web/wiklou.git] / includes / page / WikiPage.php
index bdb84c6..2d5cb78 100644 (file)
@@ -1832,7 +1832,10 @@ class WikiPage implements Page, IDBAccessObject {
                                $revisionId = $revision->insertOn( $dbw );
 
                                // Update page_latest and friends to reflect the new revision
-                               $this->updateRevisionOn( $dbw, $revision, null, $oldIsRedirect );
+                               if ( !$this->updateRevisionOn( $dbw, $revision, null, $oldIsRedirect ) ) {
+                                       $dbw->rollback( __METHOD__ );
+                                       throw new MWException( "Failed to update page row to use new revision." );
+                               }
 
                                Hooks::run( 'NewRevisionFromEditComplete',
                                        array( $this, $revision, $baseRevId, $user ) );
@@ -2192,6 +2195,7 @@ class WikiPage implements Page, IDBAccessObject {
                        foreach ( $updates as $update ) {
                                if ( $update instanceof LinksUpdate ) {
                                        $update->setRevision( $revision );
+                                       $update->setTriggeringUser( $user );
                                }
                                DeferredUpdates::addUpdate( $update );
                        }
@@ -2920,8 +2924,9 @@ class WikiPage implements Page, IDBAccessObject {
                $status->value = $logid;
 
                // Show log excerpt on 404 pages rather than just a link
+               $cache = ObjectCache::getMainStashInstance();
                $key = wfMemcKey( 'page-recent-delete', md5( $logTitle->getPrefixedText() ) );
-               ObjectCache::getMainStashInstance()->set( $key, 1, 86400 );
+               $cache->set( $key, 1, $cache::TTL_DAY );
 
                return $status;
        }
@@ -3483,22 +3488,34 @@ class WikiPage implements Page, IDBAccessObject {
                        return;
                }
 
+               $params = array(
+                       'isOpportunistic' => true,
+                       'rootJobTimestamp' => $parserOutput->getCacheTime()
+               );
+
                if ( $this->mTitle->areRestrictionsCascading() ) {
                        // If the page is cascade protecting, the links should really be up-to-date
-                       $params = array( 'prioritize' => true );
+                       JobQueueGroup::singleton()->lazyPush(
+                               RefreshLinksJob::newPrioritized( $this->mTitle, $params )
+                       );
                } elseif ( $parserOutput->hasDynamicContent() ) {
-                       // Assume the output contains time/random based magic words
-                       $params = array();
-               } else {
-                       // If the inclusions are deterministic, the edit-triggered link jobs are enough
-                       return;
-               }
-
-               // Check if the last link refresh was before page_touched
-               if ( $this->getLinksTimestamp() < $this->getTouched() ) {
-                       $params['isOpportunistic'] = true;
-                       $params['rootJobTimestamp'] = $parserOutput->getCacheTime();
-                       JobQueueGroup::singleton()->lazyPush( new RefreshLinksJob( $this->mTitle, $params ) );
+                       // Assume the output contains "dynamic" time/random based magic words.
+                       // Only update pages that expired due to dynamic content and NOT due to edits
+                       // to referenced templates/files. When the cache expires due to dynamic content,
+                       // page_touched is unchanged. We want to avoid triggering redundant jobs due to
+                       // views of pages that were just purged via HTMLCacheUpdateJob. In that case, the
+                       // template/file edit already triggered recursive RefreshLinksJob jobs.
+                       if ( $this->getLinksTimestamp() > $this->getTouched() ) {
+                               // If a page is uncacheable, do not keep spamming a job for it.
+                               // Although it would be de-duplicated, it would still waste I/O.
+                               $cache = ObjectCache::getLocalClusterInstance();
+                               $key = $cache->makeKey( 'dynamic-linksupdate', 'last', $this->getId() );
+                               if ( $cache->add( $key, time(), 60 ) ) {
+                                       JobQueueGroup::singleton()->lazyPush(
+                                               RefreshLinksJob::newDynamic( $this->mTitle, $params )
+                                       );
+                               }
+                       }
                }
        }