MediaWiki REL1_35
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 $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 public function stream_read( $count ) {
81 $return = '';
82 $leave = false;
83
84 while ( !$leave && !$this->mSource->atEnd() &&
85 strlen( $this->mBuffer ) < $count
86 ) {
87 $read = $this->mSource->readChunk();
88
89 if ( !strlen( $read ) ) {
90 $leave = true;
91 }
92
93 $this->mBuffer .= $read;
94 }
95
96 if ( strlen( $this->mBuffer ) ) {
97 $return = substr( $this->mBuffer, 0, $count );
98 $this->mBuffer = substr( $this->mBuffer, $count );
99 }
100
101 $this->mPosition += strlen( $return );
102
103 return $return;
104 }
105
110 public function stream_write( $data ) {
111 return false;
112 }
113
117 public function stream_tell() {
118 return $this->mPosition;
119 }
120
124 public function stream_eof() {
125 return $this->mSource->atEnd();
126 }
127
131 public function url_stat() {
132 $result = [];
133
134 $result['dev'] = $result[0] = 0;
135 $result['ino'] = $result[1] = 0;
136 $result['mode'] = $result[2] = 0;
137 $result['nlink'] = $result[3] = 0;
138 $result['uid'] = $result[4] = 0;
139 $result['gid'] = $result[5] = 0;
140 $result['rdev'] = $result[6] = 0;
141 $result['size'] = $result[7] = 0;
142 $result['atime'] = $result[8] = 0;
143 $result['mtime'] = $result[9] = 0;
144 $result['ctime'] = $result[10] = 0;
145 $result['blksize'] = $result[11] = 0;
146 $result['blocks'] = $result[12] = 0;
147
148 return $result;
149 }
150}
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