Make file purging also purge old versions
authorGilles Dubuc <gilles@wikimedia.org>
Thu, 29 Jun 2017 13:21:38 +0000 (15:21 +0200)
committerGilles Dubuc <gilles@wikimedia.org>
Fri, 30 Jun 2017 08:49:25 +0000 (10:49 +0200)
Also fixes purging for repos with sha1 thumb URLs.

Bug: T169198
Change-Id: Ibb98ecce83d690cc46769644038b54e37aea0b0d

includes/filerepo/file/LocalFile.php
includes/page/WikiFilePage.php

index a412250..f71e1dc 100644 (file)
@@ -1032,9 +1032,15 @@ class LocalFile extends File {
 
                $purgeList = [];
                foreach ( $files as $file ) {
 
                $purgeList = [];
                foreach ( $files as $file ) {
-                       # Check that the base file name is part of the thumb name
+                       if ( $this->repo->supportsSha1URLs() ) {
+                               $reference = $this->getSha1();
+                       } else {
+                               $reference = $this->getName();
+                       }
+
+                       # Check that the reference (filename or sha1) is part of the thumb name
                        # This is a basic sanity check to avoid erasing unrelated directories
                        # This is a basic sanity check to avoid erasing unrelated directories
-                       if ( strpos( $file, $this->getName() ) !== false
+                       if ( strpos( $file, $reference ) !== false
                                || strpos( $file, "-thumbnail" ) !== false // "short" thumb name
                        ) {
                                $purgeList[] = "{$dir}/{$file}";
                                || strpos( $file, "-thumbnail" ) !== false // "short" thumb name
                        ) {
                                $purgeList[] = "{$dir}/{$file}";
index 66fadf5..972a397 100644 (file)
@@ -170,21 +170,31 @@ class WikiFilePage extends WikiPage {
         */
        public function doPurge() {
                $this->loadFile();
         */
        public function doPurge() {
                $this->loadFile();
+
                if ( $this->mFile->exists() ) {
                        wfDebug( 'ImagePage::doPurge purging ' . $this->mFile->getName() . "\n" );
                        DeferredUpdates::addUpdate( new HTMLCacheUpdate( $this->mTitle, 'imagelinks' ) );
                if ( $this->mFile->exists() ) {
                        wfDebug( 'ImagePage::doPurge purging ' . $this->mFile->getName() . "\n" );
                        DeferredUpdates::addUpdate( new HTMLCacheUpdate( $this->mTitle, 'imagelinks' ) );
-                       $this->mFile->purgeCache( [ 'forThumbRefresh' => true ] );
                } else {
                        wfDebug( 'ImagePage::doPurge no image for '
                                . $this->mFile->getName() . "; limiting purge to cache only\n" );
                } else {
                        wfDebug( 'ImagePage::doPurge no image for '
                                . $this->mFile->getName() . "; limiting purge to cache only\n" );
-                       // even if the file supposedly doesn't exist, force any cached information
-                       // to be updated (in case the cached information is wrong)
-                       $this->mFile->purgeCache( [ 'forThumbRefresh' => true ] );
                }
                }
+
+               // even if the file supposedly doesn't exist, force any cached information
+               // to be updated (in case the cached information is wrong)
+
+               // Purge current version and its thumbnails
+               $this->mFile->purgeCache( [ 'forThumbRefresh' => true ] );
+
+               // Purge the old versions and their thumbnails
+               foreach ( $this->mFile->getHistory() as $oldFile ) {
+                       $oldFile->purgeCache( [ 'forThumbRefresh' => true ] );
+               }
+
                if ( $this->mRepo ) {
                        // Purge redirect cache
                        $this->mRepo->invalidateImageRedirect( $this->mTitle );
                }
                if ( $this->mRepo ) {
                        // Purge redirect cache
                        $this->mRepo->invalidateImageRedirect( $this->mTitle );
                }
+
                return parent::doPurge();
        }
 
                return parent::doPurge();
        }