Index: branches/filerepo-work/phase3/includes/filerepo/OldLocalFile.php |
— | — | @@ -6,7 +6,7 @@ |
7 | 7 | * @addtogroup FileRepo
|
8 | 8 | */
|
9 | 9 | class OldLocalFile extends LocalFile {
|
10 | | - var $requestedTime, $archive_name, $deleted=0;
|
| 10 | + var $requestedTime, $archive_name;
|
11 | 11 |
|
12 | 12 | const CACHE_VERSION = 1;
|
13 | 13 | const MAX_CACHE_ROWS = 20;
|
— | — | @@ -18,7 +18,6 @@ |
19 | 19 | function __construct( $title, $repo, $time ) {
|
20 | 20 | parent::__construct( $title, $repo );
|
21 | 21 | $this->requestedTime = $time;
|
22 | | - $this->isOldFile = true;
|
23 | 22 | }
|
24 | 23 |
|
25 | 24 | function getCacheKey() {
|
— | — | @@ -26,6 +25,15 @@ |
27 | 26 | return wfMemcKey( 'oldfile', $hashedName );
|
28 | 27 | }
|
29 | 28 |
|
| 29 | + function getArchiveName() {
|
| 30 | + $this->load();
|
| 31 | + return $this->archive_name;
|
| 32 | + }
|
| 33 | +
|
| 34 | + function isOld() {
|
| 35 | + return true;
|
| 36 | + }
|
| 37 | +
|
30 | 38 | /**
|
31 | 39 | * Try to load file metadata from memcached. Returns true on success.
|
32 | 40 | */
|
— | — | @@ -122,6 +130,8 @@ |
123 | 131 | if ( $row ) {
|
124 | 132 | $this->decodeRow( $row, 'oi_' );
|
125 | 133 | $this->loadFromRow( $row, 'oi_' );
|
| 134 | + // Check for rows from a previous schema, quietly upgrade them
|
| 135 | + $this->maybeUpgradeRow();
|
126 | 136 | } else {
|
127 | 137 | $this->fileExists = false;
|
128 | 138 | }
|
— | — | @@ -141,33 +151,29 @@ |
142 | 152 | return 'archive/' . $this->getHashPath() . '/' . urlencode( $this->archive_name );
|
143 | 153 | }
|
144 | 154 |
|
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__ );
|
152 | 177 | }
|
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 | | - }
|
172 | 178 | }
|
173 | 179 |
|
174 | 180 |
|
Index: branches/filerepo-work/phase3/includes/filerepo/LocalFile.php |
— | — | @@ -290,34 +290,18 @@ |
291 | 291 | |
292 | 292 | wfDebug(__METHOD__.': upgrading '.$this->getName()." to the current schema\n"); |
293 | 293 | |
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 | + ); |
322 | 306 | wfProfileOut( __METHOD__ ); |
323 | 307 | } |
324 | 308 | |
Index: branches/filerepo-work/phase3/includes/filerepo/File.php |
— | — | @@ -47,7 +47,7 @@ |
48 | 48 | /** |
49 | 49 | * The following member variables are not lazy-initialised |
50 | 50 | */ |
51 | | - var $repo, $title, $lastError, $isOldFile=false; |
| 51 | + var $repo, $title, $lastError; |
52 | 52 | |
53 | 53 | function __construct( $title, $repo ) { |
54 | 54 | $this->title = $title; |
— | — | @@ -825,6 +825,22 @@ |
826 | 826 | } |
827 | 827 | |
828 | 828 | /** |
| 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 | + /** |
829 | 845 | * Was this file ever deleted from the wiki? |
830 | 846 | * |
831 | 847 | * @return bool |
— | — | @@ -953,6 +969,17 @@ |
954 | 970 | } |
955 | 971 | return wfTimestamp( filemtime( $path ) ); |
956 | 972 | } |
| 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 | + } |
957 | 984 | } |
958 | 985 | |
959 | 986 | ?> |