29require_once __DIR__ .
'/../Maintenance.php';
30require_once __DIR__ .
'/../../includes/export/WikiExporter.php';
141 parent::__construct();
142 $this->stderr = fopen(
"php://stderr",
"wt" );
157 $this->
addOption(
'plugin',
'Load a dump plugin class. Specify as <class>[:<file>].',
158 false,
true,
false,
true );
159 $this->
addOption(
'output',
'Begin a filtered output stream; Specify as <type>:<file>. ' .
160 '<type>s: file, gzip, bzip2, 7zip, dbzip2, lbzip2',
false,
true,
'o',
true );
161 $this->
addOption(
'filter',
'Add a filter on an output branch. Specify as ' .
162 '<type>[:<options>]. <types>s: latest, notalk, namespace',
false,
true,
false,
true );
163 $this->
addOption(
'report',
'Report position and speed after every n pages processed. ' .
164 'Default: 100.',
false,
true );
165 $this->
addOption(
'server',
'Force reading from MySQL server',
false,
true );
166 $this->
addOption(
'7ziplevel',
'7zip compression level for all 7zip outputs. Used for ' .
167 '-mx option to 7za command.',
false,
true );
171 $this->
addOption(
'schema-version',
'Schema version to use for output.',
false,
true );
182 parent::finalSetup( $settingsBuilder );
186 $this->
addOption(
'schema-version',
'Schema version to use for output. ' .
195 $this->outputTypes[$name] = $class;
203 $this->filterTypes[$name] = $class;
217 $register = [ $class,
'register' ];
228 $this->schemaVersion = WikiExporter::schemaVersion();
231 foreach ( $options as [ $opt, $param ] ) {
234 $val = explode(
':', $param, 2 );
236 if ( count( $val ) === 1 ) {
238 } elseif ( count( $val ) === 2 ) {
244 $split = explode(
':', $param, 2 );
245 if ( count( $split ) !== 2 ) {
246 $this->
fatalError(
'Invalid output parameter' );
248 [ $type, $file ] = $split;
249 if (
$sink !==
null ) {
252 if ( !isset( $this->outputTypes[$type] ) ) {
253 $this->
fatalError(
"Unrecognized output sink type '$type'" );
255 $class = $this->outputTypes[$type];
256 if ( $type ===
"7zip" ) {
257 $sink =
new $class( $file, intval( $this->
getOption(
'7ziplevel' ) ) );
259 $sink =
new $class( $file );
266 $split = explode(
':', $param, 2 );
269 if ( !isset( $this->filterTypes[$key] ) ) {
270 $this->
fatalError(
"Unrecognized filter type '$key'" );
273 $type = $this->filterTypes[$key];
275 if ( count( $split ) === 2 ) {
276 $filter =
new $type(
$sink, $split[1] );
278 $filter =
new $type(
$sink );
286 case 'schema-version':
287 if ( !in_array( $param, XmlDumpWriter::$supportedSchemas ) ) {
289 "Unsupported schema version $param. Supported versions: " .
290 implode(
', ', XmlDumpWriter::$supportedSchemas )
293 $this->schemaVersion = $param;
299 $this->reportingInterval = intval( $this->
getOption(
'report' ) );
303 $this->server = $this->
getOption(
'server' );
309 if ( count( $sinks ) > 1 ) {
316 public function dump( $history, $text = WikiExporter::TEXT ) {
317 # Notice messages will foul up your XML output even if they're
318 # relatively harmless.
319 if ( ini_get(
'display_errors' ) ) {
320 ini_set(
'display_errors',
'stderr' );
327 $exporter = $services->getWikiExporterFactory()->getWikiExporter(
331 $this->limitNamespaces
333 $exporter->setSchemaVersion( $this->schemaVersion );
338 $exporter->setOutputSink( $wrapper );
340 if ( !$this->skipHeader ) {
341 $exporter->openStream();
343 # Log item dumps: all or by range
344 if ( $history & WikiExporter::LOGS ) {
345 if ( $this->startId || $this->endId ) {
346 $exporter->logsByRange( $this->startId, $this->endId );
348 $exporter->allLogs();
350 } elseif ( $this->pages ===
null ) {
351 # Page dumps: all or by page ID range
352 if ( $this->startId || $this->endId ) {
353 $exporter->pagesByRange( $this->startId, $this->endId, $this->orderRevs );
354 } elseif ( $this->revStartId || $this->revEndId ) {
355 $exporter->revsByRange( $this->revStartId, $this->revEndId );
357 $exporter->allPages();
360 # Dump of specific pages
361 $exporter->pagesByName( $this->pages );
364 if ( !$this->skipFooter ) {
365 $exporter->closeStream();
378 $table = ( $history == WikiExporter::CURRENT ) ?
'page' :
'revision';
379 $field = ( $history == WikiExporter::CURRENT ) ?
'page_id' :
'rev_id';
382 if ( $this->forcedDb ===
null ) {
385 $this->maxCount = $dbr->newSelectQueryBuilder()
386 ->select(
"MAX($field)" )
388 ->caller( __METHOD__ )->fetchField();
389 $this->startTime = microtime(
true );
391 $this->ID = getmypid();
401 if ( $this->forcedDb !==
null ) {
406 $this->lb = $lbFactory->newMainLB();
407 $db = $this->lb->getMaintenanceConnectionRef(
DB_REPLICA,
'dump' );
423 parent::setDB( $db );
424 $this->forcedDb = $db;
428 if ( isset( $this->lb ) ) {
429 $this->lb->closeAll( __METHOD__ );
448 public function report( $final =
false ) {
449 if ( $final xor ( $this->
revCount % $this->reportingInterval == 0 ) ) {
455 if ( $this->reporting ) {
457 $nowts = microtime(
true );
465 $eta = $this->startTime + $deltaAll / $portion;
467 $pageRate = $this->pageCount / $deltaAll;
468 $revRate = $this->
revCount / $deltaAll;
475 $pageRatePart = $this->pageCountPart / $deltaPart;
476 $revRatePart = $this->revCountPart / $deltaPart;
482 $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
484 "%s: %s (ID %d) %d pages (%0.1f|%0.1f/sec all|curr), "
485 .
"%d revs (%0.1f|%0.1f/sec all|curr), ETA %s [max %d]",
486 $now, $dbDomain, $this->ID, $this->pageCount, $pageRate,
487 $pageRatePart, $this->
revCount, $revRate, $revRatePart, $etats,
490 $this->lastTime = $nowts;
496 if ( $this->reporting ) {
497 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
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>
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
finalSetup(SettingsBuilder $settingsBuilder)
Handle some last-minute setup here.
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...
array $orderedOptions
Used to read the options in the order they were passed.
hasOption( $name)
Checks to see if a particular option was set.
getServiceContainer()
Returns the main service container.
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.
$wgDBserver
Config variable stub for the DBserver setting, for use by phpdoc and IDEs.
Advanced database interface for IDatabase handles that include maintenance methods.