MediaWiki
REL1_19
|
00001 <?php 00026 require_once( dirname( __FILE__ ) . '/Maintenance.php' ); 00027 00028 class DeleteImageCache extends Maintenance { 00029 public function __construct() { 00030 parent::__construct(); 00031 $this->mDescription = "Delete image information from the cache"; 00032 $this->addOption( 'sleep', 'How many seconds to sleep between deletions', true, true ); 00033 $this->addOption( 'until', 'Timestamp to delete all entries prior to', true, true ); 00034 } 00035 00036 public function execute() { 00037 global $wgMemc; 00038 00039 $until = preg_replace( "/[^\d]/", '', $this->getOption( 'until' ) ); 00040 $sleep = (int)$this->getOption( 'sleep' ) * 1000; // milliseconds 00041 00042 ini_set( 'display_errors', false ); 00043 00044 $dbr = wfGetDB( DB_SLAVE ); 00045 00046 $res = $dbr->select( 'image', 00047 array( 'img_name' ), 00048 array( "img_timestamp < {$until}" ), 00049 __METHOD__ 00050 ); 00051 00052 $i = 0; 00053 $total = $this->getImageCount(); 00054 00055 foreach ( $res as $row ) { 00056 if ( $i % $this->report == 0 ) 00057 $this->output( sprintf( "%s: %13s done (%s)\n", wfWikiID(), "$i/$total", wfPercent( $i / $total * 100 ) ) ); 00058 $md5 = md5( $row->img_name ); 00059 $wgMemc->delete( wfMemcKey( 'Image', $md5 ) ); 00060 00061 if ( $sleep != 0 ) 00062 usleep( $sleep ); 00063 00064 ++$i; 00065 } 00066 } 00067 00068 private function getImageCount() { 00069 $dbr = wfGetDB( DB_SLAVE ); 00070 return $dbr->selectField( 'image', 'COUNT(*)', array(), __METHOD__ ); 00071 } 00072 } 00073 00074 $maintClass = "DeleteImageCache"; 00075 require_once( RUN_MAINTENANCE_IF_MAIN );