r29966 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r29965‎ | r29966 | r29967 >
Date:06:48, 20 January 2008
Author:vasilievvv
Status:old
Tags:
Comment:
Introduced File::getHistory(), which should be used instead of ugly nextHistoryLine() which is now deprecated
Modified paths:
  • /trunk/phase3/includes/ImagePage.php (modified) (history)
  • /trunk/phase3/includes/filerepo/File.php (modified) (history)
  • /trunk/phase3/includes/filerepo/LocalFile.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ImagePage.php
@@ -411,25 +411,23 @@
412412
413413 $sk = $wgUser->getSkin();
414414
415 - $line = $this->img->nextHistoryLine();
416 -
417 - if ( $line ) {
 415+ if ( $this->img ) {
418416 $list = new ImageHistoryList( $sk, $this->img );
419 - $file = $this->repo->newFileFromRow( $line );
 417+ $file = $this->img;
420418 $dims = $file->getDimensionsString();
421419 $s = $list->beginImageHistoryList() .
422 - $list->imageHistoryLine( true, wfTimestamp(TS_MW, $line->img_timestamp),
423 - $this->mTitle->getDBkey(), $line->img_user,
424 - $line->img_user_text, $line->img_size, $line->img_description,
 420+ $list->imageHistoryLine( true, wfTimestamp(TS_MW, $file->getTimestamp()),
 421+ $this->mTitle->getDBkey(), $file->getUser('id'),
 422+ $file->getUser('text'), $file->getSize(), $file->getDescription(),
425423 $dims
426424 );
427425
428 - while ( $line = $this->img->nextHistoryLine() ) {
429 - $file = $this->repo->newFileFromRow( $line );
 426+ $hist = $this->img->getHistory();
 427+ foreach( $hist as $file ) {
430428 $dims = $file->getDimensionsString();
431 - $s .= $list->imageHistoryLine( false, $line->oi_timestamp,
432 - $line->oi_archive_name, $line->oi_user,
433 - $line->oi_user_text, $line->oi_size, $line->oi_description,
 429+ $s .= $list->imageHistoryLine( false, wfTimestamp(TS_MW, $file->getTimestamp()),
 430+ $file->getArchiveName(), $file->getUser('id'),
 431+ $file->getUser('text'), $file->getSize(), $file->getDescription(),
434432 $dims
435433 );
436434 }
Index: trunk/phase3/includes/filerepo/LocalFile.php
@@ -5,7 +5,7 @@
66 /**
77 * Bump this number when serialized cache records may be incompatible.
88 */
9 -define( 'MW_FILE_VERSION', 4 );
 9+define( 'MW_FILE_VERSION', 5 );
1010
1111 /**
1212 * Class to represent a local file in the wiki's own database
@@ -29,24 +29,26 @@
3030 /**#@+
3131 * @private
3232 */
33 - var $fileExists, # does the file file exist on disk? (loadFromXxx)
34 - $historyLine, # Number of line to return by nextHistoryLine() (constructor)
35 - $historyRes, # result of the query for the file's history (nextHistoryLine)
36 - $width, # \
37 - $height, # |
38 - $bits, # --- returned by getimagesize (loadFromXxx)
39 - $attr, # /
40 - $media_type, # MEDIATYPE_xxx (bitmap, drawing, audio...)
41 - $mime, # MIME type, determined by MimeMagic::guessMimeType
42 - $major_mime, # Major mime type
43 - $minor_mime, # Minor mime type
44 - $size, # Size in bytes (loadFromXxx)
45 - $metadata, # Handler-specific metadata
46 - $timestamp, # Upload timestamp
47 - $sha1, # SHA-1 base 36 content hash
48 - $dataLoaded, # Whether or not all this has been loaded from the database (loadFromXxx)
49 - $upgraded, # Whether the row was upgraded on load
50 - $locked; # True if the image row is locked
 33+ var $fileExists, # does the file file exist on disk? (loadFromXxx)
 34+ $historyLine, # Number of line to return by nextHistoryLine() (constructor)
 35+ $historyRes, # result of the query for the file's history (nextHistoryLine)
 36+ $width, # \
 37+ $height, # |
 38+ $bits, # --- returned by getimagesize (loadFromXxx)
 39+ $attr, # /
 40+ $media_type, # MEDIATYPE_xxx (bitmap, drawing, audio...)
 41+ $mime, # MIME type, determined by MimeMagic::guessMimeType
 42+ $major_mime, # Major mime type
 43+ $minor_mime, # Minor mime type
 44+ $size, # Size in bytes (loadFromXxx)
 45+ $metadata, # Handler-specific metadata
 46+ $timestamp, # Upload timestamp
 47+ $sha1, # SHA-1 base 36 content hash
 48+ $user, $user_text, # User, who uploaded the file
 49+ $description, # Description of current revision of the file
 50+ $dataLoaded, # Whether or not all this has been loaded from the database (loadFromXxx)
 51+ $upgraded, # Whether the row was upgraded on load
 52+ $locked; # True if the image row is locked
5153
5254 /**#@-*/
5355
@@ -155,7 +157,7 @@
156158
157159 function getCacheFields( $prefix = 'img_' ) {
158160 static $fields = array( 'size', 'width', 'height', 'bits', 'media_type',
159 - 'major_mime', 'minor_mime', 'metadata', 'timestamp', 'sha1' );
 161+ 'major_mime', 'minor_mime', 'metadata', 'timestamp', 'sha1', 'user', 'user_text' );
160162 static $results = array();
161163 if ( $prefix == '' ) {
162164 return $fields;
@@ -382,6 +384,19 @@
383385 }
384386
385387 /**
 388+ * Returns ID or name of user who uploaded the file
 389+ *
 390+ * @param $type string 'text' or 'id'
 391+ */
 392+ function getUser($type='text') {
 393+ if( $type == 'text' ) {
 394+ return $this->user_text;
 395+ } elseif( $type == 'id' ) {
 396+ return $this->user;
 397+ }
 398+ }
 399+
 400+ /**
386401 * Get handler-specific metadata
387402 */
388403 function getMetadata() {
@@ -559,6 +574,28 @@
560575 /** purgeDescription inherited */
561576 /** purgeEverything inherited */
562577
 578+ function getHistory($limit = null, $start = null, $end = null) {
 579+ $dbr = $this->repo->getSlaveDB();
 580+ $conds = $opts = array();
 581+ $conds[] = "oi_name = '" . $this->title->getDBKey() . "'";
 582+ if( $start !== null ) {
 583+ $conds[] = "oi_timestamp < '" . $dbr->timestamp( $start ) . "'";
 584+ }
 585+ if( $end !== null ) {
 586+ $conds[] = "oi_timestamp > '" . $dbr->timestamp( $end ). "'";
 587+ }
 588+ if( $limit ) {
 589+ $opts['LIMIT'] = $limit;
 590+ }
 591+ $opts['ORDER BY'] = 'oi_timestamp DESC';
 592+ $res = $dbr->select('oldimage', '*', $conds, __METHOD__, $opts);
 593+ $r = array();
 594+ while( $row = $dbr->fetchObject($res) ) {
 595+ $r[] = OldLocalFile::newFromRow($row, $this->repo);
 596+ }
 597+ return $r;
 598+ }
 599+
563600 /**
564601 * Return the history of this file, line by line.
565602 * starts with current version, then old versions.
@@ -968,6 +1005,11 @@
9691006 return $html;
9701007 }
9711008
 1009+ function getDescription() {
 1010+ $this->load();
 1011+ return $this->description;
 1012+ }
 1013+
9721014 function getTimestamp() {
9731015 $this->load();
9741016 return $this->timestamp;
Index: trunk/phase3/includes/filerepo/File.php
@@ -220,6 +220,14 @@
221221 public function getHeight( $page = 1 ) { return false; }
222222
223223 /**
 224+ * Returns ID or name of user who uploaded the file
 225+ * STUB
 226+ *
 227+ * @param $type string 'text' or 'id'
 228+ */
 229+ public function getUser( $type='text' ) { return null; }
 230+
 231+ /**
224232 * Get the duration of a media file in seconds
225233 */
226234 public function getLength() {
@@ -628,6 +636,18 @@
629637 }
630638
631639 /**
 640+ * Return a fragment of the history of file.
 641+ *
 642+ * STUB
 643+ * @param $limit integer Limit of rows to return
 644+ * @param $start timestamp Only revisions older than $start will be returned
 645+ * @param $end timestamp Only revisions newer than $end will be returned
 646+ */
 647+ function getHistory($limit = null, $start = null, $end = null) {
 648+ return false;
 649+ }
 650+
 651+ /**
632652 * Return the history of this file, line by line. Starts with current version,
633653 * then old versions. Should return an object similar to an image/oldimage
634654 * database row.
@@ -994,6 +1014,14 @@
9951015 }
9961016
9971017 /**
 1018+ * Get discription of file revision
 1019+ * STUB
 1020+ */
 1021+ function getDescription() {
 1022+ return null;
 1023+ }
 1024+
 1025+ /**
9981026 * Get the 14-character timestamp of the file upload, or false if
9991027 * it doesn't exist
10001028 */

Status & tagging log