r22475 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22474‎ | r22475 | r22476 >
Date:15:03, 27 May 2007
Author:tstarling
Status:old
Tags:
Comment:
Fixed OOP train wreck. OldLocalFile is the class where oldimage table handling is implemented, don't put special-case oldimage hacks in its parent. Likewise, OldLocalFile does not implement private archive handling so userCan() should be a stub here. Added stubs for userCan and isDeleted in the ultimate parent class, this means that callers do not need to know what subclass they are dealing with.
Modified paths:
  • /branches/filerepo-work/phase3/includes/filerepo/File.php (modified) (history)
  • /branches/filerepo-work/phase3/includes/filerepo/LocalFile.php (modified) (history)
  • /branches/filerepo-work/phase3/includes/filerepo/OldLocalFile.php (modified) (history)

Diff [purge]

Index: branches/filerepo-work/phase3/includes/filerepo/OldLocalFile.php
@@ -6,7 +6,7 @@
77 * @addtogroup FileRepo
88 */
99 class OldLocalFile extends LocalFile {
10 - var $requestedTime, $archive_name, $deleted=0;
 10+ var $requestedTime, $archive_name;
1111
1212 const CACHE_VERSION = 1;
1313 const MAX_CACHE_ROWS = 20;
@@ -18,7 +18,6 @@
1919 function __construct( $title, $repo, $time ) {
2020 parent::__construct( $title, $repo );
2121 $this->requestedTime = $time;
22 - $this->isOldFile = true;
2322 }
2423
2524 function getCacheKey() {
@@ -26,6 +25,15 @@
2726 return wfMemcKey( 'oldfile', $hashedName );
2827 }
2928
 29+ function getArchiveName() {
 30+ $this->load();
 31+ return $this->archive_name;
 32+ }
 33+
 34+ function isOld() {
 35+ return true;
 36+ }
 37+
3038 /**
3139 * Try to load file metadata from memcached. Returns true on success.
3240 */
@@ -122,6 +130,8 @@
123131 if ( $row ) {
124132 $this->decodeRow( $row, 'oi_' );
125133 $this->loadFromRow( $row, 'oi_' );
 134+ // Check for rows from a previous schema, quietly upgrade them
 135+ $this->maybeUpgradeRow();
126136 } else {
127137 $this->fileExists = false;
128138 }
@@ -141,33 +151,29 @@
142152 return 'archive/' . $this->getHashPath() . '/' . urlencode( $this->archive_name );
143153 }
144154
145 - /**
146 - * int $field one of DELETED_* bitfield constants
147 - * for file or revision rows
148 - * @return bool
149 - */
150 - function isDeleted( $field ) {
151 - return ($this->deleted & $field) == $field;
 155+ function upgradeRow() {
 156+ wfProfileIn( __METHOD__ );
 157+
 158+ $this->loadFromFile();
 159+
 160+ $dbw = $this->repo->getMasterDB();
 161+ list( $major, $minor ) = self::splitMime( $this->mime );
 162+
 163+ wfDebug(__METHOD__.': upgrading '.$this->archive_name." to the current schema\n");
 164+ $dbw->update( 'oldimage',
 165+ array(
 166+ 'oi_width' => $this->width,
 167+ 'oi_height' => $this->height,
 168+ 'oi_bits' => $this->bits,
 169+ 'oi_media_type' => $this->media_type,
 170+ 'oi_major_mime' => $major,
 171+ 'oi_minor_mime' => $minor,
 172+ 'oi_metadata' => $this->metadata,
 173+ ), array( 'oi_name' => $this->getName(), 'oi_timestamp' => $this->requestedTime ),
 174+ __METHOD__
 175+ );
 176+ wfProfileOut( __METHOD__ );
152177 }
153 -
154 - /**
155 - * Determine if the current user is allowed to view a particular
156 - * field of this file, if it's marked as deleted.
157 - * @param int $field
158 - * @return bool
159 - */
160 - function userCan( $field ) {
161 - if( ($this->deleted & $field) == $field ) {
162 - global $wgUser;
163 - $permission = ( $this->deleted & File::DELETED_RESTRICTED ) == File::DELETED_RESTRICTED
164 - ? 'hiderevision'
165 - : 'deleterevision';
166 - wfDebug( "Checking for $permission due to $field match on $this->mDeleted\n" );
167 - return $wgUser->isAllowed( $permission );
168 - } else {
169 - return true;
170 - }
171 - }
172178 }
173179
174180
Index: branches/filerepo-work/phase3/includes/filerepo/LocalFile.php
@@ -290,34 +290,18 @@
291291
292292 wfDebug(__METHOD__.': upgrading '.$this->getName()." to the current schema\n");
293293
294 - if( !$this->isOldImage ) {
295 - $dbw->update( 'image',
296 - array(
297 - 'img_width' => $this->width,
298 - 'img_height' => $this->height,
299 - 'img_bits' => $this->bits,
300 - 'img_media_type' => $this->media_type,
301 - 'img_major_mime' => $major,
302 - 'img_minor_mime' => $minor,
303 - 'img_metadata' => $this->metadata,
304 - ), array( 'img_name' => $this->getName() ),
305 - __METHOD__
306 - );
307 - } else {
308 - $dbw->update( 'oldimage',
309 - array(
310 - 'oi_width' => $this->width,
311 - 'oi_height' => $this->height,
312 - 'oi_bits' => $this->bits,
313 - 'oi_media_type' => $this->media_type,
314 - 'oi_major_mime' => $major,
315 - 'oi_minor_mime' => $minor,
316 - 'oi_metadata' => $this->metadata,
317 - ), array( 'oi_name' => $this->getName(), 'oi_timestamp' => $this->requestedTime ),
318 - __METHOD__
319 - );
320 - }
321 -
 294+ $dbw->update( 'image',
 295+ array(
 296+ 'img_width' => $this->width,
 297+ 'img_height' => $this->height,
 298+ 'img_bits' => $this->bits,
 299+ 'img_media_type' => $this->media_type,
 300+ 'img_major_mime' => $major,
 301+ 'img_minor_mime' => $minor,
 302+ 'img_metadata' => $this->metadata,
 303+ ), array( 'img_name' => $this->getName() ),
 304+ __METHOD__
 305+ );
322306 wfProfileOut( __METHOD__ );
323307 }
324308
Index: branches/filerepo-work/phase3/includes/filerepo/File.php
@@ -47,7 +47,7 @@
4848 /**
4949 * The following member variables are not lazy-initialised
5050 */
51 - var $repo, $title, $lastError, $isOldFile=false;
 51+ var $repo, $title, $lastError;
5252
5353 function __construct( $title, $repo ) {
5454 $this->title = $title;
@@ -825,6 +825,22 @@
826826 }
827827
828828 /**
 829+ * Returns true if the image is an old version
 830+ * STUB
 831+ */
 832+ function isOld() {
 833+ return false;
 834+ }
 835+
 836+ /**
 837+ * Is this file a "deleted" file in a private archive?
 838+ * STUB
 839+ */
 840+ function isDeleted( $field ) {
 841+ return false;
 842+ }
 843+
 844+ /**
829845 * Was this file ever deleted from the wiki?
830846 *
831847 * @return bool
@@ -953,6 +969,17 @@
954970 }
955971 return wfTimestamp( filemtime( $path ) );
956972 }
 973+
 974+ /**
 975+ * Determine if the current user is allowed to view a particular
 976+ * field of this file, if it's marked as deleted.
 977+ * STUB
 978+ * @param int $field
 979+ * @return bool
 980+ */
 981+ function userCan( $field ) {
 982+ return true;
 983+ }
957984 }
958985
959986 ?>