r80282 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80281‎ | r80282 | r80283 >
Date:17:02, 14 January 2011
Author:btongminh
Status:deferred
Tags:license-work 
Comment:
Initial mostly broken read only file properties fetching
Modified paths:
  • /branches/license-work/phase3/includes/Revision.php (modified) (history)
  • /branches/license-work/phase3/includes/filerepo/FileProperties.php (added) (history)

Diff [purge]

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
185 + native
Index: branches/license-work/phase3/includes/Revision.php
@@ -258,7 +258,8 @@
259259 'rev_minor_edit',
260260 'rev_deleted',
261261 'rev_len',
262 - 'rev_parent_id'
 262+ 'rev_parent_id',
 263+ 'rev_fileprops_id',
263264 );
264265 }
265266
@@ -301,6 +302,7 @@
302303 $this->mMinorEdit = intval( $row->rev_minor_edit );
303304 $this->mTimestamp = $row->rev_timestamp;
304305 $this->mDeleted = intval( $row->rev_deleted );
 306+ $this->mFileProps = intval( $row->rev_file_props );
305307
306308 if( !isset( $row->rev_parent_id ) )
307309 $this->mParentId = is_null($row->rev_parent_id) ? null : 0;
@@ -342,6 +344,7 @@
343345 $this->mDeleted = isset( $row['deleted'] ) ? intval( $row['deleted'] ) : 0;
344346 $this->mSize = isset( $row['len'] ) ? intval( $row['len'] ) : null;
345347 $this->mParentId = isset( $row['parent_id'] ) ? intval( $row['parent_id'] ) : null;
 348+ $this->mFileProps = isset( $row['file_props'] ) ? intval( $row['file_props'] ) : 0;
346349
347350 // Enforce spacing trimming on supplied text
348351 $this->mComment = isset( $row['comment'] ) ? trim( strval( $row['comment'] ) ) : null;
@@ -435,6 +438,10 @@
436439 public function getPage() {
437440 return $this->mPage;
438441 }
 442+
 443+ public function getFilePropsVersion() {
 444+ return $this->mFileProps;
 445+ }
439446
440447 /**
441448 * Fetch revision's user id if it's available to the specified audience.
@@ -854,7 +861,8 @@
855862 'rev_deleted' => $this->mDeleted,
856863 'rev_len' => $this->mSize,
857864 '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,
859867 ), __METHOD__
860868 );
861869

Follow-up revisions

RevisionCommit summaryAuthorDate
r80291Follow-up to r80282, r80290: Revert changes to Revision.php; allow saving propsbtongminh18:43, 14 January 2011
r80302license-work: Autoloader for r80282catrope19:22, 14 January 2011

Status & tagging log