2005-10-16 17:33:41 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2010-09-05 13:15:48 +00:00
|
|
|
* Base classes for database dumpers
|
|
|
|
|
*
|
|
|
|
|
* Copyright © 2005 Brion Vibber <brion@pobox.com>
|
2014-03-20 15:45:01 +00:00
|
|
|
* https://www.mediawiki.org/
|
2006-01-07 13:09:30 +00:00
|
|
|
*
|
2005-10-16 17:33:41 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2006-01-07 13:09:30 +00:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
2005-10-16 17:33:41 +00:00
|
|
|
* (at your option) any later version.
|
2006-01-07 13:09:30 +00:00
|
|
|
*
|
2005-10-16 17:33:41 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
2006-01-07 13:09:30 +00:00
|
|
|
*
|
2005-10-16 17:33:41 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
2006-04-05 07:43:17 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-10-16 17:33:41 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @file
|
|
|
|
|
* @ingroup Dump Maintenance
|
2005-10-16 17:33:41 +00:00
|
|
|
*/
|
|
|
|
|
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
/**
|
|
|
|
|
* @ingroup Dump Maintenance
|
|
|
|
|
*/
|
2006-06-27 04:42:53 +00:00
|
|
|
class DumpDBZip2Output extends DumpPipeOutput {
|
2012-04-07 20:41:31 +00:00
|
|
|
function __construct( $file ) {
|
2010-09-22 13:54:53 +00:00
|
|
|
parent::__construct( "dbzip2", $file );
|
2006-06-27 04:42:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
2005-10-16 17:33:41 +00:00
|
|
|
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
/**
|
|
|
|
|
* @ingroup Dump Maintenance
|
|
|
|
|
*/
|
2005-10-16 17:33:41 +00:00
|
|
|
class BackupDumper {
|
2014-04-23 11:45:13 +00:00
|
|
|
public $reporting = true;
|
|
|
|
|
public $pages = null; // all pages
|
|
|
|
|
public $skipHeader = false; // don't output <mediawiki> and <siteinfo>
|
|
|
|
|
public $skipFooter = false; // don't output </mediawiki>
|
|
|
|
|
public $startId = 0;
|
|
|
|
|
public $endId = 0;
|
|
|
|
|
public $revStartId = 0;
|
|
|
|
|
public $revEndId = 0;
|
|
|
|
|
public $dumpUploads = false;
|
|
|
|
|
public $dumpUploadFileContents = false;
|
|
|
|
|
|
|
|
|
|
protected $reportingInterval = 100;
|
|
|
|
|
protected $pageCount = 0;
|
|
|
|
|
protected $revCount = 0;
|
|
|
|
|
protected $server = null; // use default
|
|
|
|
|
protected $sink = null; // Output filters
|
|
|
|
|
protected $lastTime = 0;
|
|
|
|
|
protected $pageCountLast = 0;
|
|
|
|
|
protected $revCountLast = 0;
|
|
|
|
|
|
|
|
|
|
protected $outputTypes = array();
|
|
|
|
|
protected $filterTypes = array();
|
|
|
|
|
|
|
|
|
|
protected $ID = 0;
|
2011-09-16 21:50:30 +00:00
|
|
|
|
2012-04-03 09:23:20 +00:00
|
|
|
/**
|
|
|
|
|
* The dependency-injected database to use.
|
|
|
|
|
*
|
|
|
|
|
* @var DatabaseBase|null
|
|
|
|
|
*
|
|
|
|
|
* @see self::setDb
|
|
|
|
|
*/
|
|
|
|
|
protected $forcedDb = null;
|
|
|
|
|
|
2014-04-23 11:45:13 +00:00
|
|
|
/** @var LoadBalancer */
|
2011-09-16 21:50:30 +00:00
|
|
|
protected $lb;
|
|
|
|
|
|
2014-04-23 11:45:13 +00:00
|
|
|
// @todo Unused?
|
|
|
|
|
private $stubText = false; // include rev_text_id instead of text; for 2-pass dump
|
|
|
|
|
|
2011-09-16 21:50:30 +00:00
|
|
|
function __construct( $args ) {
|
2005-10-16 17:33:41 +00:00
|
|
|
$this->stderr = fopen( "php://stderr", "wt" );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-12-14 20:56:43 +00:00
|
|
|
// Built-in output and filter plugins
|
|
|
|
|
$this->registerOutput( 'file', 'DumpFileOutput' );
|
|
|
|
|
$this->registerOutput( 'gzip', 'DumpGZipOutput' );
|
|
|
|
|
$this->registerOutput( 'bzip2', 'DumpBZip2Output' );
|
2006-06-27 04:42:53 +00:00
|
|
|
$this->registerOutput( 'dbzip2', 'DumpDBZip2Output' );
|
2005-12-14 20:56:43 +00:00
|
|
|
$this->registerOutput( '7zip', 'Dump7ZipOutput' );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-12-14 20:56:43 +00:00
|
|
|
$this->registerFilter( 'latest', 'DumpLatestFilter' );
|
|
|
|
|
$this->registerFilter( 'notalk', 'DumpNotalkFilter' );
|
|
|
|
|
$this->registerFilter( 'namespace', 'DumpNamespaceFilter' );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-10-16 17:33:41 +00:00
|
|
|
$this->sink = $this->processArgs( $args );
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-12-14 20:56:43 +00:00
|
|
|
/**
|
2014-04-17 20:48:32 +00:00
|
|
|
* @param string $name
|
|
|
|
|
* @param string $class Name of output filter plugin class
|
2005-12-14 20:56:43 +00:00
|
|
|
*/
|
|
|
|
|
function registerOutput( $name, $class ) {
|
|
|
|
|
$this->outputTypes[$name] = $class;
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-12-14 20:56:43 +00:00
|
|
|
/**
|
2014-04-17 20:48:32 +00:00
|
|
|
* @param string $name
|
|
|
|
|
* @param string $class Name of filter plugin class
|
2005-12-14 20:56:43 +00:00
|
|
|
*/
|
|
|
|
|
function registerFilter( $name, $class ) {
|
|
|
|
|
$this->filterTypes[$name] = $class;
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-12-14 20:56:43 +00:00
|
|
|
/**
|
|
|
|
|
* Load a plugin and register it
|
2010-03-03 21:28:03 +00:00
|
|
|
*
|
2014-04-17 20:48:32 +00:00
|
|
|
* @param string $class Name of plugin class; must have a static 'register'
|
|
|
|
|
* method that takes a BackupDumper as a parameter.
|
|
|
|
|
* @param string $file Full or relative path to the PHP file to load, or empty
|
2005-12-14 20:56:43 +00:00
|
|
|
*/
|
|
|
|
|
function loadPlugin( $class, $file ) {
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( $file != '' ) {
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once $file;
|
2005-12-14 20:56:43 +00:00
|
|
|
}
|
|
|
|
|
$register = array( $class, 'register' );
|
|
|
|
|
call_user_func_array( $register, array( &$this ) );
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-10-16 17:33:41 +00:00
|
|
|
/**
|
2014-04-17 20:48:32 +00:00
|
|
|
* @param array $args
|
|
|
|
|
* @return array
|
2005-10-16 17:33:41 +00:00
|
|
|
*/
|
|
|
|
|
function processArgs( $args ) {
|
|
|
|
|
$sink = null;
|
|
|
|
|
$sinks = array();
|
2010-05-22 16:50:39 +00:00
|
|
|
foreach ( $args as $arg ) {
|
2007-01-12 05:50:03 +00:00
|
|
|
$matches = array();
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( preg_match( '/^--(.+?)(?:=(.+?)(?::(.+?))?)?$/', $arg, $matches ) ) {
|
2014-04-23 11:45:13 +00:00
|
|
|
wfSuppressWarnings();
|
2014-04-23 18:08:06 +00:00
|
|
|
list( /* $full */, $opt, $val, $param ) = $matches;
|
2014-04-23 11:45:13 +00:00
|
|
|
wfRestoreWarnings();
|
|
|
|
|
|
2013-04-26 14:42:31 +00:00
|
|
|
switch ( $opt ) {
|
2014-04-23 18:08:06 +00:00
|
|
|
case "plugin":
|
|
|
|
|
$this->loadPlugin( $val, $param );
|
|
|
|
|
break;
|
|
|
|
|
case "output":
|
|
|
|
|
if ( !is_null( $sink ) ) {
|
|
|
|
|
$sinks[] = $sink;
|
|
|
|
|
}
|
|
|
|
|
if ( !isset( $this->outputTypes[$val] ) ) {
|
|
|
|
|
$this->fatalError( "Unrecognized output sink type '$val'" );
|
|
|
|
|
}
|
|
|
|
|
$type = $this->outputTypes[$val];
|
|
|
|
|
$sink = new $type( $param );
|
|
|
|
|
break;
|
|
|
|
|
case "filter":
|
|
|
|
|
if ( is_null( $sink ) ) {
|
|
|
|
|
$sink = new DumpOutput();
|
|
|
|
|
}
|
|
|
|
|
if ( !isset( $this->filterTypes[$val] ) ) {
|
|
|
|
|
$this->fatalError( "Unrecognized filter type '$val'" );
|
|
|
|
|
}
|
|
|
|
|
$type = $this->filterTypes[$val];
|
|
|
|
|
$filter = new $type( $sink, $param );
|
|
|
|
|
|
|
|
|
|
// references are lame in php...
|
|
|
|
|
unset( $sink );
|
|
|
|
|
$sink = $filter;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case "report":
|
|
|
|
|
$this->reportingInterval = intval( $val );
|
|
|
|
|
break;
|
|
|
|
|
case "server":
|
|
|
|
|
$this->server = $val;
|
|
|
|
|
break;
|
|
|
|
|
case "force-normal":
|
|
|
|
|
if ( !function_exists( 'utf8_normalize' ) ) {
|
|
|
|
|
$this->fatalError( "UTF-8 normalization extension not loaded. " .
|
|
|
|
|
"Install or remove --force-normal parameter to use slower code." );
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
$this->processOption( $opt, $val, $param );
|
2005-10-16 17:33:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( is_null( $sink ) ) {
|
2005-10-16 17:33:41 +00:00
|
|
|
$sink = new DumpOutput();
|
|
|
|
|
}
|
|
|
|
|
$sinks[] = $sink;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( count( $sinks ) > 1 ) {
|
2005-10-16 17:33:41 +00:00
|
|
|
return new DumpMultiWriter( $sinks );
|
|
|
|
|
} else {
|
|
|
|
|
return $sink;
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-10-16 17:33:41 +00:00
|
|
|
function processOption( $opt, $val, $param ) {
|
|
|
|
|
// extension point for subclasses to add options
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2008-09-18 00:02:57 +00:00
|
|
|
function dump( $history, $text = WikiExporter::TEXT ) {
|
2005-10-16 17:33:41 +00:00
|
|
|
# Notice messages will foul up your XML output even if they're
|
|
|
|
|
# relatively harmless.
|
2013-04-17 14:52:47 +00:00
|
|
|
if ( ini_get( 'display_errors' ) ) {
|
2007-12-06 21:07:49 +00:00
|
|
|
ini_set( 'display_errors', 'stderr' );
|
2013-04-17 14:52:47 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2006-01-26 08:06:05 +00:00
|
|
|
$this->initProgress( $history );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2007-03-09 15:26:41 +00:00
|
|
|
$db = $this->backupDb();
|
2006-11-04 15:27:55 +00:00
|
|
|
$exporter = new WikiExporter( $db, $history, WikiExporter::STREAM, $text );
|
2008-03-04 02:03:52 +00:00
|
|
|
$exporter->dumpUploads = $this->dumpUploads;
|
2011-04-30 21:35:09 +00:00
|
|
|
$exporter->dumpUploadFileContents = $this->dumpUploadFileContents;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-10-16 17:33:41 +00:00
|
|
|
$wrapper = new ExportProgressFilter( $this->sink, $this );
|
|
|
|
|
$exporter->setOutputSink( $wrapper );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2013-04-17 14:52:47 +00:00
|
|
|
if ( !$this->skipHeader ) {
|
2005-10-16 17:33:41 +00:00
|
|
|
$exporter->openStream();
|
2013-04-17 14:52:47 +00:00
|
|
|
}
|
2008-09-18 00:02:57 +00:00
|
|
|
# Log item dumps: all or by range
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( $history & WikiExporter::LOGS ) {
|
|
|
|
|
if ( $this->startId || $this->endId ) {
|
2008-09-18 00:02:57 +00:00
|
|
|
$exporter->logsByRange( $this->startId, $this->endId );
|
|
|
|
|
} else {
|
|
|
|
|
$exporter->allLogs();
|
|
|
|
|
}
|
2013-04-17 14:52:47 +00:00
|
|
|
} elseif ( is_null( $this->pages ) ) {
|
2014-04-23 18:08:06 +00:00
|
|
|
# Page dumps: all or by page ID range
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( $this->startId || $this->endId ) {
|
2005-10-16 17:33:41 +00:00
|
|
|
$exporter->pagesByRange( $this->startId, $this->endId );
|
2011-11-02 07:58:43 +00:00
|
|
|
} elseif ( $this->revStartId || $this->revEndId ) {
|
|
|
|
|
$exporter->revsByRange( $this->revStartId, $this->revEndId );
|
2005-10-16 17:33:41 +00:00
|
|
|
} else {
|
|
|
|
|
$exporter->allPages();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2014-04-23 18:08:06 +00:00
|
|
|
# Dump of specific pages
|
2005-10-16 17:33:41 +00:00
|
|
|
$exporter->pagesByName( $this->pages );
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-17 14:52:47 +00:00
|
|
|
if ( !$this->skipFooter ) {
|
2005-10-16 17:33:41 +00:00
|
|
|
$exporter->closeStream();
|
2013-04-17 14:52:47 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-10-16 17:33:41 +00:00
|
|
|
$this->report( true );
|
|
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2006-01-26 08:06:05 +00:00
|
|
|
/**
|
|
|
|
|
* Initialise starting time and maximum revision count.
|
|
|
|
|
* We'll make ETA calculations based an progress, assuming relatively
|
|
|
|
|
* constant per-revision rate.
|
2014-04-17 20:48:32 +00:00
|
|
|
* @param int $history WikiExporter::CURRENT or WikiExporter::FULL
|
2006-01-26 08:06:05 +00:00
|
|
|
*/
|
2006-10-11 17:58:42 +00:00
|
|
|
function initProgress( $history = WikiExporter::FULL ) {
|
2010-05-22 16:50:39 +00:00
|
|
|
$table = ( $history == WikiExporter::CURRENT ) ? 'page' : 'revision';
|
|
|
|
|
$field = ( $history == WikiExporter::CURRENT ) ? 'page_id' : 'rev_id';
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2012-04-03 09:23:20 +00:00
|
|
|
$dbr = $this->forcedDb;
|
|
|
|
|
if ( $this->forcedDb === null ) {
|
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
|
}
|
2010-12-03 10:08:47 +00:00
|
|
|
$this->maxCount = $dbr->selectField( $table, "MAX($field)", '', __METHOD__ );
|
2012-09-04 19:05:40 +00:00
|
|
|
$this->startTime = microtime( true );
|
2011-08-28 19:06:52 +00:00
|
|
|
$this->lastTime = $this->startTime;
|
|
|
|
|
$this->ID = getmypid();
|
2006-01-26 08:06:05 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2009-09-14 22:32:30 +00:00
|
|
|
/**
|
2010-03-03 21:28:03 +00:00
|
|
|
* @todo Fixme: the --server parameter is currently not respected, as it
|
|
|
|
|
* doesn't seem terribly easy to ask the load balancer for a particular
|
|
|
|
|
* connection by name.
|
2011-10-18 17:31:54 +00:00
|
|
|
* @return DatabaseBase
|
2009-09-14 22:32:30 +00:00
|
|
|
*/
|
2007-03-09 15:26:41 +00:00
|
|
|
function backupDb() {
|
2012-04-03 09:23:20 +00:00
|
|
|
if ( $this->forcedDb !== null ) {
|
|
|
|
|
return $this->forcedDb;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-14 22:32:30 +00:00
|
|
|
$this->lb = wfGetLBFactory()->newMainLB();
|
2013-10-22 18:23:02 +00:00
|
|
|
$db = $this->lb->getConnection( DB_SLAVE, 'dump' );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2007-03-09 15:26:41 +00:00
|
|
|
// Discourage the server from disconnecting us if it takes a long time
|
|
|
|
|
// to read out the big ol' batch query.
|
2012-02-09 21:08:06 +00:00
|
|
|
$db->setSessionOptions( array( 'connTimeout' => 3600 * 24 ) );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2005-10-16 17:33:41 +00:00
|
|
|
return $db;
|
|
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2012-04-03 09:23:20 +00:00
|
|
|
/**
|
|
|
|
|
* Force the dump to use the provided database connection for database
|
|
|
|
|
* operations, wherever possible.
|
|
|
|
|
*
|
2014-04-17 20:48:32 +00:00
|
|
|
* @param DatabaseBase|null $db (Optional) the database connection to use. If null, resort to
|
|
|
|
|
* use the globally provided ways to get database connections.
|
2012-04-03 09:23:20 +00:00
|
|
|
*/
|
|
|
|
|
function setDb( DatabaseBase $db = null ) {
|
|
|
|
|
$this->forcedDb = $db;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-14 22:32:30 +00:00
|
|
|
function __destruct() {
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( isset( $this->lb ) ) {
|
2009-09-14 22:32:30 +00:00
|
|
|
$this->lb->closeAll();
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-10-16 17:33:41 +00:00
|
|
|
function backupServer() {
|
|
|
|
|
global $wgDBserver;
|
2014-04-23 18:08:06 +00:00
|
|
|
|
2005-10-16 17:33:41 +00:00
|
|
|
return $this->server
|
|
|
|
|
? $this->server
|
|
|
|
|
: $wgDBserver;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function reportPage() {
|
|
|
|
|
$this->pageCount++;
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-10-16 17:33:41 +00:00
|
|
|
function revCount() {
|
|
|
|
|
$this->revCount++;
|
2006-01-26 08:06:05 +00:00
|
|
|
$this->report();
|
2005-10-16 17:33:41 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-10-16 17:33:41 +00:00
|
|
|
function report( $final = false ) {
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( $final xor ( $this->revCount % $this->reportingInterval == 0 ) ) {
|
2005-10-16 17:33:41 +00:00
|
|
|
$this->showReport();
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-10-16 17:33:41 +00:00
|
|
|
function showReport() {
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( $this->reporting ) {
|
2005-10-16 17:33:41 +00:00
|
|
|
$now = wfTimestamp( TS_DB );
|
2012-09-04 19:05:40 +00:00
|
|
|
$nowts = microtime( true );
|
|
|
|
|
$deltaAll = $nowts - $this->startTime;
|
|
|
|
|
$deltaPart = $nowts - $this->lastTime;
|
2011-08-28 19:06:52 +00:00
|
|
|
$this->pageCountPart = $this->pageCount - $this->pageCountLast;
|
|
|
|
|
$this->revCountPart = $this->revCount - $this->revCountLast;
|
|
|
|
|
|
|
|
|
|
if ( $deltaAll ) {
|
2006-01-26 08:06:05 +00:00
|
|
|
$portion = $this->revCount / $this->maxCount;
|
2011-08-28 19:06:52 +00:00
|
|
|
$eta = $this->startTime + $deltaAll / $portion;
|
2005-10-16 17:33:41 +00:00
|
|
|
$etats = wfTimestamp( TS_DB, intval( $eta ) );
|
2011-08-28 19:06:52 +00:00
|
|
|
$pageRate = $this->pageCount / $deltaAll;
|
|
|
|
|
$revRate = $this->revCount / $deltaAll;
|
2005-10-16 17:33:41 +00:00
|
|
|
} else {
|
2011-08-28 19:06:52 +00:00
|
|
|
$pageRate = '-';
|
|
|
|
|
$revRate = '-';
|
2005-10-16 17:33:41 +00:00
|
|
|
$etats = '-';
|
|
|
|
|
}
|
2011-08-28 19:06:52 +00:00
|
|
|
if ( $deltaPart ) {
|
|
|
|
|
$pageRatePart = $this->pageCountPart / $deltaPart;
|
|
|
|
|
$revRatePart = $this->revCountPart / $deltaPart;
|
|
|
|
|
} else {
|
|
|
|
|
$pageRatePart = '-';
|
|
|
|
|
$revRatePart = '-';
|
|
|
|
|
}
|
2014-04-23 11:45:13 +00:00
|
|
|
$this->progress( sprintf(
|
|
|
|
|
"%s: %s (ID %d) %d pages (%0.1f|%0.1f/sec all|curr), "
|
|
|
|
|
. "%d revs (%0.1f|%0.1f/sec all|curr), ETA %s [max %d]",
|
|
|
|
|
$now, wfWikiID(), $this->ID, $this->pageCount, $pageRate,
|
|
|
|
|
$pageRatePart, $this->revCount, $revRate, $revRatePart, $etats,
|
|
|
|
|
$this->maxCount
|
|
|
|
|
) );
|
2011-08-28 19:06:52 +00:00
|
|
|
$this->lastTime = $nowts;
|
|
|
|
|
$this->revCountLast = $this->revCount;
|
2005-10-16 17:33:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-10-16 17:33:41 +00:00
|
|
|
function progress( $string ) {
|
|
|
|
|
fwrite( $this->stderr, $string . "\n" );
|
|
|
|
|
}
|
2011-07-06 19:57:52 +00:00
|
|
|
|
|
|
|
|
function fatalError( $msg ) {
|
|
|
|
|
$this->progress( "$msg\n" );
|
2013-04-26 14:42:31 +00:00
|
|
|
die( 1 );
|
2011-07-06 19:57:52 +00:00
|
|
|
}
|
2005-10-16 17:33:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ExportProgressFilter extends DumpFilter {
|
2011-09-16 21:54:35 +00:00
|
|
|
function __construct( &$sink, &$progress ) {
|
2010-09-22 13:54:53 +00:00
|
|
|
parent::__construct( $sink );
|
2005-10-16 17:33:41 +00:00
|
|
|
$this->progress = $progress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function writeClosePage( $string ) {
|
|
|
|
|
parent::writeClosePage( $string );
|
|
|
|
|
$this->progress->reportPage();
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-10-16 17:33:41 +00:00
|
|
|
function writeRevision( $rev, $string ) {
|
|
|
|
|
parent::writeRevision( $rev, $string );
|
|
|
|
|
$this->progress->revCount();
|
|
|
|
|
}
|
|
|
|
|
}
|