Fixed a few filerepo bugs, added some documentation
authorTim Starling <tstarling@users.mediawiki.org>
Thu, 31 May 2007 01:43:41 +0000 (01:43 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Thu, 31 May 2007 01:43:41 +0000 (01:43 +0000)
RELEASE-NOTES
includes/DefaultSettings.php
includes/filerepo/FSRepo.php
includes/filerepo/File.php
includes/filerepo/LocalFile.php
includes/filerepo/LocalRepo.php
includes/filerepo/RepoGroup.php

index 49e4204..25e0385 100644 (file)
@@ -47,6 +47,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   file repositories.
 * Added a Content-Disposition header to thumb.php output
 * Improved thumb.php error handling
+* Display file history on local image description pages of shared images
 
 
 == Bugfixes since 1.10 ==
index f0bbe3e..32488d1 100644 (file)
@@ -1405,6 +1405,13 @@ $wgEnableUploads = false;
 /**
  * Show EXIF data, on by default if available.
  * Requires PHP's EXIF extension: http://www.php.net/manual/en/ref.exif.php
+ *
+ * NOTE FOR WINDOWS USERS:
+ * To enable EXIF functions, add the folloing lines to the
+ * "Windows extensions" section of php.ini:
+ *
+ * extension=extensions/php_mbstring.dll
+ * extension=extensions/php_exif.dll
  */
 $wgShowEXIF = function_exists( 'exif_read_data' );
 
index f1eaf29..af5aa63 100644 (file)
@@ -3,6 +3,8 @@
 /**
  * A repository for files accessible via the local filesystem. Does not support
  * database access or registration.
+ *
+ * TODO: split off abstract base FileRepo
  */
 
 class FSRepo {
@@ -11,6 +13,7 @@ class FSRepo {
        var $directory, $url, $hashLevels, $thumbScriptUrl, $transformVia404;
        var $descBaseUrl, $scriptDirUrl, $articleUrl, $fetchDescription;
        var $fileFactory = array( 'UnregisteredLocalFile', 'newFromTitle' );
+       var $oldFileFactory = false;
 
        function __construct( $info ) {
                // Required settings
@@ -47,7 +50,11 @@ class FSRepo {
                        }
                }
                if ( $time ) {
-                       return call_user_func( $this->oldFileFactor, $title, $this, $time );
+                       if ( $this->oldFileFactory ) {
+                               return call_user_func( $this->oldFileFactory, $title, $this, $time );
+                       } else {
+                               return false;
+                       }
                } else {
                        return call_user_func( $this->fileFactory, $title, $this );
                }
@@ -61,39 +68,59 @@ class FSRepo {
         * @param mixed $time 14-character timestamp, or false for the current version
         */
        function findFile( $title, $time = false ) {
+               # First try the current version of the file to see if it precedes the timestamp
                $img = $this->newFile( $title );
                if ( !$img ) {
                        return false;
                }
-               if ( $img->exists() && $img->getTimestamp() <= $time ) {
+               if ( $img->exists() && ( !$time || $img->getTimestamp() <= $time ) ) {
                        return $img;
                }
+               # Now try an old version of the file
                $img = $this->newFile( $title, $time );
                if ( $img->exists() ) {
                        return $img;
                }
        }
 
+       /**
+        * Get the public root directory of the repository.
+        */
        function getRootDirectory() {
                return $this->directory;
        }
 
+       /**
+        * Get the public root URL of the repository
+        */
        function getRootUrl() {
                return $this->url;
        }
 
+       /**
+        * Returns true if the repository uses a multi-level directory structure
+        */
        function isHashed() {
                return (bool)$this->hashLevels;
        }
 
+       /**
+        * Get the URL of thumb.php
+        */
        function getThumbScriptUrl() {
                return $this->thumbScriptUrl;
        }
 
+       /**
+        * Returns true if the repository can transform files via a 404 handler
+        */
        function canTransformVia404() {
                return $this->transformVia404;
        }
 
+       /**
+        * Get the local directory corresponding to one of the three basic zones
+        */
        function getZonePath( $zone ) {
                switch ( $zone ) {
                        case 'public':
@@ -107,6 +134,9 @@ class FSRepo {
                }
        }
 
+       /**
+        * Get the URL corresponding to one of the three basic zones
+        */
        function getZoneUrl( $zone ) {
                switch ( $zone ) {
                        case 'public':
@@ -205,6 +235,17 @@ class FSRepo {
                }
        }
 
+       /**
+        * Copy or move a file either from the local filesystem or from an mwrepo://
+        * virtual URL, into this repository at the specified destination location.
+        *
+        * @param string $srcPath The source path or URL
+        * @param string $dstPath The destination relative path
+        * @param string $archivePath The relative path where the existing file is to
+        *        be archived, if there is one.
+        * @param integer $flags Bitfield, may be FSRepo::DELETE_SOURCE to indicate
+        *        that the source file should be deleted if possible
+        */
        function publish( $srcPath, $dstPath, $archivePath, $flags = 0 ) {
                if ( substr( $srcPath, 0, 9 ) == 'mwrepo://' ) {
                        $srcPath = $this->resolveVirtualUrl( $srcPath );
@@ -272,6 +313,9 @@ class FSRepo {
                }
        }
 
+       /**
+        * Get the name of this repository, as specified by $info['name]' to the constructor
+        */
        function getName() {
                return $this->name;
        }
index 1e59d2f..84de8e9 100644 (file)
  * Stub functions which should be overridden are marked with STUB. Some more 
  * concrete functions are also typically overridden by child classes.
  *
+ * Note that only the repo object knows what its file class is called. You should
+ * never name a file class explictly outside of the repo class. Instead use the 
+ * repo's factory functions to generate file objects, for example:
  *
- * NOTE FOR WINDOWS USERS:
- * To enable EXIF functions, add the folloing lines to the
- * "Windows extensions" section of php.ini:
+ * RepoGroup::singleton()->getLocalRepo()->newFile($title);
  *
- * extension=extensions/php_mbstring.dll
- * extension=extensions/php_exif.dll
+ * The convenience functions wfLocalFile() and wfFindFile() should be sufficient
+ * in most cases.
  *
  * @addtogroup FileRepo
  */
@@ -49,6 +50,9 @@ class File {
         */
        var $repo, $title, $lastError;
 
+       /**
+        * Call this constructor from child classes
+        */
        function __construct( $title, $repo ) {
                $this->title = $title;
                $this->repo = $repo;
index 3a70fd7..501fa42 100644 (file)
@@ -13,6 +13,15 @@ define( 'MW_FILE_VERSION', 4 );
  * Provides methods to retrieve paths (physical, logical, URL),
  * to generate image thumbnails or for uploading.
  *
+ * Note that only the repo object knows what its file class is called. You should
+ * never name a file class explictly outside of the repo class. Instead use the 
+ * repo's factory functions to generate file objects, for example:
+ *
+ * RepoGroup::singleton()->getLocalRepo()->newFile($title);
+ *
+ * The convenience functions wfLocalFile() and wfFindFile() should be sufficient
+ * in most cases.
+ *
  * @addtogroup FileRepo
  */
 class LocalFile extends File
@@ -39,10 +48,18 @@ class LocalFile extends File
 
        /**#@-*/
 
+       /**
+        * Create a LocalFile from a title
+        * Do not call this except from inside a repo class.
+        */
        function newFromTitle( $title, $repo ) {
                return new self( $title, $repo );
        }
 
+       /**
+        * Create a LocalFile from a title
+        * Do not call this except from inside a repo class.
+        */
        function newFromRow( $row, $repo ) {
                $title = Title::makeTitle( NS_IMAGE, $row->img_name );
                $file = new self( $title, $repo );
@@ -50,6 +67,10 @@ class LocalFile extends File
                return $file;
        }
 
+       /**
+        * Constructor.
+        * Do not call this except from inside a repo class.
+        */
        function __construct( $title, $repo ) {
                if( !is_object( $title ) ) {
                        throw new MWException( __CLASS__.' constructor given bogus title.' );
@@ -1134,7 +1155,7 @@ class LocalFile extends File
                                        continue;
                                }
 
-                               $restoredImage = new self( $row->fa_name, $this->repo );
+                               $restoredImage = new self( Title::makeTitle( NS_IMAGE, $row->fa_name ), $this->repo );
 
                                if( $revisions == 1 && !$exists ) {
                                        $destPath = $restoredImage->getFullPath();
index 4903015..be32c02 100644 (file)
@@ -5,6 +5,7 @@
  */
 class LocalRepo extends FSRepo {
        var $fileFactory = array( 'LocalFile', 'newFromTitle' );
+       var $oldFileFactory = array( 'OldLocalFile', 'newFromTitle' );
 
        function getSlaveDB() {
                return wfGetDB( DB_SLAVE );
index 3055382..021d3ba 100644 (file)
@@ -1,11 +1,19 @@
 <?php
 
+/**
+ * Prioritized list of file repositories
+ * @addtogroup filerepo
+ */
 class RepoGroup {
        var $localRepo, $foreignRepos, $reposInitialised = false;
        var $localInfo, $foreignInfo;
 
        protected static $instance;
 
+       /**
+        * Get a RepoGroup instance. At present only one instance of RepoGroup is
+        * needed in a MediaWiki invocation, this may change in the future.
+        */
        function singleton() {
                if ( self::$instance ) {
                        return self::$instance;
@@ -45,7 +53,7 @@ class RepoGroup {
                        return $image;
                }
                foreach ( $this->foreignRepos as $repo ) {
-                       $image = $repo->findFile( $image, $time );
+                       $image = $repo->findFile( $title, $time );
                        if ( $image ) {
                                return $image;
                        }
@@ -69,6 +77,10 @@ class RepoGroup {
                }
        }
 
+       /**
+        * Get the local repository, i.e. the one corresponding to the local image
+        * table. Files are typically uploaded to the local repository.
+        */
        function getLocalRepo() {
                return $this->getRepo( 'local' );
        }
@@ -89,7 +101,10 @@ class RepoGroup {
                }
        }
 
-       function newRepo( $info ) {
+       /**
+        * Create a repo class based on an info structure
+        */
+       protected function newRepo( $info ) {
                $class = $info['class'];
                return new $class( $info );
        }