28require_once __DIR__ .
'/../Maintenance.php';
29require_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,
'o',
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 [ $opt, $param ] ) {
199 $val = explode(
':', $param, 2 );
201 if ( count( $val ) === 1 ) {
203 } elseif ( count( $val ) === 2 ) {
209 $split = explode(
':', $param, 2 );
210 if ( count( $split ) !== 2 ) {
211 $this->
fatalError(
'Invalid output parameter' );
214 if (
$sink !==
null ) {
217 if ( !isset( $this->outputTypes[
$type] ) ) {
218 $this->
fatalError(
"Unrecognized output sink type '$type'" );
220 $class = $this->outputTypes[
$type];
221 if (
$type ===
"7zip" ) {
229 if (
$sink ===
null ) {
233 $split = explode(
':', $param, 2 );
236 if ( !isset( $this->filterTypes[$key] ) ) {
237 $this->
fatalError(
"Unrecognized filter type '$key'" );
240 $type = $this->filterTypes[$key];
242 if ( count( $split ) === 1 ) {
244 } elseif ( count( $split ) === 2 ) {
253 case 'schema-version':
254 if ( !in_array( $param, XmlDumpWriter::$supportedSchemas ) ) {
256 "Unsupported schema version $param. Supported versions: " .
257 implode(
', ', XmlDumpWriter::$supportedSchemas )
260 $this->schemaVersion = $param;
266 $this->reportingInterval = intval( $this->
getOption(
'report' ) );
270 $this->server = $this->
getOption(
'server' );
273 if (
$sink ===
null ) {
278 if ( count( $sinks ) > 1 ) {
286 # Notice messages will foul up your XML output even if they're
287 # relatively harmless.
288 if ( ini_get(
'display_errors' ) ) {
289 ini_set(
'display_errors',
'stderr' );
295 $exporter =
new WikiExporter( $db, $history, $text, $this->limitNamespaces );
296 $exporter->setSchemaVersion( $this->schemaVersion );
301 $exporter->setOutputSink( $wrapper );
303 if ( !$this->skipHeader ) {
304 $exporter->openStream();
306 # Log item dumps: all or by range
308 if ( $this->startId || $this->endId ) {
309 $exporter->logsByRange( $this->startId, $this->endId );
311 $exporter->allLogs();
313 } elseif ( $this->pages ===
null ) {
314 # Page dumps: all or by page ID range
315 if ( $this->startId || $this->endId ) {
316 $exporter->pagesByRange( $this->startId, $this->endId, $this->orderRevs );
317 } elseif ( $this->revStartId || $this->revEndId ) {
318 $exporter->revsByRange( $this->revStartId, $this->revEndId );
320 $exporter->allPages();
323 # Dump of specific pages
324 $exporter->pagesByName( $this->pages );
327 if ( !$this->skipFooter ) {
328 $exporter->closeStream();
345 if ( $this->forcedDb ===
null ) {
348 $this->maxCount =
$dbr->selectField( $table,
"MAX($field)",
'', __METHOD__ );
349 $this->startTime = microtime(
true );
351 $this->ID = getmypid();
361 if ( $this->forcedDb !==
null ) {
365 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
366 $this->lb = $lbFactory->newMainLB();
367 $db = $this->lb->getMaintenanceConnectionRef(
DB_REPLICA,
'dump' );
383 parent::setDB( $db );
384 $this->forcedDb = $db;
388 if ( isset( $this->lb ) ) {
389 $this->lb->closeAll( __METHOD__ );
408 public function report( $final =
false ) {
409 if ( $final xor ( $this->
revCount % $this->reportingInterval == 0 ) ) {
415 if ( $this->reporting ) {
417 $nowts = microtime(
true );
425 $eta = $this->startTime + $deltaAll / $portion;
427 $pageRate = $this->pageCount / $deltaAll;
428 $revRate = $this->
revCount / $deltaAll;
435 $pageRatePart = $this->pageCountPart / $deltaPart;
436 $revRatePart = $this->revCountPart / $deltaPart;
442 $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
444 "%s: %s (ID %d) %d pages (%0.1f|%0.1f/sec all|curr), "
445 .
"%d revs (%0.1f|%0.1f/sec all|curr), ETA %s [max %d]",
446 $now, $dbDomain, $this->ID, $this->pageCount, $pageRate,
447 $pageRatePart, $this->
revCount, $revRate, $revRatePart, $etats,
450 $this->lastTime = $nowts;
456 if ( $this->reporting ) {
457 fwrite( $this->stderr, $string .
"\n" );
$wgDBserver
Database host name or IP address.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
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.
string null $thisRevFormat
initProgress( $history=WikiExporter::FULL)
Initialise starting time and maximum revision count.
processOptions()
Processes arguments and sets $this->$sink accordingly.
registerOutput( $name, $class)
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.
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.
static schemaVersion()
Returns the default export schema version, as defined by $wgXmlDumpSchemaVersion.
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.