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