]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - maintenance/backupPrefetch.inc
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / maintenance / backupPrefetch.inc
index 9d74313777c811678b4f1e59556a6b3493952db2..6a2d3bf626565264dec0d1236dedb8673e1f1068 100644 (file)
@@ -2,6 +2,24 @@
 /**
  * Helper class for the --prefetch option of dumpTextPass.php
  *
+ * Copyright © 2005 Brion Vibber <brion@pobox.com>
+ * https://www.mediawiki.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
  * @file
  * @ingroup Maintenance
  */
  * @ingroup Maintenance
  */
 class BaseDump {
-       var $reader = null;
-       var $atEnd = false;
-       var $atPageEnd = false;
-       var $lastPage = 0;
-       var $lastRev = 0;
-       var $infiles = null;
-
-       function BaseDump( $infile ) {
-               $this->infiles = explode(';',$infile);
+       /** @var XMLReader */
+       protected $reader = null;
+       protected $atEnd = false;
+       protected $atPageEnd = false;
+       protected $lastPage = 0;
+       protected $lastRev = 0;
+       protected $infiles = null;
+
+       public function __construct( $infile ) {
+               $this->infiles = explode( ';', $infile );
                $this->reader = new XMLReader();
-               $infile = array_shift($this->infiles);
-               $this->reader->open( $infile );
+               $infile = array_shift( $this->infiles );
+               if ( defined( 'LIBXML_PARSEHUGE' ) ) {
+                       $this->reader->open( $infile, null, LIBXML_PARSEHUGE );
+               } else {
+                       $this->reader->open( $infile );
+               }
        }
 
        /**
@@ -41,9 +64,9 @@ class BaseDump {
         * from the dump stream. May return null if the page is
         * unavailable.
         *
-        * @param $page Integer: ID number of page to read
-        * @param $rev Integer: ID number of revision to read
-        * @return string or null
+        * @param int $page ID number of page to read
+        * @param int $rev ID number of revision to read
+        * @return string|null
         */
        function prefetch( $page, $rev ) {
                $page = intval( $page );
@@ -53,18 +76,24 @@ class BaseDump {
                        $this->nextPage();
                }
                if ( $this->lastPage > $page || $this->atEnd ) {
-                       $this->debug( "BaseDump::prefetch already past page $page looking for rev $rev  [$this->lastPage, $this->lastRev]" );
+                       $this->debug( "BaseDump::prefetch already past page $page "
+                               . "looking for rev $rev  [$this->lastPage, $this->lastRev]" );
+
                        return null;
                }
                while ( $this->lastRev < $rev && !$this->atEnd && !$this->atPageEnd ) {
-                       $this->debug( "BaseDump::prefetch at page $this->lastPage, rev $this->lastRev, looking for $page, $rev" );
+                       $this->debug( "BaseDump::prefetch at page $this->lastPage, rev $this->lastRev, "
+                               . "looking for $page, $rev" );
                        $this->nextRev();
                }
                if ( $this->lastRev == $rev && !$this->atEnd ) {
                        $this->debug( "BaseDump::prefetch hit on $page, $rev [$this->lastPage, $this->lastRev]" );
+
                        return $this->nextText();
                } else {
-                       $this->debug( "BaseDump::prefetch already past rev $rev on page $page  [$this->lastPage, $this->lastRev]" );
+                       $this->debug( "BaseDump::prefetch already past rev $rev on page $page "
+                               . "[$this->lastPage, $this->lastRev]" );
+
                        return null;
                }
        }
@@ -87,8 +116,8 @@ class BaseDump {
                        }
                } else {
                        $this->close();
-                       if (count($this->infiles)) {
-                               $infile = array_shift($this->infiles);
+                       if ( count( $this->infiles ) ) {
+                               $infile = array_shift( $this->infiles );
                                $this->reader->open( $infile );
                                $this->atEnd = false;
                        }
@@ -110,30 +139,39 @@ class BaseDump {
 
        /**
         * @access private
+        * @return string
         */
        function nextText() {
                $this->skipTo( 'text' );
+
                return strval( $this->nodeContents() );
        }
 
        /**
         * @access private
+        * @param string $name
+        * @param string $parent
+        * @return bool|null
         */
        function skipTo( $name, $parent = 'page' ) {
                if ( $this->atEnd ) {
                        return false;
                }
                while ( $this->reader->read() ) {
-                       if ( $this->reader->nodeType == XMLReader::ELEMENT &&
-                               $this->reader->name == $name ) {
+                       if ( $this->reader->nodeType == XMLReader::ELEMENT
+                               && $this->reader->name == $name
+                       ) {
                                return true;
                        }
-                       if ( $this->reader->nodeType == XMLReader::END_ELEMENT &&
-                               $this->reader->name == $parent ) {
+                       if ( $this->reader->nodeType == XMLReader::END_ELEMENT
+                               && $this->reader->name == $parent
+                       ) {
                                $this->debug( "BaseDump::skipTo found </$parent> searching for <$name>" );
+
                                return false;
                        }
                }
+
                return $this->close();
        }
 
@@ -142,7 +180,7 @@ class BaseDump {
         * Fetches text contents of the current element, assuming
         * no sub-elements or such scary things.
         *
-        * @return String
+        * @return string
         * @access private
         */
        function nodeContents() {
@@ -154,25 +192,28 @@ class BaseDump {
                }
                $buffer = "";
                while ( $this->reader->read() ) {
-                       switch( $this->reader->nodeType ) {
-                       case XMLReader::TEXT:
-//                     case XMLReader::WHITESPACE:
-                       case XMLReader::SIGNIFICANT_WHITESPACE:
-                               $buffer .= $this->reader->value;
-                               break;
-                       case XMLReader::END_ELEMENT:
-                               return $buffer;
+                       switch ( $this->reader->nodeType ) {
+                               case XMLReader::TEXT:
+                               // case XMLReader::WHITESPACE:
+                               case XMLReader::SIGNIFICANT_WHITESPACE:
+                                       $buffer .= $this->reader->value;
+                                       break;
+                               case XMLReader::END_ELEMENT:
+                                       return $buffer;
                        }
                }
+
                return $this->close();
        }
 
        /**
         * @access private
+        * @return null
         */
        function close() {
                $this->reader->close();
                $this->atEnd = true;
+
                return null;
        }
 }