r99442 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99441‎ | r99442 | r99443 >
Date:22:48, 10 October 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Stylize
Modified paths:
  • /trunk/extensions/SwiftMedia/SwiftMedia.body.php (modified) (history)
  • /trunk/extensions/SwiftMedia/SwiftMedia.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SwiftMedia/SwiftMedia.php
@@ -12,7 +12,7 @@
1313 $wgAutoloadClasses['SwiftForeignDBFile'] =
1414 $wgAutoloadClasses['SwiftForeignDBRepo'] =
1515 $wgAutoloadClasses['SwiftForeignDBviaLBRepo'] =
16 - $wgAutoloadClasses['SwiftRepo'] = dirname(__FILE__) . '/SwiftMedia.body.php';
 16+ $wgAutoloadClasses['SwiftRepo'] = dirname( __FILE__ ) . '/SwiftMedia.body.php';
1717 $wgAutoloadClasses['CF_Authentication'] =
1818 $wgAutoloadClasses['CF_Connection'] =
1919 $wgAutoloadClasses['CF_Container'] =
Index: trunk/extensions/SwiftMedia/SwiftMedia.body.php
@@ -29,28 +29,28 @@
3030 */
3131 var
3232 $conn; # our connection to the Swift proxy.
33 - #$fileExists, # does the file file exist on disk? (loadFromXxx)
34 - #$historyLine, # Number of line to return by nextHistoryLine() (constructor)
35 - #$historyRes, # result of the query for the file's history (nextHistoryLine)
36 - #$width, # \
37 - #$height, # |
38 - #$bits, # --- returned by getimagesize (loadFromXxx)
39 - #$attr, # /
40 - #$media_type, # MEDIATYPE_xxx (bitmap, drawing, audio...)
41 - #$mime, # MIME type, determined by MimeMagic::guessMimeType
42 - #$major_mime, # Major mime type
43 - #$minor_mime, # Minor mime type
44 - #$size, # Size in bytes (loadFromXxx)
45 - #$metadata, # Handler-specific metadata
46 - #$timestamp, # Upload timestamp
47 - #$sha1, # SHA-1 base 36 content hash
48 - #$user, $user_text, # User, who uploaded the file
49 - #$description, # Description of current revision of the file
50 - #$dataLoaded, # Whether or not all this has been loaded from the database (loadFromXxx)
51 - #$upgraded, # Whether the row was upgraded on load
52 - #$locked, # True if the image row is locked
53 - #$missing, # True if file is not present in file system. Not to be cached in memcached
54 - #$deleted; # Bitfield akin to rev_deleted
 33+ # $fileExists, # does the file file exist on disk? (loadFromXxx)
 34+ # $historyLine, # Number of line to return by nextHistoryLine() (constructor)
 35+ # $historyRes, # result of the query for the file's history (nextHistoryLine)
 36+ # $width, # \
 37+ # $height, # |
 38+ # $bits, # --- returned by getimagesize (loadFromXxx)
 39+ # $attr, # /
 40+ # $media_type, # MEDIATYPE_xxx (bitmap, drawing, audio...)
 41+ # $mime, # MIME type, determined by MimeMagic::guessMimeType
 42+ # $major_mime, # Major mime type
 43+ # $minor_mime, # Minor mime type
 44+ # $size, # Size in bytes (loadFromXxx)
 45+ # $metadata, # Handler-specific metadata
 46+ # $timestamp, # Upload timestamp
 47+ # $sha1, # SHA-1 base 36 content hash
 48+ # $user, $user_text, # User, who uploaded the file
 49+ # $description, # Description of current revision of the file
 50+ # $dataLoaded, # Whether or not all this has been loaded from the database (loadFromXxx)
 51+ # $upgraded, # Whether the row was upgraded on load
 52+ # $locked, # True if the image row is locked
 53+ # $missing, # True if file is not present in file system. Not to be cached in memcached
 54+ # $deleted; # Bitfield akin to rev_deleted
