00001 <?php 00022 require_once( dirname(__FILE__) . '/Maintenance.php' ); 00023 00024 class CheckImages extends Maintenance { 00025 00026 public function __construct() { 00027 parent::__construct(); 00028 $this->mDescription = "Check images to see if they exist, are readable, etc"; 00029 $this->setBatchSize( 1000 ); 00030 } 00031 00032 public function execute() { 00033 $start = ''; 00034 $dbr = wfGetDB( DB_SLAVE ); 00035 00036 $numImages = 0; 00037 $numGood = 0; 00038 00039 do { 00040 $res = $dbr->select( 'image', '*', array( 'img_name > ' . $dbr->addQuotes( $start ) ), 00041 __METHOD__, array( 'LIMIT' => $this->mBatchSize ) ); 00042 foreach ( $res as $row ) { 00043 $numImages++; 00044 $start = $row->img_name; 00045 $file = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row ); 00046 $path = $file->getPath(); 00047 if ( !$path ) { 00048 $this->output( "{$row->img_name}: not locally accessible\n" ); 00049 continue; 00050 } 00051 $stat = @stat( $file->getPath() ); 00052 if ( !$stat ) { 00053 $this->output( "{$row->img_name}: missing\n" ); 00054 continue; 00055 } 00056 00057 if ( $stat['mode'] & 040000 ) { 00058 $this->output( "{$row->img_name}: is a directory\n" ); 00059 continue; 00060 } 00061 00062 if ( $stat['size'] == 0 && $row->img_size != 0 ) { 00063 $this->output( "{$row->img_name}: truncated, was {$row->img_size}\n" ); 00064 continue; 00065 } 00066 00067 if ( $stat['size'] != $row->img_size ) { 00068 $this->output( "{$row->img_name}: size mismatch DB={$row->img_size}, actual={$stat['size']}\n" ); 00069 continue; 00070 } 00071 00072 $numGood++; 00073 } 00074 00075 } while ( $res->numRows() ); 00076 00077 $this->output( "Good images: $numGood/$numImages\n" ); 00078 } 00079 } 00080 00081 $maintClass = "CheckImages"; 00082 require_once( DO_MAINTENANCE );