27require_once __DIR__ .
'/Maintenance.php';
82 parent::__construct();
83 $this->stderr = fopen(
"php://stderr",
"wt" );
97 $this->
addOption(
'plugin',
'Load a dump plugin class. Specify as <class>[:<file>].',
98 false,
true,
false,
true );
99 $this->
addOption(
'output',
'Begin a filtered output stream; Specify as <type>:<file>. ' .
100 '<type>s: file, gzip, bzip2, 7zip, dbzip2',
false,
true,
false,
true );
101 $this->
addOption(
'filter',
'Add a filter on an output branch. Specify as ' .
102 '<type>[:<options>]. <types>s: latest, notalk, namespace',
false,
true,
'o',
true );
103 $this->
addOption(
'report',
'Report position and speed after every n pages processed. ' .
104 'Default: 100.',
false,
true );
105 $this->
addOption(
'server',
'Force reading from MySQL server',
false,
true );
106 $this->
addOption(
'7ziplevel',
'7zip compression level for all 7zip outputs. Used for ' .
107 '-mx option to 7za command.',
false,
true );
122 $this->outputTypes[
$name] = $class;
130 $this->filterTypes[
$name] = $class;
144 $register = [ $class,
'register' ];
145 call_user_func_array( $register, [ $this ] );
149 throw new MWException(
'execute() must be overridden in subclasses' );
166 $val = explode(
':', $param );
168 if ( count( $val ) === 1 ) {
170 } elseif ( count( $val ) === 2 ) {
173 $this->
fatalError(
'Invalid plugin parameter' );
179 $split = explode(
':', $param, 2 );
180 if ( count( $split ) !== 2 ) {
181 $this->
fatalError(
'Invalid output parameter' );
184 if ( !is_null(
$sink ) ) {
187 if ( !isset( $this->outputTypes[
$type] ) ) {
188 $this->
fatalError(
"Unrecognized output sink type '$type'" );
190 $class = $this->outputTypes[
$type];
191 if (
$type ===
"7zip" ) {
192 $sink =
new $class( $file, intval( $this->
getOption(
'7ziplevel' ) ) );
194 $sink =
new $class( $file );
199 if ( is_null(
$sink ) ) {
203 $split = explode(
':', $param );
206 if ( !isset( $this->filterTypes[$key] ) ) {
207 $this->
fatalError(
"Unrecognized filter type '$key'" );
210 $type = $this->filterTypes[$key];
212 if ( count( $split ) === 1 ) {
214 } elseif ( count( $split ) === 2 ) {
217 $this->
fatalError(
'Invalid filter parameter' );
229 $this->reportingInterval = intval( $this->
getOption(
'report' ) );
233 $this->server = $this->
getOption(
'server' );
236 if ( is_null(
$sink ) ) {
241 if ( count( $sinks ) > 1 ) {
248 function dump( $history, $text = WikiExporter::TEXT ) {
249 # Notice messages will foul up your XML output even if they're
250 # relatively harmless.
251 if ( ini_get(
'display_errors' ) ) {
252 ini_set(
'display_errors',
'stderr' );
258 $exporter =
new WikiExporter( $db, $history, WikiExporter::STREAM, $text );
263 $exporter->setOutputSink( $wrapper );
265 if ( !$this->skipHeader ) {
266 $exporter->openStream();
268 # Log item dumps: all or by range
269 if ( $history & WikiExporter::LOGS ) {
270 if ( $this->startId || $this->endId ) {
271 $exporter->logsByRange( $this->startId, $this->endId );
273 $exporter->allLogs();
275 } elseif ( is_null( $this->
pages ) ) {
276 # Page dumps: all or by page ID range
277 if ( $this->startId || $this->endId ) {
278 $exporter->pagesByRange( $this->startId, $this->endId, $this->orderRevs );
279 } elseif ( $this->revStartId || $this->revEndId ) {
280 $exporter->revsByRange( $this->revStartId, $this->revEndId );
282 $exporter->allPages();
285 # Dump of specific pages
286 $exporter->pagesByName( $this->
pages );
289 if ( !$this->skipFooter ) {
290 $exporter->closeStream();
303 $table = ( $history == WikiExporter::CURRENT ) ?
'page' :
'revision';
304 $field = ( $history == WikiExporter::CURRENT ) ?
'page_id' :
'rev_id';
307 if ( $this->forcedDb ===
null ) {
310 $this->maxCount =
$dbr->selectField( $table,
"MAX($field)",
'', __METHOD__ );
311 $this->startTime = microtime(
true );
312 $this->lastTime = $this->startTime;
313 $this->ID = getmypid();
323 if ( $this->forcedDb !==
null ) {
327 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
328 $this->lb = $lbFactory->newMainLB();
329 $db = $this->lb->getConnection(
DB_REPLICA,
'dump' );
346 parent::setDB( $db );
347 $this->forcedDb = $db;
351 if ( isset( $this->lb ) ) {
352 $this->lb->closeAll();
374 if ( $final xor ( $this->
revCount % $this->reportingInterval == 0 ) ) {
380 if ( $this->reporting ) {
382 $nowts = microtime(
true );
383 $deltaAll = $nowts - $this->startTime;
389 $portion = $this->
revCount / $this->maxCount;
390 $eta = $this->startTime + $deltaAll / $portion;
392 $pageRate = $this->pageCount / $deltaAll;
393 $revRate = $this->
revCount / $deltaAll;
400 $pageRatePart = $this->pageCountPart / $deltaPart;
401 $revRatePart = $this->revCountPart / $deltaPart;
407 "%s: %s (ID %d) %d pages (%0.1f|%0.1f/sec all|curr), "
408 .
"%d revs (%0.1f|%0.1f/sec all|curr), ETA %s [max %d]",
409 $now,
wfWikiID(), $this->ID, $this->pageCount, $pageRate,
410 $pageRatePart, $this->
revCount, $revRate, $revRatePart, $etats,
413 $this->lastTime = $nowts;
419 if ( $this->reporting ) {
420 fwrite( $this->stderr, $string .
"\n" );
$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 param 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
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
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