Index: branches/license-work/phase3/includes/filerepo/FileProperties.php |
— | — | @@ -0,0 +1,83 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class FileProperties { |
| 5 | + public function __construct( $file, $revision = null ) { |
| 6 | + $this->file = file; |
| 7 | + $this->revId = $revision; |
| 8 | + |
| 9 | + $this->authors = array(); |
| 10 | + $this->licenses = array(); |
| 11 | + |
| 12 | + $this->load(); |
| 13 | + } |
| 14 | + |
| 15 | + public function load() { |
| 16 | + $revision = Revision::newFromTitle( $this->file->getTitle(), $this->revId ); |
| 17 | + $fp = $revision->getFilePropsVersion(); |
| 18 | + if ( $fp ) { |
| 19 | + $dbr = wfGetDB( DB_SLAVE ); |
| 20 | + $res = $dbr->select( 'file_props', |
| 21 | + array( 'fp_key', 'fp_value_int', 'fp_value_tex' ), |
| 22 | + array( 'fp_id' => $fp ), |
| 23 | + __METHOD__ ); |
| 24 | + $this->loadFromResult( $res ); |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + public function loadFromResult( $res ) { |
| 29 | + $result = array(); |
| 30 | + |
| 31 | + foreach ( $res as $row ) { |
| 32 | + switch ( $row->fp_key ) { |
| 33 | + case 'author': |
| 34 | + $this->authors[] = FileAuthor::newFromRow( $row ); |
| 35 | + break; |
| 36 | + case 'license': |
| 37 | + $this->licenses[] = FileLicense::newFromRow( $row ); |
| 38 | + break; |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + if ( $this->licenses ) { |
| 43 | + FileLicense::loadArray( $this->licenses ); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + public function getLicenses() { |
| 48 | + return $this->licenses; |
| 49 | + } |
| 50 | + public function getAuthors() { |
| 51 | + return $this->authors; |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +class FileAuthor { |
| 56 | + public static function newFromRow( $row ) { |
| 57 | + return new self( $row->fp_value_int, $row->fp_value_text ); |
| 58 | + } |
| 59 | + |
| 60 | + public function __construct( $id, $text ) { |
| 61 | + $this->id = $id; |
| 62 | + $this->text = $text; |
| 63 | + } |
| 64 | + public function getUserId() { |
| 65 | + return $this->id; |
| 66 | + } |
| 67 | + public function getText() { |
| 68 | + if ( $this->text ) { |
| 69 | + return $this->text; |
| 70 | + } |
| 71 | + return User::newFromId( $this->id )->getName(); |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +class FileLicense { |
| 76 | + public static function newFromRow( $row ) { |
| 77 | + return new self( $row->fp_value_int ); |
| 78 | + } |
| 79 | + |
| 80 | + public function __construct( $id ) { |
| 81 | + $this->id = $id; |
| 82 | + } |
| 83 | + |
| 84 | +} |
Property changes on: branches/license-work/phase3/includes/filerepo/FileProperties.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 85 | + native |
Index: branches/license-work/phase3/includes/Revision.php |
— | — | @@ -258,7 +258,8 @@ |
259 | 259 | 'rev_minor_edit', |
260 | 260 | 'rev_deleted', |
261 | 261 | 'rev_len', |
262 | | - 'rev_parent_id' |
| 262 | + 'rev_parent_id', |
| 263 | + 'rev_fileprops_id', |
263 | 264 | ); |
264 | 265 | } |
265 | 266 | |
— | — | @@ -301,6 +302,7 @@ |
302 | 303 | $this->mMinorEdit = intval( $row->rev_minor_edit ); |
303 | 304 | $this->mTimestamp = $row->rev_timestamp; |
304 | 305 | $this->mDeleted = intval( $row->rev_deleted ); |
| 306 | + $this->mFileProps = intval( $row->rev_file_props ); |
305 | 307 | |
306 | 308 | if( !isset( $row->rev_parent_id ) ) |
307 | 309 | $this->mParentId = is_null($row->rev_parent_id) ? null : 0; |
— | — | @@ -342,6 +344,7 @@ |
343 | 345 | $this->mDeleted = isset( $row['deleted'] ) ? intval( $row['deleted'] ) : 0; |
344 | 346 | $this->mSize = isset( $row['len'] ) ? intval( $row['len'] ) : null; |
345 | 347 | $this->mParentId = isset( $row['parent_id'] ) ? intval( $row['parent_id'] ) : null; |
| 348 | + $this->mFileProps = isset( $row['file_props'] ) ? intval( $row['file_props'] ) : 0; |
346 | 349 | |
347 | 350 | // Enforce spacing trimming on supplied text |
348 | 351 | $this->mComment = isset( $row['comment'] ) ? trim( strval( $row['comment'] ) ) : null; |
— | — | @@ -435,6 +438,10 @@ |
436 | 439 | public function getPage() { |
437 | 440 | return $this->mPage; |
438 | 441 | } |
| 442 | + |
| 443 | + public function getFilePropsVersion() { |
| 444 | + return $this->mFileProps; |
| 445 | + } |
439 | 446 | |
440 | 447 | /** |
441 | 448 | * Fetch revision's user id if it's available to the specified audience. |
— | — | @@ -854,7 +861,8 @@ |
855 | 862 | 'rev_deleted' => $this->mDeleted, |
856 | 863 | 'rev_len' => $this->mSize, |
857 | 864 | 'rev_parent_id' => is_null($this->mParentId) ? |
858 | | - $this->getPreviousRevisionId( $dbw ) : $this->mParentId |
| 865 | + $this->getPreviousRevisionId( $dbw ) : $this->mParentId, |
| 866 | + 'rev_file_props' => $this->mFileProps, |
859 | 867 | ), __METHOD__ |
860 | 868 | ); |
861 | 869 | |