Index: trunk/extensions/WindowsAzureStorage/includes/filerepo/backend/WindowsAzureFileBackend.php |
— | — | @@ -27,23 +27,23 @@ |
28 | 28 | function doStore( array $p ) { |
29 | 29 | return $this->doStoreInternal( $p ); |
30 | 30 | } |
31 | | - |
| 31 | + |
32 | 32 | function doCopy( array $p ) { |
33 | 33 | return $this->doCopyInternal( $p ); |
34 | 34 | } |
35 | | - |
| 35 | + |
36 | 36 | function doDelete( array $p ) { |
37 | 37 | return $this->doDeleteInternal( $p ); |
38 | 38 | } |
39 | | - |
| 39 | + |
40 | 40 | function doConcatenate( array $p ) { |
41 | 41 | return $this->dodoConcatenateInternal( $p ); |
42 | 42 | } |
43 | | - |
| 43 | + |
44 | 44 | function doCreate( array $p ) { |
45 | 45 | return $this->doCreateInternal( $p ); |
46 | 46 | } |
47 | | - |
| 47 | + |
48 | 48 | /** |
49 | 49 | * @see FileBackend::move() |
50 | 50 | */ |
— | — | @@ -60,13 +60,13 @@ |
61 | 61 | $status->setResult( true, $status->value ); // ignore delete() errors |
62 | 62 | return $status; |
63 | 63 | } |
64 | | - |
| 64 | + |
65 | 65 | /** @var Microsoft_WindowsAzure_Storage_Blob */ |
66 | 66 | protected $storageClient = null; |
67 | 67 | |
68 | | - /** @var Array Map of container names to Azure container names */ |
| 68 | + /** @var Array Map of container names to Azure container names */ |
69 | 69 | protected $containerPaths = array(); |
70 | | - |
| 70 | + |
71 | 71 | /** |
72 | 72 | * @see FileBackend::__construct() |
73 | 73 | * Additional $config params include: |
— | — | @@ -74,7 +74,7 @@ |
75 | 75 | * azureAccount : Windows Azure user used by MediaWiki |
76 | 76 | * azureKey : Authentication key for the above user (used to get sessions) |
77 | 77 | * //azureContainer : Identifier of the container. (Optional. If not provided wikiId will be used as container name) |
78 | | - * containerPaths : Map of container names to Azure container names |
| 78 | + * containerPaths : Map of container names to Azure container names |
79 | 79 | */ |
80 | 80 | public function __construct( array $config ) { |
81 | 81 | parent::__construct( $config ); |
— | — | @@ -84,14 +84,14 @@ |
85 | 85 | $config['azureKey'] |
86 | 86 | ); |
87 | 87 | |
88 | | - $this->containerPaths = (array)$config['containerPaths']; |
| 88 | + $this->containerPaths = (array)$config['containerPaths']; |
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
92 | 92 | * @see FileBackend::resolveContainerPath() |
93 | 93 | */ |
94 | 94 | protected function resolveContainerPath( $container, $relStoragePath ) { |
95 | | - //Azure container naming conventions; http://msdn.microsoft.com/en-us/library/dd135715.aspx |
| 95 | + //Azure container naming conventions; http://msdn.microsoft.com/en-us/library/dd135715.aspx |
96 | 96 | |
97 | 97 | if ( strlen( urlencode( $relStoragePath ) ) > 1024 ) { |
98 | 98 | return null; |
— | — | @@ -150,11 +150,11 @@ |
151 | 151 | |
152 | 152 | // (a) Check the source container |
153 | 153 | try { //TODO: Unnecessary --> remove |
154 | | - $container = $this->storageClient->getContainer( $srcCont ); |
| 154 | + $container = $this->storageClient->getContainer( $srcCont ); |
155 | 155 | } |
156 | | - catch ( Exception $e ) { |
| 156 | + catch ( Exception $e ) { |
157 | 157 | // TODO: remove error_log |
158 | | - error_log( __METHOD__.':'.__LINE__.' '.$e->getMessage() ); |
| 158 | + error_log( __METHOD__.':'.__LINE__.' '.$e->getMessage() ); |
159 | 159 | $status->fatal( 'backend-fail-internal' ); |
160 | 160 | return $status; |
161 | 161 | } |
— | — | @@ -163,8 +163,8 @@ |
164 | 164 | try { |
165 | 165 | $this->storageClient->deleteBlob( $srcCont, $srcRel ); |
166 | 166 | } |
167 | | - catch ( Exception $e ) { |
168 | | - error_log( __METHOD__.':'.__LINE__.' '.$e->getMessage() ); |
| 167 | + catch ( Exception $e ) { |
| 168 | + error_log( __METHOD__.':'.__LINE__.' '.$e->getMessage() ); |
169 | 169 | $status->fatal( 'backend-fail-internal' ); |
170 | 170 | } |
171 | 171 | |
— | — | @@ -184,19 +184,19 @@ |
185 | 185 | } |
186 | 186 | |
187 | 187 | // (a) Check if the destination object already exists |
188 | | - $blobExists = $this->storageClient->blobExists( $dstCont, $dstRel ); |
189 | | - if ( $blobExists && empty( $params['overwriteDest'] ) ) { //Blob exists _and_ should not be overridden |
190 | | - $status->fatal( 'backend-fail-alreadyexists', $params['dst'] ); |
191 | | - return $status; |
192 | | - } |
| 188 | + $blobExists = $this->storageClient->blobExists( $dstCont, $dstRel ); |
| 189 | + if ( $blobExists && empty( $params['overwriteDest'] ) ) { //Blob exists _and_ should not be overridden |
| 190 | + $status->fatal( 'backend-fail-alreadyexists', $params['dst'] ); |
| 191 | + return $status; |
| 192 | + } |
193 | 193 | |
194 | 194 | // (b) Actually create the object |
195 | 195 | try { |
196 | 196 | // TODO: how do I know the container exists? Should we call prepare? |
197 | | - $this->storageClient->putBlobData( $dstCont, $dstRel, $params['content'] ); |
| 197 | + $this->storageClient->putBlobData( $dstCont, $dstRel, $params['content'] ); |
198 | 198 | } |
199 | | - catch ( Exception $e ) { |
200 | | - error_log( __METHOD__.':'.__LINE__.' '.$e->getMessage() ); |
| 199 | + catch ( Exception $e ) { |
| 200 | + error_log( __METHOD__.':'.__LINE__.' '.$e->getMessage() ); |
201 | 201 | $status->fatal( 'backend-fail-internal' ); |
202 | 202 | } |
203 | 203 | |
— | — | @@ -209,36 +209,36 @@ |
210 | 210 | function prepare( array $params ) { |
211 | 211 | $status = Status::newGood(); |
212 | 212 | |
213 | | - list( $c, $dir ) = $this->resolveStoragePath( $params['dir'] ); |
| 213 | + list( $c, $dir ) = $this->resolveStoragePath( $params['dir'] ); |
214 | 214 | if ( $dir === null ) { |
215 | 215 | $status->fatal( 'backend-fail-invalidpath', $params['dir'] ); |
216 | 216 | return $status; // invalid storage path |
217 | 217 | } |
218 | | - try { |
219 | | - $this->storageClient->createContainerIfNotExists( $c ); |
220 | | - $this->storageClient->setContainerAcl( $c, Microsoft_WindowsAzure_Storage_Blob::ACL_PUBLIC );//TODO: Really set public? |
| 218 | + try { |
| 219 | + $this->storageClient->createContainerIfNotExists( $c ); |
| 220 | + $this->storageClient->setContainerAcl( $c, Microsoft_WindowsAzure_Storage_Blob::ACL_PUBLIC );//TODO: Really set public? |
221 | 221 | |
222 | | - //TODO: check if readable and writeable |
223 | | - //$container = $this->storageClient->getContainer( $c ); |
224 | | - //$status->fatal( 'directoryreadonlyerror', $params['dir'] ); |
225 | | - //$status->fatal( 'directorynotreadableerror', $params['dir'] ); |
226 | | - } |
227 | | - catch (Exception $e ) { |
228 | | - $status->fatal( 'directorycreateerror', $params['dir'] ); |
| 222 | + //TODO: check if readable and writeable |
| 223 | + //$container = $this->storageClient->getContainer( $c ); |
| 224 | + //$status->fatal( 'directoryreadonlyerror', $params['dir'] ); |
| 225 | + //$status->fatal( 'directorynotreadableerror', $params['dir'] ); |
| 226 | + } |
| 227 | + catch (Exception $e ) { |
| 228 | + $status->fatal( 'directorycreateerror', $params['dir'] ); |
229 | 229 | return $status; |
230 | | - } |
| 230 | + } |
231 | 231 | return $status; |
232 | 232 | } |
233 | | - |
234 | | - /** |
| 233 | + |
| 234 | + /** |
235 | 235 | * @see FileBackend::resolveContainerName() |
236 | 236 | */ |
237 | | - protected function resolveContainerName( $container ) { |
238 | | - //Azure container naming conventions; http://msdn.microsoft.com/en-us/library/dd135715.aspx |
239 | | - $container = strtolower($container); |
240 | | - $container = preg_replace( '#[^a-z0-9\-]#', '', $container ); |
| 237 | + protected function resolveContainerName( $container ) { |
| 238 | + //Azure container naming conventions; http://msdn.microsoft.com/en-us/library/dd135715.aspx |
| 239 | + $container = strtolower($container); |
| 240 | + $container = preg_replace( '#[^a-z0-9\-]#', '', $container ); |
241 | 241 | // TODO: -test und test- geht auch nicht |
242 | | - $container = preg_replace( '#-{2,}#', '-', $container ); |
| 242 | + $container = preg_replace( '#-{2,}#', '-', $container ); |
243 | 243 | |
244 | 244 | return $container; |
245 | 245 | } |
— | — | @@ -256,7 +256,7 @@ |
257 | 257 | * @see FileBackend::fileExists() |
258 | 258 | */ |
259 | 259 | function fileExists( array $params ) { |
260 | | - list( $c, $dir ) = $this->resolveStoragePath( $params['src'] ); |
| 260 | + list( $c, $dir ) = $this->resolveStoragePath( $params['src'] ); |
261 | 261 | // TODO: null? Telling names |
262 | 262 | $exists = $this->storageClient->blobExists( $c, $dir ); |
263 | 263 | //error_log( __METHOD__.'::blobExists - result: '.$exists ); |
— | — | @@ -272,38 +272,38 @@ |
273 | 273 | return false; // invalid storage path |
274 | 274 | } |
275 | 275 | |
276 | | - $timestamp= false; |
| 276 | + $timestamp= false; |
277 | 277 | try { |
278 | | - //TODO Maybe use getBlobData()? |
279 | | - $blob = $this->storageClient->getBlobInstance( $srcCont, $srcRel ); |
280 | | - $timestamp = wfTimestamp( TS_MW, $blob->lastmodified ); //TODO: Timezone? |
| 278 | + //TODO Maybe use getBlobData()? |
| 279 | + $blob = $this->storageClient->getBlobInstance( $srcCont, $srcRel ); |
| 280 | + $timestamp = wfTimestamp( TS_MW, $blob->lastmodified ); //TODO: Timezone? |
281 | 281 | } catch ( Exception $e ) { // some other exception? |
282 | | - error_log( __METHOD__.':'.__LINE__.' '.$e->getMessage() ); |
| 282 | + error_log( __METHOD__.':'.__LINE__.' '.$e->getMessage() ); |
283 | 283 | } |
284 | | - return $timestamp; |
| 284 | + return $timestamp; |
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
288 | 288 | * @see FileBackend::getFileList() |
289 | 289 | */ |
290 | 290 | function getFileList( array $params ) { |
291 | | - $files = array(); |
| 291 | + $files = array(); |
292 | 292 | list( $c, $dir ) = $this->resolveStoragePath( $params['dir'] ); |
293 | | - try { |
294 | | - if ( $dir === null ) { |
295 | | - $blobs = $this->storageClient->listBlobs($c); |
296 | | - } |
297 | | - else { |
298 | | - $blobs = $this->storageClient->listBlobs( $c, $dir );//TODO:Check if $dir really is a startsequence of the blob name |
299 | | - } |
300 | | - foreach( $blobs as $blob ) { |
301 | | - $files[] = $blob->name; |
302 | | - } |
303 | | - } |
304 | | - catch( Exception $e ) { |
305 | | - error_log( __METHOD__.':'.__LINE__.' '.$e->getMessage() ); |
306 | | - return null; |
307 | | - } |
| 293 | + try { |
| 294 | + if ( $dir === null ) { |
| 295 | + $blobs = $this->storageClient->listBlobs($c); |
| 296 | + } |
| 297 | + else { |
| 298 | + $blobs = $this->storageClient->listBlobs( $c, $dir );//TODO:Check if $dir really is a startsequence of the blob name |
| 299 | + } |
| 300 | + foreach( $blobs as $blob ) { |
| 301 | + $files[] = $blob->name; |
| 302 | + } |
| 303 | + } |
| 304 | + catch( Exception $e ) { |
| 305 | + error_log( __METHOD__.':'.__LINE__.' '.$e->getMessage() ); |
| 306 | + return null; |
| 307 | + } |
308 | 308 | |
309 | 309 | // if there are no files matching the prefix, return empty array |
310 | 310 | return $files; |
— | — | @@ -329,10 +329,10 @@ |
330 | 330 | $tmpPath = $tmpFile->getPath(); |
331 | 331 | |
332 | 332 | try { |
333 | | - $this->storageClient->getBlob( $srcCont, $srcRel, $tmpPath ); |
| 333 | + $this->storageClient->getBlob( $srcCont, $srcRel, $tmpPath ); |
334 | 334 | } |
335 | | - catch ( Exception $e ) { |
336 | | - error_log( __METHOD__.':'.__LINE__.' '.$e->getMessage() ); |
| 335 | + catch ( Exception $e ) { |
| 336 | + error_log( __METHOD__.':'.__LINE__.' '.$e->getMessage() ); |
337 | 337 | $tmpFile = null; |
338 | 338 | } |
339 | 339 | |
Index: trunk/extensions/WindowsAzureStorage/WindowsAzureStorage.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | /* |
4 | 4 | (c) Hallo Welt! Medienwerkstatt GmbH, 2011 GPL |
5 | | - |
| 5 | + |
6 | 6 | This program is free software; you can redistribute it and/or modify |
7 | 7 | it under the terms of the GNU General Public License as published by |
8 | 8 | the Free Software Foundation; either version 2 of the License, or |
— | — | @@ -39,21 +39,21 @@ |
40 | 40 | |
41 | 41 | /* Those are just development values. You may override them or specify your own backend definition in LocalSettings.php */ |
42 | 42 | $wgFileBackends[] = array( |
43 | | - 'name' => 'azure-backend', |
44 | | - 'class' => 'WindowsAzureFileBackend', |
45 | | - //'wikiId' => 'some_unique_ID', |
46 | | - 'lockManager' => 'nullLockManager', |
47 | | - 'azureHost' => 'http://127.0.0.1:10000', |
48 | | - 'azureAccount' => 'devstoreaccount1', |
49 | | - 'azureKey' => 'Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==', |
50 | | - //'azureContainer' => 'developcontainer', |
51 | | - |
52 | | - //IMPORTANT: Mind the container naming conventions! http://msdn.microsoft.com/en-us/library/dd135715.aspx |
53 | | - 'containerPaths' => array( |
54 | | - 'media-public' => 'media-public', |
55 | | - 'media-thumb' => 'media-thumb', |
56 | | - 'media-deleted' => 'media-deleted', |
57 | | - 'media-temp' => 'media-temp', |
| 43 | + 'name' => 'azure-backend', |
| 44 | + 'class' => 'WindowsAzureFileBackend', |
| 45 | + //'wikiId' => 'some_unique_ID', |
| 46 | + 'lockManager' => 'nullLockManager', |
| 47 | + 'azureHost' => 'http://127.0.0.1:10000', |
| 48 | + 'azureAccount' => 'devstoreaccount1', |
| 49 | + 'azureKey' => 'Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==', |
| 50 | + //'azureContainer' => 'developcontainer', |
58 | 51 | |
59 | | - ) |
60 | | -); |
\ No newline at end of file |
| 52 | + //IMPORTANT: Mind the container naming conventions! http://msdn.microsoft.com/en-us/library/dd135715.aspx |
| 53 | + 'containerPaths' => array( |
| 54 | + 'media-public' => 'media-public', |
| 55 | + 'media-thumb' => 'media-thumb', |
| 56 | + 'media-deleted' => 'media-deleted', |
| 57 | + 'media-temp' => 'media-temp', |
| 58 | + |
| 59 | + ) |
| 60 | +); |