Go to the documentation of this file.
30 require_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 );
109 if ( $this->mBatchSize <= 0 ) {
110 $this->
error(
"Batch size is too low...", 12 );
118 if ( $start !==
false ) {
124 'ORDER BY' =>
'img_name ASC',
131 array_merge( $conds, $conds2 ),
136 if (
$res->numRows() > 0 ) {
137 $row1 =
$res->current();
138 $this->
output(
"Processing next {$res->numRows()} row(s) starting with {$row1->img_name}.\n" );
142 foreach (
$res as $row ) {
145 $file = $repo->newFileFromRow( $row );
146 if ( $file->getUpgraded() ) {
149 $newLength = strlen( $file->getMetadata() );
150 $oldLength = strlen( $row->img_metadata );
151 if ( $newLength < $oldLength - 5 ) {
160 "Warning: File:{$row->img_name} used to have " .
161 "$oldLength bytes of metadata but now has $newLength bytes.\n"
163 } elseif ( $verbose ) {
164 $this->
output(
"Refreshed File:{$row->img_name}.\n" );
170 $newLength = strlen( $file->getMetadata() );
171 $oldLength = strlen( $row->img_metadata );
172 if ( $newLength < $oldLength - 5 ) {
175 "Warning: File:{$row->img_name} used to have " .
176 "$oldLength bytes of metadata but now has $newLength bytes. (forced)\n"
180 $this->
output(
"Forcibly refreshed File:{$row->img_name}.\n" );
184 $this->
output(
"Skipping File:{$row->img_name}.\n" );
188 }
catch ( Exception
$e ) {
189 $this->
output(
"{$row->img_name} failed. {$e->getMessage()}\n" );
192 $conds2 = [
'img_name > ' .
$dbw->
addQuotes( $row->img_name ) ];
196 $total = $upgraded + $leftAlone;
198 $this->
output(
"\nFinished refreshing file metadata for $total files. "
199 .
"$upgraded needed to be refreshed, $leftAlone did not need to "
200 .
"be but were refreshed anyways, and $error refreshes were suspicious.\n" );
202 $this->
output(
"\nFinished refreshing file metadata for $total files. "
203 .
"$upgraded were refreshed, $leftAlone were already up to date, "
204 .
"and $error refreshes were suspicious.\n" );
217 $mediatype = $this->
getOption(
'mediatype',
false );
218 $like = $this->
getOption(
'metadata-contains',
false );
220 if ( $end !==
false ) {
223 if (
$mime !==
false ) {
225 $conds[
'img_major_mime'] = $major;
226 if ( $minor !==
'*' ) {
227 $conds[
'img_minor_mime'] = $minor;
230 if ( $mediatype !==
false ) {
231 $conds[
'img_media_type'] = $mediatype;
253 if ( $brokenOnly && $force ) {
254 $this->
error(
'Cannot use --broken-only and --force together. ', 2 );
int $mBatchSize
Batch size.
$wgUpdateCompatibleMetadata
If to automatically update the img_metadata field if the metadata field is outdated but compatible wi...
static singleton()
Get a RepoGroup instance.
addDescription( $text)
Set the description text.
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
require_once RUN_MAINTENANCE_IF_MAIN
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
static splitMime( $mime)
Split an internet media type into its two components; if not a two-part name, set the minor type to '...
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
when a variable name is used in a it is silently declared as a new masking the global
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
if( $ext=='php'|| $ext=='php5') $mime
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
getOption( $name, $default=null)
Get an option, or return the default.
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
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
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 param exists.
Advanced database interface for IDatabase handles that include maintenance methods.
setBatchSize( $s=0)
Set the batch size.