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 ==
/**
* 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' );
/**
* A repository for files accessible via the local filesystem. Does not support
* database access or registration.
+ *
+ * TODO: split off abstract base FileRepo
*/
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
}
}
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 );
}
* @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':
}
}
+ /**
+ * Get the URL corresponding to one of the three basic zones
+ */
function getZoneUrl( $zone ) {
switch ( $zone ) {
case 'public':
}
}
+ /**
+ * 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 );
}
}
+ /**
+ * Get the name of this repository, as specified by $info['name]' to the constructor
+ */
function getName() {
return $this->name;
}
* 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
*/
*/
var $repo, $title, $lastError;
+ /**
+ * Call this constructor from child classes
+ */
function __construct( $title, $repo ) {
$this->title = $title;
$this->repo = $repo;
* 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
/**#@-*/
+ /**
+ * 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 );
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.' );
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();
*/
class LocalRepo extends FSRepo {
var $fileFactory = array( 'LocalFile', 'newFromTitle' );
+ var $oldFileFactory = array( 'OldLocalFile', 'newFromTitle' );
function getSlaveDB() {
return wfGetDB( DB_SLAVE );
<?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;
return $image;
}
foreach ( $this->foreignRepos as $repo ) {
- $image = $repo->findFile( $image, $time );
+ $image = $repo->findFile( $title, $time );
if ( $image ) {
return $image;
}
}
}
+ /**
+ * 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' );
}
}
}
- function newRepo( $info ) {
+ /**
+ * Create a repo class based on an info structure
+ */
+ protected function newRepo( $info ) {
$class = $info['class'];
return new $class( $info );
}