MediaWiki REL1_39
UploadSourceAdapter.php
Go to the documentation of this file.
1<?php
33 public static $sourceRegistrations = [];
34
36 public $context;
37
39 private $mSource;
40
42 private $mBuffer = '';
43
45 private $mPosition;
46
51 public static function registerSource( ImportSource $source ) {
52 $id = wfRandomString();
53
54 self::$sourceRegistrations[$id] = $source;
55
56 return $id;
57 }
58
66 public function stream_open( $path, $mode, $options, &$opened_path ) {
67 $url = parse_url( $path );
68 if ( !isset( $url['host'] ) ) {
69 return false;
70 }
71 $id = $url['host'];
72
73 if ( !isset( self::$sourceRegistrations[$id] ) ) {
74 return false;
75 }
76
77 $this->mSource = self::$sourceRegistrations[$id];
78
79 return true;
80 }
81
86 public function stream_read( $count ) {
87 $return = '';
88 $leave = false;
89
90 while ( !$leave && !$this->mSource->atEnd() &&
91 strlen( $this->mBuffer ) < $count
92 ) {
93 $read = $this->mSource->readChunk();
94
95 if ( !strlen( $read ) ) {
96 $leave = true;
97 }
98
99 $this->mBuffer .= $read;
100 }
101
102 if ( strlen( $this->mBuffer ) ) {
103 $return = substr( $this->mBuffer, 0, $count );
104 $this->mBuffer = substr( $this->mBuffer, $count );
105 }
106
107 $this->mPosition += strlen( $return );
108
109 return $return;
110 }
111
116 public function stream_write( $data ) {
117 return false;
118 }
119
123 public function stream_tell() {
124 return $this->mPosition;
125 }
126
130 public function stream_eof() {
131 return $this->mSource->atEnd();
132 }
133
137 public function url_stat() {
138 $result = [];
139
140 $result['dev'] = $result[0] = 0;
141 $result['ino'] = $result[1] = 0;
142 $result['mode'] = $result[2] = 0;
143 $result['nlink'] = $result[3] = 0;
144 $result['uid'] = $result[4] = 0;
145 $result['gid'] = $result[5] = 0;
146 $result['rdev'] = $result[6] = 0;
147 $result['size'] = $result[7] = 0;
148 $result['atime'] = $result[8] = 0;
149 $result['mtime'] = $result[9] = 0;
150 $result['ctime'] = $result[10] = 0;
151 $result['blksize'] = $result[11] = 0;
152 $result['blocks'] = $result[12] = 0;
153
154 return $result;
155 }
156}
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.
resource null $context
Must exists on stream wrapper class.
stream_open( $path, $mode, $options, &$opened_path)
static ImportSource[] $sourceRegistrations
static registerSource(ImportSource $source)
Source interface for XML import.
$source