30 require_once __DIR__ .
'/Maintenance.php';
45 parent::__construct();
47 $this->
addDescription(
'Script to update image metadata records' );
52 'Reload metadata from file even if the metadata looks ok',
59 'Only fix really broken records, leave old but still compatible records alone.'
63 'Output extra information about each upgraded/non-upgraded file.',
68 $this->
addOption(
'start',
'Name of file to start with',
false,
true );
69 $this->
addOption(
'end',
'Name of file to end with',
false,
true );
73 'Only refresh files with this media type, e.g. BITMAP, UNKNOWN etc.',
79 "Only refresh files with this MIME type. Can accept wild-card 'image/*'. "
80 .
"Potentially inefficient unless 'mediatype' is also specified",
86 '(Inefficient!) Only refresh files where the img_metadata field '
87 .
'contains this string. Can be used if its known a specific '
88 .
'property was being extracted incorrectly.',
96 $brokenOnly = $this->
hasOption(
'broken-only' );
98 $start = $this->
getOption(
'start',
false );
106 if ( $this->mBatchSize <= 0 ) {
107 $this->
error(
"Batch size is too low...", 12 );
115 if ( $start !==
false ) {
121 'ORDER BY' =>
'img_name ASC',
128 array_merge( $conds, $conds2 ),
133 if (
$res->numRows() > 0 ) {
134 $row1 =
$res->current();
135 $this->
output(
"Processing next {$this->mBatchSize} rows starting with {$row1->img_name}.\n" );
138 $this->
error(
"No images to process.", 4 );
141 foreach (
$res as $row ) {
142 $file = $repo->newFileFromRow( $row );
143 if ( $file->getUpgraded() ) {
146 $newLength = strlen( $file->getMetadata() );
147 $oldLength = strlen( $row->img_metadata );
148 if ( $newLength < $oldLength - 5 ) {
156 $this->
output(
"Warning: File:{$row->img_name} used to have " .
157 "$oldLength bytes of metadata but now has $newLength bytes.\n" );
158 } elseif ( $verbose ) {
159 $this->
output(
"Refreshed File:{$row->img_name}.\n" );
165 $newLength = strlen( $file->getMetadata() );
166 $oldLength = strlen( $row->img_metadata );
167 if ( $newLength < $oldLength - 5 ) {
169 $this->
output(
"Warning: File:{$row->img_name} used to have " .
170 "$oldLength bytes of metadata but now has $newLength bytes. (forced)\n" );
173 $this->
output(
"Forcibly refreshed File:{$row->img_name}.\n" );
177 $this->
output(
"Skipping File:{$row->img_name}.\n" );
182 $conds2 = [
'img_name > ' .
$dbw->
addQuotes( $row->img_name ) ];
186 $total = $upgraded + $leftAlone;
188 $this->
output(
"\nFinished refreshing file metadata for $total files. "
189 .
"$upgraded needed to be refreshed, $leftAlone did not need to "
190 .
"be but were refreshed anyways, and $error refreshes were suspicious.\n" );
192 $this->
output(
"\nFinished refreshing file metadata for $total files. "
193 .
"$upgraded were refreshed, $leftAlone were already up to date, "
194 .
"and $error refreshes were suspicious.\n" );
207 $mediatype = $this->
getOption(
'mediatype',
false );
208 $like = $this->
getOption(
'metadata-contains',
false );
210 if ( $end !==
false ) {
213 if (
$mime !==
false ) {
215 $conds[
'img_major_mime'] = $major;
216 if ( $minor !==
'*' ) {
217 $conds[
'img_minor_mime'] = $minor;
220 if ( $mediatype !==
false ) {
221 $conds[
'img_media_type'] = $mediatype;
238 $wgUpdateCompatibleMetadata =
false;
240 $wgUpdateCompatibleMetadata =
true;
243 if ( $brokenOnly && $force ) {
244 $this->
error(
'Cannot use --broken-only and --force together. ', 2 );
select($table, $vars, $conds= '', $fname=__METHOD__, $options=[], $join_conds=[])
Execute a SELECT query constructed using the various parameters provided.
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
wfWaitForSlaves($ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the slaves 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 '...
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
if($ext== 'php'||$ext== 'php5') $mime
getDB($db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
hasOption($name)
Checks to see if a particular param exists.
require_once RUN_MAINTENANCE_IF_MAIN
when a variable name is used in a it is silently declared as a new local masking the global
addOption($name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
anyString()
Returns a token for buildLike() that denotes a '' to be used in a LIKE query.
buildLike()
LIKE statement wrapper, receives a variable-length argument list with parts of pattern to match conta...
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
static singleton()
Get a RepoGroup instance.
addQuotes($s)
Adds quotes and backslashes.
addDescription($text)
Set the description text.
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
getOption($name, $default=null)
Get an option, or return the default.
output($out, $channel=null)
Throw some output to the user.
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
int $mBatchSize
Batch size.
error($err, $die=0)
Throw an error to the user.
setBatchSize($s=0)
Set the batch size.
$wgUpdateCompatibleMetadata
If to automatically update the img_metadata field if the metadata field is outdated but compatible wi...