https://www.mediawiki.org/wiki/Special:Code/MediaWiki/104815

Revision: 104815
Author:   aaron
Date:     2011-12-01 00:49:53 +0000 (Thu, 01 Dec 2011)
Log Message:
-----------
* Fixed undefined vars in FileOp
* Fixed code merge fail in wfMkDirParents()
* Updated callers of File::getPropsFromPath and File::sha1Base36 (avoids 
deprecated notices)

Modified Paths:
--------------
    branches/FileBackend/phase3/includes/GlobalFunctions.php
    branches/FileBackend/phase3/includes/filerepo/FileRepo.php
    branches/FileBackend/phase3/includes/filerepo/RepoGroup.php
    branches/FileBackend/phase3/includes/filerepo/backend/FileOp.php
    branches/FileBackend/phase3/includes/filerepo/file/FSFile.php
    branches/FileBackend/phase3/includes/filerepo/file/LocalFile.php
    branches/FileBackend/phase3/includes/media/ExifBitmap.php
    branches/FileBackend/phase3/includes/media/Generic.php
    branches/FileBackend/phase3/includes/upload/UploadBase.php
    branches/FileBackend/phase3/includes/upload/UploadStash.php

Modified: branches/FileBackend/phase3/includes/GlobalFunctions.php
===================================================================
--- branches/FileBackend/phase3/includes/GlobalFunctions.php    2011-12-01 
00:46:41 UTC (rev 104814)
+++ branches/FileBackend/phase3/includes/GlobalFunctions.php    2011-12-01 
00:49:53 UTC (rev 104815)
@@ -2387,11 +2387,6 @@
                wfDebug( "$caller: called wfMkdirParents($dir)\n" );
        }
 
-       if ( FileBackend::isStoragePath( $dir ) ) {
-               throw new MWException( "Given virtual path `$dir`." );
-               return false;
-       }
-
        if( strval( $dir ) === '' || file_exists( $dir ) ) {
                return true;
        }

Modified: branches/FileBackend/phase3/includes/filerepo/FileRepo.php
===================================================================
--- branches/FileBackend/phase3/includes/filerepo/FileRepo.php  2011-12-01 
00:46:41 UTC (rev 104814)
+++ branches/FileBackend/phase3/includes/filerepo/FileRepo.php  2011-12-01 
00:49:53 UTC (rev 104815)
@@ -116,8 +116,11 @@
                        if ( $doZones && !in_array( $zone, $doZones ) ) {
                                continue;
                        }
-                       $params = array( 'dir' => $this->getZonePath( $zone ) );
-                       $status->merge( $this->backend->prepare( $params ) );
+                       $root = $this->getZonePath( $zone );
+                       if ( $root !== null ) {
+                               $params = array( 'dir' => $this->getZonePath( 
$zone ) );
+                               $status->merge( $this->backend->prepare( 
$params ) );
+                       }
                }
                return $status;
        }

Modified: branches/FileBackend/phase3/includes/filerepo/RepoGroup.php
===================================================================
--- branches/FileBackend/phase3/includes/filerepo/RepoGroup.php 2011-12-01 
00:46:41 UTC (rev 104814)
+++ branches/FileBackend/phase3/includes/filerepo/RepoGroup.php 2011-12-01 
00:49:53 UTC (rev 104815)
@@ -366,7 +366,7 @@
                        $repo = $this->getRepo( $repoName );
                        return $repo->getFileProps( $fileName );
                } else {
-                       return File::getPropsFromPath( $fileName );
+                       return FSFile::getPropsFromPath( $fileName );
                }
        }
 

