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->
addOption(
'username-interwiki',
'Use interwiki usernames with this prefix',
false,
true );
87 'Treat all usernames as interwiki. ' .
88 'The default is to assign edits to local users where they exist.',
91 $this->
addArg(
'file',
'Dump file to import [else use stdin]',
false );
96 $this->
fatalError(
"Wiki is in read-only mode; you'll need to disable it for import to work." );
99 $this->reportingInterval = intval( $this->
getOption(
'report', 100 ) );
100 if ( !$this->reportingInterval ) {
101 $this->reportingInterval = 100;
104 $this->dryRun = $this->
hasOption(
'dry-run' );
105 $this->uploads = $this->
hasOption(
'uploads' );
106 if ( $this->
hasOption(
'image-base-path' ) ) {
107 $this->imageBasePath = $this->
getOption(
'image-base-path' );
109 if ( $this->
hasOption(
'namespaces' ) ) {
119 $this->
output(
"Done!\n" );
120 $this->
output(
"You might want to run rebuildrecentchanges.php to regenerate RecentChanges,\n" );
121 $this->
output(
"and initSiteStats.php to update page and revision counts\n" );
126 $this->nsFilter =
false;
130 $this->nsFilter = array_unique( array_map( [ $this,
'getNsIndex' ],
$namespaces ) );
136 if ( $result !==
false ) {
139 $ns = intval( $namespace );
140 if ( strval( $ns ) === $namespace &&
$wgContLang->getNsText( $ns ) !==
false ) {
143 $this->
fatalError(
"Unknown namespace text / index specified: $namespace" );
153 if ( $obj instanceof
Title ) {
155 } elseif ( $obj instanceof
Revision ) {
156 $title = $obj->getTitle();
158 $title = $obj->title;
160 throw new MWException(
"Cannot get namespace of object in " . __METHOD__ );
163 if ( is_null( $title ) ) {
168 $ns = $title->getNamespace();
170 return is_array( $this->nsFilter ) && !in_array( $ns, $this->nsFilter );
181 $title =
$rev->getTitle();
183 $this->
progress(
"Got bogus revision with null title!" );
195 if ( !$this->dryRun ) {
196 call_user_func( $this->importCallback,
$rev );
205 if ( $this->uploads ) {
209 $this->uploadCount++;
211 $this->
progress(
"upload: " . $revision->getFilename() );
213 if ( !$this->dryRun ) {
218 return $dbw->deadlockLoop( [ $revision,
'importUpload' ] );
232 if ( !$this->dryRun ) {
233 call_user_func( $this->logItemCallback,
$rev );
238 if ( $final xor ( $this->pageCount % $this->reportingInterval == 0 ) ) {
244 if ( !$this->mQuiet ) {
245 $delta = microtime(
true ) - $this->startTime;
247 $rate = sprintf(
"%.2f", $this->pageCount / $delta );
248 $revrate = sprintf(
"%.2f", $this->revCount / $delta );
253 # Logs dumps don't have page tallies
254 if ( $this->pageCount ) {
255 $this->
progress(
"$this->pageCount ($rate pages/sec $revrate revs/sec)" );
257 $this->
progress(
"$this->revCount ($revrate revs/sec)" );
264 fwrite( $this->stderr, $string .
"\n" );
268 if ( preg_match(
'/\.gz$/', $filename ) ) {
269 $filename =
'compress.zlib://' . $filename;
270 } elseif ( preg_match(
'/\.bz2$/', $filename ) ) {
271 $filename =
'compress.bzip2://' . $filename;
272 } elseif ( preg_match(
'/\.7z$/', $filename ) ) {
273 $filename =
'mediawiki.compress.7z://' . $filename;
276 $file = fopen( $filename,
'rt' );
282 $file = fopen(
'php://stdin',
'rt' );
283 if ( self::posix_isatty( $file ) ) {
291 $this->startTime = microtime(
true );
297 $importer->disableStatisticsUpdate();
300 $importer->setDebug(
true );
302 if ( $this->
hasOption(
'no-updates' ) ) {
303 $importer->setNoUpdates(
true );
305 if ( $this->
hasOption(
'username-prefix' ) ) {
306 $importer->setUsernamePrefix(
312 $statusRootPage = $importer->setTargetRootPage( $this->
getOption(
'rootpage' ) );
313 if ( !$statusRootPage->isGood() ) {
315 $this->
fatalError( $statusRootPage->getMessage()->text() );
320 $nthPage = (int)$this->
getOption(
'skip-to' );
321 $importer->setPageOffset( $nthPage );
322 $this->pageCount = $nthPage - 1;
324 $importer->setPageCallback( [ $this,
'reportPage' ] );
325 $importer->setNoticeCallback(
function ( $msg,
$params ) {
328 $this->importCallback = $importer->setRevisionCallback(
329 [ $this,
'handleRevision' ] );
330 $this->uploadCallback = $importer->setUploadCallback(
331 [ $this,
'handleUpload' ] );
332 $this->logItemCallback = $importer->setLogItemCallback(
333 [ $this,
'handleLogItem' ] );
334 if ( $this->uploads ) {
335 $importer->setImportUploads(
true );
337 if ( $this->imageBasePath ) {
338 $importer->setImageBasePath( $this->imageBasePath );
341 if ( $this->dryRun ) {
342 $importer->setPageOutCallback(
null );
345 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.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
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
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "<div ...>$1</div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
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