LogEntry: Make associated rev id persistent (store in logging and log_search)
[lhc/web/wiklou.git] / includes / filerepo / file / LocalFile.php
index 0da1ae8..b7d6f98 100644 (file)
@@ -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,11 +1394,12 @@ 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
@@ -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 ) );