28 require_once __DIR__ .
'/Maintenance.php';
37 parent::__construct();
39 $this->
addOption(
'verbose',
'Output information about each file.',
false,
false,
'v' );
40 $this->
addOption(
'start',
'Name of file to start with',
false,
true );
41 $this->
addOption(
'end',
'Name of file to end with',
false,
true );
42 $this->
addOption(
'media_type',
'Media type to filter for',
false,
true );
43 $this->
addOption(
'major_mime',
'Major mime type to filter for',
false,
true );
44 $this->
addOption(
'minor_mime',
'Minor mime type to filter for',
false,
true );
47 'Set true to refresh file content type from mime data in db',
55 $repo = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo();
56 $start = str_replace(
' ',
'_', $this->
getOption(
'start',
'' ) );
57 $end = str_replace(
' ',
'_', $this->
getOption(
'end',
'' ) );
59 $media_type = str_replace(
' ',
'_', $this->
getOption(
'media_type',
'' ) );
61 $major_mime = str_replace(
' ',
'_', $this->
getOption(
'major_mime',
'' ) );
63 $minor_mime = str_replace(
' ',
'_', $this->
getOption(
'minor_mime',
'' ) );
71 $conds = [
"img_name > {$dbr->addQuotes( $start )}" ];
73 if ( strlen( $end ) ) {
74 $conds[] =
"img_name <= {$dbr->addQuotes( $end )}";
77 if ( strlen( $media_type ) ) {
78 $conds[] =
"img_media_type = {$dbr->addQuotes( $media_type )}";
81 if ( strlen( $major_mime ) ) {
82 $conds[] =
"img_major_mime = {$dbr->addQuotes( $major_mime )}";
85 if ( strlen( $minor_mime ) ) {
86 $conds[] =
"img_minor_mime = {$dbr->addQuotes( $minor_mime )}";
89 $res =
$dbr->select( $fileQuery[
'tables'],
95 'ORDER BY' =>
'img_name ASC'
100 if (
$res->numRows() > 0 ) {
101 $row1 =
$res->current();
102 $this->
output(
"Processing next {$res->numRows()} row(s) starting with {$row1->img_name}.\n" );
106 $backendOperations = [];
108 foreach (
$res as $row ) {
109 $file = $repo->newFileFromRow( $row );
110 $headers =
$file->getContentHeaders();
111 if ( $this->
getOption(
'refreshContentType',
false ) ) {
112 $headers[
'Content-Type'] = $row->img_major_mime .
'/' . $row->img_minor_mime;
115 if ( count( $headers ) ) {
116 $backendOperations[] = [
117 'op' =>
'describe',
'src' =>
$file->getPath(),
'headers' => $headers
122 foreach (
$file->getHistory() as $oldFile ) {
123 $headers = $oldFile->getContentHeaders();
124 if ( count( $headers ) ) {
125 $backendOperations[] = [
126 'op' =>
'describe',
'src' => $oldFile->getPath(),
'headers' => $headers
132 $this->
output(
"Queued headers update for file '{$row->img_name}'.\n" );
135 $start = $row->img_name;
138 $backendOperationsCount = count( $backendOperations );
139 $count += $backendOperationsCount;
141 $this->
output(
"Updating headers for {$backendOperationsCount} file(s).\n" );
143 }
while (
$res->numRows() === $this->getBatchSize() );
145 $this->
output(
"Done. Updated headers for $count file(s).\n" );
153 $status = $repo->getBackend()->doQuickOperations( $backendOperations );
155 if ( !$status->isGood() ) {
156 $this->
error(
"Encountered error: " . print_r( $status,
true ) );
162 require_once RUN_MAINTENANCE_IF_MAIN;
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...
getDB( $db, $groups=[], $dbDomain=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 option was set.
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.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.