From: Victor Vasiliev Date: Sun, 20 Jan 2008 06:48:57 +0000 (+0000) Subject: Introduced File::getHistory(), which should be used instead of ugly nextHistoryLine... X-Git-Tag: 1.31.0-rc.0~49901 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/modifier.php?a=commitdiff_plain;h=d7a2058e1548e0fc4d1f0cd96afccf78c71dd921;p=lhc%2Fweb%2Fwiklou.git Introduced File::getHistory(), which should be used instead of ugly nextHistoryLine() which is now deprecated --- diff --git a/includes/ImagePage.php b/includes/ImagePage.php index e68fbfa8c4..0d20799125 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -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 ); } diff --git a/includes/filerepo/File.php b/includes/filerepo/File.php index a81abcb57a..c913022f20 100644 --- a/includes/filerepo/File.php +++ b/includes/filerepo/File.php @@ -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 diff --git a/includes/filerepo/LocalFile.php b/includes/filerepo/LocalFile.php index 06f7b0d264..105fb74682 100644 --- a/includes/filerepo/LocalFile.php +++ b/includes/filerepo/LocalFile.php @@ -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;