Go to the documentation of this file.
28 require_once __DIR__ .
'/../Maintenance.php';
29 require_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. ' .
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' );
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' );
186 if ( !is_null(
$sink ) ) {
189 if ( !isset( $this->outputTypes[
$type] ) ) {
190 $this->
fatalError(
"Unrecognized output sink type '$type'" );
192 $class = $this->outputTypes[
$type];
193 if (
$type ===
"7zip" ) {
201 if ( is_null(
$sink ) ) {
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':
228 "Unsupported schema version $param. Supported versions: " .
232 $this->schemaVersion = $param;
238 $this->reportingInterval = intval( $this->
getOption(
'report' ) );
245 if ( is_null(
$sink ) ) {
250 if (
count( $sinks ) > 1 ) {
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
280 if ( $this->startId || $this->endId ) {
281 $exporter->logsByRange( $this->startId, $this->endId );
283 $exporter->allLogs();
285 } elseif ( is_null( $this->
pages ) ) {
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();
317 if ( $this->forcedDb ===
null ) {
320 $this->maxCount =
$dbr->selectField( $table,
"MAX($field)",
'', __METHOD__ );
321 $this->startTime = microtime(
true );
322 $this->lastTime = $this->startTime;
323 $this->ID = getmypid();
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 ) {
390 $nowts = microtime(
true );
391 $deltaAll = $nowts - $this->startTime;
397 $portion = $this->
revCount / $this->maxCount;
398 $eta = $this->startTime + $deltaAll / $portion;
400 $pageRate = $this->pageCount / $deltaAll;
401 $revRate = $this->
revCount / $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,
421 $this->lastTime = $nowts;
427 if ( $this->reporting ) {
428 fwrite( $this->stderr, $string .
"\n" );
registerOutput( $name, $class)
static schemaVersion()
Returns the default export schema version, as defined by $wgXmlDumpSchemaVersion.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
$wgDBserver
Database host name or IP address.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
static string[] $supportedSchemas
the schema versions supported for output @final
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
IDatabase null $forcedDb
The dependency-injected database to use.
The ContentHandler facility adds support for arbitrary content types on wiki pages
loadWithArgv( $argv)
Load params and arguments from a given array of command-line arguments.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
setDB(IDatabase $db=null)
Force the dump to use the provided database connection for database operations, wherever possible.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
array $orderedOptions
Used to read the options in the order they were passed.
loadPlugin( $class, $file)
Load a plugin and register it.
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
initProgress( $history=WikiExporter::FULL)
Initialise starting time and maximum revision count.
Allows to change the fields on the form that will be generated $name
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
execute()
Do the actual work.
getOption( $name, $default=null)
Get an option, or return the default.
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
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
processOptions()
Processes arguments and sets $this->$sink accordingly.
dump( $history, $text=WikiExporter::TEXT)
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
hasOption( $name)
Checks to see if a particular option exists.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same so they can t rely on Unix and must forbid reads to even standard directories like tmp lest users read each others files We cannot assume that the user has the ability to install or run any programs not written as web accessible PHP scripts Since anything that works on cheap shared hosting will work if you have shell or root access MediaWiki s design is based around catering to the lowest common denominator Although we support higher end setups as the way many things work by default is tailored toward shared hosting These defaults are unconventional from the point of view of and they certainly aren t ideal for someone who s installing MediaWiki as MediaWiki does not conform to normal Unix filesystem layout Hopefully we ll offer direct support for standard layouts in the but for now *any change to the location of files is unsupported *Moving things and leaving symlinks will *probably *not break but it is *strongly *advised not to try any more intrusive changes to get MediaWiki to conform more closely to your filesystem hierarchy Any such attempt will almost certainly result in unnecessary bugs The standard recommended location to install relative to the web is it should be possible to enable the appropriate rewrite rules by if you can reconfigure the web server
registerFilter( $name, $class)