Make resolveConflictOn() accept a prefix different from the page name (needed for...
[lhc/web/wiklou.git] / maintenance / dumpTextPass.php
index 703fa1e..c55208f 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @addtogroup SpecialPage
+ * @file
+ * @ingroup Maintenance
  */
 
 $originalDir = getcwd();
 
-require_once( 'commandLine.inc' );
+require_once( dirname(__FILE__) . '/commandLine.inc' );
 require_once( 'backup.inc' );
 
 /**
- * Stream wrapper around 7za filter program.
- * Required since we can't pass an open file resource to XMLReader->open()
- * which is used for the text prefetch.
+ * @ingroup Maintenance
  */
-class SevenZipStream {
-       var $stream;
-       
-       private function stripPath( $path ) {
-               $prefix = 'mediawiki.compress.7z://';
-               return substr( $path, strlen( $prefix ) );
-       }
-       
-       function stream_open( $path, $mode, $options, &$opened_path ) {
-               if( $mode{0} == 'r' ) {
-                       $options = 'e -bd -so';
-               } elseif( $mode{0} == 'w' ) {
-                       $options = 'a -bd -si';
-               } else {
-                       return false;
-               }
-               $arg = wfEscapeShellArg( $this->stripPath( $path ) );
-               $command = "7za $options $arg";
-               if( !wfIsWindows() ) {
-                       // Suppress the stupid messages on stderr
-                       $command .= ' 2>/dev/null';
-               }
-               $this->stream = popen( $command, $mode );
-               return ($this->stream !== false);
-       }
-       
-       function url_stat( $path, $flags ) {
-               return stat( $this->stripPath( $path ) );
-       }
-       
-       // This is all so lame; there should be a default class we can extend
-       
-       function stream_close() {
-               return fclose( $this->stream );
-       }
-       
-       function stream_flush() {
-               return fflush( $this->stream );
-       }
-       
-       function stream_read( $count ) {
-               return fread( $this->stream, $count );
-       }
-       
-       function stream_write( $data ) {
-               return fwrite( $this->stream, $data );
-       }
-       
-       function stream_tell() {
-               return ftell( $this->stream );
-       }
-       
-       function stream_eof() {
-               return feof( $this->stream );
-       }
-       
-       function stream_seek( $offset, $whence ) {
-               return fseek( $this->stream, $offset, $whence );
-       }
-}
-stream_wrapper_register( 'mediawiki.compress.7z', 'SevenZipStream' );
-
-
 class TextPassDumper extends BackupDumper {
        var $prefetch = null;
        var $input = "php://stdin";
@@ -146,7 +82,8 @@ class TextPassDumper extends BackupDumper {
                
                switch( $opt ) {
                case 'prefetch':
-                       require_once 'maintenance/backupPrefetch.inc';
+                       global $IP;
+                       require_once "$IP/maintenance/backupPrefetch.inc";
                        $this->prefetch = new BaseDump( $url );
                        break;
                case 'stub':
@@ -402,7 +339,7 @@ class TextPassDumper extends BackupDumper {
                // Subprocess may not send everything at once, we have to loop.
                while( $nbytes > strlen( $text ) ) {
                        $buffer = fread( $this->spawnRead, $nbytes - strlen( $text ) );
-                       if( $text === false ) break;
+                       if( $buffer === false ) break;
                        $text .= $buffer;
                }
                
@@ -481,7 +418,7 @@ class TextPassDumper extends BackupDumper {
 
        function clearOpenElement( $style ) {
                if( $this->openElement ) {
-                       $this->buffer .= wfElement( $this->openElement[0], $this->openElement[1], $style );
+                       $this->buffer .= Xml::element( $this->openElement[0], $this->openElement[1], $style );
                        $this->openElement = false;
                }
        }
@@ -493,7 +430,7 @@ $dumper = new TextPassDumper( $argv );
 if( true ) {
        $dumper->dump();
 } else {
-       $dumper->progress( <<<END
+       $dumper->progress( <<<ENDS
 This script postprocesses XML dumps from dumpBackup.php to add
 page text which was stubbed out (using --stub).
 
@@ -512,7 +449,7 @@ Options:
   --server=h  Force reading from MySQL server h
   --current   Base ETA on number of pages in database instead of all revisions
   --spawn     Spawn a subprocess for loading text records
-END
+ENDS
 );
 }