Merge "Fix Postgres support"
[lhc/web/wiklou.git] / includes / import / WikiImporter.php
index 328cdad..2fc9f5e 100644 (file)
@@ -39,12 +39,15 @@ class WikiImporter {
        private $mNoticeCallback, $mDebug;
        private $mImportUploads, $mImageBasePath;
        private $mNoUpdates = false;
+       private $pageOffset = 0;
        /** @var Config */
        private $config;
        /** @var ImportTitleFactory */
        private $importTitleFactory;
        /** @var array */
        private $countableCache = [];
+       /** @var bool */
+       private $disableStatisticsUpdate = false;
 
        /**
         * Creates an ImportXMLReader drawing from the source provided
@@ -144,6 +147,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
         *
@@ -303,6 +316,14 @@ class WikiImporter {
                $this->mImportUploads = $import;
        }
 
+       /**
+        * Statistics update can cause a lot of time
+        * @since 1.29
+        */
+       public function disableStatisticsUpdate() {
+               $this->disableStatisticsUpdate = true;
+       }
+
        /**
         * Default per-page callback. Sets up some things related to site statistics
         * @param array $titleAndForeignTitle Two-element array, with Title object at
@@ -381,21 +402,23 @@ class WikiImporter {
                // suffers from issues of replica DB lag. We let WikiPage handle the total page
                // and revision count, and we implement our own custom logic for the
                // article (content page) count.
-               $page = WikiPage::factory( $title );
-               $page->loadPageData( 'fromdbmaster' );
-               $content = $page->getContent();
-               if ( $content === null ) {
-                       wfDebug( __METHOD__ . ': Skipping article count adjustment for ' . $title .
-                               ' because WikiPage::getContent() returned null' );
-               } else {
-                       $editInfo = $page->prepareContentForEdit( $content );
-                       $countKey = 'title_' . $title->getPrefixedText();
-                       $countable = $page->isCountable( $editInfo );
-                       if ( array_key_exists( $countKey, $this->countableCache ) &&
-                               $countable != $this->countableCache[$countKey] ) {
-                               DeferredUpdates::addUpdate( SiteStatsUpdate::factory( [
-                                       'articles' => ( (int)$countable - (int)$this->countableCache[$countKey] )
-                               ] ) );
+               if ( !$this->disableStatisticsUpdate ) {
+                       $page = WikiPage::factory( $title );
+                       $page->loadPageData( 'fromdbmaster' );
+                       $content = $page->getContent();
+                       if ( $content === null ) {
+                               wfDebug( __METHOD__ . ': Skipping article count adjustment for ' . $title .
+                                       ' because WikiPage::getContent() returned null' );
+                       } else {
+                               $editInfo = $page->prepareContentForEdit( $content );
+                               $countKey = 'title_' . $title->getPrefixedText();
+                               $countable = $page->isCountable( $editInfo );
+                               if ( array_key_exists( $countKey, $this->countableCache ) &&
+                                       $countable != $this->countableCache[$countKey] ) {
+                                       DeferredUpdates::addUpdate( SiteStatsUpdate::factory( [
+                                               'articles' => ( (int)$countable - (int)$this->countableCache[$countKey] )
+                                       ] ) );
+                               }
                        }
                }
 
@@ -534,7 +557,7 @@ class WikiImporter {
        public function doImport() {
                // Calls to reader->read need to be wrapped in calls to
                // libxml_disable_entity_loader() to avoid local file
-               // inclusion attacks (bug 46932).
+               // inclusion attacks (T48932).
                $oldDisable = libxml_disable_entity_loader( true );
                $this->reader->read();
 
@@ -550,9 +573,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 ] ) ) {