MediaWiki  1.34.4
UploadSourceAdapter.php
Go to the documentation of this file.
1 <?php
33  public static $sourceRegistrations = [];
34 
36  private $mSource;
37 
39  private $mBuffer;
40 
42  private $mPosition;
43 
48  static function registerSource( ImportSource $source ) {
49  $id = wfRandomString();
50 
51  self::$sourceRegistrations[$id] = $source;
52 
53  return $id;
54  }
55 
63  function stream_open( $path, $mode, $options, &$opened_path ) {
64  $url = parse_url( $path );
65  $id = $url['host'];
66 
67  if ( !isset( self::$sourceRegistrations[$id] ) ) {
68  return false;
69  }
70 
71  $this->mSource = self::$sourceRegistrations[$id];
72 
73  return true;
74  }
75 
80  function stream_read( $count ) {
81  $return = '';
82  $leave = false;
83 
84  while ( !$leave && !$this->mSource->atEnd() &&
85  strlen( $this->mBuffer ) < $count ) {
86  $read = $this->mSource->readChunk();
87 
88  if ( !strlen( $read ) ) {
89  $leave = true;
90  }
91 
92  $this->mBuffer .= $read;
93  }
94 
95  if ( strlen( $this->mBuffer ) ) {
96  $return = substr( $this->mBuffer, 0, $count );
97  $this->mBuffer = substr( $this->mBuffer, $count );
98  }
99 
100  $this->mPosition += strlen( $return );
101 
102  return $return;
103  }
104 
109  function stream_write( $data ) {
110  return false;
111  }
112 
116  function stream_tell() {
117  return $this->mPosition;
118  }
119 
123  function stream_eof() {
124  return $this->mSource->atEnd();
125  }
126 
130  function url_stat() {
131  $result = [];
132 
133  $result['dev'] = $result[0] = 0;
134  $result['ino'] = $result[1] = 0;
135  $result['mode'] = $result[2] = 0;
136  $result['nlink'] = $result[3] = 0;
137  $result['uid'] = $result[4] = 0;
138  $result['gid'] = $result[5] = 0;
139  $result['rdev'] = $result[6] = 0;
140  $result['size'] = $result[7] = 0;
141  $result['atime'] = $result[8] = 0;
142  $result['mtime'] = $result[9] = 0;
143  $result['ctime'] = $result[10] = 0;
144  $result['blksize'] = $result[11] = 0;
145  $result['blocks'] = $result[12] = 0;
146 
147  return $result;
148  }
149 }
UploadSourceAdapter\registerSource
static registerSource(ImportSource $source)
Definition: UploadSourceAdapter.php:48
UploadSourceAdapter\url_stat
url_stat()
Definition: UploadSourceAdapter.php:130
UploadSourceAdapter\$mBuffer
string $mBuffer
Definition: UploadSourceAdapter.php:39
UploadSourceAdapter\stream_tell
stream_tell()
Definition: UploadSourceAdapter.php:116
UploadSourceAdapter\stream_read
stream_read( $count)
Definition: UploadSourceAdapter.php:80
UploadSourceAdapter\stream_write
stream_write( $data)
Definition: UploadSourceAdapter.php:109
UploadSourceAdapter\stream_open
stream_open( $path, $mode, $options, &$opened_path)
Definition: UploadSourceAdapter.php:63
UploadSourceAdapter\$sourceRegistrations
static ImportSource[] $sourceRegistrations
Definition: UploadSourceAdapter.php:33
UploadSourceAdapter
This is a horrible hack used to keep source compatibility.
Definition: UploadSourceAdapter.php:31
ImportSource
Source interface for XML import.
Definition: ImportSource.php:32
$path
$path
Definition: NoLocalSettings.php:25
$source
$source
Definition: mwdoc-filter.php:34
UploadSourceAdapter\$mSource
ImportSource $mSource
Definition: UploadSourceAdapter.php:36
UploadSourceAdapter\$mPosition
int $mPosition
Definition: UploadSourceAdapter.php:42
UploadSourceAdapter\stream_eof
stream_eof()
Definition: UploadSourceAdapter.php:123
wfRandomString
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
Definition: GlobalFunctions.php:274