MediaWiki  1.29.2
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->addDescription( 'Check images to see if they exist, are readable, etc' );
35  $this->setBatchSize( 1000 );
36  }
37 
38  public function execute() {
39  $start = '';
40  $dbr = $this->getDB( DB_REPLICA );
41 
42  $numImages = 0;
43  $numGood = 0;
44 
45  $repo = RepoGroup::singleton()->getLocalRepo();
46  do {
47  $res = $dbr->select( 'image', '*', [ 'img_name > ' . $dbr->addQuotes( $start ) ],
48  __METHOD__, [ '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;
57  }
58  $size = $repo->getFileSize( $file->getPath() );
59  if ( $size === false ) {
60  $this->output( "{$row->img_name}: missing\n" );
61  continue;
62  }
63 
64  if ( $size == 0 && $row->img_size != 0 ) {
65  $this->output( "{$row->img_name}: truncated, was {$row->img_size}\n" );
66  continue;
67  }
68 
69  if ( $size != $row->img_size ) {
70  $this->output( "{$row->img_name}: size mismatch DB={$row->img_size}, "
71  . "actual={$size}\n" );
72  continue;
73  }
74 
75  $numGood++;
76  }
77  } while ( $res->numRows() );
78 
79  $this->output( "Good images: $numGood/$numImages\n" );
80  }
81 }
82 
83 $maintClass = "CheckImages";
84 require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance\$mBatchSize
int $mBatchSize
Batch size.
Definition: Maintenance.php:103
RepoGroup\singleton
static singleton()
Get a RepoGroup instance.
Definition: RepoGroup.php:59
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:287
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
$res
$res
Definition: database.txt:21
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
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
CheckImages
Maintenance script to check images to see if they exist, are readable, etc.
Definition: checkImages.php:30
$dbr
if(! $regexes) $dbr
Definition: cleanup.php:94
$path
$path
Definition: NoLocalSettings.php:26
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\getDB
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1251
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:373
CheckImages\execute
execute()
Do the actual work.
Definition: checkImages.php:38
$maintClass
$maintClass
Definition: checkImages.php:83
Maintenance\setBatchSize
setBatchSize( $s=0)
Set the batch size.
Definition: Maintenance.php:314