r22585 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22584‎ | r22585 | r22586 >
Date:01:43, 31 May 2007
Author:tstarling
Status:old
Tags:
Comment:
Fixed a few filerepo bugs, added some documentation
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/filerepo/FSRepo.php (modified) (history)
  • /trunk/phase3/includes/filerepo/File.php (modified) (history)
  • /trunk/phase3/includes/filerepo/LocalFile.php (modified) (history)
  • /trunk/phase3/includes/filerepo/LocalRepo.php (modified) (history)
  • /trunk/phase3/includes/filerepo/RepoGroup.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/LocalFile.php
@@ -13,6 +13,15 @@
1414 * Provides methods to retrieve paths (physical, logical, URL),
1515 * to generate image thumbnails or for uploading.
1616 *
 17+ * Note that only the repo object knows what its file class is called. You should
 18+ * never name a file class explictly outside of the repo class. Instead use the
 19+ * repo's factory functions to generate file objects, for example:
 20+ *
 21+ * RepoGroup::singleton()->getLocalRepo()->newFile($title);
 22+ *
 23+ * The convenience functions wfLocalFile() and wfFindFile() should be sufficient
 24+ * in most cases.
 25+ *
1726 * @addtogroup FileRepo
1827 */
1928 class LocalFile extends File
@@ -39,10 +48,18 @@
4049
4150 /**#@-*/
4251
 52+ /**
 53+ * Create a LocalFile from a title
 54+ * Do not call this except from inside a repo class.
 55+ */
4356 function newFromTitle( $title, $repo ) {
4457 return new self( $title, $repo );
4558 }
4659
 60+ /**
 61+ * Create a LocalFile from a title
 62+ * Do not call this except from inside a repo class.
 63+ */
4764 function newFromRow( $row, $repo ) {
4865 $title = Title::makeTitle( NS_IMAGE, $row->img_name );
4966 $file = new self( $title, $repo );
@@ -50,6 +67,10 @@
5168 return $file;
5269 }
5370
 71+ /**
 72+ * Constructor.
 73+ * Do not call this except from inside a repo class.
 74+ */
