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