X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FimportDump.php;h=6717a8ebde04654ac82004eb30d381760834bbc3;hb=a2f5d05ae842d26847d924ed5f57776108101363;hp=bf594952c90a0575f00fe4652186c41825eb7d4a;hpb=adbfc6eac54956ad82c9046b3b4f20e761cea94a;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/importDump.php b/maintenance/importDump.php index bf594952c9..6717a8ebde 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)' ); @@ -105,7 +109,8 @@ TEXT; } $this->output( "Done!\n" ); - $this->output( "You might want to run rebuildrecentchanges.php to regenerate RecentChanges\n" ); + $this->output( "You might want to run rebuildrecentchanges.php to regenerate RecentChanges,\n" ); + $this->output( "and initSiteStats.php to update page and revision counts\n" ); } function setNsfilter( array $namespaces ) { @@ -114,12 +119,13 @@ TEXT; return; } - $this->nsFilter = array_unique( array_map( array( $this, 'getNsIndex' ), $namespaces ) ); + $this->nsFilter = array_unique( array_map( [ $this, 'getNsIndex' ], $namespaces ) ); } private function getNsIndex( $namespace ) { global $wgContLang; - if ( ( $result = $wgContLang->getNsIndex( $namespace ) ) !== false ) { + $result = $wgContLang->getNsIndex( $namespace ); + if ( $result !== false ) { return $result; } $ns = intval( $namespace ); @@ -134,16 +140,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 ); } @@ -190,9 +204,9 @@ 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' ) ); + return $dbw->deadlockLoop( [ $revision, 'importUpload' ] ); } } @@ -270,19 +284,30 @@ TEXT; $source = new ImportStreamSource( $handle ); $importer = new WikiImporter( $source, $this->getConfig() ); + // Updating statistics require a lot of time so disable it + $importer->disableStatisticsUpdate(); + if ( $this->hasOption( 'debug' ) ) { $importer->setDebug( true ); } if ( $this->hasOption( 'no-updates' ) ) { $importer->setNoUpdates( true ); } - $importer->setPageCallback( array( &$this, 'reportPage' ) ); + 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( [ $this, 'reportPage' ] ); $this->importCallback = $importer->setRevisionCallback( - array( &$this, 'handleRevision' ) ); + [ $this, 'handleRevision' ] ); $this->uploadCallback = $importer->setUploadCallback( - array( &$this, 'handleUpload' ) ); + [ $this, 'handleUpload' ] ); $this->logItemCallback = $importer->setLogItemCallback( - array( &$this, 'handleLogItem' ) ); + [ $this, 'handleLogItem' ] ); if ( $this->uploads ) { $importer->setImportUploads( true ); }