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 $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 (
$sink !==
null ) {
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 (
$sink ===
null ) {
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':
256 if ( !in_array( $param, XmlDumpWriter::$supportedSchemas ) ) {
258 "Unsupported schema version $param. Supported versions: " .
259 implode(
', ', XmlDumpWriter::$supportedSchemas )
262 $this->schemaVersion = $param;
268 $this->reportingInterval = intval( $this->
getOption(
'report' ) );
272 $this->server = $this->
getOption(
'server' );
275 if (
$sink ===
null ) {
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 ( $this->pages ===
null ) {
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( __METHOD__ );
410 public function report( $final =
false ) {
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;
444 $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
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" );
$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.