Purge upstream caches when deleting file assets.
authorBryan Davis <bd808@wikimedia.org>
Mon, 19 Aug 2013 18:11:44 +0000 (18:11 +0000)
committerBryan Davis <bd808@wikimedia.org>
Mon, 19 Aug 2013 18:11:44 +0000 (18:11 +0000)
Inform upstream caches when a file asset is deleted by calling
SquidUpdate::purge(). This helps prevent unintentional information leakage in
the event that the asset is being deleted for reasons of license or content.

Bug: 51064
Change-Id: Ibf57e8f32d7dd04b8508a69706be5a40b49e5abd

includes/filerepo/file/LocalFile.php
includes/revisiondelete/RevisionDelete.php

index 6e0769e..678a6ad 100644 (file)
@@ -1527,6 +1527,7 @@ class LocalFile extends File {
         * @return FileRepoStatus object.
         */
        function delete( $reason, $suppress = false ) {
+               global $wgUseSquid;
                if ( $this->getRepo()->getReadOnlyReason() !== false ) {
                        return $this->readOnlyFatalStatus();
                }
@@ -1549,6 +1550,15 @@ class LocalFile extends File {
                        $this->purgeOldThumbnails( $archiveName );
                }
 
+               if ( $wgUseSquid ) {
+                       // Purge the squid
+                       $purgeUrls = array();
+                       foreach ($archiveNames as $archiveName ) {
+                               $purgeUrls[] = $this->getArchiveUrl( $archiveName );
+                       }
+                       SquidUpdate::purge( $purgeUrls );
+               }
+
                return $status;
        }
 
@@ -1567,6 +1577,7 @@ class LocalFile extends File {
         * @return FileRepoStatus object.
         */
        function deleteOld( $archiveName, $reason, $suppress = false ) {
+               global $wgUseSquid;
                if ( $this->getRepo()->getReadOnlyReason() !== false ) {
                        return $this->readOnlyFatalStatus();
                }
@@ -1584,6 +1595,11 @@ class LocalFile extends File {
                        $this->purgeHistory();
                }
 
+               if ( $wgUseSquid ) {
+                       // Purge the squid
+                       SquidUpdate::purge( array( $this->getArchiveUrl( $archiveName ) ) );
+               }
+
                return $status;
        }
 
index 135e31f..191286d 100644 (file)
@@ -498,11 +498,19 @@ class RevDel_FileList extends RevDel_List {
        }
 
        public function doPostCommitUpdates() {
+               global $wgUseSquid;
                $file = wfLocalFile( $this->title );
                $file->purgeCache();
                $file->purgeDescription();
+               $purgeUrls = array();
                foreach ( $this->ids as $timestamp ) {
-                       $file->purgeOldThumbnails( $timestamp . '!' . $this->title->getDBkey() );
+                       $archiveName = $timestamp . '!' . $this->title->getDBkey();
+                       $file->purgeOldThumbnails( $archiveName );
+                       $purgeUrls[] = $file->getArchiveUrl( $archiveName );
+               }
+               if ( $wgUseSquid ) {
+                       // purge full images from cache
+                       SquidUpdate::purge( $purgeUrls );
                }
                return Status::newGood();
        }