r96845 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96844‎ | r96845 | r96846 >
Date:14:47, 12 September 2011
Author:reedy
Status:ok
Tags:
Comment:
REL1_18: MFT r96373, r96399
Modified paths:
  • /branches/REL1_18/phase3/RELEASE-NOTES-1.18 (modified) (history)
  • /branches/REL1_18/phase3/includes/filerepo/File.php (modified) (history)
  • /branches/REL1_18/phase3/includes/filerepo/LocalFile.php (modified) (history)

Diff [purge]

Index: branches/REL1_18/phase3/RELEASE-NOTES-1.18
@@ -441,6 +441,7 @@
442442 * Tracking categories are no longer shown in footer for special pages
443443 * (bug 30684) Fix bad escaping in mw.message for inexistent messages (i.e. <key>)
444444 * $wgOverrideSiteFeed no longer double escapes urls.
 445+* (bug 30192) Thumbnails of archived files are now deleted
445446
446447 === API changes in 1.18 ===
447448 * BREAKING CHANGE: action=watch now requires POST and token.
Index: branches/REL1_18/phase3/includes/filerepo/LocalFile.php
@@ -613,12 +613,19 @@
614614
615615 /**
616616 * Get all thumbnail names previously generated for this file
 617+ * @param $archiveName string|false Name of an archive file
 618+ * @return array first element is the base dir, then files in that base dir.
617619 */
618 - function getThumbnails() {
 620+ function getThumbnails( $archiveName = false ) {
619621 $this->load();
620622
 623+ if ( $archiveName ) {
 624+ $dir = $this->getArchiveThumbPath( $archiveName );
 625+ } else {
 626+ $dir = $this->getThumbPath();
 627+ }
621628 $files = array();
622 - $dir = $this->getThumbPath();
 629+ $files[] = $dir;
623630
624631 if ( is_dir( $dir ) ) {
625632 $handle = opendir( $dir );
@@ -680,32 +687,74 @@
681688 }
682689
683690 /**
684 - * Delete cached transformed files
 691+ * Delete cached transformed files for archived files
 692+ * @param $archiveName string name of the archived file
685693 */
 694+ function purgeOldThumbnails( $archiveName ) {
 695+ global $wgUseSquid;
 696+ // get a list of old thumbnails and URLs
 697+ $files = $this->getThumbnails( $archiveName );
 698+ $dir = array_shift( $files );
 699+ $this->purgeThumbList( $dir, $files );
 700+
 701+ // Directory should be empty, delete it too. This will probably suck on
 702+ // something like NFS or if the directory isn't actually empty, so hide
 703+ // the warnings :D
 704+ wfSuppressWarnings();
 705+ if( !rmdir( $dir ) ) {
 706+ wfDebug( __METHOD__ . ": unable to remove archive directory: $dir\n" );
 707+ }
 708+ wfRestoreWarnings();
 709+
 710+ // Purge the squid
 711+ if ( $wgUseSquid ) {
 712+ $urls = array();
 713+ foreach( $files as $file ) {
 714+ $urls[] = $this->getArchiveThumbUrl( $archiveName, $file );
 715+ }
 716+ SquidUpdate::purge( $urls );
 717+ }
 718+ }
 719+
 720+
 721+ /**
 722+ * Delete cached transformed files for the current version only.
 723+ */
686724 function purgeThumbnails() {
687725 global $wgUseSquid;
688 -
689 - // Delete thumbnails
 726+ // get a list of thumbnails and URLs
690727 $files = $this->getThumbnails();
691 - $dir = $this->getThumbPath();
692 - $urls = array();
 728+ $dir = array_shift( $files );
 729+ $this->purgeThumbList( $dir, $files );
693730
 731+ // Purge the squid
 732+ if ( $wgUseSquid ) {
 733+ $urls = array();
 734+ foreach( $files as $file ) {
 735+ $urls[] = $this->getThumbUrl( $file );
 736+ }
 737+ SquidUpdate::purge( $urls );
 738+ }
 739+ }
 740+
 741+ /**
 742+ * Delete a list of thumbnails visible at urls
 743+ * @param $dir string base dir of the files.
 744+ * @param $files array of strings: relative filenames (to $dir)
 745+ */
 746+ function purgeThumbList($dir, $files) {
 747+ global $wgExcludeFromThumbnailPurge;
 748+
 749+ wfDebug( __METHOD__ . ": " . var_export( $files, true ) . "\n" );
694750 foreach ( $files as $file ) {
695751 # Check that the base file name is part of the thumb name
696752 # This is a basic sanity check to avoid erasing unrelated directories
697753 if ( strpos( $file, $this->getName() ) !== false ) {
698 - $url = $this->getThumbUrl( $file );
699 - $urls[] = $url;
700754 wfSuppressWarnings();
701755 unlink( "$dir/$file" );
702756 wfRestoreWarnings();
703757 }
704758 }
705 -
706 - // Purge the squid
707 - if ( $wgUseSquid ) {
708 - SquidUpdate::purge( $urls );
709 - }
710759 }
711760
712761 /** purgeDescription inherited */
@@ -1174,6 +1223,7 @@
11751224 array( 'oi_name' => $this->getName() ) );
11761225 foreach ( $result as $row ) {
11771226 $batch->addOld( $row->oi_archive_name );
 1227+ $this->purgeOldThumbnails( $row->oi_archive_name );
11781228 }
11791229 $status = $batch->execute();
11801230
@@ -1208,6 +1258,7 @@
12091259
12101260 $batch = new LocalFileDeleteBatch( $this, $reason, $suppress );
12111261 $batch->addOld( $archiveName );
 1262+ $this->purgeOldThumbnails( $archiveName );
12121263 $status = $batch->execute();
12131264
12141265 $this->unlock();
Property changes on: branches/REL1_18/phase3/includes/filerepo/LocalFile.php
___________________________________________________________________
Modified: svn:mergeinfo
12151266 Merged /trunk/phase3/includes/filerepo/LocalFile.php:r96373,96399
Index: branches/REL1_18/phase3/includes/filerepo/File.php
@@ -890,11 +890,11 @@
891891 }
892892
893893 /**
894 - * Get the relative path for an archive file
 894+ * Get the relative path for an archived file
 895+ *
 896+ * @param $suffix bool|string if not false, the name of an archived thumbnail file
895897 *
896 - * @param $suffix bool
897 - *
898 - * @return string
 898+ * @return string
899899 */
900900 function getArchiveRel( $suffix = false ) {
901901 $path = 'archive/' . $this->getHashPath();
@@ -907,9 +907,26 @@
908908 }
909909
910910 /**
911 - * Get the path of the archive directory, or a particular file if $suffix is specified
 911+ * Get the relative path for an archived file's thumbs directory
 912+ * or a specific thumb if the $suffix is given.
 913+ *
 914+ * @param $archiveName string the timestamped name of an archived image
 915+ * @param $suffix bool|string if not false, the name of a thumbnail file
 916+ */
 917+ function getArchiveThumbRel( $archiveName, $suffix = false ) {
 918+ $path = 'archive/' . $this->getHashPath() . $archiveName . "/";
 919+ if ( $suffix === false ) {
 920+ $path = substr( $path, 0, -1 );
 921+ } else {
 922+ $path .= $suffix;
 923+ }
 924+ return $path;
 925+ }
 926+
 927+ /**
 928+ * Get the path of the archived file.
912929 *
913 - * @param $suffix bool
 930+ * @param $suffix bool|string if not false, the name of an archived file.
914931 *
915932 * @return string
916933 */
@@ -918,9 +935,21 @@
919936 }
920937
921938 /**
 939+ * Get the path of the archived file's thumbs, or a particular thumb if $suffix is specified
 940+ *
 941+ * @param $archiveName string the timestamped name of an archived image
 942+ * @param $suffix bool|string if not false, the name of a thumbnail file
 943+ *
 944+ * @return string
 945+ */
 946+ function getArchiveThumbPath( $archiveName, $suffix = false ) {
 947+ return $this->repo->getZonePath( 'thumb' ) . '/' . $this->getArchiveThumbRel( $archiveName, $suffix );
 948+ }
 949+
 950+ /**
922951 * Get the path of the thumbnail directory, or a particular file if $suffix is specified
923952 *
924 - * @param $suffix bool
 953+ * @param $suffix bool|string if not false, the name of a thumbnail file
925954 *
926955 * @return string
927956 */
@@ -935,7 +964,7 @@
936965 /**
937966 * Get the URL of the archive directory, or a particular file if $suffix is specified
938967 *
939 - * @param $suffix bool
 968+ * @param $suffix bool|string if not false, the name of an archived file
940969 *
941970 * @return string
942971 */
@@ -950,9 +979,27 @@
951980 }
952981
953982 /**
 983+ * Get the URL of the archived file's thumbs, or a particular thumb if $suffix is specified
 984+ *
 985+ * @param $archiveName string the timestamped name of an archived image
 986+ * @param $suffix bool|string if not false, the name of a thumbnail file
 987+ *
 988+ * @return string
 989+ */
 990+ function getArchiveThumbUrl( $archiveName, $suffix = false ) {
 991+ $path = $this->repo->getZoneUrl('thumb') . '/archive/' . $this->getHashPath() . rawurlencode( $archiveName ) . "/";
 992+ if ( $suffix === false ) {
 993+ $path = substr( $path, 0, -1 );
 994+ } else {
 995+ $path .= rawurlencode( $suffix );
 996+ }
 997+ return $path;
 998+ }
 999+
 1000+ /**
9541001 * Get the URL of the thumbnail directory, or a particular file if $suffix is specified
9551002 *
956 - * @param $suffix bool
 1003+ * @param $suffix bool|string if not false, the name of a thumbnail file
9571004 *
9581005 * @return path
9591006 */
@@ -965,9 +1012,9 @@
9661013 }
9671014
9681015 /**
969 - * Get the virtual URL for an archive file or directory
 1016+ * Get the virtual URL for an archived file's thumbs, or a specific thumb.
9701017 *
971 - * @param bool|string $suffix
 1018+ * @param $suffix bool|string if not false, the name of a thumbnail file
9721019 *
9731020 * @return string
9741021 */
@@ -984,7 +1031,7 @@
9851032 /**
9861033 * Get the virtual URL for a thumbnail file or directory
9871034 *
988 - * @param $suffix bool
 1035+ * @param $suffix bool|string if not false, the name of a thumbnail file
9891036 *
9901037 * @return string
9911038 */
@@ -999,7 +1046,7 @@
10001047 /**
10011048 * Get the virtual URL for the file itself
10021049 *
1003 - * @param $suffix bool
 1050+ * @param $suffix bool|string if not false, the name of a thumbnail file
10041051 *
10051052 * @return string
10061053 */
Property changes on: branches/REL1_18/phase3/includes/filerepo/File.php
___________________________________________________________________
Modified: svn:mergeinfo
10071054 Merged /trunk/phase3/includes/filerepo/File.php:r96373,96399

Follow-up revisions

RevisionCommit summaryAuthorDate
r96846Move RELEASE-NOTES from r96373 from RELEASE-NOTES-1.18 to RELEASE-NOTES-1.19 ...reedy14:49, 12 September 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r96373(bug 30192) Thumbnails of archived images don't get deleted. Patch by Russ an...demon21:01, 6 September 2011
r96399restore proper operation of getArchive{Path|Url}nelson02:31, 7 September 2011

Status & tagging log