5475 function __construct( $title, $repo ) {
5576 if( !is_object( $title ) ) {
5677 throw new MWException( __CLASS__.' constructor given bogus title.' );
@@ -1134,7 +1155,7 @@
11351156 continue;
11361157 }
11371158
1138 - $restoredImage = new self( $row->fa_name, $this->repo );
 1159+ $restoredImage = new self( Title::makeTitle( NS_IMAGE, $row->fa_name ), $this->repo );
11391160
11401161 if( $revisions == 1 && !$exists ) {
11411162 $destPath = $restoredImage->getFullPath();
Index: trunk/phase3/includes/filerepo/FSRepo.php
@@ -3,6 +3,8 @@
44 /**
55 * A repository for files accessible via the local filesystem. Does not support
66 * database access or registration.
 7+ *
 8+ * TODO: split off abstract base FileRepo
79 */
810
911 class FSRepo {
@@ -11,6 +13,7 @@
1214 var $directory, $url, $hashLevels, $thumbScriptUrl, $transformVia404;
1315 var $descBaseUrl, $scriptDirUrl, $articleUrl, $fetchDescription;
1416 var $fileFactory = array( 'UnregisteredLocalFile', 'newFromTitle' );
 17+ var $oldFileFactory = false;
1518
1619 function __construct( $info ) {
1720 // Required settings
@@ -47,7 +50,11 @@
4851 }
4952 }
5053 if ( $time ) {
51 - return call_user_func( $this->oldFileFactor, $title, $this, $time );
 54+ if ( $this->oldFileFactory ) {
 55+ return call_user_func( $this->oldFileFactory, $title, $this, $time );
 56+ } else {
 57+ return false;
 58+ }
5259 } else {
5360 return call_user_func( $this->fileFactory, $title, $this );
5461 }
@@ -61,39 +68,59 @@
6269 * @param mixed $time 14-character timestamp, or false for the current version
6370 */
6471 function findFile( $title, $time = false ) {
 72+ # First try the current version of the file to see if it precedes the timestamp
6573 $img = $this->newFile( $title );
6674 if ( !$img ) {
6775 return false;
6876 }
69 - if ( $img->exists() && $img->getTimestamp() <= $time ) {
 77+ if ( $img->exists() && ( !$time || $img->getTimestamp() <= $time ) ) {
7078 return $img;
7179 }
 80+ # Now try an old version of the file
7281 $img = $this->newFile( $title, $time );
7382 if ( $img->exists() ) {
7483 return $img;
7584 }
7685 }
7786
 87+ /**
 88+ * Get the public root directory of the repository.
 89+ */
7890 function getRootDirectory() {
7991 return $this->directory;
8092 }
8193
 94+ /**
 95+ * Get the public root URL of the repository
 96+ */
8297 function getRootUrl() {
8398 return $this->url;
8499 }
85100
 101+ /**
 102+ * Returns true if the repository uses a multi-level directory structure
 103+ */
86104 function isHashed() {
87105 return (bool)$this->hashLevels;
88106 }
89107
 108+ /**
 109+ * Get the URL of thumb.php
 110+ */
90111 function getThumbScriptUrl() {
91112 return $this->thumbScriptUrl;
92113 }
93114
 115+ /**
 116+ * Returns true if the repository can transform files via a 404 handler
 117+ */
94118 function canTransformVia404() {
95119 return $this->transformVia404;
96120 }
97121
 122+ /**
 123+ * Get the local directory corresponding to one of the three basic zones
 124+ */
98125 function getZonePath( $zone ) {
99126 switch ( $zone ) {
100127 case 'public':
@@ -107,6 +134,9 @@
108135 }
109136 }
110137
 138+ /**
 139+ * Get the URL corresponding to one of the three basic zones
 140+ */
111141 function getZoneUrl( $zone ) {
112142 switch ( $zone ) {
113143 case 'public':
@@ -205,6 +235,17 @@
206236 }
207237 }
208238
 239+ /**
 240+ * Copy or move a file either from the local filesystem or from an mwrepo://
 241+ * virtual URL, into this repository at the specified destination location.
 242+ *
 243+ * @param string $srcPath The source path or URL
 244+ * @param string $dstPath The destination relative path
 245+ * @param string $archivePath The relative path where the existing file is to
 246+ * be archived, if there is one.
 247+ * @param integer $flags Bitfield, may be FSRepo::DELETE_SOURCE to indicate
 248+ * that the source file should be deleted if possible
 249+ */
209250 function publish( $srcPath, $dstPath, $archivePath, $flags = 0 ) {
210251 if ( substr( $srcPath, 0, 9 ) == 'mwrepo://' ) {
211252 $srcPath = $this->resolveVirtualUrl( $srcPath );
@@ -272,6 +313,9 @@
273314 }
274315 }
275316
 317+ /**
 318+ * Get the name of this repository, as specified by $info['name]' to the constructor
 319+ */
276320 function getName() {
277321 return $this->name;
278322 }
Index: trunk/phase3/includes/filerepo/File.php
@@ -10,13 +10,14 @@
1111 * Stub functions which should be overridden are marked with STUB. Some more
1212 * concrete functions are also typically overridden by child classes.
1313 *
 14+ * Note that only the repo object knows what its file class is called. You should
 15+ * never name a file class explictly outside of the repo class. Instead use the
 16+ * repo's factory functions to generate file objects, for example:
1417 *
15 - * NOTE FOR WINDOWS USERS:
16 - * To enable EXIF functions, add the folloing lines to the
17 - * "Windows extensions" section of php.ini:
 18+ * RepoGroup::singleton()->getLocalRepo()->newFile($title);
1819 *
19 - * extension=extensions/php_mbstring.dll
20 - * extension=extensions/php_exif.dll
 20+ * The convenience functions wfLocalFile() and wfFindFile() should be sufficient
 21+ * in most cases.
2122 *
2223 * @addtogroup FileRepo
2324 */
@@ -49,6 +50,9 @@
5051 */
5152 var $repo, $title, $lastError;
5253
 54+ /**
 55+ * Call this constructor from child classes
 56+ */
5357 function __construct( $title, $repo ) {
5458 $this->title = $title;
5559 $this->repo = $repo;
Index: trunk/phase3/includes/filerepo/LocalRepo.php
@@ -5,6 +5,7 @@
66 */
77 class LocalRepo extends FSRepo {
88 var $fileFactory = array( 'LocalFile', 'newFromTitle' );
 9+ var $oldFileFactory = array( 'OldLocalFile', 'newFromTitle' );
910
1011 function getSlaveDB() {
1112 return wfGetDB( DB_SLAVE );
Index: trunk/phase3/includes/filerepo/RepoGroup.php
@@ -1,11 +1,19 @@
22 <?php
33
 4+/**
 5+ * Prioritized list of file repositories
 6+ * @addtogroup filerepo
 7+ */
48 class RepoGroup {
59 var $localRepo, $foreignRepos, $reposInitialised = false;
610 var $localInfo, $foreignInfo;
711
812 protected static $instance;
913
 14+ /**
 15+ * Get a RepoGroup instance. At present only one instance of RepoGroup is
 16+ * needed in a MediaWiki invocation, this may change in the future.
 17+ */
1018 function singleton() {
1119 if ( self::$instance ) {
1220 return self::$instance;
@@ -45,7 +53,7 @@
4654 return $image;
4755 }
4856 foreach ( $this->foreignRepos as $repo ) {
49 - $image = $repo->findFile( $image, $time );
 57+ $image = $repo->findFile( $title, $time );
5058 if ( $image ) {
5159 return $image;
5260 }
@@ -69,6 +77,10 @@
7078 }
7179 }
7280
 81+ /**
 82+ * Get the local repository, i.e. the one corresponding to the local image
 83+ * table. Files are typically uploaded to the local repository.
 84+ */
7385 function getLocalRepo() {
7486 return $this->getRepo( 'local' );
7587 }
@@ -89,7 +101,10 @@
90102 }
91103 }
92104
93 - function newRepo( $info ) {
 105+ /**
 106+ * Create a repo class based on an info structure
 107+ */
 108+ protected function newRepo( $info ) {
94109 $class = $info['class'];
95110 return new $class( $info );
96111 }
Index: trunk/phase3/includes/DefaultSettings.php
@@ -1405,6 +1405,13 @@
14061406 /**
14071407 * Show EXIF data, on by default if available.
14081408 * Requires PHP's EXIF extension: http://www.php.net/manual/en/ref.exif.php
 1409+ *
 1410+ * NOTE FOR WINDOWS USERS:
 1411+ * To enable EXIF functions, add the folloing lines to the
 1412+ * "Windows extensions" section of php.ini:
 1413+ *
 1414+ * extension=extensions/php_mbstring.dll
 1415+ * extension=extensions/php_exif.dll
14091416 */
14101417 $wgShowEXIF = function_exists( 'exif_read_data' );
14111418
Index: trunk/phase3/RELEASE-NOTES
@@ -47,6 +47,7 @@
4848 file repositories.
4949 * Added a Content-Disposition header to thumb.php output
5050 * Improved thumb.php error handling
 51+* Display file history on local image description pages of shared images
5152
5253
5354 == Bugfixes since 1.10 ==

Follow-up revisions

RevisionCommit summaryAuthorDate
r22587Merged revisions 22555-22586 via svnmerge from...david03:19, 31 May 2007