28 require_once __DIR__ .
'/../Maintenance.php';
29 require_once __DIR__ .
'/../../includes/export/WikiExporter.php';
139 parent::__construct();
140 $this->stderr = fopen(
"php://stderr",
"wt" );
155 $this->
addOption(
'plugin',
'Load a dump plugin class. Specify as <class>[:<file>].',
156 false,
true,
false,
true );
157 $this->
addOption(
'output',
'Begin a filtered output stream; Specify as <type>:<file>. ' .
158 '<type>s: file, gzip, bzip2, 7zip, dbzip2, lbzip2',
false,
true,
'o',
true );
159 $this->
addOption(
'filter',
'Add a filter on an output branch. Specify as ' .
160 '<type>[:<options>]. <types>s: latest, notalk, namespace',
false,
true,
false,
true );
161 $this->
addOption(
'report',
'Report position and speed after every n pages processed. ' .
162 'Default: 100.',
false,
true );
163 $this->
addOption(
'server',
'Force reading from MySQL server',
false,
true );
164 $this->
addOption(
'7ziplevel',
'7zip compression level for all 7zip outputs. Used for ' .
165 '-mx option to 7za command.',
false,
true );
169 $this->
addOption(
'schema-version',
'Schema version to use for output.',
false,
true );
180 parent::finalSetup( $settingsBuilder );
183 $schemaVersion = $settingsBuilder->getConfig()->get( MainConfigNames::XmlDumpSchemaVersion );
184 $this->
addOption(
'schema-version',
'Schema version to use for output. ' .
193 $this->outputTypes[$name] = $class;
201 $this->filterTypes[$name] = $class;
215 $register = [ $class,
'register' ];
229 foreach ( $options as [ $opt, $param ] ) {
232 $val = explode(
':', $param, 2 );
234 if ( count( $val ) === 1 ) {
236 } elseif ( count( $val ) === 2 ) {
242 $split = explode(
':', $param, 2 );
243 if ( count( $split ) !== 2 ) {
244 $this->
fatalError(
'Invalid output parameter' );
246 [ $type,
$file ] = $split;
247 if (
$sink !==
null ) {
250 if ( !isset( $this->outputTypes[$type] ) ) {
251 $this->
fatalError(
"Unrecognized output sink type '$type'" );
253 $class = $this->outputTypes[$type];
254 if ( $type ===
"7zip" ) {
262 if (
$sink ===
null ) {
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':
289 "Unsupported schema version $param. Supported versions: " .
293 $this->schemaVersion = $param;
299 $this->reportingInterval = intval( $this->
getOption(
'report' ) );
303 $this->server = $this->
getOption(
'server' );
306 if (
$sink ===
null ) {
311 if ( count( $sinks ) > 1 ) {
319 # Notice messages will foul up your XML output even if they're
320 # relatively harmless.
321 if ( ini_get(
'display_errors' ) ) {
322 ini_set(
'display_errors',
'stderr' );
329 $exporter = $services->getWikiExporterFactory()->getWikiExporter(
333 $this->limitNamespaces
335 $exporter->setSchemaVersion( $this->schemaVersion );
340 $exporter->setOutputSink( $wrapper );
342 if ( !$this->skipHeader ) {
343 $exporter->openStream();
345 # Log item dumps: all or by range
347 if ( $this->startId || $this->endId ) {
348 $exporter->logsByRange( $this->startId, $this->endId );
350 $exporter->allLogs();
352 } elseif ( $this->pages ===
null ) {
353 # Page dumps: all or by page ID range
354 if ( $this->startId || $this->endId ) {
355 $exporter->pagesByRange( $this->startId, $this->endId, $this->orderRevs );
356 } elseif ( $this->revStartId || $this->revEndId ) {
357 $exporter->revsByRange( $this->revStartId, $this->revEndId );
359 $exporter->allPages();
362 # Dump of specific pages
363 $exporter->pagesByName( $this->pages );
366 if ( !$this->skipFooter ) {
367 $exporter->closeStream();
384 if ( $this->forcedDb ===
null ) {
387 $this->maxCount = $dbr->newSelectQueryBuilder()
388 ->select(
"MAX($field)" )
390 ->caller( __METHOD__ )->fetchField();
391 $this->startTime = microtime(
true );
393 $this->ID = getmypid();
403 if ( $this->forcedDb !==
null ) {
408 $this->lb = $lbFactory->newMainLB();
409 $db = $this->lb->getMaintenanceConnectionRef(
DB_REPLICA,
'dump' );
413 $db->setSessionOptions( [
'connTimeout' => 3600 * 24 ] );
425 parent::setDB( $db );
426 $this->forcedDb = $db;
430 if ( isset( $this->lb ) ) {
431 $this->lb->closeAll( __METHOD__ );
450 public function report( $final =
false ) {
451 if ( $final xor ( $this->
revCount % $this->reportingInterval == 0 ) ) {
457 if ( $this->reporting ) {
459 $nowts = microtime(
true );
467 $eta = $this->startTime + $deltaAll / $portion;
469 $pageRate = $this->pageCount / $deltaAll;
470 $revRate = $this->
revCount / $deltaAll;
477 $pageRatePart = $this->pageCountPart / $deltaPart;
478 $revRatePart = $this->revCountPart / $deltaPart;
484 $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
486 "%s: %s (ID %d) %d pages (%0.1f|%0.1f/sec all|curr), "
487 .
"%d revs (%0.1f|%0.1f/sec all|curr), ETA %s [max %d]",
488 $now, $dbDomain, $this->ID, $this->pageCount, $pageRate,
489 $pageRatePart, $this->
revCount, $revRate, $revRatePart, $etats,
492 $this->lastTime = $nowts;
498 if ( $this->reporting ) {
499 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>
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.
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.
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.