24 require_once __DIR__ .
'/Maintenance.php';
28 parent::__construct();
30 $this->
addDescription(
"Find unregistered files in the 'public' repo zone." );
32 'Only scan files in this subdirectory (e.g. "a/a0")',
false,
true );
33 $this->
addOption(
'verbose',
"Mention file paths checked" );
38 $subdir = $this->
getOption(
'subdir',
'' );
41 $repo = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo();
42 if ( $repo->hasSha1Storage() ) {
43 $this->
fatalError(
"Local repo uses SHA-1 file storage names; aborting." );
46 $directory = $repo->getZonePath(
'public' );
47 if ( $subdir !=
'' ) {
48 $directory .=
"/$subdir/";
52 $this->
output(
"Scanning files under $directory:\n" );
55 $list = $repo->getBackend()->getFileList( [
'dir' => $directory ] );
56 if ( $list ===
null ) {
57 $this->
fatalError(
"Could not get file listing." );
61 foreach ( $list as
$path ) {
62 if ( preg_match(
'#^(thumb|deleted)/#',
$path ) ) {
68 $this->
checkFiles( $repo, $pathBatch, $verbose );
72 $this->
checkFiles( $repo, $pathBatch, $verbose );
76 if ( !count( $paths ) ) {
86 foreach ( $paths as
$path ) {
87 $name = basename(
$path );
88 if ( preg_match(
'#^archive/#',
$path ) ) {
90 $this->
output(
"Checking old file $name\n" );
94 [ ,
$base ] = explode(
'!', $name, 2 );
95 $oiWheres[] =
$dbr->makeList(
96 [
'oi_name' =>
$base,
'oi_archive_name' => $name ],
101 $this->
output(
"Checking current file $name\n" );
114 [
'name' =>
'img_name',
'old' => 0 ],
115 $imgIN ? [
'img_name' => $imgIN ] :
'1=0',
120 [
'name' =>
'oi_archive_name',
'old' => 1 ],
121 $oiWheres ?
$dbr->makeList( $oiWheres,
LIST_OR ) :
'1=0',
132 foreach (
$res as $row ) {
134 $oldNamesFound[] = $row->name;
136 $curNamesFound[] = $row->name;
140 foreach ( array_diff( $curNames, $curNamesFound ) as $name ) {
144 $this->
output( $name .
"\n" .
$file->getCanonicalUrl() .
"\n\n" );
146 $this->
error(
"Cannot get URL for bad file title '$name'" );
150 foreach ( array_diff( $oldNames, $oldNamesFound ) as $name ) {
151 [ ,
$base ] = explode(
'!', $name, 2 );
154 $this->
output( $name .
"\n" .
$file->getCanonicalUrl() .
"\n\n" );
160 require_once RUN_MAINTENANCE_IF_MAIN;
newFile( $title, $time=false)
Create a new File object from the local repository.
execute()
Do the actual work.
__construct()
Default constructor.
checkFiles(LocalRepo $repo, array $paths, $verbose)
Local repository that stores files in the local filesystem and registers them in the wiki's own datab...
getReplicaDB()
Get a connection to the replica DB.
newFromArchiveName( $title, $archiveName)
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
getBatchSize()
Returns batch size.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.