MediaWiki  1.23.15
MemoryFileBackend.php
Go to the documentation of this file.
1 <?php
36  protected $files = array();
37 
38  public function isPathUsableInternal( $storagePath ) {
39  return true;
40  }
41 
42  protected function doCreateInternal( array $params ) {
43  $status = Status::newGood();
44 
45  $dst = $this->resolveHashKey( $params['dst'] );
46  if ( $dst === null ) {
47  $status->fatal( 'backend-fail-invalidpath', $params['dst'] );
48 
49  return $status;
50  }
51 
52  $this->files[$dst] = array(
53  'data' => $params['content'],
54  'mtime' => wfTimestamp( TS_MW, time() )
55  );
56 
57  return $status;
58  }
59 
60  protected function doStoreInternal( array $params ) {
61  $status = Status::newGood();
62 
63  $dst = $this->resolveHashKey( $params['dst'] );
64  if ( $dst === null ) {
65  $status->fatal( 'backend-fail-invalidpath', $params['dst'] );
66 
67  return $status;
68  }
69 
71  $data = file_get_contents( $params['src'] );
73  if ( $data === false ) { // source doesn't exist?
74  $status->fatal( 'backend-fail-store', $params['src'], $params['dst'] );
75 
76  return $status;
77  }
78 
79  $this->files[$dst] = array(
80  'data' => $data,
81  'mtime' => wfTimestamp( TS_MW, time() )
82  );
83 
84  return $status;
85  }
86 
87  protected function doCopyInternal( array $params ) {
88  $status = Status::newGood();
89 
90  $src = $this->resolveHashKey( $params['src'] );
91  if ( $src === null ) {
92  $status->fatal( 'backend-fail-invalidpath', $params['src'] );
93 
94  return $status;
95  }
96 
97  $dst = $this->resolveHashKey( $params['dst'] );
98  if ( $dst === null ) {
99  $status->fatal( 'backend-fail-invalidpath', $params['dst'] );
100 
101  return $status;
102  }
103 
104  if ( !isset( $this->files[$src] ) ) {
105  if ( empty( $params['ignoreMissingSource'] ) ) {
106  $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] );
107  }
108 
109  return $status;
110  }
111 
112  $this->files[$dst] = array(
113  'data' => $this->files[$src]['data'],
114  'mtime' => wfTimestamp( TS_MW, time() )
115  );
116 
117  return $status;
118  }
119 
120  protected function doDeleteInternal( array $params ) {
121  $status = Status::newGood();
122 
123  $src = $this->resolveHashKey( $params['src'] );
124  if ( $src === null ) {
125  $status->fatal( 'backend-fail-invalidpath', $params['src'] );
126 
127  return $status;
128  }
129 
130  if ( !isset( $this->files[$src] ) ) {
131  if ( empty( $params['ignoreMissingSource'] ) ) {
132  $status->fatal( 'backend-fail-delete', $params['src'] );
133  }
134 
135  return $status;
136  }
137 
138  unset( $this->files[$src] );
139 
140  return $status;
141  }
142 
143  protected function doGetFileStat( array $params ) {
144  $src = $this->resolveHashKey( $params['src'] );
145  if ( $src === null ) {
146  return null;
147  }
148 
149  if ( isset( $this->files[$src] ) ) {
150  return array(
151  'mtime' => $this->files[$src]['mtime'],
152  'size' => strlen( $this->files[$src]['data'] ),
153  );
154  }
155 
156  return false;
157  }
158 
159  protected function doGetLocalCopyMulti( array $params ) {
160  $tmpFiles = array(); // (path => TempFSFile)
161  foreach ( $params['srcs'] as $srcPath ) {
162  $src = $this->resolveHashKey( $srcPath );
163  if ( $src === null || !isset( $this->files[$src] ) ) {
164  $fsFile = null;
165  } else {
166  // Create a new temporary file with the same extension...
168  $fsFile = TempFSFile::factory( 'localcopy_', $ext );
169  if ( $fsFile ) {
170  $bytes = file_put_contents( $fsFile->getPath(), $this->files[$src]['data'] );
171  if ( $bytes !== strlen( $this->files[$src]['data'] ) ) {
172  $fsFile = null;
173  }
174  }
175  }
176  $tmpFiles[$srcPath] = $fsFile;
177  }
178 
179  return $tmpFiles;
180  }
181 
182  protected function doStreamFile( array $params ) {
183  $status = Status::newGood();
184 
185  $src = $this->resolveHashKey( $params['src'] );
186  if ( $src === null || !isset( $this->files[$src] ) ) {
187  $status->fatal( 'backend-fail-stream', $params['src'] );
188 
189  return $status;
190  }
191 
192  print $this->files[$src]['data'];
193 
194  return $status;
195  }
196 
197  protected function doDirectoryExists( $container, $dir, array $params ) {
198  $prefix = rtrim( "$container/$dir", '/' ) . '/';
199  foreach ( $this->files as $path => $data ) {
200  if ( strpos( $path, $prefix ) === 0 ) {
201  return true;
202  }
203  }
204 
205  return false;
206  }
207 
208  public function getDirectoryListInternal( $container, $dir, array $params ) {
209  $dirs = array();
210  $prefix = rtrim( "$container/$dir", '/' ) . '/';
211  $prefixLen = strlen( $prefix );
212  foreach ( $this->files as $path => $data ) {
213  if ( strpos( $path, $prefix ) === 0 ) {
214  $relPath = substr( $path, $prefixLen );
215  if ( $relPath === false ) {
216  continue;
217  } elseif ( strpos( $relPath, '/' ) === false ) {
218  continue; // just a file
219  }
220  $parts = array_slice( explode( '/', $relPath ), 0, -1 ); // last part is file name
221  if ( !empty( $params['topOnly'] ) ) {
222  $dirs[$parts[0]] = 1; // top directory
223  } else {
224  $current = '';
225  foreach ( $parts as $part ) { // all directories
226  $dir = ( $current === '' ) ? $part : "$current/$part";
227  $dirs[$dir] = 1;
228  $current = $dir;
229  }
230  }
231  }
232  }
233 
234  return array_keys( $dirs );
235  }
236 
237  public function getFileListInternal( $container, $dir, array $params ) {
238  $files = array();
239  $prefix = rtrim( "$container/$dir", '/' ) . '/';
240  $prefixLen = strlen( $prefix );
241  foreach ( $this->files as $path => $data ) {
242  if ( strpos( $path, $prefix ) === 0 ) {
243  $relPath = substr( $path, $prefixLen );
244  if ( $relPath === false ) {
245  continue;
246  } elseif ( !empty( $params['topOnly'] ) && strpos( $relPath, '/' ) !== false ) {
247  continue;
248  }
249  $files[] = $relPath;
250  }
251  }
252 
253  return $files;
254  }
255 
256  protected function directoriesAreVirtual() {
257  return true;
258  }
259 
266  protected function resolveHashKey( $storagePath ) {
267  list( $fullCont, $relPath ) = $this->resolveStoragePathReal( $storagePath );
268  if ( $relPath === null ) {
269  return null; // invalid
270  }
271 
272  return ( $relPath !== '' ) ? "$fullCont/$relPath" : $fullCont;
273  }
274 }
MemoryFileBackend\doCopyInternal
doCopyInternal(array $params)
Definition: MemoryFileBackend.php:86
MemoryFileBackend\doDirectoryExists
doDirectoryExists( $container, $dir, array $params)
Definition: MemoryFileBackend.php:196
MemoryFileBackend\doStreamFile
doStreamFile(array $params)
Definition: MemoryFileBackend.php:181
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
MemoryFileBackend\doDeleteInternal
doDeleteInternal(array $params)
Definition: MemoryFileBackend.php:119
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:2530
MemoryFileBackend\getDirectoryListInternal
getDirectoryListInternal( $container, $dir, array $params)
Do not call this function from places outside FileBackend.
Definition: MemoryFileBackend.php:207
MemoryFileBackend\doGetFileStat
doGetFileStat(array $params)
Definition: MemoryFileBackend.php:142
wfSuppressWarnings
wfSuppressWarnings( $end=false)
Reference-counted warning suppression.
Definition: GlobalFunctions.php:2434
FileBackend\extensionFromPath
static extensionFromPath( $path, $case='lowercase')
Get the final extension from a storage or FS path.
Definition: FileBackend.php:1401
Status\newGood
static newGood( $value=null)
Factory function for good results.
Definition: Status.php:77
$params
$params
Definition: styleTest.css.php:40
MemoryFileBackend\doStoreInternal
doStoreInternal(array $params)
Definition: MemoryFileBackend.php:59
wfRestoreWarnings
wfRestoreWarnings()
Restore error level to previous value.
Definition: GlobalFunctions.php:2464
MemoryFileBackend\$files
array $files
Map of (file path => (data,mtime) *.
Definition: MemoryFileBackend.php:35
MemoryFileBackend\doGetLocalCopyMulti
doGetLocalCopyMulti(array $params)
Definition: MemoryFileBackend.php:158
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
$dirs
$dirs
Definition: mergeMessageFileList.php:163
MemoryFileBackend\isPathUsableInternal
isPathUsableInternal( $storagePath)
Check if a file can be created or changed at a given storage path.
Definition: MemoryFileBackend.php:37
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
TS_MW
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
Definition: GlobalFunctions.php:2478
TempFSFile\factory
static factory( $prefix, $extension='')
Make a new temporary file on the file system.
Definition: TempFSFile.php:44
MemoryFileBackend
Simulation of a backend storage in memory.
Definition: MemoryFileBackend.php:34
FileBackendStore\resolveStoragePathReal
resolveStoragePathReal( $storagePath)
Like resolveStoragePath() except null values are returned if the container is sharded and the shard c...
Definition: FileBackendStore.php:1418
MemoryFileBackend\getFileListInternal
getFileListInternal( $container, $dir, array $params)
Do not call this function from places outside FileBackend.
Definition: MemoryFileBackend.php:236
MemoryFileBackend\doCreateInternal
doCreateInternal(array $params)
Definition: MemoryFileBackend.php:41
FileBackendStore
Base class for all backends using particular storage medium.
Definition: FileBackendStore.php:38
MemoryFileBackend\resolveHashKey
resolveHashKey( $storagePath)
Get the absolute file system path for a storage path.
Definition: MemoryFileBackend.php:265
$dir
if(count( $args)==0) $dir
Definition: importImages.php:49
$ext
$ext
Definition: NoLocalSettings.php:34
$path
$path
Definition: NoLocalSettings.php:35
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
MemoryFileBackend\directoriesAreVirtual
directoriesAreVirtual()
Is this a key/value store where directories are just virtual? Virtual directories exists in so much a...
Definition: MemoryFileBackend.php:255