MediaWiki
REL1_39
SevenZipStream.php
Go to the documentation of this file.
1
<?php
27
use
MediaWiki\Shell\Shell
;
28
36
class
SevenZipStream
{
38
protected
$stream
;
39
41
public
$context
;
42
43
public
static
function
register
() {
44
static
$done =
false
;
45
if
( !$done ) {
46
$done =
true
;
47
stream_wrapper_register(
'mediawiki.compress.7z'
, self::class );
48
}
49
}
50
51
private
function
stripPath(
$path
) {
52
$prefix =
'mediawiki.compress.7z://'
;
53
54
return
substr(
$path
, strlen( $prefix ) );
55
}
56
57
public
function
stream_open
(
$path
, $mode, $options, &$opened_path ) {
58
if
( $mode[0] ==
'r'
) {
59
$options =
'e -bd -so'
;
60
} elseif ( $mode[0] ==
'w'
) {
61
$options =
'a -bd -si'
;
62
}
else
{
63
return
false
;
64
}
65
$arg = Shell::escape( $this->stripPath(
$path
) );
66
$command
=
"7za $options $arg"
;
67
if
( !
wfIsWindows
() ) {
68
// Suppress the stupid messages on stderr
69
$command
.=
' 2>/dev/null'
;
70
}
71
// popen() doesn't like two-letter modes
72
$this->stream = popen(
$command
, $mode[0] );
73
return
( $this->stream !==
false
);
74
}
75
76
public
function
url_stat
(
$path
, $flags ) {
77
return
stat( $this->stripPath(
$path
) );
78
}
79
80
public
function
stream_close
() {
81
return
fclose( $this->stream );
82
}
83
84
public
function
stream_flush
() {
85
return
fflush( $this->stream );
86
}
87
88
public
function
stream_read
( $count ) {
89
return
fread( $this->stream, $count );
90
}
91
92
public
function
stream_write
( $data ) {
93
return
fwrite( $this->stream, $data );
94
}
95
96
public
function
stream_tell
() {
97
return
ftell( $this->stream );
98
}
99
100
public
function
stream_eof
() {
101
return
feof( $this->stream );
102
}
103
104
public
function
stream_seek
( $offset, $whence ) {
105
return
fseek( $this->stream, $offset, $whence );
106
}
107
}
wfIsWindows
wfIsWindows()
Check if the operating system is Windows.
Definition
GlobalFunctions.php:1462
$path
$path
Definition
NoLocalSettings.php:25
MediaWiki\Shell\Shell
Executes shell commands.
Definition
Shell.php:46
SevenZipStream
Stream wrapper around 7za filter program.
Definition
SevenZipStream.php:36
SevenZipStream\stream_write
stream_write( $data)
Definition
SevenZipStream.php:92
SevenZipStream\stream_eof
stream_eof()
Definition
SevenZipStream.php:100
SevenZipStream\stream_open
stream_open( $path, $mode, $options, &$opened_path)
Definition
SevenZipStream.php:57
SevenZipStream\$stream
resource false $stream
Definition
SevenZipStream.php:38
SevenZipStream\stream_tell
stream_tell()
Definition
SevenZipStream.php:96
SevenZipStream\stream_flush
stream_flush()
Definition
SevenZipStream.php:84
SevenZipStream\stream_read
stream_read( $count)
Definition
SevenZipStream.php:88
SevenZipStream\stream_close
stream_close()
Definition
SevenZipStream.php:80
SevenZipStream\$context
resource null $context
Must exists on stream wrapper class.
Definition
SevenZipStream.php:41
SevenZipStream\url_stat
url_stat( $path, $flags)
Definition
SevenZipStream.php:76
SevenZipStream\stream_seek
stream_seek( $offset, $whence)
Definition
SevenZipStream.php:104
$command
$command
Definition
mcc.php:125
maintenance
includes
SevenZipStream.php
Generated on Mon Dec 2 2024 06:25:18 for MediaWiki by
1.10.0