30require_once __DIR__ .
'/Maintenance.php';
48 parent::__construct();
50 $this->
addDescription(
'Script to update image metadata records' );
55 'Reload metadata from file even if the metadata looks ok',
62 'Only fix really broken records, leave old but still compatible records alone.'
66 'Output extra information about each upgraded/non-upgraded file.',
71 $this->
addOption(
'start',
'Name of file to start with',
false,
true );
72 $this->
addOption(
'end',
'Name of file to end with',
false,
true );
76 'Only refresh files with this media type, e.g. BITMAP, UNKNOWN etc.',
82 "Only refresh files with this MIME type. Can accept wild-card 'image/*'. "
83 .
"Potentially inefficient unless 'mediatype' is also specified",
89 '(Inefficient!) Only refresh files where the img_metadata field '
90 .
'contains this string. Can be used if its known a specific '
91 .
'property was being extracted incorrectly.',
99 $brokenOnly = $this->
hasOption(
'broken-only' );
100 $verbose = $this->
hasOption(
'verbose' );
101 $start = $this->
getOption(
'start',
false );
110 if ( $batchSize <= 0 ) {
111 $this->
fatalError(
"Batch size is too low...", 12 );
119 if ( $start !==
false ) {
124 'LIMIT' => $batchSize,
125 'ORDER BY' =>
'img_name ASC',
132 $fileQuery[
'tables'],
133 $fileQuery[
'fields'],
134 array_merge( $conds, $conds2 ),
140 if (
$res->numRows() > 0 ) {
141 $row1 =
$res->current();
142 $this->
output(
"Processing next {$res->numRows()} row(s) starting with {$row1->img_name}.\n" );
146 foreach (
$res as $row ) {
149 $file = $repo->newFileFromRow( $row );
150 if ( $file->getUpgraded() ) {
153 $newLength = strlen( $file->getMetadata() );
154 $oldLength = strlen( $row->img_metadata );
155 if ( $newLength < $oldLength - 5 ) {
164 "Warning: File:{$row->img_name} used to have " .
165 "$oldLength bytes of metadata but now has $newLength bytes.\n"
167 } elseif ( $verbose ) {
168 $this->
output(
"Refreshed File:{$row->img_name}.\n" );
174 $newLength = strlen( $file->getMetadata() );
175 $oldLength = strlen( $row->img_metadata );
176 if ( $newLength < $oldLength - 5 ) {
179 "Warning: File:{$row->img_name} used to have " .
180 "$oldLength bytes of metadata but now has $newLength bytes. (forced)\n"
184 $this->
output(
"Forcibly refreshed File:{$row->img_name}.\n" );
188 $this->
output(
"Skipping File:{$row->img_name}.\n" );
192 }
catch ( Exception
$e ) {
193 $this->
output(
"{$row->img_name} failed. {$e->getMessage()}\n" );
196 $conds2 = [
'img_name > ' .
$dbw->
addQuotes( $row->img_name ) ];
198 }
while (
$res->numRows() === $batchSize );
200 $total = $upgraded + $leftAlone;
202 $this->
output(
"\nFinished refreshing file metadata for $total files. "
203 .
"$upgraded needed to be refreshed, $leftAlone did not need to "
204 .
"be but were refreshed anyways, and $error refreshes were suspicious.\n" );
206 $this->
output(
"\nFinished refreshing file metadata for $total files. "
207 .
"$upgraded were refreshed, $leftAlone were already up to date, "
208 .
"and $error refreshes were suspicious.\n" );
221 $mediatype = $this->
getOption(
'mediatype',
false );
222 $like = $this->
getOption(
'metadata-contains',
false );
224 if ( $end !==
false ) {
227 if (
$mime !==
false ) {
229 $conds[
'img_major_mime'] = $major;
230 if ( $minor !==
'*' ) {
231 $conds[
'img_minor_mime'] = $minor;
234 if ( $mediatype !==
false ) {
235 $conds[
'img_media_type'] = $mediatype;
257 if ( $brokenOnly && $force ) {
258 $this->
fatalError(
'Cannot use --broken-only and --force together. ', 2 );
$wgUpdateCompatibleMetadata
If to automatically update the img_metadata field if the metadata field is outdated but compatible wi...
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
static splitMime( $mime)
Split an internet media type into its two components; if not a two-part name, set the minor type to '...
static getQueryInfo(array $options=[])
Return the tables, fields, and join conditions to be selected to create a new localfile object.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
hasOption( $name)
Checks to see if a particular option exists.
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.
setBatchSize( $s=0)
Set the batch size.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
static singleton()
Get a RepoGroup instance.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
returning false will NOT prevent logging $e
Advanced database interface for IDatabase handles that include maintenance methods.
require_once RUN_MAINTENANCE_IF_MAIN
if( $ext=='php'|| $ext=='php5') $mime