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