Introduced File::getHistory(), which should be used instead of ugly nextHistoryLine...
authorVictor Vasiliev <vasilievvv@users.mediawiki.org>
Sun, 20 Jan 2008 06:48:57 +0000 (06:48 +0000)
committerVictor Vasiliev <vasilievvv@users.mediawiki.org>
Sun, 20 Jan 2008 06:48:57 +0000 (06:48 +0000)
includes/ImagePage.php
includes/filerepo/File.php
includes/filerepo/LocalFile.php

index e68fbfa..0d20799 100644 (file)
@@ -411,25 +411,23 @@ EOT
 
                $sk = $wgUser->getSkin();
 
-               $line = $this->img->nextHistoryLine();
-
-               if ( $line ) {
+               if ( $this->img ) {
                        $list = new ImageHistoryList( $sk, $this->img );
-                       $file = $this->repo->newFileFromRow( $line );
+                       $file = $this->img;
                        $dims = $file->getDimensionsString();
                        $s = $list->beginImageHistoryList() .
-                               $list->imageHistoryLine( true, wfTimestamp(TS_MW, $line->img_timestamp),
-                                       $this->mTitle->getDBkey(),  $line->img_user,
-                                       $line->img_user_text, $line->img_size, $line->img_description,
+                               $list->imageHistoryLine( true, wfTimestamp(TS_MW, $file->getTimestamp()),
+                                       $this->mTitle->getDBkey(),  $file->getUser('id'),
+                                       $file->getUser('text'), $file->getSize(), $file->getDescription(),
                                        $dims
                                );
 
-                       while ( $line = $this->img->nextHistoryLine() ) {
-                               $file = $this->repo->newFileFromRow( $line );
+                       $hist = $this->img->getHistory();
+                       foreach( $hist as $file ) {
                                $dims = $file->getDimensionsString();
-                               $s .= $list->imageHistoryLine( false, $line->oi_timestamp,
-                                       $line->oi_archive_name, $line->oi_user,
-                                       $line->oi_user_text, $line->oi_size, $line->oi_description,
+                               $s .= $list->imageHistoryLine( false, wfTimestamp(TS_MW, $file->getTimestamp()),
+                                       $file->getArchiveName(), $file->getUser('id'),
+                                       $file->getUser('text'), $file->getSize(), $file->getDescription(),
                                        $dims
                                );
                        }
index a81abcb..c913022 100644 (file)
@@ -219,6 +219,14 @@ abstract class File {
         */
        public function getHeight( $page = 1 ) { return false; }
 
+       /**
+        * Returns ID or name of user who uploaded the file
+        * STUB
+        *
+        * @param $type string 'text' or 'id'
+        */
+       public function getUser( $type='text' ) { return null; }
+
        /**
         * Get the duration of a media file in seconds
         */
@@ -627,6 +635,18 @@ abstract class File {
                }
        }
 
+       /**
+        * Return a fragment of the history of file.
+        *
+        * STUB
+        * @param $limit integer Limit of rows to return
+        * @param $start timestamp Only revisions older than $start will be returned
+        * @param $end timestamp Only revisions newer than $end will be returned
+        */
+       function getHistory($limit = null, $start = null, $end = null) {
+               return false;
+       }
+
        /**
         * Return the history of this file, line by line. Starts with current version, 
         * then old versions. Should return an object similar to an image/oldimage 
@@ -993,6 +1013,14 @@ abstract class File {
                }
        }
 
+       /**
+        * Get discription of file revision
+        * STUB
+        */
+       function getDescription() {
+               return null;
+       }
+
        /**
         * Get the 14-character timestamp of the file upload, or false if
         * it doesn't exist 
index 06f7b0d..105fb74 100644 (file)
@@ -5,7 +5,7 @@
 /**
  * Bump this number when serialized cache records may be incompatible.
  */
-define( 'MW_FILE_VERSION', 4 );
+define( 'MW_FILE_VERSION', 5 );
 
 /**
  * Class to represent a local file in the wiki's own database
@@ -29,24 +29,26 @@ class LocalFile extends File
        /**#@+
         * @private
         */
-       var     $fileExists,    # does the file file exist on disk? (loadFromXxx)
-               $historyLine,   # Number of line to return by nextHistoryLine() (constructor)
-               $historyRes,    # result of the query for the file's history (nextHistoryLine)
-               $width,         # \
-               $height,        #  |
-               $bits,          #   --- returned by getimagesize (loadFromXxx)
-               $attr,          # /
-               $media_type,    # MEDIATYPE_xxx (bitmap, drawing, audio...)
-               $mime,          # MIME type, determined by MimeMagic::guessMimeType
-               $major_mime,    # Major mime type
-               $minor_mime,    # Minor mime type
-               $size,          # Size in bytes (loadFromXxx)
-               $metadata,      # Handler-specific metadata
-               $timestamp,     # Upload timestamp
-               $sha1,          # SHA-1 base 36 content hash
-               $dataLoaded,    # Whether or not all this has been loaded from the database (loadFromXxx)
-               $upgraded,      # Whether the row was upgraded on load
-               $locked;        # True if the image row is locked
+       var     $fileExists,       # does the file file exist on disk? (loadFromXxx)
+               $historyLine,      # Number of line to return by nextHistoryLine() (constructor)
+               $historyRes,       # result of the query for the file's history (nextHistoryLine)
+               $width,            # \
+               $height,           #  |
+               $bits,             #   --- returned by getimagesize (loadFromXxx)
+               $attr,             # /
+               $media_type,       # MEDIATYPE_xxx (bitmap, drawing, audio...)
+               $mime,             # MIME type, determined by MimeMagic::guessMimeType
+               $major_mime,       # Major mime type
+               $minor_mime,       # Minor mime type
+               $size,             # Size in bytes (loadFromXxx)
+               $metadata,         # Handler-specific metadata
+               $timestamp,        # Upload timestamp
+               $sha1,             # SHA-1 base 36 content hash
+               $user, $user_text, # User, who uploaded the file
+               $description,      # Description of current revision of the file
+               $dataLoaded,       # Whether or not all this has been loaded from the database (loadFromXxx)
+               $upgraded,         # Whether the row was upgraded on load
+               $locked;           # True if the image row is locked
 
        /**#@-*/
 
@@ -155,7 +157,7 @@ class LocalFile extends File
 
        function getCacheFields( $prefix = 'img_' ) {
                static $fields = array( 'size', 'width', 'height', 'bits', 'media_type', 
-                       'major_mime', 'minor_mime', 'metadata', 'timestamp', 'sha1' );
+                       'major_mime', 'minor_mime', 'metadata', 'timestamp', 'sha1', 'user', 'user_text' );
                static $results = array();
                if ( $prefix == '' ) {
                        return $fields;
@@ -381,6 +383,19 @@ class LocalFile extends File
                }
        }
 
+       /**
+        * Returns ID or name of user who uploaded the file
+        *
+        * @param $type string 'text' or 'id'
+        */
+       function getUser($type='text') {
+               if( $type == 'text' ) {
+                       return $this->user_text;
+               } elseif( $type == 'id' ) {
+                       return $this->user;
+               }
+       }
+
        /**
         * Get handler-specific metadata
         */
@@ -559,6 +574,28 @@ class LocalFile extends File
        /** purgeDescription inherited */
        /** purgeEverything inherited */
 
+       function getHistory($limit = null, $start = null, $end = null) {
+               $dbr = $this->repo->getSlaveDB();
+               $conds = $opts = array();
+               $conds[] = "oi_name = '" . $this->title->getDBKey() . "'";
+               if( $start !== null ) {
+                       $conds[] = "oi_timestamp < '" . $dbr->timestamp( $start ) . "'";
+               }
+               if( $end !== null ) {
+                       $conds[] = "oi_timestamp > '" . $dbr->timestamp( $end ). "'";
+               }
+               if( $limit ) {
+                       $opts['LIMIT'] = $limit;
+               }
+               $opts['ORDER BY'] = 'oi_timestamp DESC';
+               $res = $dbr->select('oldimage', '*', $conds, __METHOD__, $opts);
+               $r = array();
+               while( $row = $dbr->fetchObject($res) ) {
+                       $r[] = OldLocalFile::newFromRow($row, $this->repo);
+               }
+               return $r;
+       }
+       
        /**
         * Return the history of this file, line by line.
         * starts with current version, then old versions.
@@ -968,6 +1005,11 @@ class LocalFile extends File
                return $html;
        }
 
+       function getDescription() {
+               $this->load();
+               return $this->description;
+       }
+
        function getTimestamp() {
                $this->load();
                return $this->timestamp;