Go to the documentation of this file.
24 require_once __DIR__ .
'/Maintenance.php';
33 parent::__construct();
35 $this->
addOption(
'force',
"Recalculate sha1 for rows that already have a value" );
36 $this->
addOption(
'multiversiononly',
"Calculate only for files with several versions" );
37 $this->
addOption(
'method',
"Use 'pipe' to pipe to mysql command line,\n" .
38 "\t\tdefault uses Database class",
false,
true );
41 'Fix for a specific file, without File: namespace prefixed',
48 return 'populate img_sha1';
52 return 'img_sha1 column of image table already populated.';
64 $method = $this->
getOption(
'method',
'normal' );
67 $isRegen = ( $force || $file !=
'' );
69 $t = -microtime(
true );
75 [
'img_name' => $file ],
81 $this->
output(
"Populating img_sha1 field for specified files\n" );
83 if ( $this->
hasOption(
'multiversiononly' ) ) {
85 $this->
output(
"Populating and recalculating img_sha1 field for versioned files\n" );
88 $this->
output(
"Populating and recalculating img_sha1 field\n" );
90 $conds = [
'img_sha1' =>
'' ];
91 $this->
output(
"Populating img_sha1 field\n" );
93 if ( $this->
hasOption(
'multiversiononly' ) ) {
94 $res = $dbw->select(
'oldimage',
95 [
'img_name' =>
'DISTINCT(oi_name)' ], $conds, __METHOD__ );
97 $res = $dbw->select(
'image', [
'img_name' ], $conds, __METHOD__ );
101 $imageTable = $dbw->tableName(
'image' );
102 $oldImageTable = $dbw->tableName(
'oldimage' );
104 if ( $method ==
'pipe' ) {
113 $this->
output(
"Using pipe method\n" );
114 $pipe = popen( $cmd,
'w' );
117 $numRows =
$res->numRows();
119 foreach (
$res as $row ) {
122 "Done %d of %d, %5.3f%% \r", $i, $numRows, $i / $numRows * 100 ) );
132 $sha1 = $file->getRepo()->getFileSha1( $file->getPath() );
133 if ( strval( $sha1 ) !==
'' ) {
134 if ( $isRegen && $file->getSha1() !== $sha1 ) {
139 $sql =
"UPDATE $imageTable SET img_sha1=" . $dbw->addQuotes( $sha1 ) .
140 " WHERE img_name=" . $dbw->addQuotes( $file->getName() );
141 if ( $method ==
'pipe' ) {
142 fwrite( $pipe,
"$sql;\n" );
144 $dbw->query( $sql, __METHOD__ );
149 foreach ( $file->getHistory()
as $oldFile ) {
150 $sha1 = $oldFile->getRepo()->getFileSha1( $oldFile->getPath() );
151 if ( strval( $sha1 ) !==
'' ) {
152 if ( $isRegen && $oldFile->getSha1() !== $sha1 ) {
155 $oldFile->upgradeRow();
157 $sql =
"UPDATE $oldImageTable SET oi_sha1=" . $dbw->addQuotes( $sha1 ) .
158 " WHERE (oi_name=" . $dbw->addQuotes( $oldFile->getName() ) .
" AND" .
159 " oi_archive_name=" . $dbw->addQuotes( $oldFile->getArchiveName() ) .
")";
160 if ( $method ==
'pipe' ) {
161 fwrite( $pipe,
"$sql;\n" );
163 $dbw->query( $sql, __METHOD__ );
170 if ( $method ==
'pipe' ) {
174 $t += microtime(
true );
175 $this->
output( sprintf(
"\nDone %d files in %.1f seconds\n", $numRows,
$t ) );
$wgDBserver
Database host name or IP address.
controlled by the following MediaWiki still creates a BagOStuff but calls it to it are no ops If the cache daemon can t be it should also disable itself fairly $wgDBname
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addDescription( $text)
Set the description text.
require_once RUN_MAINTENANCE_IF_MAIN
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
$wgDBpassword
Database user's password.
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
updateSkippedMessage()
Message to show that the update was done already and was just skipped.
getUpdateKey()
Get the update key name to go in the update log table.
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
__construct()
Default constructor.
Maintenance script to populate the img_sha1 field.
doDBUpdates()
Do the actual work.
getOption( $name, $default=null)
Get an option, or return the default.
execute()
Do the actual work.
getBatchSize()
Returns batch size.
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.
wfEscapeShellArg(... $args)
Version of escapeshellarg() that works better on Windows.
output( $out, $channel=null)
Throw some output to the user.
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
$wgDBuser
Database username.
hasOption( $name)
Checks to see if a particular option exists.
wfLocalFile( $title)
Get an object referring to a locally registered file.