Revert r64853 (add $wgLogAutocreatedAccounts to enable/disable account autocreation...
[mediawiki.git] / maintenance / checkImages.php
blob96b93f22ba4c9a11972517e6170f6dbd95389156
1 <?php
2 /**
3 * Check images to see if they exist, are readable, etc etc
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.
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.
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
20 * @file
21 * @ingroup Maintenance
23 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
25 class CheckImages extends Maintenance {
27 public function __construct() {
28 parent::__construct();
29 $this->mDescription = "Check images to see if they exist, are readable, etc";
30 $this->setBatchSize( 1000 );
33 public function execute() {
34 $start = '';
35 $dbr = wfGetDB( DB_SLAVE );
37 $numImages = 0;
38 $numGood = 0;
40 do {
41 $res = $dbr->select( 'image', '*', array( 'img_name > ' . $dbr->addQuotes( $start ) ),
42 __METHOD__, array( 'LIMIT' => $this->mBatchSize ) );
43 foreach ( $res as $row ) {
44 $numImages++;
45 $start = $row->img_name;
46 $file = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
47 $path = $file->getPath();
48 if ( !$path ) {
49 $this->output( "{$row->img_name}: not locally accessible\n" );
50 continue;
52 $stat = @stat( $file->getPath() );
53 if ( !$stat ) {
54 $this->output( "{$row->img_name}: missing\n" );
55 continue;
58 if ( $stat['mode'] & 040000 ) {
59 $this->output( "{$row->img_name}: is a directory\n" );
60 continue;
63 if ( $stat['size'] == 0 && $row->img_size != 0 ) {
64 $this->output( "{$row->img_name}: truncated, was {$row->img_size}\n" );
65 continue;
68 if ( $stat['size'] != $row->img_size ) {
69 $this->output( "{$row->img_name}: size mismatch DB={$row->img_size}, actual={$stat['size']}\n" );
70 continue;
73 $numGood++;
76 } while ( $res->numRows() );
78 $this->output( "Good images: $numGood/$numImages\n" );
82 $maintClass = "CheckImages";
83 require_once( RUN_MAINTENANCE_IF_MAIN );