r22472 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22471‎ | r22472 | r22473 >
Date:07:55, 27 May 2007
Author:aaron
Status:old
Tags:
Comment:
*Add isOldFile method to File, expand updateRow() for oldimage rows, add usercan functions to OldLocalFile
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;
 10+ var $requestedTime, $archive_name, $deleted=0;
1111
1212 const CACHE_VERSION = 1;
1313 const MAX_CACHE_ROWS = 20;
@@ -18,6 +18,7 @@
1919 function __construct( $title, $repo, $time ) {
2020 parent::__construct( $title, $repo );
2121 $this->requestedTime = $time;
 22+ $this->isOldFile = true;
2223 }
2324
2425 function getCacheKey() {
@@ -139,6 +140,34 @@
140141 function getUrlRel() {
141142 return 'archive/' . $this->getHashPath() . '/' . urlencode( $this->archive_name );
142143 }
 144+
 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;
 152+ }
 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+ }
143172 }
144173
145174
Index: branches/filerepo-work/phase3/includes/filerepo/LocalFile.php
@@ -281,17 +281,34 @@
282282
283283 wfDebug(__METHOD__.': upgrading '.$this->getName()." to the current schema\n");
284284
285 - $dbw->update( 'image',
286 - array(
287 - 'img_width' => $this->width,
288 - 'img_height' => $this->height,
289 - 'img_bits' => $this->bits,
290 - 'img_media_type' => $this->media_type,
291 - 'img_major_mime' => $major,
292 - 'img_minor_mime' => $minor,
293 - 'img_metadata' => $this->metadata,
294 - ), array( 'img_name' => $this->getName() ), __METHOD__
295 - );
 285+ if( !$this->isOldImage ) {
 286+ $dbw->update( 'image',
 287+ array(
 288+ 'img_width' => $this->width,
 289+ 'img_height' => $this->height,
 290+ 'img_bits' => $this->bits,
 291+ 'img_media_type' => $this->media_type,
 292+ 'img_major_mime' => $major,
 293+ 'img_minor_mime' => $minor,
 294+ 'img_metadata' => $this->metadata,
 295+ ), array( 'img_name' => $this->getName() ),
 296+ __METHOD__
 297+ );
 298+ } else {
 299+ $dbw->update( 'oldimage',
 300+ array(
 301+ 'oi_width' => $this->width,
 302+ 'oi_height' => $this->height,
 303+ 'oi_bits' => $this->bits,
 304+ 'oi_media_type' => $this->media_type,
 305+ 'oi_major_mime' => $major,
 306+ 'oi_minor_mime' => $minor,
 307+ 'oi_metadata' => $this->metadata,
 308+ ), array( 'oi_name' => $this->getName(), 'oi_timestamp' => $this->requestedTime ),
 309+ __METHOD__
 310+ );
 311+ }
 312+
296313 wfProfileOut( __METHOD__ );
297314 }
298315
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;
 51+ var $repo, $title, $lastError, $isOldFile=false;
5252
5353 function __construct( $title, $repo ) {
5454 $this->title = $title;