33require_once __DIR__ .
'/Maintenance.php';
71 parent::__construct();
77 $this->
addDescription(
'Script to update image metadata records' );
79 $this->
addOption(
'missing',
'Check for files without associated database record' );
80 $this->
addOption(
'dry-run',
'Only report, don\'t update the database' );
87 MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode()
88 ->setReason(
'Dry run mode, image upgrades are suppressed' );
102 if ( $this->repo ===
null ) {
103 $this->repo = RepoGroup::singleton()->getLocalRepo();
135 $now = microtime(
true );
141 $this->
output(
sprintf(
"%s: %6.2f%% done on %s; ETA %s [%d/%d] %.2f/sec <%.2f%% updated>\n",
156 $this->
output(
"Processing $table...\n" );
162 foreach ( $result
as $row ) {
170 $this->
output(
"Finished $table... $this->updated of $this->processed rows updated\n" );
174 $callback = [
$this,
'imageCallback' ];
183 return $file->getUpgraded();
188 [
$this,
'oldimageCallback' ] );
194 if ( $row->oi_archive_name ==
'' ) {
195 $this->
output(
"Empty oi_archive_name for oi_name={$row->oi_name}\n" );
201 return $file->getUpgraded();
205 $this->
getRepo()->enumFiles( [
$this,
'checkMissingImage' ] );
210 $row = $this->
dbw->selectRow(
'image',
212 [
'img_name' => $filename ],
222 $services = MediaWikiServices::getInstance();
224 $altname = $services->getContentLanguage()->checkTitleEncoding( $filename );
228 $this->
output(
"Estimating transcoding... $altname\n" );
236 if ( $filename ==
'' ) {
237 $this->
output(
"Empty filename for $fullpath\n" );
242 $file = $services->getRepoGroup()->getLocalRepo()->newFile( $filename );
243 if ( !
$file->recordUpload(
245 '(recovered file, missing upload log entry)',
252 $this->
output(
"Error uploading file $fullpath\n" );
$wgUpdateCompatibleMetadata
If to automatically update the img_metadata field if the metadata field is outdated but compatible wi...
wfBaseName( $path, $suffix='')
Return the final portion of a pathname.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
const RUN_MAINTENANCE_IF_MAIN
Maintenance script to update image metadata records.
__construct()
Default constructor.
buildTable( $table, $key, $queryInfo, $callback)
oldimageCallback( $row, $copy)
checkMissingImage( $fullpath)
IMaintainableDatabase $dbw
imageCallback( $row, $copy)
execute()
Do the actual work.
addMissingImage( $filename, $fullpath)
static getQueryInfo(array $options=[])
Return the tables, fields, and join conditions to be selected to create a new localfile object.
A repository that stores files in the local filesystem and registers them in the wiki's own database.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option exists.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
static getQueryInfo(array $options=[])
Return the tables, fields, and join conditions to be selected to create a new oldlocalfile object.
Advanced database interface for IDatabase handles that include maintenance methods.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.