28require_once __DIR__ .
'/../Maintenance.php';
29require_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' ];
220 throw new MWException(
'execute() must be overridden in subclasses' );
230 $this->schemaVersion = WikiExporter::schemaVersion();
233 foreach ( $options as [ $opt, $param ] ) {
236 $val = explode(
':', $param, 2 );
238 if ( count( $val ) === 1 ) {
240 } elseif ( count( $val ) === 2 ) {
246 $split = explode(
':', $param, 2 );
247 if ( count( $split ) !== 2 ) {
248 $this->
fatalError(
'Invalid output parameter' );
251 if (
$sink !==
null ) {
254 if ( !isset( $this->outputTypes[
$type] ) ) {
255 $this->
fatalError(
"Unrecognized output sink type '$type'" );
257 $class = $this->outputTypes[
$type];
258 if (
$type ===
"7zip" ) {
266 if (
$sink ===
null ) {
270 $split = explode(
':', $param, 2 );
273 if ( !isset( $this->filterTypes[$key] ) ) {
274 $this->
fatalError(
"Unrecognized filter type '$key'" );
277 $type = $this->filterTypes[$key];
279 if ( count( $split ) === 2 ) {
290 case 'schema-version':
291 if ( !in_array( $param, XmlDumpWriter::$supportedSchemas ) ) {
293 "Unsupported schema version $param. Supported versions: " .
294 implode(
', ', XmlDumpWriter::$supportedSchemas )
297 $this->schemaVersion = $param;
303 $this->reportingInterval = intval( $this->
getOption(
'report' ) );
307 $this->server = $this->
getOption(
'server' );
310 if (
$sink ===
null ) {
315 if ( count( $sinks ) > 1 ) {
322 public function dump( $history, $text = WikiExporter::TEXT ) {
323 # Notice messages will foul up your XML output even if they're
324 # relatively harmless.
325 if ( ini_get(
'display_errors' ) ) {
326 ini_set(
'display_errors',
'stderr' );
332 $services = MediaWikiServices::getInstance();
333 $exporter = $services->getWikiExporterFactory()->getWikiExporter(
337 $this->limitNamespaces
339 $exporter->setSchemaVersion( $this->schemaVersion );
344 $exporter->setOutputSink( $wrapper );
346 if ( !$this->skipHeader ) {
347 $exporter->openStream();
349 # Log item dumps: all or by range
350 if ( $history & WikiExporter::LOGS ) {
351 if ( $this->startId || $this->endId ) {
352 $exporter->logsByRange( $this->startId, $this->endId );
354 $exporter->allLogs();
356 } elseif ( $this->pages ===
null ) {
357 # Page dumps: all or by page ID range
358 if ( $this->startId || $this->endId ) {
359 $exporter->pagesByRange( $this->startId, $this->endId, $this->orderRevs );
360 } elseif ( $this->revStartId || $this->revEndId ) {
361 $exporter->revsByRange( $this->revStartId, $this->revEndId );
363 $exporter->allPages();
366 # Dump of specific pages
367 $exporter->pagesByName( $this->pages );
370 if ( !$this->skipFooter ) {
371 $exporter->closeStream();
384 $table = ( $history == WikiExporter::CURRENT ) ?
'page' :
'revision';
385 $field = ( $history == WikiExporter::CURRENT ) ?
'page_id' :
'rev_id';
388 if ( $this->forcedDb ===
null ) {
391 $this->maxCount =
$dbr->selectField( $table,
"MAX($field)",
'', __METHOD__ );
392 $this->startTime = microtime(
true );
394 $this->ID = getmypid();
404 if ( $this->forcedDb !==
null ) {
408 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
409 $this->lb = $lbFactory->newMainLB();
410 $db = $this->lb->getMaintenanceConnectionRef(
DB_REPLICA,
'dump' );
426 parent::setDB( $db );
427 $this->forcedDb = $db;
431 if ( isset( $this->lb ) ) {
432 $this->lb->closeAll( __METHOD__ );
451 public function report( $final =
false ) {
452 if ( $final xor ( $this->
revCount % $this->reportingInterval == 0 ) ) {
458 if ( $this->reporting ) {
460 $nowts = microtime(
true );
468 $eta = $this->startTime + $deltaAll / $portion;
470 $pageRate = $this->pageCount / $deltaAll;
471 $revRate = $this->
revCount / $deltaAll;
478 $pageRatePart = $this->pageCountPart / $deltaPart;
479 $revRatePart = $this->revCountPart / $deltaPart;
485 $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
487 "%s: %s (ID %d) %d pages (%0.1f|%0.1f/sec all|curr), "
488 .
"%d revs (%0.1f|%0.1f/sec all|curr), ETA %s [max %d]",
489 $now, $dbDomain, $this->ID, $this->pageCount, $pageRate,
490 $pageRatePart, $this->
revCount, $revRate, $revRatePart, $etats,
493 $this->lastTime = $nowts;
499 if ( $this->reporting ) {
500 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
execute()
Do the actual work.
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...
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.
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.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.