28 require_once __DIR__ .
'/../Maintenance.php';
29 require_once __DIR__ .
'/../../includes/export/WikiExporter.php';
140 parent::__construct();
141 $this->stderr = fopen(
"php://stderr",
"wt" );
156 $this->
addOption(
'plugin',
'Load a dump plugin class. Specify as <class>[:<file>].',
157 false,
true,
false,
true );
158 $this->
addOption(
'output',
'Begin a filtered output stream; Specify as <type>:<file>. ' .
159 '<type>s: file, gzip, bzip2, 7zip, dbzip2, lbzip2',
false,
true,
'o',
true );
160 $this->
addOption(
'filter',
'Add a filter on an output branch. Specify as ' .
161 '<type>[:<options>]. <types>s: latest, notalk, namespace',
false,
true,
false,
true );
162 $this->
addOption(
'report',
'Report position and speed after every n pages processed. ' .
163 'Default: 100.',
false,
true );
164 $this->
addOption(
'server',
'Force reading from MySQL server',
false,
true );
165 $this->
addOption(
'7ziplevel',
'7zip compression level for all 7zip outputs. Used for ' .
166 '-mx option to 7za command.',
false,
true );
170 $this->
addOption(
'schema-version',
'Schema version to use for output.',
false,
true );
181 parent::finalSetup( $settingsBuilder );
184 $schemaVersion = $settingsBuilder->getConfig()->get( MainConfigNames::XmlDumpSchemaVersion );
185 $this->
addOption(
'schema-version',
'Schema version to use for output. ' .
194 $this->outputTypes[$name] = $class;
202 $this->filterTypes[$name] = $class;
216 $register = [ $class,
'register' ];
221 throw new MWException(
'execute() must be overridden in subclasses' );
234 foreach ( $options as [ $opt, $param ] ) {
237 $val = explode(
':', $param, 2 );
239 if ( count( $val ) === 1 ) {
241 } elseif ( count( $val ) === 2 ) {
247 $split = explode(
':', $param, 2 );
248 if ( count( $split ) !== 2 ) {
249 $this->
fatalError(
'Invalid output parameter' );
252 if (
$sink !==
null ) {
255 if ( !isset( $this->outputTypes[
$type] ) ) {
256 $this->
fatalError(
"Unrecognized output sink type '$type'" );
258 $class = $this->outputTypes[
$type];
259 if (
$type ===
"7zip" ) {
267 if (
$sink ===
null ) {
271 $split = explode(
':', $param, 2 );
274 if ( !isset( $this->filterTypes[$key] ) ) {
275 $this->
fatalError(
"Unrecognized filter type '$key'" );
278 $type = $this->filterTypes[$key];
280 if ( count( $split ) === 2 ) {
291 case 'schema-version':
294 "Unsupported schema version $param. Supported versions: " .
298 $this->schemaVersion = $param;
304 $this->reportingInterval = intval( $this->
getOption(
'report' ) );
308 $this->server = $this->
getOption(
'server' );
311 if (
$sink ===
null ) {
316 if ( count( $sinks ) > 1 ) {
324 # Notice messages will foul up your XML output even if they're
325 # relatively harmless.
326 if ( ini_get(
'display_errors' ) ) {
327 ini_set(
'display_errors',
'stderr' );
333 $services = MediaWikiServices::getInstance();
334 $exporter = $services->getWikiExporterFactory()->getWikiExporter(
338 $this->limitNamespaces
340 $exporter->setSchemaVersion( $this->schemaVersion );
345 $exporter->setOutputSink( $wrapper );
347 if ( !$this->skipHeader ) {
348 $exporter->openStream();
350 # Log item dumps: all or by range
352 if ( $this->startId || $this->endId ) {
353 $exporter->logsByRange( $this->startId, $this->endId );
355 $exporter->allLogs();
357 } elseif ( $this->pages ===
null ) {
358 # Page dumps: all or by page ID range
359 if ( $this->startId || $this->endId ) {
360 $exporter->pagesByRange( $this->startId, $this->endId, $this->orderRevs );
361 } elseif ( $this->revStartId || $this->revEndId ) {
362 $exporter->revsByRange( $this->revStartId, $this->revEndId );
364 $exporter->allPages();
367 # Dump of specific pages
368 $exporter->pagesByName( $this->pages );
371 if ( !$this->skipFooter ) {
372 $exporter->closeStream();
389 if ( $this->forcedDb ===
null ) {
392 $this->maxCount =
$dbr->selectField( $table,
"MAX($field)",
'', __METHOD__ );
393 $this->startTime = microtime(
true );
395 $this->ID = getmypid();
405 if ( $this->forcedDb !==
null ) {
409 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
410 $this->lb = $lbFactory->newMainLB();
411 $db = $this->lb->getMaintenanceConnectionRef(
DB_REPLICA,
'dump' );
427 parent::setDB( $db );
428 $this->forcedDb = $db;
432 if ( isset( $this->lb ) ) {
433 $this->lb->closeAll( __METHOD__ );
452 public function report( $final =
false ) {
453 if ( $final xor ( $this->
revCount % $this->reportingInterval == 0 ) ) {
459 if ( $this->reporting ) {
461 $nowts = microtime(
true );
469 $eta = $this->startTime + $deltaAll / $portion;
471 $pageRate = $this->pageCount / $deltaAll;
472 $revRate = $this->
revCount / $deltaAll;
479 $pageRatePart = $this->pageCountPart / $deltaPart;
480 $revRatePart = $this->revCountPart / $deltaPart;
486 $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
488 "%s: %s (ID %d) %d pages (%0.1f|%0.1f/sec all|curr), "
489 .
"%d revs (%0.1f|%0.1f/sec all|curr), ETA %s [max %d]",
490 $now, $dbDomain, $this->ID, $this->pageCount, $pageRate,
491 $pageRatePart, $this->
revCount, $revRate, $revRatePart, $etats,
494 $this->lastTime = $nowts;
500 if ( $this->reporting ) {
501 fwrite( $this->stderr, $string .
"\n" );
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
string null $server
null means use default
array null $limitNamespaces
dump( $history, $text=WikiExporter::TEXT)
setDB(IMaintainableDatabase $db)
Force the dump to use the provided database connection for database operations, wherever possible.
registerFilter( $name, $class)
string null $thisRevModel
execute()
Do the actual work.
IMaintainableDatabase null $forcedDb
The dependency-injected database to use.
DumpMultiWriter DumpOutput null $sink
Output filters.
bool $skipHeader
don't output <mediawiki> and <siteinfo>
bool $skipFooter
don't output </mediawiki>
finalSetup(SettingsBuilder $settingsBuilder=null)
Handle some last-minute setup here.
string[] null $pages
null means all pages
string null $thisRevFormat
initProgress( $history=WikiExporter::FULL)
Initialise starting time and maximum revision count.
string null $schemaVersion
null means use default
processOptions()
Processes arguments and sets $this->$sink accordingly.
registerOutput( $name, $class)
bool $dumpUploadFileContents
ExportProgressFilter $egress
loadPlugin( $class, $file)
Load a plugin and register it.
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.
array $orderedOptions
Used to read the options in the order they were passed.
hasOption( $name)
Checks to see if a particular option was set.
loadWithArgv( $argv)
Load params and arguments from a given array of command-line arguments.
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.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
A class containing constants representing the names of configuration variables.
static schemaVersion()
Returns the default export schema version, as defined by the XmlDumpSchemaVersion setting.
static string[] $supportedSchemas
the schema versions supported for output @final
$wgDBserver
Config variable stub for the DBserver setting, for use by phpdoc and IDEs.
Advanced database interface for IDatabase handles that include maintenance methods.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.