Index: trunk/phase3/maintenance/pruneFileCache.php |
— | — | @@ -0,0 +1,102 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Prune file cache for pages, objects, resources, ect... |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation; either version 2 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License along |
| 17 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | + * http://www.gnu.org/copyleft/gpl.html |
| 20 | + * |
| 21 | + * @ingroup Maintenance |
| 22 | + */ |
| 23 | + |
| 24 | +require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
| 25 | + |
| 26 | +class PruneFileCache extends Maintenance { |
| 27 | + public function __construct() { |
| 28 | + parent::__construct(); |
| 29 | + $this->mDescription = "Build file cache for content pages"; |
| 30 | + $this->addOption( 'agedays', 'How many days old files must be in order to delete', true, true ); |
| 31 | + $this->addOption( 'subdir', 'Prune one $wgFileCacheDirectory subdirectory name', false, true ); |
| 32 | + } |
| 33 | + |
| 34 | + public function execute() { |
| 35 | + global $wgUseFileCache, $wgFileCacheDirectory; |
| 36 | + |
| 37 | + if ( !$wgUseFileCache ) { |
| 38 | + $this->error( "Nothing to do -- \$wgUseFileCache is disabled.", true ); |
| 39 | + } |
| 40 | + |
| 41 | + $age = $this->getOption( 'agedays' ); |
| 42 | + if ( !ctype_digit( $age ) ) { |
| 43 | + $this->error( "Non-integer 'age' parameter given.", true ); |
| 44 | + } |
| 45 | + // Delete items with a TS older than this |
| 46 | + $this->minSurviveTimestamp = time() - ( 86400 * $age ); |
| 47 | + |
| 48 | + $dir = $wgFileCacheDirectory; |
| 49 | + if ( !is_dir( $dir ) ) { |
| 50 | + $this->error( "Nothing to do -- \$wgFileCacheDirectory directory not found.", true ); |
| 51 | + } |
| 52 | + |
| 53 | + $subDir = $this->getOption( 'subdir' ); |
| 54 | + if ( $subDir !== null ) { |
| 55 | + if ( !is_dir( "$dir/$subDir" ) ) { |
| 56 | + $this->error( "The specified subdirectory `$subDir` does not exist.", true ); |
| 57 | + } |
| 58 | + $this->output( "Pruning `$dir/$subDir` directory...\n" ); |
| 59 | + $this->prune_directory( "$dir/$subDir", 'report' ); |
| 60 | + $this->output( "Done pruning `$dir/$subDir` directory\n" ); |
| 61 | + } else { |
| 62 | + $this->output( "Pruning `$dir` directory...\n" ); |
| 63 | + // Note: don't prune things like .cdb files on the top level! |
| 64 | + $this->prune_directory( $dir, 'report' ); |
| 65 | + $this->output( "Done pruning `$dir` directory\n" ); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * @param $dir string |
| 71 | + * @param $report string|bool Use 'report' to report the directories being scanned |
| 72 | + */ |
| 73 | + protected function prune_directory( $dir, $report = false ) { |
| 74 | + $tsNow = time(); |
| 75 | + $dirHandle = opendir( $dir ); |
| 76 | + while ( false !== ( $file = readdir( $dirHandle ) ) ) { |
| 77 | + // Skip ".", "..", and also any dirs or files like ".svn" or ".htaccess" |
| 78 | + if ( $file[0] != "." ) { |
| 79 | + $path = $dir . '/' . $file; // absolute |
| 80 | + if ( is_dir( $path ) ) { |
| 81 | + if ( $report === 'report' ) { |
| 82 | + $this->output( "Scanning `$path`...\n" ); |
| 83 | + } |
| 84 | + $this->prune_directory( $path ); |
| 85 | + } else { |
| 86 | + $mts = filemtime( $path ); |
| 87 | + // Sanity check the file extension against known cache types |
| 88 | + if ( $mts < $this->minSurviveTimestamp |
| 89 | + && preg_match( '/\.(?:html|cache)(?:\.gz)?$/', $file ) |
| 90 | + && unlink( $path ) ) |
| 91 | + { |
| 92 | + $daysOld = round( ( $tsNow - $mts ) / 86400, 2 ); |
| 93 | + $this->output( "Deleted `$path` [days=$daysOld]\n" ); |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | + closedir( $dirHandle ); |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +$maintClass = "PruneFileCache"; |
| 103 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
Property changes on: trunk/phase3/maintenance/pruneFileCache.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 104 | + native |
Index: trunk/phase3/includes/cache/ResourceFileCache.php |
— | — | @@ -19,9 +19,9 @@ |
20 | 20 | $cache = new self(); |
21 | 21 | |
22 | 22 | if ( $context->getOnly() === 'styles' ) { |
23 | | - $cache->mType = $cache->mExt = 'css'; |
| 23 | + $cache->mType = 'css'; |
24 | 24 | } else { |
25 | | - $cache->mType = $cache->mExt = 'js'; |
| 25 | + $cache->mType = 'js'; |
26 | 26 | } |
27 | 27 | $modules = array_unique( $context->getModules() ); // remove duplicates |
28 | 28 | sort( $modules ); // normalize the order (permutation => combination) |