LogEntry: Make associated rev id persistent (store in logging and log_search)
[lhc/web/wiklou.git] / includes / filerepo / file / LocalFile.php
index dcc8741..b7d6f98 100644 (file)
@@ -858,14 +858,14 @@ class LocalFile extends File {
        }
 
        /**
-        * Refresh metadata in memcached, but don't touch thumbnails or squid
+        * Refresh metadata in memcached, but don't touch thumbnails or CDN
         */
        function purgeMetadataCache() {
                $this->invalidateCache();
        }
 
        /**
-        * Delete all previously generated thumbnails, refresh metadata in memcached and purge the squid.
+        * Delete all previously generated thumbnails, refresh metadata in memcached and purge the CDN.
         *
         * @param array $options An array potentially with the key forThumbRefresh.
         *
@@ -878,9 +878,9 @@ class LocalFile extends File {
                // Delete thumbnails
                $this->purgeThumbnails( $options );
 
-               // Purge squid cache for this file
+               // Purge CDN cache for this file
                DeferredUpdates::addUpdate(
-                       new SquidUpdate( array( $this->getUrl() ) ),
+                       new CdnCacheUpdate( array( $this->getUrl() ) ),
                        DeferredUpdates::PRESEND
                );
        }
@@ -899,12 +899,12 @@ class LocalFile extends File {
                $dir = array_shift( $files );
                $this->purgeThumbList( $dir, $files );
 
-               // Purge the squid
+               // Purge the CDN
                $urls = array();
                foreach ( $files as $file ) {
                        $urls[] = $this->getArchiveThumbUrl( $archiveName, $file );
                }
-               DeferredUpdates::addUpdate( new SquidUpdate( $urls ), DeferredUpdates::PRESEND );
+               DeferredUpdates::addUpdate( new CdnCacheUpdate( $urls ), DeferredUpdates::PRESEND );
        }
 
        /**
@@ -914,7 +914,7 @@ class LocalFile extends File {
        public function purgeThumbnails( $options = array() ) {
                // Delete thumbnails
                $files = $this->getThumbnails();
-               // Always purge all files from squid regardless of handler filters
+               // Always purge all files from CDN regardless of handler filters
                $urls = array();
                foreach ( $files as $file ) {
                        $urls[] = $this->getThumbUrl( $file );
@@ -935,8 +935,8 @@ class LocalFile extends File {
                $dir = array_shift( $files );
                $this->purgeThumbList( $dir, $files );
 
-               // Purge the squid
-               DeferredUpdates::addUpdate( new SquidUpdate( $urls ), DeferredUpdates::PRESEND );
+               // Purge the CDN
+               DeferredUpdates::addUpdate( new CdnCacheUpdate( $urls ), DeferredUpdates::PRESEND );
        }
 
        /**
@@ -1330,6 +1330,7 @@ class LocalFile extends File {
                }
 
                $descTitle = $this->getTitle();
+               $descId = $descTitle->getArticleID();
                $wikiPage = new WikiFilePage( $descTitle );
                $wikiPage->setFile( $this );
 
@@ -1362,7 +1363,7 @@ class LocalFile extends File {
 
                        $nullRevision = Revision::newNullRevision(
                                $dbw,
-                               $descTitle->getArticleID(),
+                               $descId,
                                $editSummary,
                                false,
                                $user
@@ -1374,6 +1375,8 @@ class LocalFile extends File {
                                        array( $wikiPage, $nullRevision, $nullRevision->getParentId(), $user )
                                );
                                $wikiPage->updateRevisionOn( $dbw, $nullRevision );
+                               // Associate null revision id
+                               $logEntry->setAssociatedRevId( $nullRevision->getId() );
                        }
 
                        $newPageContent = null;
@@ -1391,15 +1394,16 @@ class LocalFile extends File {
                # b) They won't cause rollback of the log publish/update above
                $that = $this;
                $dbw->onTransactionIdle( function () use (
-                       $that, $reupload, $wikiPage, $newPageContent, $comment, $user, $logEntry, $logId
+                       $that, $reupload, $wikiPage, $newPageContent, $comment, $user, $logEntry, $logId, $descId
                ) {
                        # Update memcache after the commit
                        $that->invalidateCache();
 
+                       $updateLogPage = false;
                        if ( $newPageContent ) {
                                # New file page; create the description page.
                                # There's already a log entry, so don't make a second RC entry
-                               # Squid and file cache for the description page are purged by doEditContent.
+                               # CDN and file cache for the description page are purged by doEditContent.
                                $status = $wikiPage->doEditContent(
                                        $newPageContent,
                                        $comment,
@@ -1408,25 +1412,51 @@ class LocalFile extends File {
                                        $user
                                );
 
+                               if ( isset( $status->value['revision'] ) ) {
+                                       // Associate new page revision id
+                                       $logEntry->setAssociatedRevId( $status->value['revision']->getId() );
+                               }
                                // This relies on the resetArticleID() call in WikiPage::insertOn(),
                                // which is triggered on $descTitle by doEditContent() above.
                                if ( isset( $status->value['revision'] ) ) {
                                        /** @var $rev Revision */
                                        $rev = $status->value['revision'];
