Change WikiImporter to now requires the second parameter to be an instance of the...
[lhc/web/wiklou.git] / includes / import / WikiImporter.php
index 06b579a..2099709 100644 (file)
@@ -39,6 +39,7 @@ class WikiImporter {
        private $mNoticeCallback, $mDebug;
        private $mImportUploads, $mImageBasePath;
        private $mNoUpdates = false;
+       private $pageOffset = 0;
        /** @var Config */
        private $config;
        /** @var ImportTitleFactory */
@@ -54,16 +55,12 @@ class WikiImporter {
         * @param Config $config
         * @throws Exception
         */
-       function __construct( ImportSource $source, Config $config = null ) {
+       function __construct( ImportSource $source, Config $config ) {
                if ( !class_exists( 'XMLReader' ) ) {
                        throw new Exception( 'Import requires PHP to have been compiled with libxml support' );
                }
 
                $this->reader = new XMLReader();
-               if ( !$config ) {
-                       wfDeprecated( __METHOD__ . ' without a Config instance', '1.25' );
-                       $config = MediaWikiServices::getInstance()->getMainConfig();
-               }
                $this->config = $config;
 
                if ( !in_array( 'uploadsource', stream_get_wrappers() ) ) {
@@ -146,6 +143,16 @@ class WikiImporter {
                $this->mNoUpdates = $noupdates;
        }
 
+       /**
+        * Sets 'pageOffset' value. So it will skip the first n-1 pages
+        * and start from the nth page. It's 1-based indexing.
+        * @param int $nthPage
+        * @since 1.29
+        */
+       function setPageOffset( $nthPage ) {
+               $this->pageOffset = $nthPage;
+       }
+
        /**
         * Set a callback that displays notice messages
         *
@@ -383,8 +390,8 @@ class WikiImporter {
         * @return bool
         */
        public function finishImportPage( $title, $foreignTitle, $revCount,
-                       $sRevCount, $pageInfo ) {
-
+               $sRevCount, $pageInfo
+       ) {
                // Update article count statistics (T42009)
                // The normal counting logic in WikiPage->doEditUpdates() is designed for
                // one-revision-at-a-time editing, not bulk imports. In this situation it
@@ -417,7 +424,7 @@ class WikiImporter {
 
        /**
         * Alternate per-revision callback, for debugging.
-        * @param WikiRevision $revision
+        * @param WikiRevision &$revision
         */
        public function debugRevisionHandler( &$revision ) {
                $this->debug( "Got revision:" );
@@ -562,9 +569,19 @@ class WikiImporter {
                $keepReading = $this->reader->read();
                $skip = false;
                $rethrow = null;
+               $pageCount = 0;
                try {
                        while ( $keepReading ) {
                                $tag = $this->reader->localName;
+                               if ( $this->pageOffset ) {
+                                       if ( $tag === 'page' ) {
+                                               $pageCount++;
+                                       }
+                                       if ( $pageCount < $this->pageOffset ) {
+                                               $keepReading = $this->reader->next();
+                                               continue;
+                                       }
+                               }
                                $type = $this->reader->nodeType;
 
                                if ( !Hooks::run( 'ImportHandleToplevelXMLTag', [ $this ] ) ) {
@@ -670,7 +687,6 @@ class WikiImporter {
         * @return bool|mixed
         */
        private function processLogItem( $logInfo ) {
-
                $revision = new WikiRevision( $this->config );
 
                if ( isset( $logInfo['id'] ) ) {