MediaWiki REL1_41
checkImages.php
Go to the documentation of this file.
1<?php
25
26require_once __DIR__ . '/Maintenance.php';
27
33class CheckImages extends Maintenance {
34
35 public function __construct() {
36 parent::__construct();
37 $this->addDescription( 'Check images to see if they exist, are readable, etc' );
38 $this->setBatchSize( 1000 );
39 }
40
41 public function execute() {
42 $start = '';
43 $dbr = $this->getDB( DB_REPLICA );
44
45 $numImages = 0;
46 $numGood = 0;
47
48 $repo = $this->getServiceContainer()->getRepoGroup()->getLocalRepo();
49 do {
50 $queryBuilder = FileSelectQueryBuilder::newForFile( $dbr );
51
52 $res = $queryBuilder->where( 'img_name > ' . $dbr->addQuotes( $start ) )
53 ->limit( $this->getBatchSize() )
54 ->caller( __METHOD__ )->fetchResultSet();
55 foreach ( $res as $row ) {
56 $numImages++;
57 $start = $row->img_name;
58 $file = $repo->newFileFromRow( $row );
59 $path = $file->getPath();
60 if ( !$path ) {
61 $this->output( "{$row->img_name}: not locally accessible\n" );
62 continue;
63 }
64 $size = $repo->getFileSize( $file->getPath() );
65 if ( $size === false ) {
66 $this->output( "{$row->img_name}: missing\n" );
67 continue;
68 }
69
70 if ( $size == 0 && $row->img_size != 0 ) {
71 $this->output( "{$row->img_name}: truncated, was {$row->img_size}\n" );
72 continue;
73 }
74
75 if ( $size != $row->img_size ) {
76 $this->output( "{$row->img_name}: size mismatch DB={$row->img_size}, "
77 . "actual={$size}\n" );
78 continue;
79 }
80
81 $numGood++;
82 }
83 } while ( $res->numRows() );
84
85 $this->output( "Good images: $numGood/$numImages\n" );
86 }
87}
88
89$maintClass = CheckImages::class;
90require_once RUN_MAINTENANCE_IF_MAIN;
getDB()
$maintClass
Maintenance script to check images to see if they exist, are readable, etc.
__construct()
Default constructor.
execute()
Do the actual work.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
getServiceContainer()
Returns the main service container.
getBatchSize()
Returns batch size.
addDescription( $text)
Set the description text.
setBatchSize( $s=0)
const DB_REPLICA
Definition defines.php:26
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42