Modified: branches/FileBackend/phase3/includes/filerepo/backend/FileOp.php
===================================================================
--- branches/FileBackend/phase3/includes/filerepo/backend/FileOp.php    
2011-12-01 00:46:41 UTC (rev 104814)
+++ branches/FileBackend/phase3/includes/filerepo/backend/FileOp.php    
2011-12-01 00:49:53 UTC (rev 104815)
@@ -335,6 +335,8 @@
  *     overwriteSame : override any existing file at destination
  */
 class StoreFileOp extends FileOp {
+       protected $checkDest = true;
+
        protected function doPrecheck( array &$predicates ) {
                $status = Status::newGood();
                // Check if destination file exists
@@ -400,6 +402,8 @@
  *     overwriteSame : override any existing file at destination
  */
 class CreateFileOp extends FileOp {
+       protected $checkDest = true;
+
        protected function doPrecheck( array &$predicates ) {
                $status = Status::newGood();
                // Check if destination file exists

Modified: branches/FileBackend/phase3/includes/filerepo/file/FSFile.php
===================================================================
--- branches/FileBackend/phase3/includes/filerepo/file/FSFile.php       
2011-12-01 00:46:41 UTC (rev 104814)
+++ branches/FileBackend/phase3/includes/filerepo/file/FSFile.php       
2011-12-01 00:49:53 UTC (rev 104815)
@@ -20,6 +20,9 @@
         * @param String $path Path to temporary file on local disk
         */
        public function __construct( $path ) {
+               if ( FileBackend::isStoragePath( $path ) ) {
+                       throw new MWException( "Given virtual path `$path`." );
+               }
                $this->path = $path;
        }
 
@@ -166,4 +169,34 @@
                wfProfileOut( __METHOD__ );
                return $hash;
        }
+
+       /**
+        * Get an associative array containing information about a file in the 
local filesystem.
+        *
+        * @param $path String: absolute local filesystem path
+        * @param $ext Mixed: the file extension, or true to extract it from 
the filename.
+        *             Set it to false to ignore the extension.
+        *
+        * @return array
+        */
+       static function getPropsFromPath( $path, $ext = true ) {
+               $fsFile = new FSFile( $path );
+               return $fsFile->getProps();
+       }
+
+       /**
+        * Get a SHA-1 hash of a file in the local filesystem, in base-36 lower 
case
+        * encoding, zero padded to 31 digits.
+        *
+        * 160 log 2 / log 36 = 30.95, so the 160-bit hash fills 31 digits in 
base 36
+        * fairly neatly.
+        *
+        * @param $path string
+        *
+        * @return false|string False on failure
+        */
+       static function getSha1Base36FromPath( $path ) {
+               $fsFile = new FSFile( $path );
+               return $fsFile->sha1Base36();
+       }
 }

Modified: branches/FileBackend/phase3/includes/filerepo/file/LocalFile.php
===================================================================
--- branches/FileBackend/phase3/includes/filerepo/file/LocalFile.php    
2011-12-01 00:46:41 UTC (rev 104814)
+++ branches/FileBackend/phase3/includes/filerepo/file/LocalFile.php    
2011-12-01 00:49:53 UTC (rev 104815)
@@ -1366,7 +1366,8 @@
                $this->load();
                // Initialise now if necessary
                if ( $this->sha1 == '' && $this->fileExists ) {
-                       $this->sha1 = File::sha1Base36( $this->getPath() );
+                       $tmpPath = $this->getLocalCopyPath();
+                       $this->sha1 = FSFile::sha1Base36( $tmpPath );
                        if ( !wfReadOnly() && strval( $this->sha1 ) != '' ) {
                                $dbw = $this->repo->getMasterDB();
                                $dbw->update( 'image',

Modified: branches/FileBackend/phase3/includes/media/ExifBitmap.php
===================================================================
--- branches/FileBackend/phase3/includes/media/ExifBitmap.php   2011-12-01 
00:46:41 UTC (rev 104814)
+++ branches/FileBackend/phase3/includes/media/ExifBitmap.php   2011-12-01 
00:49:53 UTC (rev 104815)
@@ -137,7 +137,7 @@
                global $wgEnableAutoRotation;
                $gis = parent::getImageSize( $image, $path );
                
-               // Don't just call $image->getMetadata(); 
File::getPropsFromPath() calls us with a bogus object.
+               // Don't just call $image->getMetadata(); 
FSFile::getPropsFromPath() calls us with a bogus object.
                // This may mean we read EXIF data twice on initial upload.
                if ( $wgEnableAutoRotation ) {
                        $meta = $this->getMetadata( $image, $path );

Modified: branches/FileBackend/phase3/includes/media/Generic.php
===================================================================
--- branches/FileBackend/phase3/includes/media/Generic.php      2011-12-01 
00:46:41 UTC (rev 104814)
+++ branches/FileBackend/phase3/includes/media/Generic.php      2011-12-01 
00:49:53 UTC (rev 104815)
@@ -97,7 +97,7 @@
         * Get handler-specific metadata which will be saved in the 
img_metadata field.
         *
         * @param $image File: the image object, or false if there isn't one.
-        *   Warning, File::getPropsFromPath might pass an (object)array() 
instead (!)
+        *   Warning, FSFile::getPropsFromPath might pass an (object)array() 
instead (!)
         * @param $path String: the filename
         * @return String
         */

Modified: branches/FileBackend/phase3/includes/upload/UploadBase.php
===================================================================
--- branches/FileBackend/phase3/includes/upload/UploadBase.php  2011-12-01 
00:46:41 UTC (rev 104814)
+++ branches/FileBackend/phase3/includes/upload/UploadBase.php  2011-12-01 
00:49:53 UTC (rev 104815)
@@ -362,7 +362,7 @@
                # we need to populate mFinalExtension
                $this->getTitle();
 
-               $this->mFileProps = File::getPropsFromPath( $this->mTempPath, 
$this->mFinalExtension );
+               $this->mFileProps = FSFile::getPropsFromPath( $this->mTempPath, 
$this->mFinalExtension );
 
                # check mime type, if desired
                $mime = $this->mFileProps[ 'file-mime' ];
@@ -548,7 +548,7 @@
                }
 
                // Check dupes against existing files
-               $hash = File::sha1Base36( $this->mTempPath );
+               $hash = FSFile::sha1Base36( $this->mTempPath );
                $dupes = RepoGroup::singleton()->findBySha1( $hash );
                $title = $this->getTitle();
                // Remove all matches against self

Modified: branches/FileBackend/phase3/includes/upload/UploadStash.php
===================================================================
--- branches/FileBackend/phase3/includes/upload/UploadStash.php 2011-12-01 
00:46:41 UTC (rev 104814)
+++ branches/FileBackend/phase3/includes/upload/UploadStash.php 2011-12-01 
00:49:53 UTC (rev 104815)
@@ -109,7 +109,7 @@
                        if ( $this->repo->isVirtualUrl( $path ) ) {
                                $path = $this->repo->resolveVirtualUrl( $path );
                        }
-                       $this->fileProps[$key] = File::getPropsFromPath( $path 
);
+                       $this->fileProps[$key] = FSFile::getPropsFromPath( 
$path );
                }
 
                if ( ! $this->files[$key]->exists() ) {
@@ -163,7 +163,7 @@
                        wfDebug( __METHOD__ . " tried to stash file at '$path', 
but it doesn't exist\n" );
                        throw new UploadStashBadPathException( "path doesn't 
exist" );
                }
-               $fileProps = File::getPropsFromPath( $path );
+               $fileProps = FSFile::getPropsFromPath( $path );
                wfDebug( __METHOD__ . " stashing file at '$path'\n" );
 
                // we will be initializing from some tmpnam files that don't 
have extensions.
@@ -215,7 +215,7 @@
                                        $error = array( 'unknown', 'no error 
recorded' );
                                }
                        }
-                       throw new UploadStashFileException( "error storing file 
in '$path': " . implode( '; ', $error ) );
+                       throw new UploadStashFileException( "Error storing file 
in '$path': " . implode( '; ', $error ) );
                }
                $stashPath = $storeStatus->value;
 


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to