33require_once __DIR__ .
'/Maintenance.php';
71 parent::__construct();
72 $this->
addDescription(
'Script to update image metadata records' );
74 $this->
addOption(
'missing',
'Check for files without associated database record' );
75 $this->
addOption(
'dry-run',
'Only report, don\'t update the database' );
80 $this->dryrun = $this->
hasOption(
'dry-run' );
81 if ( $this->dryrun ) {
82 MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode()
83 ->setReason(
'Dry run mode, image upgrades are suppressed' );
97 if ( $this->repo ===
null ) {
98 $this->repo = MediaWikiServices::getInstance()->getRepoGroup()
99 ->newCustomLocalRepo( [
101 'updateCompatibleMetadata' =>
true
118 $this->processed = 0;
121 $this->startTime = microtime(
true );
128 if ( $this->processed % 100 != 0 ) {
134 $now = microtime(
true );
136 $estimatedTotalTime = $delta / $portion;
137 $eta = $this->startTime + $estimatedTotalTime;
138 $rate = $this->processed / $delta;
140 $this->
output( sprintf(
"%s: %6.2f%% done on %s; ETA %s [%d/%d] %.2f/sec <%.2f%% updated>\n",
148 $updateRate * 100.0 ) );
153 $count = $this->dbw->selectField(
$table,
'count(*)',
'', __METHOD__ );
155 $this->
output(
"Processing $table...\n" );
158 $queryInfo[
'tables'], $queryInfo[
'fields'], [], __METHOD__, [], $queryInfo[
'joins']
161 foreach ( $result as $row ) {
162 $update = call_user_func( $callback, $row,
null );
169 $this->
output(
"Finished $table... $this->updated of $this->processed rows updated\n" );
173 $callback = [ $this,
'imageCallback' ];
174 $this->
buildTable(
'image',
'img_name', LocalFile::getQueryInfo(), $callback );
182 return $file->getUpgraded();
187 [ $this,
'oldimageCallback' ] );
193 if ( $row->oi_archive_name ==
'' ) {
194 $this->
output(
"Empty oi_archive_name for oi_name={$row->oi_name}\n" );
200 return $file->getUpgraded();
204 $this->
getRepo()->enumFiles( [ $this,
'checkMissingImage' ] );
209 $row = $this->dbw->selectRow(
'image',
211 [
'img_name' => $filename ],
221 $timestamp = $this->dbw->timestamp( $this->
getRepo()->getFileTimestamp( $fullpath ) );
222 $services = MediaWikiServices::getInstance();
224 $altname = $services->getContentLanguage()->checkTitleEncoding( $filename );
225 if ( $altname != $filename ) {
226 if ( $this->dryrun ) {
227 $filename = $altname;
228 $this->
output(
"Estimating transcoding... $altname\n" );
232 $filename = $this->renameFile( $filename );
236 if ( $filename ==
'' ) {
237 $this->
output(
"Empty filename for $fullpath\n" );
241 if ( !$this->dryrun ) {
242 $file = $services->getRepoGroup()->getLocalRepo()->newFile( $filename );
243 $pageText = SpecialUpload::getInitialPageText(
244 '(recovered file, missing upload log entry)'
247 $status =
$file->recordUpload3(
249 '(recovered file, missing upload log entry)',
255 if ( !$status->isOK() ) {
256 $this->
output(
"Error uploading file $fullpath\n" );
261 $this->
output( $fullpath .
"\n" );
266require_once RUN_MAINTENANCE_IF_MAIN;
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.
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)
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 was set.
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.
static newSystemUser( $name, $options=[])
Static factory method for creation of a "system" user from username.
const MAINTENANCE_SCRIPT_USER
Username used for various maintenance scripts.
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.