00001 <?php
00012 $optionsWithArgs = array( 'until', 'sleep', 'report' );
00013
00014 require_once 'commandLine.inc';
00015
00019 class DeleteImageCache {
00020 var $until, $sleep, $report;
00021
00022 function DeleteImageCache( $until, $sleep, $report ) {
00023 $this->until = $until;
00024 $this->sleep = $sleep;
00025 $this->report = $report;
00026 }
00027
00028 function main() {
00029 global $wgMemc;
00030 $fname = 'DeleteImageCache::main';
00031
00032 ini_set( 'display_errors', false );
00033
00034 $dbr = wfGetDB( DB_SLAVE );
00035
00036 $res = $dbr->select( 'image',
00037 array( 'img_name' ),
00038 array( "img_timestamp < {$this->until}" ),
00039 $fname
00040 );
00041
00042 $i = 0;
00043 $total = $this->getImageCount();
00044
00045 while ( $row = $dbr->fetchObject( $res ) ) {
00046 if ($i % $this->report == 0)
00047 printf("%s: %13s done (%s)\n", wfWikiID(), "$i/$total", wfPercent( $i / $total * 100 ));
00048 $md5 = md5( $row->img_name );
00049 $wgMemc->delete( wfMemcKey( 'Image', $md5 ) );
00050
00051 if ($this->sleep != 0)
00052 usleep( $this->sleep );
00053
00054 ++$i;
00055 }
00056 }
00057
00058 function getImageCount() {
00059 $fname = 'DeleteImageCache::getImageCount';
00060
00061 $dbr = wfGetDB( DB_SLAVE );
00062 return $dbr->selectField( 'image', 'COUNT(*)', array(), $fname );
00063 }
00064 }
00065
00066 $until = preg_replace( "/[^\d]/", '', $options['until'] );
00067 $sleep = (int)$options['sleep'] * 1000;
00068 $report = (int)$options['report'];
00069
00070 $dic = new DeleteImageCache( $until, $sleep, $report );
00071 $dic->main();
00072