MediaWiki  1.23.1
checkImages.php
Go to the documentation of this file.
1 <?php
23 require_once __DIR__ . '/Maintenance.php';
24 
30 class CheckImages extends Maintenance {
31 
32  public function __construct() {
33  parent::__construct();
34  $this->mDescription = "Check images to see if they exist, are readable, etc";
35  $this->setBatchSize( 1000 );
36  }
37 
38  public function execute() {
39  $start = '';
40  $dbr = wfGetDB( DB_SLAVE );
41 
42  $numImages = 0;
43  $numGood = 0;
44 
45  do {
46  $res = $dbr->select( 'image', '*', array( 'img_name > ' . $dbr->addQuotes( $start ) ),
47  __METHOD__, array( 'LIMIT' => $this->mBatchSize ) );
48  foreach ( $res as $row ) {
49  $numImages++;
50  $start = $row->img_name;
51  $file = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
52  $path = $file->getPath();
53  if ( !$path ) {
54  $this->output( "{$row->img_name}: not locally accessible\n" );
55  continue;
56  }
58  $stat = stat( $file->getPath() );
60  if ( !$stat ) {
61  $this->output( "{$row->img_name}: missing\n" );
62  continue;
63  }
64 
65  if ( $stat['mode'] & 040000 ) {
66  $this->output( "{$row->img_name}: is a directory\n" );
67  continue;
68  }
69 
70  if ( $stat['size'] == 0 && $row->img_size != 0 ) {
71  $this->output( "{$row->img_name}: truncated, was {$row->img_size}\n" );
72  continue;
73  }
74 
75  if ( $stat['size'] != $row->img_size ) {
76  $this->output( "{$row->img_name}: size mismatch DB={$row->img_size}, actual={$stat['size']}\n" );
77  continue;
78  }
79 
80  $numGood++;
81  }
82 
83  } while ( $res->numRows() );
84 
85  $this->output( "Good images: $numGood/$numImages\n" );
86  }
87 }
88 
89 $maintClass = "CheckImages";
90 require_once RUN_MAINTENANCE_IF_MAIN;
RepoGroup\singleton
static singleton()
Get a RepoGroup instance.
Definition: RepoGroup.php:53
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3650
wfSuppressWarnings
wfSuppressWarnings( $end=false)
Reference-counted warning suppression.
Definition: GlobalFunctions.php:2387
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
CheckImages\__construct
__construct()
Default constructor.
Definition: checkImages.php:32
$dbr
$dbr
Definition: testCompression.php:48
wfRestoreWarnings
wfRestoreWarnings()
Restore error level to previous value.
Definition: GlobalFunctions.php:2417
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
CheckImages
Maintenance script to check images to see if they exist, are readable, etc.
Definition: checkImages.php:30
$file
if(PHP_SAPI !='cli') $file
Definition: UtfNormalTest2.php:30
DB_SLAVE
const DB_SLAVE
Definition: Defines.php:55
$path
$path
Definition: NoLocalSettings.php:35
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:314
CheckImages\execute
execute()
Do the actual work.
Definition: checkImages.php:38
$maintClass
$maintClass
Definition: checkImages.php:89
$res
$res
Definition: database.txt:21
Maintenance\setBatchSize
setBatchSize( $s=0)
Set the batch size.
Definition: Maintenance.php:254