Index: branches/REL1_18/phase3/RELEASE-NOTES-1.18 |
— | — | @@ -441,6 +441,7 @@ |
442 | 442 | * Tracking categories are no longer shown in footer for special pages |
443 | 443 | * (bug 30684) Fix bad escaping in mw.message for inexistent messages (i.e. <key>) |
444 | 444 | * $wgOverrideSiteFeed no longer double escapes urls. |
| 445 | +* (bug 30192) Thumbnails of archived files are now deleted |
445 | 446 | |
446 | 447 | === API changes in 1.18 === |
447 | 448 | * BREAKING CHANGE: action=watch now requires POST and token. |
Index: branches/REL1_18/phase3/includes/filerepo/LocalFile.php |
— | — | @@ -613,12 +613,19 @@ |
614 | 614 | |
615 | 615 | /** |
616 | 616 | * 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. |
617 | 619 | */ |
618 | | - function getThumbnails() { |
| 620 | + function getThumbnails( $archiveName = false ) { |
619 | 621 | $this->load(); |
620 | 622 | |
| 623 | + if ( $archiveName ) { |
| 624 | + $dir = $this->getArchiveThumbPath( $archiveName ); |
| 625 | + } else { |
| 626 | + $dir = $this->getThumbPath(); |
| 627 | + } |
621 | 628 | $files = array(); |
622 | | - $dir = $this->getThumbPath(); |
| 629 | + $files[] = $dir; |
623 | 630 | |
624 | 631 | if ( is_dir( $dir ) ) { |
625 | 632 | $handle = opendir( $dir ); |
— | — | @@ -680,32 +687,74 @@ |
681 | 688 | } |
682 | 689 | |
683 | 690 | /** |
684 | | - * Delete cached transformed files |
| 691 | + * Delete cached transformed files for archived files |
| 692 | + * @param $archiveName string name of the archived file |
685 | 693 | */ |
| 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 | + */ |
686 | 724 | function purgeThumbnails() { |
687 | 725 | global $wgUseSquid; |
688 | | - |
689 | | - // Delete thumbnails |
| 726 | + // get a list of thumbnails and URLs |
690 | 727 | $files = $this->getThumbnails(); |
691 | | - $dir = $this->getThumbPath(); |
692 | | - $urls = array(); |
| 728 | + $dir = array_shift( $files ); |
| 729 | + $this->purgeThumbList( $dir, $files ); |
693 | 730 | |
| 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" ); |
694 | 750 | foreach ( $files as $file ) { |
695 | 751 | # Check that the base file name is part of the thumb name |
696 | 752 | # This is a basic sanity check to avoid erasing unrelated directories |
697 | 753 | if ( strpos( $file, $this->getName() ) !== false ) { |
698 | | - $url = $this->getThumbUrl( $file ); |
699 | | - $urls[] = $url; |
700 | 754 | wfSuppressWarnings(); |
701 | 755 | unlink( "$dir/$file" ); |
702 | 756 | wfRestoreWarnings(); |
703 | 757 | } |
704 | 758 | } |
705 | | - |
706 | | - // Purge the squid |
707 | | - if ( $wgUseSquid ) { |
708 | | - SquidUpdate::purge( $urls ); |
709 | | - } |
710 | 759 | } |
711 | 760 | |
712 | 761 | /** purgeDescription inherited */ |
— | — | @@ -1174,6 +1223,7 @@ |
1175 | 1224 | array( 'oi_name' => $this->getName() ) ); |
1176 | 1225 | foreach ( $result as $row ) { |
1177 | 1226 | $batch->addOld( $row->oi_archive_name ); |
| 1227 | + $this->purgeOldThumbnails( $row->oi_archive_name ); |
1178 | 1228 | } |
1179 | 1229 | $status = $batch->execute(); |
1180 | 1230 | |
— | — | @@ -1208,6 +1258,7 @@ |
1209 | 1259 | |
1210 | 1260 | $batch = new LocalFileDeleteBatch( $this, $reason, $suppress ); |
1211 | 1261 | $batch->addOld( $archiveName ); |
| 1262 | + $this->purgeOldThumbnails( $archiveName ); |
1212 | 1263 | $status = $batch->execute(); |
1213 | 1264 | |
1214 | 1265 | $this->unlock(); |
Property changes on: branches/REL1_18/phase3/includes/filerepo/LocalFile.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
1215 | 1266 | Merged /trunk/phase3/includes/filerepo/LocalFile.php:r96373,96399 |
Index: branches/REL1_18/phase3/includes/filerepo/File.php |
— | — | @@ -890,11 +890,11 @@ |
891 | 891 | } |
892 | 892 | |
893 | 893 | /** |
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 |
895 | 897 | * |
896 | | - * @param $suffix bool |
897 | | - * |
898 | | - * @return string |
| 898 | + * @return string |
899 | 899 | */ |
900 | 900 | function getArchiveRel( $suffix = false ) { |
901 | 901 | $path = 'archive/' . $this->getHashPath(); |
— | — | @@ -907,9 +907,26 @@ |
908 | 908 | } |
909 | 909 | |
910 | 910 | /** |
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. |
912 | 929 | * |
913 | | - * @param $suffix bool |
| 930 | + * @param $suffix bool|string if not false, the name of an archived file. |
914 | 931 | * |
915 | 932 | * @return string |
916 | 933 | */ |
— | — | @@ -918,9 +935,21 @@ |
919 | 936 | } |
920 | 937 | |
921 | 938 | /** |
| 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 | + /** |
922 | 951 | * Get the path of the thumbnail directory, or a particular file if $suffix is specified |
923 | 952 | * |
924 | | - * @param $suffix bool |
| 953 | + * @param $suffix bool|string if not false, the name of a thumbnail file |
925 | 954 | * |
926 | 955 | * @return string |
927 | 956 | */ |
— | — | @@ -935,7 +964,7 @@ |
936 | 965 | /** |
937 | 966 | * Get the URL of the archive directory, or a particular file if $suffix is specified |
938 | 967 | * |
939 | | - * @param $suffix bool |
| 968 | + * @param $suffix bool|string if not false, the name of an archived file |
940 | 969 | * |
941 | 970 | * @return string |
942 | 971 | */ |
— | — | @@ -950,9 +979,27 @@ |
951 | 980 | } |
952 | 981 | |
953 | 982 | /** |
| 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 | + /** |
954 | 1001 | * Get the URL of the thumbnail directory, or a particular file if $suffix is specified |
955 | 1002 | * |
956 | | - * @param $suffix bool |
| 1003 | + * @param $suffix bool|string if not false, the name of a thumbnail file |
957 | 1004 | * |
958 | 1005 | * @return path |
959 | 1006 | */ |
— | — | @@ -965,9 +1012,9 @@ |
966 | 1013 | } |
967 | 1014 | |
968 | 1015 | /** |
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. |
970 | 1017 | * |
971 | | - * @param bool|string $suffix |
| 1018 | + * @param $suffix bool|string if not false, the name of a thumbnail file |
972 | 1019 | * |
973 | 1020 | * @return string |
974 | 1021 | */ |
— | — | @@ -984,7 +1031,7 @@ |
985 | 1032 | /** |
986 | 1033 | * Get the virtual URL for a thumbnail file or directory |
987 | 1034 | * |
988 | | - * @param $suffix bool |
| 1035 | + * @param $suffix bool|string if not false, the name of a thumbnail file |
989 | 1036 | * |
990 | 1037 | * @return string |
991 | 1038 | */ |
— | — | @@ -999,7 +1046,7 @@ |
1000 | 1047 | /** |
1001 | 1048 | * Get the virtual URL for the file itself |
1002 | 1049 | * |
1003 | | - * @param $suffix bool |
| 1050 | + * @param $suffix bool|string if not false, the name of a thumbnail file |
1004 | 1051 | * |
1005 | 1052 | * @return string |
1006 | 1053 | */ |
Property changes on: branches/REL1_18/phase3/includes/filerepo/File.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
1007 | 1054 | Merged /trunk/phase3/includes/filerepo/File.php:r96373,96399 |