MediaWiki  master
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  public static function registerSource( ImportSource $source ) {
49  $id = wfRandomString();
50 
51  self::$sourceRegistrations[$id] = $source;
52 
53  return $id;
54  }
55 
63  public function stream_open( $path, $mode, $options, &$opened_path ) {
64  $url = parse_url( $path );
65  if ( !isset( $url['host'] ) ) {
66  return false;
67  }
68  $id = $url['host'];
69 
70  if ( !isset( self::$sourceRegistrations[$id] ) ) {
71  return false;
72  }
73 
74  $this->mSource = self::$sourceRegistrations[$id];
75 
76  return true;
77  }
78 
83  public function stream_read( $count ) {
84  $return = '';
85  $leave = false;
86 
87  while ( !$leave && !$this->mSource->atEnd() &&
88  strlen( $this->mBuffer ) < $count
89  ) {
90  $read = $this->mSource->readChunk();
91 
92  if ( !strlen( $read ) ) {
93  $leave = true;
94  }
95 
96  $this->mBuffer .= $read;
97  }
98 
99  if ( strlen( $this->mBuffer ) ) {
100  $return = substr( $this->mBuffer, 0, $count );
101  $this->mBuffer = substr( $this->mBuffer, $count );
102  }
103 
104  $this->mPosition += strlen( $return );
105 
106  return $return;
107  }
108 
113  public function stream_write( $data ) {
114  return false;
115  }
116 
120  public function stream_tell() {
121  return $this->mPosition;
122  }
123 
127  public function stream_eof() {
128  return $this->mSource->atEnd();
129  }
130 
134  public function url_stat() {
135  $result = [];
136 
137  $result['dev'] = $result[0] = 0;
138  $result['ino'] = $result[1] = 0;
139  $result['mode'] = $result[2] = 0;
140  $result['nlink'] = $result[3] = 0;
141  $result['uid'] = $result[4] = 0;
142  $result['gid'] = $result[5] = 0;
143  $result['rdev'] = $result[6] = 0;
144  $result['size'] = $result[7] = 0;
145  $result['atime'] = $result[8] = 0;
146  $result['mtime'] = $result[9] = 0;
147  $result['ctime'] = $result[10] = 0;
148  $result['blksize'] = $result[11] = 0;
149  $result['blocks'] = $result[12] = 0;
150 
151  return $result;
152  }
153 }
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
This is a horrible hack used to keep source compatibility.
stream_open( $path, $mode, $options, &$opened_path)
static ImportSource[] $sourceRegistrations
static registerSource(ImportSource $source)
Source interface for XML import.
$source