Merge "ApiSetNotificationTimestamp: Make entirewatchlist more efficient"
[lhc/web/wiklou.git] / maintenance / importDump.php
index cf0e7d8..7c20748 100644 (file)
@@ -24,6 +24,8 @@
  * @ingroup Maintenance
  */
 
+use MediaWiki\MediaWikiServices;
+
 require_once __DIR__ . '/Maintenance.php';
 
 /**
@@ -82,6 +84,12 @@ TEXT
                );
                $this->addOption( 'image-base-path', 'Import files from a specified path', false, true );
                $this->addOption( 'skip-to', 'Start from nth page by skipping first n-1 pages', false, true );
+               $this->addOption( 'username-prefix', 'Prefix for interwiki usernames', false, true );
+               $this->addOption( 'no-local-users',
+                       'Treat all usernames as interwiki. ' .
+                       'The default is to assign edits to local users where they exist.',
+                       false, false
+               );
                $this->addArg( 'file', 'Dump file to import [else use stdin]', false );
        }
 
@@ -125,13 +133,13 @@ TEXT
        }
 
        private function getNsIndex( $namespace ) {
-               global $wgContLang;
-               $result = $wgContLang->getNsIndex( $namespace );
+               $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+               $result = $contLang->getNsIndex( $namespace );
                if ( $result !== false ) {
                        return $result;
                }
                $ns = intval( $namespace );
-               if ( strval( $ns ) === $namespace && $wgContLang->getNsText( $ns ) !== false ) {
+               if ( strval( $ns ) === $namespace && $contLang->getNsText( $ns ) !== false ) {
                        return $ns;
                }
                $this->fatalError( "Unknown namespace text / index specified: $namespace" );
@@ -139,6 +147,7 @@ TEXT
 
        /**
         * @param Title|Revision $obj
+        * @throws MWException
         * @return bool
         */
        private function skippedNamespace( $obj ) {
@@ -295,6 +304,12 @@ TEXT
                if ( $this->hasOption( 'no-updates' ) ) {
                        $importer->setNoUpdates( true );
                }
+               if ( $this->hasOption( 'username-prefix' ) ) {
+                       $importer->setUsernamePrefix(
+                               $this->getOption( 'username-prefix' ),
+                               !$this->hasOption( 'no-local-users' )
+                       );
+               }
                if ( $this->hasOption( 'rootpage' ) ) {
                        $statusRootPage = $importer->setTargetRootPage( $this->getOption( 'rootpage' ) );
                        if ( !$statusRootPage->isGood() ) {
@@ -309,6 +324,9 @@ TEXT
                        $this->pageCount = $nthPage - 1;
                }
                $importer->setPageCallback( [ $this, 'reportPage' ] );
+               $importer->setNoticeCallback( function ( $msg, $params ) {
+                       echo wfMessage( $msg, $params )->text() . "\n";
+               } );
                $this->importCallback = $importer->setRevisionCallback(
                        [ $this, 'handleRevision' ] );
                $this->uploadCallback = $importer->setUploadCallback(
@@ -330,5 +348,5 @@ TEXT
        }
 }
 
-$maintClass = 'BackupReader';
+$maintClass = BackupReader::class;
 require_once RUN_MAINTENANCE_IF_MAIN;