27require_once __DIR__ .
'/Maintenance.php';
45 parent::__construct();
46 $gz = in_array(
'compress.zlib', stream_get_wrappers() )
48 :
'(disabled; requires PHP zlib module)';
49 $bz2 = in_array(
'compress.bzip2', stream_get_wrappers() )
51 :
'(disabled; requires PHP bzip2 module)';
55This script
reads pages from an XML file as produced from Special:Export or
56dumpBackup.php, and saves them into the current wiki.
61 .7z (
if 7za executable is in PATH)
63Note that
for very large data sets, importDump.php may be slow; there are
64alternate methods which can be much faster
for full site restoration:
68 $this->stderr = fopen(
"php://stderr",
"wt" );
70 'Report position and speed after every n pages processed',
false,
true );
72 'Import only the pages from namespaces belonging to the list of ' .
73 'pipe-separated namespace names or namespace indexes',
false,
true );
74 $this->
addOption(
'rootpage',
'Pages will be imported as subpages of the specified page',
76 $this->
addOption(
'dry-run',
'Parse dump without actually importing pages' );
77 $this->
addOption(
'debug',
'Output extra verbose debug information' );
78 $this->
addOption(
'uploads',
'Process file upload data if included (experimental)' );
81 'Disable link table updates. Is faster but leaves the wiki in an inconsistent state'
83 $this->
addOption(
'image-base-path',
'Import files from a specified path',
false,
true );
84 $this->
addOption(
'skip-to',
'Start from nth page by skipping first n-1 pages',
false,
true );
85 $this->
addArg(
'file',
'Dump file to import [else use stdin]',
false );
90 $this->
error(
"Wiki is in read-only mode; you'll need to disable it for import to work.",
true );
93 $this->reportingInterval = intval( $this->
getOption(
'report', 100 ) );
94 if ( !$this->reportingInterval ) {
95 $this->reportingInterval = 100;
98 $this->dryRun = $this->
hasOption(
'dry-run' );
99 $this->uploads = $this->
hasOption(
'uploads' );
100 if ( $this->
hasOption(
'image-base-path' ) ) {
101 $this->imageBasePath = $this->
getOption(
'image-base-path' );
103 if ( $this->
hasOption(
'namespaces' ) ) {
113 $this->
output(
"Done!\n" );
114 $this->
output(
"You might want to run rebuildrecentchanges.php to regenerate RecentChanges,\n" );
115 $this->
output(
"and initSiteStats.php to update page and revision counts\n" );
120 $this->nsFilter =
false;
124 $this->nsFilter = array_unique( array_map( [ $this,
'getNsIndex' ],
$namespaces ) );
130 if ( $result !==
false ) {
133 $ns = intval( $namespace );
134 if ( strval( $ns ) === $namespace &&
$wgContLang->getNsText( $ns ) !==
false ) {
137 $this->
error(
"Unknown namespace text / index specified: $namespace",
true );
146 if ( $obj instanceof
Title ) {
148 } elseif ( $obj instanceof
Revision ) {
149 $title = $obj->getTitle();
151 $title = $obj->title;
153 throw new MWException(
"Cannot get namespace of object in " . __METHOD__ );
156 if ( is_null( $title ) ) {
161 $ns = $title->getNamespace();
163 return is_array( $this->nsFilter ) && !in_array( $ns, $this->nsFilter );
174 $title =
$rev->getTitle();
176 $this->
progress(
"Got bogus revision with null title!" );
188 if ( !$this->dryRun ) {
189 call_user_func( $this->importCallback,
$rev );
198 if ( $this->uploads ) {
202 $this->uploadCount++;
204 $this->
progress(
"upload: " . $revision->getFilename() );
206 if ( !$this->dryRun ) {
211 return $dbw->deadlockLoop( [ $revision,
'importUpload' ] );
225 if ( !$this->dryRun ) {
226 call_user_func( $this->logItemCallback,
$rev );
231 if ( $final xor ( $this->pageCount % $this->reportingInterval == 0 ) ) {
237 if ( !$this->mQuiet ) {
238 $delta = microtime(
true ) - $this->startTime;
240 $rate = sprintf(
"%.2f", $this->pageCount / $delta );
241 $revrate = sprintf(
"%.2f", $this->revCount / $delta );
246 # Logs dumps don't have page tallies
247 if ( $this->pageCount ) {
248 $this->
progress(
"$this->pageCount ($rate pages/sec $revrate revs/sec)" );
250 $this->
progress(
"$this->revCount ($revrate revs/sec)" );
257 fwrite( $this->stderr, $string .
"\n" );
261 if ( preg_match(
'/\.gz$/', $filename ) ) {
262 $filename =
'compress.zlib://' . $filename;
263 } elseif ( preg_match(
'/\.bz2$/', $filename ) ) {
264 $filename =
'compress.bzip2://' . $filename;
265 } elseif ( preg_match(
'/\.7z$/', $filename ) ) {
266 $filename =
'mediawiki.compress.7z://' . $filename;
269 $file = fopen( $filename,
'rt' );
275 $file = fopen(
'php://stdin',
'rt' );
276 if ( self::posix_isatty( $file ) ) {
284 $this->startTime = microtime(
true );
290 $importer->disableStatisticsUpdate();
293 $importer->setDebug(
true );
295 if ( $this->
hasOption(
'no-updates' ) ) {
296 $importer->setNoUpdates(
true );
299 $statusRootPage = $importer->setTargetRootPage( $this->
getOption(
'rootpage' ) );
300 if ( !$statusRootPage->isGood() ) {
302 $this->
error( $statusRootPage->getMessage()->text(), 1 );
307 $nthPage = (int)$this->
getOption(
'skip-to' );
308 $importer->setPageOffset( $nthPage );
309 $this->pageCount = $nthPage - 1;
311 $importer->setPageCallback( [ $this,
'reportPage' ] );
312 $this->importCallback = $importer->setRevisionCallback(
313 [ $this,
'handleRevision' ] );
314 $this->uploadCallback = $importer->setUploadCallback(
315 [ $this,
'handleUpload' ] );
316 $this->logItemCallback = $importer->setLogItemCallback(
317 [ $this,
'handleLogItem' ] );
318 if ( $this->uploads ) {
319 $importer->setImportUploads(
true );
321 if ( $this->imageBasePath ) {
322 $importer->setImageBasePath( $this->imageBasePath );
325 if ( $this->dryRun ) {
326 $importer->setPageOutCallback(
null );
329 return $importer->doImport();
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition files
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
wfReadOnly()
Check whether the wiki is in read-only mode.
Maintenance script that imports XML dump files into the current wiki.
importFromFile( $filename)
execute()
Do the actual work.
__construct()
Default constructor.
importFromHandle( $handle)
setNsfilter(array $namespaces)
Imports a XML dump from a file (either from file upload, files on disk, or HTTP)
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true)
Add some args that are needed.
hasArg( $argId=0)
Does a given argument exist?
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
hasOption( $name)
Checks to see if a particular param exists.
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
maybeHelp( $force=false)
Maybe show the help.
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.
Represents a title within MediaWiki.
XML file reader for the page data importer.
Represents a revision, log entry or upload during the import process.
The ContentHandler facility adds support for arbitrary content types on wiki pages
Use of locking reads(e.g. the FOR UPDATE clause) is not advised. They are poorly implemented in InnoDB and will cause regular deadlock errors. It 's also surprisingly easy to cripple the wiki with lock contention. Instead of locking reads
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at https
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an and does all the work of translating among various forms such as plain database etc For and for historical it also represents a few features of articles that don t involve their such as access rights See also title txt Article Encapsulates access to the page table of the database The object represents a an and maintains state such as etc Revision Encapsulates individual page revision data and access to the revision text blobs storage system Higher level code should never touch text storage directly
namespace being checked & $result
namespace and then decline to actually register it & $namespaces
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults error
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
require_once RUN_MAINTENANCE_IF_MAIN