]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - maintenance/checkImages.php
MediaWiki 1.16.0
[autoinstallsdev/mediawiki.git] / maintenance / checkImages.php
1 <?php
2 /**
3  * Check images to see if they exist, are readable, etc etc
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  * http://www.gnu.org/copyleft/gpl.html
19  *
20  * @ingroup Maintenance
21  */
22 require_once( dirname(__FILE__) . '/Maintenance.php' );
23
24 class CheckImages extends Maintenance {
25
26         public function __construct() {
27                 parent::__construct();
28                 $this->mDescription = "Check images to see if they exist, are readable, etc";
29                 $this->setBatchSize( 1000 );
30         }
31         
32         public function execute() {
33                 $start = '';
34                 $dbr = wfGetDB( DB_SLAVE );
35
36                 $numImages = 0;
37                 $numGood = 0;
38         
39                 do {
40                         $res = $dbr->select( 'image', '*', array( 'img_name > ' . $dbr->addQuotes( $start ) ), 
41                                 __METHOD__, array( 'LIMIT' => $this->mBatchSize ) );
42                         foreach ( $res as $row ) {
43                                 $numImages++;
44                                 $start = $row->img_name;
45                                 $file = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
46                                 $path = $file->getPath();
47                                 if ( !$path ) {
48                                         $this->output( "{$row->img_name}: not locally accessible\n" );
49                                         continue;
50                                 }
51                                 $stat = @stat( $file->getPath() );
52                                 if ( !$stat ) {
53                                         $this->output( "{$row->img_name}: missing\n" );
54                                         continue;
55                                 }
56         
57                                 if ( $stat['mode'] & 040000 ) {
58                                         $this->output( "{$row->img_name}: is a directory\n" );
59                                         continue;
60                                 }
61         
62                                 if ( $stat['size'] == 0 && $row->img_size != 0 ) {
63                                         $this->output( "{$row->img_name}: truncated, was {$row->img_size}\n" );
64                                         continue;
65                                 }
66         
67                                 if ( $stat['size'] != $row->img_size ) {
68                                         $this->output( "{$row->img_name}: size mismatch DB={$row->img_size}, actual={$stat['size']}\n" );
69                                         continue;
70                                 }
71         
72                                 $numGood++;
73                         }
74         
75                 } while ( $res->numRows() );
76         
77                 $this->output( "Good images: $numGood/$numImages\n" );
78         }
79 }
80
81 $maintClass = "CheckImages";
82 require_once( DO_MAINTENANCE );