MediaWiki
REL1_40
checkImages.php
Go to the documentation of this file.
1
<?php
24
use
MediaWiki\MediaWikiServices
;
25
26
require_once __DIR__ .
'/Maintenance.php'
;
27
33
class
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;
94
require_once RUN_MAINTENANCE_IF_MAIN;
getDB
getDB()
$path
$path
Definition
NoLocalSettings.php:27
$maintClass
$maintClass
Definition
checkImages.php:93
CheckImages
Maintenance script to check images to see if they exist, are readable, etc.
Definition
checkImages.php:33
CheckImages\__construct
__construct()
Default constructor.
Definition
checkImages.php:35
CheckImages\execute
execute()
Do the actual work.
Definition
checkImages.php:41
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition
Maintenance.php:66
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition
Maintenance.php:466
Maintenance\getBatchSize
getBatchSize()
Returns batch size.
Definition
Maintenance.php:399
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition
Maintenance.php:340
Maintenance\setBatchSize
setBatchSize( $s=0)
Definition
Maintenance.php:406
MediaWiki\MediaWikiServices
Service locator for MediaWiki core services.
Definition
MediaWikiServices.php:223
DB_REPLICA
const DB_REPLICA
Definition
defines.php:26
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition
router.php:42
$res
$res
Definition
testCompression.php:58
$dbr
$dbr
Definition
testCompression.php:55
maintenance
checkImages.php
Generated on Thu Jun 27 2024 14:04:55 for MediaWiki by
1.10.0