MediaWiki
REL1_24
|
00001 <?php 00034 class SevenZipStream { 00035 protected $stream; 00036 00037 private function stripPath( $path ) { 00038 $prefix = 'mediawiki.compress.7z://'; 00039 00040 return substr( $path, strlen( $prefix ) ); 00041 } 00042 00043 function stream_open( $path, $mode, $options, &$opened_path ) { 00044 if ( $mode[0] == 'r' ) { 00045 $options = 'e -bd -so'; 00046 } elseif ( $mode[0] == 'w' ) { 00047 $options = 'a -bd -si'; 00048 } else { 00049 return false; 00050 } 00051 $arg = wfEscapeShellArg( $this->stripPath( $path ) ); 00052 $command = "7za $options $arg"; 00053 if ( !wfIsWindows() ) { 00054 // Suppress the stupid messages on stderr 00055 $command .= ' 2>/dev/null'; 00056 } 00057 $this->stream = popen( $command, $mode[0] ); // popen() doesn't like two-letter modes 00058 return ( $this->stream !== false ); 00059 } 00060 00061 function url_stat( $path, $flags ) { 00062 return stat( $this->stripPath( $path ) ); 00063 } 00064 00065 // This is all so lame; there should be a default class we can extend 00066 00067 function stream_close() { 00068 return fclose( $this->stream ); 00069 } 00070 00071 function stream_flush() { 00072 return fflush( $this->stream ); 00073 } 00074 00075 function stream_read( $count ) { 00076 return fread( $this->stream, $count ); 00077 } 00078 00079 function stream_write( $data ) { 00080 return fwrite( $this->stream, $data ); 00081 } 00082 00083 function stream_tell() { 00084 return ftell( $this->stream ); 00085 } 00086 00087 function stream_eof() { 00088 return feof( $this->stream ); 00089 } 00090 00091 function stream_seek( $offset, $whence ) { 00092 return fseek( $this->stream, $offset, $whence ); 00093 } 00094 } 00095 00096 stream_wrapper_register( 'mediawiki.compress.7z', 'SevenZipStream' );