r84924 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84923‎ | r84924 | r84925 >
Date:21:40, 28 March 2011
Author:aaron
Status:ok (Comments)
Tags:
Comment:
Reverted r84918 per CR
Modified paths:
  • /trunk/phase3/includes/filerepo/FileRepo.php (modified) (history)
  • /trunk/phase3/includes/filerepo/RepoGroup.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/FileRepo.php
@@ -30,6 +30,7 @@
3131 * Override these in the base class
3232 */
3333 var $fileFactory = false, $oldFileFactory = false;
 34+ var $fileFactoryKey = false, $oldFileFactoryKey = false;
3435
3536 function __construct( $info ) {
3637 // Required settings
@@ -178,6 +179,63 @@
179180 }
180181
181182 /**
 183+ * Create a new File object from the local repository
 184+ * @param $sha1 Mixed: base 36 SHA-1 hash
 185+ * @param $time Mixed: time at which the image was uploaded.
 186+ * If this is specified, the returned object will be an
 187+ * of the repository's old file class instead of a current
 188+ * file. Repositories not supporting version control should
 189+ * return false if this parameter is set.
 190+ *
 191+ * @return File
 192+ */
 193+ function newFileFromKey( $sha1, $time = false ) {
 194+ if ( $time ) {
 195+ if ( $this->oldFileFactoryKey ) {
 196+ return call_user_func( $this->oldFileFactoryKey, $sha1, $this, $time );
 197+ }
 198+ } else {
 199+ if ( $this->fileFactoryKey ) {
 200+ return call_user_func( $this->fileFactoryKey, $sha1, $this );
 201+ }
 202+ }
 203+ return false;
 204+ }
 205+
 206+ /**
 207+ * Find an instance of the file with this key, created at the specified time
 208+ * Returns false if the file does not exist. Repositories not supporting
 209+ * version control should return false if the time is specified.
 210+ *
 211+ * @param $sha1 String base 36 SHA-1 hash
 212+ * @param $options Option array, same as findFile().
 213+ */
 214+ function findFileFromKey( $sha1, $options = array() ) {
 215+ $time = isset( $options['time'] ) ? $options['time'] : false;
 216+
 217+ # First try the current version of the file to see if it precedes the timestamp
 218+ $img = $this->newFileFromKey( $sha1 );
 219+ if ( !$img ) {
 220+ return false;
 221+ }
 222+ if ( $img->exists() && ( !$time || $img->getTimestamp() == $time ) ) {
 223+ return $img;
 224+ }
 225+ # Now try an old version of the file
 226+ if ( $time !== false ) {
 227+ $img = $this->newFileFromKey( $sha1, $time );
 228+ if ( $img && $img->exists() ) {
 229+ if ( !$img->isDeleted(File::DELETED_FILE) ) {
 230+ return $img;
 231+ } else if ( !empty( $options['private'] ) && $img->userCan(File::DELETED_FILE) ) {
 232+ return $img;
 233+ }
 234+ }
 235+ }
 236+ return false;
 237+ }
 238+
 239+ /**
182240 * Get the URL of thumb.php
183241 */
184242 function getThumbScriptUrl() {
Index: trunk/phase3/includes/filerepo/RepoGroup.php
@@ -212,6 +212,29 @@
213213 }
214214
215215 /**
 216+ * Find an instance of the file with this key, created at the specified time
 217+ * Returns false if the file does not exist.
 218+ *
 219+ * @param $hash String base 36 SHA-1 hash
 220+ * @param $options Option array, same as findFile()
 221+ * @return File object or false if it is not found
 222+ */
 223+ function findFileFromKey( $hash, $options = array() ) {
 224+ if ( !$this->reposInitialised ) {
 225+ $this->initialiseRepos();
 226+ }
 227+
 228+ $file = $this->localRepo->findFileFromKey( $hash, $options );
 229+ if ( !$file ) {
 230+ foreach ( $this->foreignRepos as $repo ) {
 231+ $file = $repo->findFileFromKey( $hash, $options );
 232+ if ( $file ) break;
 233+ }
 234+ }
 235+ return $file;
 236+ }
 237+
 238+ /**
216239 * Find all instances of files with this key
217240 *
218241 * @param $hash String base 36 SHA-1 hash

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r84918findFileFromKey, newFileFromKey, $fileFactoryKey, and $oldFileFactoryKey were...nelson19:57, 28 March 2011

Comments

#Comment by Saper (talk | contribs)   19:18, 2 April 2011

We need this in 1.17 to apply the fix for the bug:28348 included in r85202.

#Comment by Saper (talk | contribs)   19:20, 2 April 2011

er, I meant bugzilla:28348.

#Comment by Aaron Schulz (talk | contribs)   00:35, 3 April 2011

Removing 1.17 tag: the revision this reverted was not part of 1.17.

Status & tagging log