X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=maintenance%2FimportDump.php;h=7c452a6325359e89aece05a768ec04253cf82478;hb=59db24e90bc6027cb8bf2756eb8cb52230d24966;hp=8cea5a2c5db0e7128b7fa9b425d61b860e7f00b3;hpb=38ba6b620be9f6333d902055ae1c0c610af4985e;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/importDump.php b/maintenance/importDump.php index 8cea5a2c5d..7c452a6325 100644 --- a/maintenance/importDump.php +++ b/maintenance/importDump.php @@ -49,7 +49,8 @@ class BackupReader extends Maintenance { ? 'ok' : '(disabled; requires PHP bzip2 module)'; - $this->mDescription = <<addDescription( + << -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)' ); @@ -135,16 +139,24 @@ TEXT; * @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 ); } @@ -191,7 +203,7 @@ TEXT; 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' ) ); } @@ -277,6 +289,14 @@ TEXT; 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' ) );