Merge "Remove not used private member variable mParserWarnings from OutputPage"
[mediawiki.git] / maintenance / checkImages.php
blob976192711f22bcdc033ed3376d6b5871d71d9c80
1 <?php
2 /**
3 * Check images to see if they exist, are readable, 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 __DIR__ . '/Maintenance.php';
25 /**
26 * Maintenance script to check images to see if they exist, are readable, etc.
28 * @ingroup Maintenance
30 class CheckImages extends Maintenance {
32 public function __construct() {
33 parent::__construct();
34 $this->mDescription = "Check images to see if they exist, are readable, etc";
35 $this->setBatchSize( 1000 );
38 public function execute() {
39 $start = '';
40 $dbr = $this->getDB( DB_SLAVE );
42 $numImages = 0;
43 $numGood = 0;
45 $repo = RepoGroup::singleton()->getLocalRepo();
46 do {
47 $res = $dbr->select( 'image', '*', array( 'img_name > ' . $dbr->addQuotes( $start ) ),
48 __METHOD__, array( 'LIMIT' => $this->mBatchSize ) );
49 foreach ( $res as $row ) {
50 $numImages++;
51 $start = $row->img_name;
52 $file = $repo->newFileFromRow( $row );
53 $path = $file->getPath();
54 if ( !$path ) {
55 $this->output( "{$row->img_name}: not locally accessible\n" );
56 continue;
58 $size = $repo->getFileSize( $file->getPath() );
59 if ( $size === false ) {
60 $this->output( "{$row->img_name}: missing\n" );
61 continue;
64 if ( $size == 0 && $row->img_size != 0 ) {
65 $this->output( "{$row->img_name}: truncated, was {$row->img_size}\n" );
66 continue;
69 if ( $size != $row->img_size ) {
70 $this->output( "{$row->img_name}: size mismatch DB={$row->img_size}, "
71 . "actual={$size}\n" );
72 continue;
75 $numGood++;
77 } while ( $res->numRows() );
79 $this->output( "Good images: $numGood/$numImages\n" );
83 $maintClass = "CheckImages";
84 require_once RUN_MAINTENANCE_IF_MAIN;