mDescription = 'Script to update file HTTP headers'; $this->addOption( 'verbose', 'Output information about each file.', false, false, 'v' ); $this->addOption( 'start', 'Name of file to start with', false, true ); $this->addOption( 'end', 'Name of file to end with', false, true ); $this->setBatchSize( 200 ); } public function execute() { $repo = RepoGroup::singleton()->getLocalRepo(); $start = str_replace( ' ', '_', $this->getOption( 'start', '' ) ); // page on img_name $end = str_replace( ' ', '_', $this->getOption( 'end', '' ) ); // page on img_name $count = 0; $dbr = wfGetDB( DB_SLAVE ); do { $conds = array( "img_name > {$dbr->addQuotes( $start )}" ); if ( strlen( $end ) ) { $conds[] = "img_name <= {$dbr->addQuotes( $end )}"; } $res = $dbr->select( 'image', '*', $conds, __METHOD__, array( 'LIMIT' => $this->mBatchSize, 'ORDER BY' => 'img_name ASC' ) ); foreach ( $res as $row ) { $file = $repo->newFileFromRow( $row ); $headers = $file->getStreamHeaders(); if ( count( $headers ) ) { $this->updateFileHeaders( $file, $headers ); } // Do all of the older file versions... foreach ( $file->getHistory() as $oldFile ) { $headers = $oldFile->getStreamHeaders(); if ( count( $headers ) ) { $this->updateFileHeaders( $oldFile, $headers ); } } if ( $this->hasOption( 'verbose' ) ) { $this->output( "Updated headers for file '{$row->img_name}'.\n" ); } ++$count; $start = $row->img_name; // advance } } while ( $res->numRows() > 0 ); $this->output( "Done. Updated headers for $count file(s).\n" ); } protected function updateFileHeaders( File $file, array $headers ) { $status = $file->getRepo()->getBackend()->describe( array( 'src' => $file->getPath(), 'headers' => $headers ) ); if ( !$status->isGood() ) { $this->error( "Encountered error: " . print_r( $status, true ) ); } } } $maintClass = 'RefreshFileHeaders'; require_once RUN_MAINTENANCE_IF_MAIN;