? 'ok'
: '(disabled; requires PHP bzip2 module)';
- $this->mDescription = <<<TEXT
+ $this->addDescription(
+ <<<TEXT
This script reads pages from an XML file as produced from Special:Export or
dumpBackup.php, and saves them into the current wiki.
Note that for very large data sets, importDump.php may be slow; there are
alternate methods which can be much faster for full site restoration:
<https://www.mediawiki.org/wiki/Manual:Importing_XML_dumps>
-TEXT;
+TEXT
+ );
$this->stderr = fopen( "php://stderr", "wt" );
$this->addOption( 'report',
'Report position and speed after every n pages processed', false, true );
$this->addOption( 'namespaces',
'Import only the pages from namespaces belonging to the list of ' .
'pipe-separated namespace names or namespace indexes', false, true );
+ $this->addOption( 'rootpage', 'Pages will be imported as subpages of the specified page',
+ false, true );
$this->addOption( 'dry-run', 'Parse dump without actually importing pages' );
$this->addOption( 'debug', 'Output extra verbose debug information' );
$this->addOption( 'uploads', 'Process file upload data if included (experimental)' );
* @return bool
*/
private function skippedNamespace( $obj ) {
+ $title = null;
if ( $obj instanceof Title ) {
- $ns = $obj->getNamespace();
+ $title = $obj;
} elseif ( $obj instanceof Revision ) {
- $ns = $obj->getTitle()->getNamespace();
+ $title = $obj->getTitle();
} elseif ( $obj instanceof WikiRevision ) {
- $ns = $obj->title->getNamespace();
+ $title = $obj->title;
} else {
throw new MWException( "Cannot get namespace of object in " . __METHOD__ );
}
+ if ( is_null( $title ) ) {
+ // Probably a log entry
+ return false;
+ }
+
+ $ns = $title->getNamespace();
+
return is_array( $this->nsFilter ) && !in_array( $ns, $this->nsFilter );
}
if ( !$this->dryRun ) {
// bluuuh hack
// call_user_func( $this->uploadCallback, $revision );
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
return $dbw->deadlockLoop( array( $revision, 'importUpload' ) );
}
if ( $this->hasOption( 'no-updates' ) ) {
$importer->setNoUpdates( true );
}
+ if ( $this->hasOption( 'rootpage' ) ) {
+ $statusRootPage = $importer->setTargetRootPage( $this->getOption( 'rootpage' ) );
+ if ( !$statusRootPage->isGood() ) {
+ // Die here so that it doesn't print "Done!"
+ $this->error( $statusRootPage->getMessage()->text(), 1 );
+ return false;
+ }
+ }
$importer->setPageCallback( array( &$this, 'reportPage' ) );
$this->importCallback = $importer->setRevisionCallback(
array( &$this, 'handleRevision' ) );