MediaWiki REL1_37
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 = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo();
49 $fileQuery = LocalFile::getQueryInfo();
50 do {
51 $res = $dbr->select( $fileQuery['tables'], $fileQuery['fields'],
52 [ 'img_name > ' . $dbr->addQuotes( $start ) ],
53 __METHOD__, [ 'LIMIT' => $this->getBatchSize() ], $fileQuery['joins'] );
54 foreach ( $res as $row ) {
55 $numImages++;
56 $start = $row->img_name;
57 $file = $repo->newFileFromRow( $row );
58 $path = $file->getPath();
59 if ( !$path ) {
60 $this->output( "{$row->img_name}: not locally accessible\n" );
61 continue;
62 }
63 $size = $repo->getFileSize( $file->getPath() );
64 if ( $size === false ) {
65 $this->output( "{$row->img_name}: missing\n" );
66 continue;
67 }
68
69 if ( $size == 0 && $row->img_size != 0 ) {
70 $this->output( "{$row->img_name}: truncated, was {$row->img_size}\n" );
71 continue;
72 }
73
74 if ( $size != $row->img_size ) {
75 $this->output( "{$row->img_name}: size mismatch DB={$row->img_size}, "
76 . "actual={$size}\n" );
77 continue;
78 }
79
80 $numGood++;
81 }
82 } while ( $res->numRows() );
83
84 $this->output( "Good images: $numGood/$numImages\n" );
85 }
86}
87
88$maintClass = CheckImages::class;
89require_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.
addDescription( $text)
Set the description text.
setBatchSize( $s=0)
MediaWikiServices is the service locator for the application scope of MediaWiki.
const DB_REPLICA
Definition defines.php:25
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42