Add list of thumbnail urls to LocalFilePurgeThumbnails hook
Bug: T268310 Change-Id: Iaa84edfe215e71d3d5fd814053d4b787652fa3b5
This commit is contained in:
parent
4debdefb16
commit
e141c9eade
3 changed files with 27 additions and 26 deletions
|
|
@ -2391,10 +2391,10 @@ class HookRunner implements
|
|||
);
|
||||
}
|
||||
|
||||
public function onLocalFilePurgeThumbnails( $file, $archiveName ) {
|
||||
public function onLocalFilePurgeThumbnails( $file, $archiveName, $urls ) {
|
||||
return $this->container->run(
|
||||
'LocalFilePurgeThumbnails',
|
||||
[ $file, $archiveName ]
|
||||
[ $file, $archiveName, $urls ]
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,9 +17,10 @@ interface LocalFilePurgeThumbnailsHook {
|
|||
*
|
||||
* @since 1.35
|
||||
*
|
||||
* @param File $file
|
||||
* @param File $file The File of which the thumbnails are being purged
|
||||
* @param string $archiveName Name of an old file version or false if it's the current one
|
||||
* @param array $urls Urls to be purged
|
||||
* @return bool|void True or no return value to continue or false to abort
|
||||
*/
|
||||
public function onLocalFilePurgeThumbnails( $file, $archiveName );
|
||||
public function onLocalFilePurgeThumbnails( $file, $archiveName, $urls );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1087,22 +1087,22 @@ class LocalFile extends File {
|
|||
* @param string $archiveName Name of the archived file
|
||||
*/
|
||||
public function purgeOldThumbnails( $archiveName ) {
|
||||
// Get a list of old thumbnails and URLs
|
||||
$files = $this->getThumbnails( $archiveName );
|
||||
// Get a list of old thumbnails
|
||||
$thumbs = $this->getThumbnails( $archiveName );
|
||||
|
||||
// Purge any custom thumbnail caches
|
||||
$this->hookRunner->onLocalFilePurgeThumbnails( $this, $archiveName );
|
||||
// Delete thumbnails from storage, and prevent the directory itself from being purged
|
||||
$dir = array_shift( $thumbs );
|
||||
$this->purgeThumbList( $dir, $thumbs );
|
||||
|
||||
// Delete thumbnails
|
||||
$dir = array_shift( $files );
|
||||
$this->purgeThumbList( $dir, $files );
|
||||
|
||||
// Purge the CDN
|
||||
$urls = [];
|
||||
foreach ( $files as $file ) {
|
||||
$urls[] = $this->getArchiveThumbUrl( $archiveName, $file );
|
||||
foreach ( $thumbs as $thumb ) {
|
||||
$urls[] = $this->getArchiveThumbUrl( $archiveName, $thumb );
|
||||
}
|
||||
|
||||
// Purge any custom thumbnail caches
|
||||
$this->hookRunner->onLocalFilePurgeThumbnails( $this, $archiveName, $urls );
|
||||
|
||||
// Purge the CDN
|
||||
$hcu = MediaWikiServices::getInstance()->getHtmlCacheUpdater();
|
||||
$hcu->purgeUrls( $urls, $hcu::PURGE_PRESEND );
|
||||
}
|
||||
|
|
@ -1114,28 +1114,28 @@ class LocalFile extends File {
|
|||
* @phan-param array{forThumbRefresh?:bool} $options
|
||||
*/
|
||||
public function purgeThumbnails( $options = [] ) {
|
||||
$files = $this->getThumbnails();
|
||||
$thumbs = $this->getThumbnails();
|
||||
|
||||
// Delete thumbnails from storage, and prevent the directory itself from being purged
|
||||
$dir = array_shift( $thumbs );
|
||||
$this->purgeThumbList( $dir, $thumbs );
|
||||
|
||||
// Always purge all files from CDN regardless of handler filters
|
||||
$urls = [];
|
||||
foreach ( $files as $file ) {
|
||||
$urls[] = $this->getThumbUrl( $file );
|
||||
foreach ( $thumbs as $thumb ) {
|
||||
$urls[] = $this->getThumbUrl( $thumb );
|
||||
}
|
||||
array_shift( $urls ); // don't purge directory
|
||||
|
||||
// Give media handler a chance to filter the file purge list
|
||||
// Give the media handler a chance to filter the file purge list
|
||||
if ( !empty( $options['forThumbRefresh'] ) ) {
|
||||
$handler = $this->getHandler();
|
||||
if ( $handler ) {
|
||||
$handler->filterThumbnailPurgeList( $files, $options );
|
||||
$handler->filterThumbnailPurgeList( $thumbs, $options );
|
||||
}
|
||||
}
|
||||
|
||||
// Purge any custom thumbnail caches
|
||||
$this->getHookRunner()->onLocalFilePurgeThumbnails( $this, false );
|
||||
|
||||
// Delete thumbnails
|
||||
$dir = array_shift( $files );
|
||||
$this->purgeThumbList( $dir, $files );
|
||||
$this->getHookRunner()->onLocalFilePurgeThumbnails( $this, false, $urls );
|
||||
|
||||
// Purge the CDN
|
||||
$hcu = MediaWikiServices::getInstance()->getHtmlCacheUpdater();
|
||||
|
|
|
|||
Loading…
Reference in a new issue