28 require_once __DIR__ .
'/../Maintenance.php';
29 require_once __DIR__ .
'/../../includes/export/WikiExporter.php';
113 parent::__construct();
114 $this->stderr = fopen(
"php://stderr",
"wt" );
129 $this->
addOption(
'plugin',
'Load a dump plugin class. Specify as <class>[:<file>].',
130 false,
true,
false,
true );
131 $this->
addOption(
'output',
'Begin a filtered output stream; Specify as <type>:<file>. ' .
132 '<type>s: file, gzip, bzip2, 7zip, dbzip2, lbzip2',
false,
true,
false,
true );
133 $this->
addOption(
'filter',
'Add a filter on an output branch. Specify as ' .
134 '<type>[:<options>]. <types>s: latest, notalk, namespace',
false,
true,
false,
true );
135 $this->
addOption(
'report',
'Report position and speed after every n pages processed. ' .
136 'Default: 100.',
false,
true );
137 $this->
addOption(
'schema-version',
'Schema version to use for output. ' .
139 $this->
addOption(
'server',
'Force reading from MySQL server',
false,
true );
140 $this->
addOption(
'7ziplevel',
'7zip compression level for all 7zip outputs. Used for ' .
141 '-mx option to 7za command.',
false,
true );
156 $this->outputTypes[$name] = $class;
164 $this->filterTypes[$name] = $class;
178 $register = [ $class,
'register' ];
183 throw new MWException(
'execute() must be overridden in subclasses' );
196 foreach ( $options as $arg ) {
197 list( $opt, $param ) = $arg;
201 $val = explode(
':', $param, 2 );
203 if ( count( $val ) === 1 ) {
205 } elseif ( count( $val ) === 2 ) {
211 $split = explode(
':', $param, 2 );
212 if ( count( $split ) !== 2 ) {
213 $this->
fatalError(
'Invalid output parameter' );
216 if ( !is_null(
$sink ) ) {
219 if ( !isset( $this->outputTypes[
$type] ) ) {
220 $this->
fatalError(
"Unrecognized output sink type '$type'" );
222 $class = $this->outputTypes[
$type];
223 if (
$type ===
"7zip" ) {
231 if ( is_null(
$sink ) ) {
235 $split = explode(
':', $param, 2 );
238 if ( !isset( $this->filterTypes[$key] ) ) {
239 $this->
fatalError(
"Unrecognized filter type '$key'" );
242 $type = $this->filterTypes[$key];
244 if ( count( $split ) === 1 ) {
246 } elseif ( count( $split ) === 2 ) {
255 case 'schema-version':
258 "Unsupported schema version $param. Supported versions: " .
262 $this->schemaVersion = $param;
268 $this->reportingInterval = intval( $this->
getOption(
'report' ) );
272 $this->server = $this->
getOption(
'server' );
275 if ( is_null(
$sink ) ) {
280 if ( count( $sinks ) > 1 ) {
288 # Notice messages will foul up your XML output even if they're
289 # relatively harmless.
290 if ( ini_get(
'display_errors' ) ) {
291 ini_set(
'display_errors',
'stderr' );
297 $exporter =
new WikiExporter( $db, $history, $text, $this->limitNamespaces );
298 $exporter->setSchemaVersion( $this->schemaVersion );
303 $exporter->setOutputSink( $wrapper );
305 if ( !$this->skipHeader ) {
306 $exporter->openStream();
308 # Log item dumps: all or by range
310 if ( $this->startId || $this->endId ) {
311 $exporter->logsByRange( $this->startId, $this->endId );
313 $exporter->allLogs();
315 } elseif ( is_null( $this->pages ) ) {
316 # Page dumps: all or by page ID range
317 if ( $this->startId || $this->endId ) {
318 $exporter->pagesByRange( $this->startId, $this->endId, $this->orderRevs );
319 } elseif ( $this->revStartId || $this->revEndId ) {
320 $exporter->revsByRange( $this->revStartId, $this->revEndId );
322 $exporter->allPages();
325 # Dump of specific pages
326 $exporter->pagesByName( $this->pages );
329 if ( !$this->skipFooter ) {
330 $exporter->closeStream();
347 if ( $this->forcedDb ===
null ) {
350 $this->maxCount =
$dbr->selectField( $table,
"MAX($field)",
'', __METHOD__ );
351 $this->startTime = microtime(
true );
353 $this->ID = getmypid();
363 if ( $this->forcedDb !==
null ) {
367 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
368 $this->lb = $lbFactory->newMainLB();
369 $db = $this->lb->getMaintenanceConnectionRef(
DB_REPLICA,
'dump' );
385 parent::setDB( $db );
386 $this->forcedDb = $db;
390 if ( isset( $this->lb ) ) {
391 $this->lb->closeAll();
411 if ( $final xor ( $this->
revCount % $this->reportingInterval == 0 ) ) {
417 if ( $this->reporting ) {
419 $nowts = microtime(
true );
427 $eta = $this->startTime + $deltaAll / $portion;
429 $pageRate = $this->pageCount / $deltaAll;
430 $revRate = $this->
revCount / $deltaAll;
437 $pageRatePart = $this->pageCountPart / $deltaPart;
438 $revRatePart = $this->revCountPart / $deltaPart;
446 "%s: %s (ID %d) %d pages (%0.1f|%0.1f/sec all|curr), "
447 .
"%d revs (%0.1f|%0.1f/sec all|curr), ETA %s [max %d]",
448 $now, $dbDomain, $this->ID, $this->pageCount, $pageRate,
449 $pageRatePart, $this->
revCount, $revRate, $revRatePart, $etats,
452 $this->lastTime = $nowts;
458 if ( $this->reporting ) {
459 fwrite( $this->stderr, $string .
"\n" );