28require_once __DIR__ .
'/../Maintenance.php';
29require_once __DIR__ .
'/../../includes/export/WikiExporter.php';
83 parent::__construct();
84 $this->stderr =
fopen(
"php://stderr",
"wt" );
99 $this->
addOption(
'plugin',
'Load a dump plugin class. Specify as <class>[:<file>].',
100 false,
true,
false,
true );
101 $this->
addOption(
'output',
'Begin a filtered output stream; Specify as <type>:<file>. ' .
102 '<type>s: file, gzip, bzip2, 7zip, dbzip2, lbzip2',
false,
true,
false,
true );
103 $this->
addOption(
'filter',
'Add a filter on an output branch. Specify as ' .
104 '<type>[:<options>]. <types>s: latest, notalk, namespace',
false,
true,
false,
true );
105 $this->
addOption(
'report',
'Report position and speed after every n pages processed. ' .
106 'Default: 100.',
false,
true );
107 $this->
addOption(
'schema-version',
'Schema version to use for output. ' .
108 'Default: ' . WikiExporter::schemaVersion(),
false,
true );
109 $this->
addOption(
'server',
'Force reading from MySQL server',
false,
true );
110 $this->
addOption(
'7ziplevel',
'7zip compression level for all 7zip outputs. Used for ' .
111 '-mx option to 7za command.',
false,
true );
126 $this->outputTypes[
$name] = $class;
134 $this->filterTypes[
$name] = $class;
148 $register = [ $class,
'register' ];
153 throw new MWException(
'execute() must be overridden in subclasses' );
163 $this->schemaVersion = WikiExporter::schemaVersion();
171 $val = explode(
':', $param, 2 );
173 if ( count( $val ) === 1 ) {
175 }
elseif ( count( $val ) === 2 ) {
181 $split = explode(
':', $param, 2 );
182 if ( count( $split ) !== 2 ) {
183 $this->
fatalError(
'Invalid output parameter' );
190 $this->
fatalError(
"Unrecognized output sink type '$type'" );
192 $class = $this->outputTypes[
$type];
193 if (
$type ===
"7zip" ) {
196 $sink =
new $class( $file );
205 $split = explode(
':', $param, 2 );
208 if ( !
isset( $this->filterTypes[$key] ) ) {
209 $this->
fatalError(
"Unrecognized filter type '$key'" );
212 $type = $this->filterTypes[$key];
214 if ( count( $split ) === 1 ) {
216 }
elseif ( count( $split ) === 2 ) {
225 case 'schema-version':
226 if ( !
in_array( $param, XmlDumpWriter::$supportedSchemas ) ) {
228 "Unsupported schema version $param. Supported versions: " .
229 implode(
', ', XmlDumpWriter::$supportedSchemas )
232 $this->schemaVersion =
$param;
242 $this->server = $this->
getOption(
'server' );
250 if ( count( $sinks ) > 1 ) {
257 function dump( $history, $text = WikiExporter::TEXT ) {
258 # Notice messages will foul up your XML output even if they're
259 # relatively harmless.
260 if (
ini_get(
'display_errors' ) ) {
261 ini_set(
'display_errors',
'stderr' );
268 $exporter->setSchemaVersion( $this->schemaVersion );
273 $exporter->setOutputSink( $wrapper );
275 if ( !$this->skipHeader ) {
276 $exporter->openStream();
278 # Log item dumps: all or by range
279 if ( $history & WikiExporter::LOGS ) {
280 if ( $this->startId || $this->endId ) {
281 $exporter->logsByRange( $this->startId, $this->endId );
283 $exporter->allLogs();
286 # Page dumps: all or by page ID range
287 if ( $this->startId || $this->endId ) {
288 $exporter->pagesByRange( $this->startId, $this->endId, $this->orderRevs );
289 }
elseif ( $this->revStartId || $this->revEndId ) {
290 $exporter->revsByRange( $this->revStartId, $this->revEndId );
292 $exporter->allPages();
295 # Dump of specific pages
296 $exporter->pagesByName( $this->
pages );
299 if ( !$this->skipFooter ) {
300 $exporter->closeStream();
313 $table = ( $history == WikiExporter::CURRENT ) ?
'page' :
'revision';
314 $field = ( $history == WikiExporter::CURRENT ) ?
'page_id' :
'rev_id';
317 if ( $this->forcedDb ===
null ) {
320 $this->maxCount =
$dbr->selectField( $table,
"MAX($field)",
'', __METHOD__ );
322 $this->lastTime = $this->startTime;
333 if ( $this->forcedDb !==
null ) {
337 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
338 $this->lb = $lbFactory->newMainLB();
339 $db = $this->lb->getConnection(
DB_REPLICA,
'dump' );
356 parent::setDB( $db );
357 $this->forcedDb = $db;
361 if (
isset( $this->lb ) ) {
362 $this->lb->closeAll();
382 if ( $final xor ( $this->
revCount % $this->reportingInterval == 0 ) ) {
388 if ( $this->reporting ) {
391 $deltaAll = $nowts - $this->startTime;
398 $eta = $this->startTime + $deltaAll /
$portion;
400 $pageRate = $this->pageCount /
$deltaAll;
408 $pageRatePart = $this->pageCountPart /
$deltaPart;
409 $revRatePart = $this->revCountPart /
$deltaPart;
415 "%s: %s (ID %d) %d pages (%0.1f|%0.1f/sec all|curr), "
416 .
"%d revs (%0.1f|%0.1f/sec all|curr), ETA %s [max %d]",
417 $now,
wfWikiID(), $this->ID, $this->pageCount, $pageRate,
418 $pageRatePart, $this->
revCount, $revRate, $revRatePart, $etats,
427 if ( $this->reporting ) {
428 fwrite( $this->stderr, $string .
"\n" );
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
$wgDBserver
Database host name or IP address.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
dump( $history, $text=WikiExporter::TEXT)
registerFilter( $name, $class)
IDatabase null $forcedDb
The dependency-injected database to use.
execute()
Do the actual work.
initProgress( $history=WikiExporter::FULL)
Initialise starting time and maximum revision count.
processOptions()
Processes arguments and sets $this->$sink accordingly.
registerOutput( $name, $class)
setDB(IDatabase $db=null)
Force the dump to use the provided database connection for database operations, wherever possible.
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 exists.
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.
The ContentHandler facility adds support for arbitrary content types on wiki pages
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Allows to change the fields on the form that will be generated $name
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file