-                                       $that->getRepo()->getMasterDB()->update(
-                                               'logging',
-                                               array( 'log_page' => $rev->getPage() ),
-                                               array( 'log_id' => $logId ),
-                                               __METHOD__
-                                       );
+                                       $updateLogPage = $rev->getPage();
                                }
                        } else {
                                # Existing file page: invalidate description page cache
                                $wikiPage->getTitle()->invalidateCache();
                                $wikiPage->getTitle()->purgeSquid();
+                               # Allow the new file version to be patrolled from the page footer
+                               Article::purgePatrolFooterCache( $descId );
                        }
 
-                       # Now that the page exists, make an RC entry.
+                       # Update associated rev id. This should be done by $logEntry->insert() earlier,
+                       # but setAssociatedRevId() wasn't called at that point yet...
+                       $logParams = $logEntry->getParameters();
+                       $logParams['associated_rev_id'] = $logEntry->getAssociatedRevId();
+                       $update = array( 'log_params' => LogEntryBase::makeParamBlob( $logParams ) );
+                       if ( $updateLogPage ) {
+                               # Also log page, in case where we just created it above
+                               $update['log_page'] = $updateLogPage;
+                       }
+                       $that->getRepo()->getMasterDB()->update(
+                               'logging',
+                               $update,
+                               array( 'log_id' => $logId ),
+                               __METHOD__
+                       );
+                       $that->getRepo()->getMasterDB()->insert(
+                               'log_search',
+                               array(
+                                       'ls_field' => 'associated_rev_id',
+                                       'ls_value' => $logEntry->getAssociatedRevId(),
+                                       'ls_log_id' => $logId,
+                               ),
+                               __METHOD__
+                       );
+
+                       # Now that the log entry is up-to-date, make an RC entry.
                        $logEntry->publish( $logId );
                        # Run hook for other updates (typically more cache purging)
                        Hooks::run( 'FileUpload', array( $that, $reupload, !$newPageContent ) );
@@ -1434,9 +1464,9 @@ class LocalFile extends File {
                        if ( $reupload ) {
                                # Delete old thumbnails
                                $that->purgeThumbnails();
-                               # Remove the old file from the squid cache
+                               # Remove the old file from the CDN cache
                                DeferredUpdates::addUpdate(
-                                       new SquidUpdate( array( $that->getUrl() ) ),
+                                       new CdnCacheUpdate( array( $that->getUrl() ) ),
                                        DeferredUpdates::PRESEND
                                );
                        } else {
@@ -1632,12 +1662,12 @@ class LocalFile extends File {
                        }
                );
 
-               // Purge the squid
+               // Purge the CDN
                $purgeUrls = array();
                foreach ( $archiveNames as $archiveName ) {
                        $purgeUrls[] = $this->getArchiveUrl( $archiveName );
                }
-               DeferredUpdates::addUpdate( new SquidUpdate( $purgeUrls ), DeferredUpdates::PRESEND );
+               DeferredUpdates::addUpdate( new CdnCacheUpdate( $purgeUrls ), DeferredUpdates::PRESEND );
 
                return $status;
        }
@@ -1675,7 +1705,7 @@ class LocalFile extends File {
                }
 
                DeferredUpdates::addUpdate(
-                       new SquidUpdate( array( $this->getArchiveUrl( $archiveName ) ) ),
+                       new CdnCacheUpdate( array( $this->getArchiveUrl( $archiveName ) ) ),
                        DeferredUpdates::PRESEND
                );