5555 /**#@-*/
5656
5757 /**
@@ -67,7 +67,7 @@
6868 * @return SwiftFile
6969 */
7070 static function newFromTitle( $title, $repo, $unused = null ) {
71 - if ( empty($title) ) {
 71+ if ( empty( $title ) ) {
7272 return null;
7373 }
7474 return new self( $title, $repo );
@@ -107,13 +107,13 @@
108108 /** isVisible inherited */
109109
110110 public function getPath() {
111 - $this->tempPath = $this->repo->getLocalCopy($this->repo->container, $this->getRel());
 111+ $this->tempPath = $this->repo->getLocalCopy( $this->repo->container, $this->getRel() );
112112 return $this->tempPath;
113113 }
114114
115115 /** Get the path of the archive directory, or a particular file if $suffix is specified */
116116 public function getArchivePath( $suffix = false ) {
117 - $this->tempPath = $this->repo->getLocalCopy($this->repo->getZoneContainer('public'), $this->getArchiveRel( $suffix ));
 117+ $this->tempPath = $this->repo->getLocalCopy( $this->repo->getZoneContainer( 'public' ), $this->getArchiveRel( $suffix ) );
118118 return $this->tempPath;
119119 }
120120
@@ -123,12 +123,12 @@
124124 if ( $suffix !== false ) {
125125 $path .= '/' . $suffix;
126126 }
127 - $this->tempPath = $this->repo->getLocalCopy($this->repo->getZoneContainer('thumb'), $path);
 127+ $this->tempPath = $this->repo->getLocalCopy( $this->repo->getZoneContainer( 'thumb' ), $path );
128128 return $this->tempPath;
129129 }
130130
131131 function __destruct() {
132 - if ($this->tempPath) {
 132+ if ( $this->tempPath ) {
133133 // Clean up temporary data.
134134 unlink( $this->tempPath );
135135 $this->tempPath = null;
@@ -151,25 +151,25 @@
152152 global $wgIgnoreImageErrors, $wgThumbnailEpoch, $wgTmpDirectory;
153153
154154 // get a temporary place to put the original.
155 - $thumbPath = tempnam( $wgTmpDirectory, 'transform_out_') . '.' . pathinfo( $thumbName, PATHINFO_EXTENSION );
 155+ $thumbPath = tempnam( $wgTmpDirectory, 'transform_out_' ) . '.' . pathinfo( $thumbName, PATHINFO_EXTENSION );
156156
157 - if ( $this->repo && $this->repo->canTransformVia404() && !($flags & self::RENDER_NOW ) ) {
 157+ if ( $this->repo && $this->repo->canTransformVia404() && !( $flags & self::RENDER_NOW ) ) {
158158 return $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
159159 }
160160
161161 // see if the file exists, and if it exists, is not too old.
162162 $conn = $this->repo->connect();
163 - $container = $this->repo->get_container($conn,$this->repo->container . '%2Fthumb');
 163+ $container = $this->repo->get_container( $conn, $this->repo->container . '%2Fthumb' );
164164 try {
165 - $pic = $container->get_object($this->getRel() . "/$thumbName");
166 - } catch (NoSuchObjectException $e) {
 165+ $pic = $container->get_object( $this->getRel() . "/$thumbName" );
 166+ } catch ( NoSuchObjectException $e ) {
167167 $pic = NULL;
168168 }
169169 if ( $pic ) {
170170 $thumbTime = $pic->last_modified;
171 - $tm = strptime($thumbTime, '%a, %d %b %Y %H:%M:%S GMT');
172 - $thumbGMT = gmmktime($tm['tm_hour'], $tm['tm_min'], $tm['tm_sec'], $tm['tm_mon']+1, $tm['tm_mday'], $tm['tm_year'] + 1900);
173 - wfDebug( __METHOD__.": $thumbName is dated $thumbGMT\n" );
 171+ $tm = strptime( $thumbTime, '%a, %d %b %Y %H:%M:%S GMT' );
 172+ $thumbGMT = gmmktime( $tm['tm_hour'], $tm['tm_min'], $tm['tm_sec'], $tm['tm_mon'] + 1, $tm['tm_mday'], $tm['tm_year'] + 1900 );
 173+ wfDebug( __METHOD__ . ": $thumbName is dated $thumbGMT\n" );
174174 if ( gmdate( 'YmdHis', $thumbGMT ) >= $wgThumbnailEpoch ) {
175175
176176 return $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
@@ -182,7 +182,7 @@
183183 $thumb = null;
184184 } elseif ( $thumb->isError() ) {
185185 $this->lastError = $thumb->toText();
186 - if ( $wgIgnoreImageErrors && !($flags & self::RENDER_NOW) ) {
 186+ if ( $wgIgnoreImageErrors && !( $flags & self::RENDER_NOW ) ) {
187187 $thumb = $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
188188 }
189189 }
@@ -217,7 +217,7 @@
218218 * Get the public root directory of the repository.
219219 */
220220 protected function getRootDirectory() {
221 - throw new MWException( __METHOD__.': not implemented' );
 221+ throw new MWException( __METHOD__ . ': not implemented' );
222222 }
223223
224224 /** getHandler inherited */
@@ -229,18 +229,18 @@
230230 * @param $archiveName string: the article name for the archived file (if archived).
231231 * @return a list of files, the first entry of which is the directory name (if applicable).
232232 */
233 - function getThumbnails($archiveName = false) {
 233+ function getThumbnails( $archiveName = false ) {
234234 $this->load();
235235
236 - if ($archiveName) {
237 - $prefix = $this->getArchiveRel($archiveName);
 236+ if ( $archiveName ) {
 237+ $prefix = $this->getArchiveRel( $archiveName );
238238 } else {
239239 $prefix = $this->getRel();
240240 }
241241 $conn = $this->repo->connect();
242 - $container = $this->repo->get_container($conn,$this->repo->container . '%2Fthumb');
243 - $files = $container->list_objects(0, NULL, $prefix);
244 - array_unshift($files, 'unused'); # return an unused $dir.
 242+ $container = $this->repo->get_container( $conn, $this->repo->container . '%2Fthumb' );
 243+ $files = $container->list_objects( 0, NULL, $prefix );
 244+ array_unshift( $files, 'unused' ); # return an unused $dir.
245245 return $files;
246246 }
247247
@@ -249,11 +249,11 @@
250250 * @param $dir string If needed for this repo, the directory prefix.
251251 * @param $files array of strings listing the thumbs to be deleted.
252252 */
253 - function purgeThumbList($dir, $files) {
 253+ function purgeThumbList( $dir, $files ) {
254254 global $wgExcludeFromThumbnailPurge;
255255
256256 $conn = $this->repo->connect();
257 - $container = $this->repo->get_container($conn,$this->repo->container . '%2Fthumb');
 257+ $container = $this->repo->get_container( $conn, $this->repo->container . '%2Fthumb' );
258258 foreach ( $files as $file ) {
259259 // Only remove files not in the $wgExcludeFromThumbnailPurge configuration variable
260260 $ext = pathinfo( $file, PATHINFO_EXTENSION );
@@ -261,8 +261,8 @@
262262 continue;
263263 }
264264
265 - wfDebug( __METHOD__ . ' deleting ' . $container->name . "/$file\n");
266 - $this->repo->swift_delete($container, $file);
 265+ wfDebug( __METHOD__ . ' deleting ' . $container->name . "/$file\n" );
 266+ $this->repo->swift_delete( $container, $file );
267267 }
268268 }
269269
@@ -311,10 +311,10 @@
312312 $this->deletedDir = false;
313313
314314 // Required settings
315 - $this->swiftuser= $info['user'];
316 - $this->swiftkey= $info['key'];
317 - $this->authurl= $info['authurl'];
318 - $this->container= $info['container'];
 315+ $this->swiftuser = $info['user'];
 316+ $this->swiftkey = $info['key'];
 317+ $this->authurl = $info['authurl'];
 318+ $this->container = $info['container'];
319319 }
320320
321321 /**
@@ -323,15 +323,15 @@
324324 * @return CF_Connection
325325 */
326326 function connect() {
327 - $auth = new CF_Authentication($this->swiftuser, $this->swiftkey, NULL, $this->authurl);
 327+ $auth = new CF_Authentication( $this->swiftuser, $this->swiftkey, NULL, $this->authurl );
328328 try {
329329 $auth->authenticate();
330 - } catch (AuthenticationException $e) {
 330+ } catch ( AuthenticationException $e ) {
331331 throw new MWException( "We can't authenticate ourselves." );
332 - #} catch (InvalidResponseException $e) {
 332+ # } catch (InvalidResponseException $e) {
333333 # throw new MWException( __METHOD__ . "unexpected response '$e'" );
334334 }
335 - return new CF_Connection($auth);
 335+ return new CF_Connection( $auth );
336336 }
337337
338338 /**
@@ -342,12 +342,12 @@
343343 *
344344 * @return CF_Container
345345 */
346 - function get_container($conn, $cont) {
 346+ function get_container( $conn, $cont ) {
347347 try {
348 - return $conn->get_container($cont);
349 - } catch (NoSuchContainerException $e) {
 348+ return $conn->get_container( $cont );
 349+ } catch ( NoSuchContainerException $e ) {
350350 throw new MWException( "A container we thought existed, doesn't." );
351 - #} catch (InvalidResponseException $e) {
 351+ # } catch (InvalidResponseException $e) {
352352 # throw new MWException( __METHOD__ . "unexpected response '$e'" );
353353 }
354354 }
@@ -359,17 +359,17 @@
360360 *
361361 * @return CF_Container
362362 */
363 - function write_swift_object( $srcPath, $dstc, $dstRel) {
 363+ function write_swift_object( $srcPath, $dstc, $dstRel ) {
364364 try {
365 - $obj = $dstc->create_object($dstRel);
366 - $obj->load_from_filename( $srcPath, True);
367 - } catch (SyntaxException $e) {
 365+ $obj = $dstc->create_object( $dstRel );
 366+ $obj->load_from_filename( $srcPath, True );
 367+ } catch ( SyntaxException $e ) {
368368 throw new MWException( 'missing required parameters' );
369 - } catch (BadContentTypeException $e) {
 369+ } catch ( BadContentTypeException $e ) {
370370 throw new MWException( 'No Content-Type was/could be set' );
371 - #} catch (InvalidResponseException $e) {
 371+ # } catch (InvalidResponseException $e) {
372372 # throw new MWException( __METHOD__ . "unexpected response '$e'" );
373 - } catch (IOException $e) {
 373+ } catch ( IOException $e ) {
374374 throw new MWException( "error opening file '$e'" );
375375 }
376376 }
@@ -381,12 +381,12 @@
382382 */
383383 function swift_delete( $container, $rel ) {
384384 try {
385 - $container->delete_object($rel);
386 - } catch (SyntaxException $e) {
 385+ $container->delete_object( $rel );
 386+ } catch ( SyntaxException $e ) {
387387 throw new MWException( "Swift object name not well-formed: '$e'" );
388 - } catch (NoSuchObjectException $e) {
 388+ } catch ( NoSuchObjectException $e ) {
389389 throw new MWException( "Swift object we are trying to delete does not exist: '$e'" );
390 - #} catch (InvalidResponseException $e) {
 390+ # } catch (InvalidResponseException $e) {
391391 # throw new MWException( "unexpected response '$e'" );
392392 }
393393 }
@@ -416,7 +416,7 @@
417417 }
418418
419419 // Check overwriting
420 - if (0) { #FIXME
 420+ if ( 0 ) { # FIXME
421421 if ( !( $flags & self::OVERWRITE ) && file_exists( $dstPath ) ) { // FIXME: $dstPath is undefined
422422 if ( $flags & self::OVERWRITE_SAME ) {
423423 $hashSource = sha1_file( $srcPath );
@@ -444,28 +444,28 @@
445445
446446 // Point to the container.
447447 $dstContainer = $this->getZoneContainer( $dstZone );
448 - $dstc = $this->get_container($conn, $dstContainer);
 448+ $dstc = $this->get_container( $conn, $dstContainer );
449449
450450 $good = true;
451451
452452 // Where are we copying this from?
453 - if (self::isVirtualUrl( $srcPath )) {
 453+ if ( self::isVirtualUrl( $srcPath ) ) {
454454 $src = $this->getContainerRel( $srcPath );
455 - list ($srcContainer, $srcRel) = $src;
456 - $srcc = $this->get_container($conn, $srcContainer);
 455+ list ( $srcContainer, $srcRel ) = $src;
 456+ $srcc = $this->get_container( $conn, $srcContainer );
457457
458 - $this->swiftcopy($srcc, $srcRel, $dstc, $dstRel);
 458+ $this->swiftcopy( $srcc, $srcRel, $dstc, $dstRel );
459459 if ( $flags & self::DELETE_SOURCE ) {
460460 $this->swift_delete( $srcc, $srcRel );
461461 }
462462 } else {
463 - $this->write_swift_object( $srcPath, $dstc, $dstRel);
 463+ $this->write_swift_object( $srcPath, $dstc, $dstRel );
464464 // php-cloudfiles throws exceptions, so failure never gets here.
465465 if ( $flags & self::DELETE_SOURCE ) {
466466 unlink ( $srcPath );
467467 }
468468 }
469 - if (0) {
 469+ if ( 0 ) {
470470 $status->error( 'filecopyerror', $srcPath, $dstPath );
471471 $good = false;
472472 }
@@ -489,19 +489,19 @@
490490 * @return mixed Status or false
491491 */
492492
493 - function append( $srcPath, $toAppendPath, $flags = 0 ){
494 - throw new MWException( __METHOD__.': Not yet implemented.' );
 493+ function append( $srcPath, $toAppendPath, $flags = 0 ) {
 494+ throw new MWException( __METHOD__ . ': Not yet implemented.' );
495495 // I think we need to count the number of files whose names
496496 // start with $toAppendPath, then add that count (with leading zeroes) to
497497 // the end of $toAppendPath and write the chunk there.
498498
499499 // Count the number of files whose names start with $toAppendPath
500500 $conn = $this->connect();
501 - $container = $this->repo->get_container($conn,$this->repo->container . "%2Ftemp");
502 - $nextone = count($container->list_objects(0, NULL, $srcPath));
 501+ $container = $this->repo->get_container( $conn, $this->repo->container . "%2Ftemp" );
 502+ $nextone = count( $container->list_objects( 0, NULL, $srcPath ) );
503503
504504 // Do the append to the next name
505 - $status = $this->store( $srcPath, 'temp', sprintf("%s.%05d", $toAppendPath, $nextone) );
 505+ $status = $this->store( $srcPath, 'temp', sprintf( "%s.%05d", $toAppendPath, $nextone ) );
506506
507507 if ( $flags & self::DELETE_SOURCE ) {
508508 unlink( $srcPath );
@@ -513,7 +513,7 @@
514514 * Finish the append operation.
515515 * @param $toAppendPath String: path to append to.
516516 */
517 - function appendFinish( $toAppendPath ){
 517+ function appendFinish( $toAppendPath ) {
518518 $conn = $this->connect();
519519 $container = $this->repo->get_container( $conn, $this->repo->container . '%2Ftemp' );
520520 $parts = $container->list_objects( 0, NULL, $srcPath ); // FIXME: $srcPath is undefined
@@ -521,7 +521,7 @@
522522
523523 // The first object as the same name as the destination, so
524524 // we read it into memory and then write it out as the first chunk.
525 - $obj = $container->get_object( array_shift($parts) );
 525+ $obj = $container->get_object( array_shift( $parts ) );
526526 $first = $obj->read();
527527
528528 $biggie = $container->create_object( $toAppendPath );
@@ -546,7 +546,7 @@
547547 * @return FileRepoStatus
548548 */
549549 function deleteBatch( $sourceDestPairs ) {
550 - wfDebug( __METHOD__ . ' deleting ' . var_export($sourceDestPairs, true) . '\n');
 550+ wfDebug( __METHOD__ . ' deleting ' . var_export( $sourceDestPairs, true ) . '\n' );
551551
552552 /**
553553 * Move the files
@@ -576,24 +576,24 @@
577577 * @return Either array of files and existence flags, or false
578578 */
579579 function fileExistsBatch( $files, $flags = 0 ) {
580 - if ($flags != self::FILES_ONLY) {
 580+ if ( $flags != self::FILES_ONLY ) {
581581 // we ONLY support when $flags & self::FILES_ONLY is set!
582 - throw new MWException( "Swift Media Store doesn't have directories");
 582+ throw new MWException( "Swift Media Store doesn't have directories" );
583583 }
584584 $result = array();
585585 $conn = $this->connect();
586586
587587 foreach ( $files as $key => $file ) {
588588 if ( !self::isVirtualUrl( $file ) ) {
589 - throw new MWException( __METHOD__ . " requires a virtual URL, not '$file'");
 589+ throw new MWException( __METHOD__ . " requires a virtual URL, not '$file'" );
590590 }
591591 $rvu = $this->getContainerRel( $file );
592 - list ($cont, $rel) = $rvu;
593 - $container = $this->get_container($conn,$cont);
 592+ list ( $cont, $rel ) = $rvu;
 593+ $container = $this->get_container( $conn, $cont );
594594 try {
595 - $obj = $container->get_object($rel);
 595+ $obj = $container->get_object( $rel );
596596 $result[$key] = true;
597 - } catch (NoSuchObjectException $e) {
 597+ } catch ( NoSuchObjectException $e ) {
598598 $result[$key] = false;
599599 }
600600 }
@@ -604,7 +604,7 @@
605605
606606 // FIXME: do we really need to reject empty titles?
607607 function newFile( $title, $time = false ) {
608 - if ( empty($title) ) {
 608+ if ( empty( $title ) ) {
609609 return null;
610610 }
611611 return parent::newFile( $title, $time );
@@ -617,38 +617,38 @@
618618 * @param $dstContainer CF_Container
619619 * @param $dstRel String: relative path to the destination.
620620 */
621 - protected function swiftcopy($srcContainer, $srcRel, $dstContainer, $dstRel ) {
 621+ protected function swiftcopy( $srcContainer, $srcRel, $dstContainer, $dstRel ) {
622622 // The destination must exist already.
623 - $obj = $dstContainer->create_object($dstRel);
 623+ $obj = $dstContainer->create_object( $dstRel );
624624 $obj->content_type = 'text/plain';
625625
626626 try {
627 - $obj->write('.');
628 - } catch (SyntaxException $e ) {
 627+ $obj->write( '.' );
 628+ } catch ( SyntaxException $e ) {
629629 throw new MWException( "Write failed: $e" );
630 - } catch (BadContentTypeException $e ) {
 630+ } catch ( BadContentTypeException $e ) {
631631 throw new MWException( "Missing Content-Type: $e" );
632 - } catch (MisMatchedChecksumException $e ) {
 632+ } catch ( MisMatchedChecksumException $e ) {
633633 throw new MWException( __METHOD__ . "should not happen: '$e'" );
634 - #} catch (InvalidResponseException $e ) {
 634+ # } catch (InvalidResponseException $e ) {
635635 # throw new MWException( __METHOD__ . "unexpected response '$e'" );
636636 }
637637
638638 try {
639 - $obj = $dstContainer->get_object($dstRel);
640 - } catch (NoSuchObjectException $e) {
 639+ $obj = $dstContainer->get_object( $dstRel );
 640+ } catch ( NoSuchObjectException $e ) {
641641 throw new MWException( 'The object we just created does not exist: ' . $dstContainer->name . "/$dstRel: $e" );
642642 }
643643
644 - wfDebug( __METHOD__ . ' copying to ' . $dstContainer->name . "/$dstRel from " . $srcContainer->name . "/$srcRel\n");
 644+ wfDebug( __METHOD__ . ' copying to ' . $dstContainer->name . "/$dstRel from " . $srcContainer->name . "/$srcRel\n" );
645645
646646 try {
647 - $obj->copy($srcContainer->name . "/$srcRel");
648 - } catch (SyntaxException $e ) {
 647+ $obj->copy( $srcContainer->name . "/$srcRel" );
 648+ } catch ( SyntaxException $e ) {
649649 throw new MWException( 'Source file does not exist: ' . $srcContainer->name . "/$srcRel: $e" );
650 - } catch (MisMatchedChecksumException $e ) {
 650+ } catch ( MisMatchedChecksumException $e ) {
651651 throw new MWException( "Checksums do not match: $e" );
652 - #} catch (InvalidResponseException $e ) {
 652+ # } catch (InvalidResponseException $e ) {
653653 # throw new MWException( __METHOD__ . "unexpected response '$e'" );
654654 }
655655 }
@@ -663,7 +663,7 @@
664664
665665 # paranoia
666666 $status = $this->newGood( array() );
667 - foreach ( $triplets as $i => $triplet ) {
 667+ foreach ( $triplets as $triplet ) {
668668 list( $srcPath, $dstRel, $archiveRel ) = $triplet;
669669
670670 if ( !$this->validateFilename( $dstRel ) ) {
@@ -680,9 +680,9 @@
681681
682682 try {
683683 $conn = $this->connect();
684 - $container = $this->get_container($conn,$this->container);
685 - } catch (InvalidResponseException $e) {
686 - $status->fatal("Unexpected Swift response: '$e'");
 684+ $container = $this->get_container( $conn, $this->container );
 685+ } catch ( InvalidResponseException $e ) {
 686+ $status->fatal( "Unexpected Swift response: '$e'" );
687687 }
688688
689689 if ( !$status->ok ) {
@@ -694,18 +694,18 @@
695695
696696 // Archive destination file if it exists
697697 try {
698 - $pic = $container->get_object($dstRel);
699 - } catch (InvalidResponseException $e) {
700 - $status->error("Unexpected Swift response: '$e'");
 698+ $pic = $container->get_object( $dstRel );
 699+ } catch ( InvalidResponseException $e ) {
 700+ $status->error( "Unexpected Swift response: '$e'" );
701701 $status->failCount++;
702702 continue;
703 - } catch (NoSuchObjectException $e) {
 703+ } catch ( NoSuchObjectException $e ) {
704704 $pic = NULL;
705705 }
706706
707 - if( $pic ) {
708 - $this->swiftcopy($container, $dstRel, $container, $archiveRel );
709 - wfDebug(__METHOD__.": moved file $dstRel to $archiveRel\n");
 707+ if ( $pic ) {
 708+ $this->swiftcopy( $container, $dstRel, $container, $archiveRel );
 709+ wfDebug( __METHOD__ . ": moved file $dstRel to $archiveRel\n" );
710710 $status->value[$i] = 'archived';
711711 } else {
712712 $status->value[$i] = 'new';
@@ -714,30 +714,30 @@
715715 $good = true;
716716 try {
717717 // Where are we copying this from?
718 - if (self::isVirtualUrl( $srcPath )) {
 718+ if ( self::isVirtualUrl( $srcPath ) ) {
719719 $src = $this->getContainerRel( $srcPath );
720 - list ($srcContainer, $srcRel) = $src;
721 - $srcc = $this->get_container($conn, $srcContainer);
 720+ list ( $srcContainer, $srcRel ) = $src;
 721+ $srcc = $this->get_container( $conn, $srcContainer );
722722
723 - $this->swiftcopy($srcc, $srcRel, $container, $dstRel);
 723+ $this->swiftcopy( $srcc, $srcRel, $container, $dstRel );
724724 if ( $flags & self::DELETE_SOURCE ) {
725725 $this->swift_delete( $srcc, $srcRel );
726726 }
727727 } else {
728 - $this->write_swift_object( $srcPath, $container, $dstRel);
 728+ $this->write_swift_object( $srcPath, $container, $dstRel );
729729 // php-cloudfiles throws exceptions, so failure never gets here.
730730 if ( $flags & self::DELETE_SOURCE ) {
731731 unlink ( $srcPath );
732732 }
733733 }
734 - } catch (InvalidResponseException $e) {
735 - $status->error("Unexpected Swift response: '$e'");
 734+ } catch ( InvalidResponseException $e ) {
 735+ $status->error( "Unexpected Swift response: '$e'" );
736736 $good = false;
737737 }
738738
739739 if ( $good ) {
740740 $status->successCount++;
741 - wfDebug(__METHOD__.": wrote tempfile $srcPath to $dstRel\n");
 741+ wfDebug( __METHOD__ . ": wrote tempfile $srcPath to $dstRel\n" );
742742 } else {
743743 $status->failCount++;
744744 }
@@ -762,15 +762,15 @@
763763 if ( self::isVirtualUrl( $file ) ) {
764764 // This is a virtual url, resolve it
765765 $path = $this->getContainerRel( $file );
766 - list( $cont, $rel) = $path;
 766+ list( $cont, $rel ) = $path;
767767 } else {
768768 // FIXME: This is a full file name
769 - throw new MWException( __METHOD__.": $file needs an unlink()" );
 769+ throw new MWException( __METHOD__ . ": $file needs an unlink()" );
770770 }
771771 }
772772
773 - wfDebug( __METHOD__.": $cont/$rel\n" );
774 - $container = $this->get_container($conn,$cont);
 773+ wfDebug( __METHOD__ . ": $cont/$rel\n" );
 774+ $container = $this->get_container( $conn, $cont );
775775 $this->swift_delete( $container, $rel );
776776 }
777777 }
@@ -785,7 +785,7 @@
786786 function cleanupDeletedBatch( $storageKeys ) {
787787 $conn = $this->connect();
788788 $cont = $this->getZoneContainer( 'deleted' );
789 - $container = $this->get_container($conn,$cont);
 789+ $container = $this->get_container( $conn, $cont );
790790
791791 $dbw = $this->getMasterDB();
792792 $status = $this->newGood();
@@ -797,14 +797,14 @@
798798 $inuse = $dbw->selectField( 'filearchive', '1',
799799 array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
800800 __METHOD__, array( 'FOR UPDATE' ) );
801 - if( !$inuse ) {
 801+ if ( !$inuse ) {
802802 $sha1 = self::getHashFromKey( $key );
803803 $ext = substr( $key, strcspn( $key, '.' ) + 1 );
804 - $ext = File::normalizeExtension($ext);
 804+ $ext = File::normalizeExtension( $ext );
805805 $inuse = $dbw->selectField( 'oldimage', '1',
806806 array( 'oi_sha1' => $sha1,
807807 'oi_archive_name ' . $dbw->buildLike( $dbw->anyString(), ".$ext" ),
808 - $dbw->bitAnd('oi_deleted', File::DELETED_FILE) => File::DELETED_FILE ),
 808+ $dbw->bitAnd( 'oi_deleted', File::DELETED_FILE ) => File::DELETED_FILE ),
809809 __METHOD__, array( 'FOR UPDATE' ) );
810810 }
811811 if ( !$inuse ) {
@@ -823,13 +823,13 @@
824824 * Makes no sense in our context -- don't let anybody call it.
825825 */
826826 function getZonePath( $zone ) {
827 - throw new MWException( __METHOD__.': not implemented' );
 827+ throw new MWException( __METHOD__ . ': not implemented' );
828828 }
829829
830830 /**
831831 * Get the Swift container corresponding to one of the three basic zones
832832 */
833 - protected function getZoneContainer( $zone ) {
 833+ public function getZoneContainer( $zone ) {
834834 switch ( $zone ) {
835835 case 'public':
836836 return $this->container;
@@ -849,22 +849,22 @@
850850 */
851851 protected function getContainerRel( $url ) {
852852 if ( substr( $url, 0, 9 ) != 'mwrepo://' ) {
853 - throw new MWException( __METHOD__.': unknown protocol' );
 853+ throw new MWException( __METHOD__ . ': unknown protocol' );
854854 }
855855
856856 $bits = explode( '/', substr( $url, 9 ), 3 );
857857 if ( count( $bits ) != 3 ) {
858 - throw new MWException( __METHOD__.": invalid mwrepo URL: $url" );
 858+ throw new MWException( __METHOD__ . ": invalid mwrepo URL: $url" );
859859 }
860860 list( $repo, $zone, $rel ) = $bits;
861861 if ( $repo !== $this->name ) {
862 - throw new MWException( __METHOD__.': fetching from a foreign repo is not supported' );
 862+ throw new MWException( __METHOD__ . ': fetching from a foreign repo is not supported' );
863863 }
864864 $container = $this->getZoneContainer( $zone );
865 - if ( $container === false) {
866 - throw new MWException( __METHOD__.": invalid zone: $zone" );
 865+ if ( $container === false ) {
 866+ throw new MWException( __METHOD__ . ": invalid zone: $zone" );
867867 }
868 - return array($container, rawurldecode( $rel ));
 868+ return array( $container, rawurldecode( $rel ) );
869869 }
870870
871871 /**
@@ -875,14 +875,14 @@
876876 function freeTemp( $virtualUrl ) {
877877 $temp = "mwrepo://{$this->name}/temp";
878878 if ( substr( $virtualUrl, 0, strlen( $temp ) ) != $temp ) {
879 - wfDebug( __METHOD__.": Invalid virtual URL\n" );
 879+ wfDebug( __METHOD__ . ": Invalid virtual URL\n" );
880880 return false;
881881 }
882882 $path = $this->getContainerRel( $virtualUrl );
883 - list ($c, $r) = $path;
 883+ list ( $c, $r ) = $path;
884884 $conn = $this->connect();
885 - $container = $this->get_container($conn,$c);
886 - $this->swift_delete($container, $r);
 885+ $container = $this->get_container( $conn, $c );
 886+ $this->swift_delete( $container, $r );
887887 }
888888
889889 /**
@@ -891,8 +891,8 @@
892892 */
893893 function resolveVirtualUrl( $url ) {
894894 $path = $this->getContainerRel( $url );
895 - list($c, $r) = $path;
896 - return $this->getLocalCopy($c, $r);
 895+ list( $c, $r ) = $path;
 896+ return $this->getLocalCopy( $c, $r );
897897 }
898898
899899
@@ -903,27 +903,27 @@
904904 * scope.
905905 * FIXME: how do we return a fatal error from Swift?
906906 */
907 - function getLocalCopy($container, $rel) {
 907+ function getLocalCopy( $container, $rel ) {
908908
909909 // get a temporary place to put the original.
910910 $tempPath = tempnam( wfTempDir(), 'swift_in_' ) . '.' . pathinfo( $rel, PATHINFO_EXTENSION );
911911
912912 /* Fetch the image out of Swift */
913913 $conn = $this->connect();
914 - $cont = $this->get_container($conn,$container);
 914+ $cont = $this->get_container( $conn, $container );
915915
916916 try {
917 - $obj = $cont->get_object($rel);
918 - } catch (NoSuchObjectException $e) {
919 - throw new MWException( "Unable to open original file at $container/$rel");
 917+ $obj = $cont->get_object( $rel );
 918+ } catch ( NoSuchObjectException $e ) {
 919+ throw new MWException( "Unable to open original file at $container/$rel" );
920920 }
921921
922 - wfDebug( __METHOD__ . " writing to $tempPath\n");
 922+ wfDebug( __METHOD__ . " writing to $tempPath\n" );
923923 try {
924 - $obj->save_to_filename( $tempPath);
925 - } catch (IOException $e) {
 924+ $obj->save_to_filename( $tempPath );
 925+ } catch ( IOException $e ) {
926926 throw new MWException( __METHOD__ . ": error opening '$e'" );
927 - } catch (InvalidResponseException $e) {
 927+ } catch ( InvalidResponseException $e ) {
928928 throw new MWException( __METHOD__ . "unexpected response '$e'" );
929929 }
930930
@@ -965,7 +965,7 @@
966966 }
967967
968968 class SwiftStashFile extends UploadStashFile {
969 - //public function __construct( $stash, $repo, $path, $key, $data ) {
 969+ // public function __construct( $stash, $repo, $path, $key, $data ) {
970970 // // We don't call parent:: because UploadStashFile expects to be able to call $this->resolveURL() and get a pathname.
971971 // $this->sessionStash = $stash;
972972 // $this->sessionKey = $key;
@@ -975,10 +975,10 @@
976976 // UnregisteredLocalFile::__construct( false, $repo, $path, false );
977977 // $this->name = basename( $this->path );
978978
979 - //}
 979+ // }
980980
981 - //function getPath() {
982 - //}
 981+ // function getPath() {
 982+ // }
983983 }
984984
985985 /**
@@ -1001,8 +1001,8 @@
10021002
10031003 static function newFromTitle( $title, $repo, $time = null ) {
10041004 # The null default value is only here to avoid an E_STRICT
1005 - if( $time === null )
1006 - throw new MWException( __METHOD__.' got null for $time parameter' );
 1005+ if ( $time === null )
 1006+ throw new MWException( __METHOD__ . ' got null for $time parameter' );
10071007 return new self( $title, $repo, $time, null );
10081008 }
10091009
@@ -1026,12 +1026,12 @@
10271027 */
10281028 static function newFromKey( $sha1, $repo, $timestamp = false ) {
10291029 $conds = array( 'oi_sha1' => $sha1 );
1030 - if( $timestamp ) {
 1030+ if ( $timestamp ) {
10311031 $conds['oi_timestamp'] = $timestamp;
10321032 }
10331033 $dbr = $repo->getSlaveDB();
10341034 $row = $dbr->selectRow( 'oldimage', self::selectFields(), $conds, __METHOD__ );
1035 - if( $row ) {
 1035+ if ( $row ) {
10361036 return self::newFromRow( $row, $repo );
10371037 } else {
10381038 return false;
@@ -1073,7 +1073,7 @@
10741074 $this->requestedTime = $time;
10751075 $this->archive_name = $archiveName;
10761076 if ( is_null( $time ) && is_null( $archiveName ) ) {
1077 - throw new MWException( __METHOD__.': must specify at least one of $time or $archiveName' );
 1077+ throw new MWException( __METHOD__ . ': must specify at least one of $time or $archiveName' );
10781078 }
10791079 }
10801080
@@ -1093,7 +1093,7 @@
10941094 }
10951095
10961096 function isVisible() {
1097 - return $this->exists() && !$this->isDeleted(File::DELETED_FILE);
 1097+ return $this->exists() && !$this->isDeleted( File::DELETED_FILE );
10981098 }
10991099
11001100 function loadFromDB() {
@@ -1137,7 +1137,7 @@
11381138
11391139 # Don't destroy file info of missing files
11401140 if ( !$this->fileExists ) {
1141 - wfDebug( __METHOD__.': file does not exist, aborting\n' );
 1141+ wfDebug( __METHOD__ . ': file does not exist, aborting\n' );
11421142 wfProfileOut( __METHOD__ );
11431143 return;
11441144 }
@@ -1145,7 +1145,7 @@
11461146 $dbw = $this->repo->getMasterDB();
11471147 list( $major, $minor ) = self::splitMime( $this->mime );
11481148
1149 - wfDebug(__METHOD__.': upgrading '.$this->archive_name.' to the current schema\n');
 1149+ wfDebug( __METHOD__ . ': upgrading ' . $this->archive_name . ' to the current schema\n' );
11501150 $dbw->update( 'oldimage',
11511151 array(
11521152 'oi_width' => $this->width,
@@ -1171,7 +1171,7 @@
11721172 */
11731173 function isDeleted( $field ) {
11741174 $this->load();
1175 - return ($this->deleted & $field) == $field;
 1175+ return ( $this->deleted & $field ) == $field;
11761176 }
11771177
11781178 /**
@@ -1244,7 +1244,7 @@
12451245 function move( $target ) {
12461246 $this->readOnlyError();
12471247 }
1248 -
 1248+
12491249 function getDescriptionUrl() {
12501250 // Restore remote behaviour
12511251 return File::getDescriptionUrl();
@@ -1287,7 +1287,7 @@
12881288 * @return DatabaseBase
12891289 */
12901290 function getMasterDB() {
1291 - wfDebug( __METHOD__.": {$this->dbServer}\n" );
 1291+ wfDebug( __METHOD__ . ": {$this->dbServer}\n" );
12921292 if ( !isset( $this->dbConn ) ) {
12931293 $this->dbConn = DatabaseBase::factory( $this->dbType,
12941294 array(
@@ -1316,7 +1316,7 @@
13171317
13181318 /**
13191319 * Get a key on the primary cache for this repository.
1320 - * Returns false if the repository's cache is not accessible at this site.
 1320+ * Returns false if the repository's cache is not accessible at this site.
13211321 * The parameters are the parts of the key, as for wfMemcKey().
13221322 */
13231323 function getSharedCacheKey( /*...*/ ) {
@@ -1330,15 +1330,15 @@
13311331 }
13321332
13331333 function store( $srcPath, $dstZone, $dstRel, $flags = 0 ) {
1334 - throw new MWException( get_class($this) . ': write operations are not supported' );
 1334+ throw new MWException( get_class( $this ) . ': write operations are not supported' );
13351335 }
13361336
13371337 function publish( $srcPath, $dstRel, $archiveRel, $flags = 0 ) {
1338 - throw new MWException( get_class($this) . ': write operations are not supported' );
 1338+ throw new MWException( get_class( $this ) . ': write operations are not supported' );
13391339 }
13401340
13411341 function deleteBatch( $sourceDestPairs ) {
1342 - throw new MWException( get_class($this) . ': write operations are not supported' );
 1342+ throw new MWException( get_class( $this ) . ': write operations are not supported' );
13431343 }
13441344 }
13451345
@@ -1354,7 +1354,7 @@
13551355 *
13561356 * @ingroup FileRepo
13571357 */
1358 -class SwiftForeignDBViaLBRepo extends SwiftRepo{
 1358+class SwiftForeignDBViaLBRepo extends SwiftRepo {
13591359 var $wiki, $dbName, $tablePrefix;
13601360 var $fileFactory = array( 'SwiftForeignDBFile', 'newFromTitle' );
13611361 var $fileFromRowFactory = array( 'SwiftForeignDBFile', 'newFromRow' );
@@ -1389,7 +1389,7 @@
13901390
13911391 /**
13921392 * Get a key on the primary cache for this repository.
1393 - * Returns false if the repository's cache is not accessible at this site.
 1393+ * Returns false if the repository's cache is not accessible at this site.
13941394 * The parameters are the parts of the key, as for wfMemcKey().
13951395 */
13961396 function getSharedCacheKey( /*...*/ ) {
@@ -1403,14 +1403,14 @@
14041404 }
14051405
14061406 function store( $srcPath, $dstZone, $dstRel, $flags = 0 ) {
1407 - throw new MWException( get_class($this) . ': write operations are not supported' );
 1407+ throw new MWException( get_class( $this ) . ': write operations are not supported' );
14081408 }
14091409
14101410 function publish( $srcPath, $dstRel, $archiveRel, $flags = 0 ) {
1411 - throw new MWException( get_class($this) . ': write operations are not supported' );
 1411+ throw new MWException( get_class( $this ) . ': write operations are not supported' );
14121412 }
14131413
14141414 function deleteBatch( $fileMap ) {
1415 - throw new MWException( get_class($this) . ': write operations are not supported' );
 1415+ throw new MWException( get_class( $this ) . ': write operations are not supported' );
14161416 }
14171417 }

Comments

#Comment by RussNelson (talk | contribs)   22:40, 11 October 2011

I appreciate the whitespace repairs, but it would be a good idea to coordinate with me before making such extensive changes. I had failed to check in my changes over the weekend, and have had an enjoyable few hours merging them back in.

Status & tagging log