25require_once __DIR__ .
'/Maintenance.php';
30 parent::__construct();
32 $this->
addDescription(
"Find unregistered files in the 'public' repo zone." );
34 'Only scan files in this subdirectory (e.g. "a/a0")',
false,
true );
35 $this->
addOption(
'verbose',
"Mention file paths checked" );
40 $subdir = $this->
getOption(
'subdir',
'' );
44 if ( $repo->hasSha1Storage() ) {
45 $this->
fatalError(
"Local repo uses SHA-1 file storage names; aborting." );
48 $directory = $repo->getZonePath(
'public' );
49 if ( $subdir !=
'' ) {
50 $directory .=
"/$subdir/";
54 $this->
output(
"Scanning files under $directory:\n" );
57 $list = $repo->getBackend()->getFileList( [
'dir' => $directory ] );
58 if ( $list ===
null ) {
59 $this->
fatalError(
"Could not get file listing." );
63 foreach ( $list as
$path ) {
64 if ( preg_match(
'#^(thumb|deleted)/#',
$path ) ) {
70 $this->
checkFiles( $repo, $pathBatch, $verbose );
74 $this->
checkFiles( $repo, $pathBatch, $verbose );
78 if ( !count( $paths ) ) {
88 foreach ( $paths as
$path ) {
89 $name = basename(
$path );
90 if ( preg_match(
'#^archive/#',
$path ) ) {
92 $this->
output(
"Checking old file $name\n" );
96 [ , $base ] = explode(
'!', $name, 2 );
97 $oiWheres[] = $dbr->expr(
'oi_name',
'=', $base )->and(
'oi_archive_name',
'=', $name );
100 $this->
output(
"Checking current file $name\n" );
107 $uqb = $dbr->newUnionQueryBuilder();
109 $dbr->newSelectQueryBuilder()
110 ->select( [
'name' =>
'img_name',
'old' =>
'0' ] )
112 ->where( $imgIN ? [
'img_name' => $imgIN ] :
'1=0' )
115 $dbr->newSelectQueryBuilder()
116 ->select( [
'name' =>
'oi_archive_name',
'old' =>
'1' ] )
118 ->where( $oiWheres ? $dbr->orExpr( $oiWheres ) :
'1=0' )
121 $res = $uqb->all()->caller( __METHOD__ )->fetchResultSet();
125 foreach ( $res as $row ) {
127 $oldNamesFound[] = $row->name;
129 $curNamesFound[] = $row->name;
133 foreach ( array_diff( $curNames, $curNamesFound ) as $name ) {
134 $file = $repo->
newFile( $name );
137 $this->
output( $name .
"\n" . $file->getCanonicalUrl() .
"\n\n" );
139 $this->
error(
"Cannot get URL for bad file title '$name'" );
143 foreach ( array_diff( $oldNames, $oldNamesFound ) as $name ) {
144 [ , $base ] = explode(
'!', $name, 2 );
147 $this->
output( $name .
"\n" . $file->getCanonicalUrl() .
"\n\n" );
154require_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...
getBatchSize()
Returns batch size.
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
error( $err, $die=0)
Throw an error to the user.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.