MediaWiki REL1_40
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->newSelectQueryBuilder()
52 ->select( $fileQuery['fields'] )
53 ->tables( $fileQuery['tables'] )
54 ->where( 'img_name > ' . $dbr->addQuotes( $start ) )
55 ->joinConds( $fileQuery['joins'] )
56 ->caller( __METHOD__ )
57 ->limit( $this->getBatchSize() )
58 ->fetchResultSet();
59 foreach ( $res as $row ) {
60 $numImages++;
61 $start = $row->img_name;
62 $file = $repo->newFileFromRow( $row );
63 $path = $file->getPath();
64 if ( !$path ) {
65 $this->output( "{$row->img_name}: not locally accessible\n" );
66 continue;
67 }
68 $size = $repo->getFileSize( $file->getPath() );
69 if ( $size === false ) {
70 $this->output( "{$row->img_name}: missing\n" );
71 continue;
72 }
73
74 if ( $size == 0 && $row->img_size != 0 ) {
75 $this->output( "{$row->img_name}: truncated, was {$row->img_size}\n" );
76 continue;
77 }
78
79 if ( $size != $row->img_size ) {
80 $this->output( "{$row->img_name}: size mismatch DB={$row->img_size}, "
81 . "actual={$size}\n" );
82 continue;
83 }
84
85 $numGood++;
86 }
87 } while ( $res->numRows() );
88
89 $this->output( "Good images: $numGood/$numImages\n" );
90 }
91}
92
93$maintClass = CheckImages::class;
94require_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.
getBatchSize()
Returns batch size.
addDescription( $text)
Set the description text.
setBatchSize( $s=0)
Service locator for MediaWiki core services.
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