r80291 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80290‎ | r80291 | r80292 >
Date:18:43, 14 January 2011
Author:btongminh
Status:ok
Tags:license-work 
Comment:
Follow-up to r80282, r80290: Revert changes to Revision.php; allow saving props
Modified paths:
  • /branches/license-work/phase3/includes/Revision.php (modified) (history)
  • /branches/license-work/phase3/includes/filerepo/FileProperties.php (modified) (history)
  • /branches/license-work/phase3/includes/filerepo/LocalFile.php (modified) (history)

Diff [purge]

Index: branches/license-work/phase3/includes/filerepo/LocalFile.php
@@ -1283,6 +1283,11 @@
12841284 $dbw = $this->repo->getMasterDB();
12851285 $dbw->rollback();
12861286 }
 1287+
 1288+ public function properties() {
 1289+ return new FileProperties( $this );
 1290+ }
 1291+
12871292 } // LocalFile class
12881293
12891294 # ------------------------------------------------------------------------------
Index: branches/license-work/phase3/includes/filerepo/FileProperties.php
@@ -12,16 +12,16 @@
1313 }
1414
1515 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 );
 16+ if ( !$this->revId ) {
 17+ $this->revId = $this->file->getTitle()->getLatestRevID();
2518 }
 19+
 20+ $dbr = $this->file->getRepo()->getSlaveDB();
 21+ $res = $dbr->select( 'file_props',
 22+ array( 'fp_key', 'fp_value_int', 'fp_value_text' ),
 23+ array( 'fp_rev_id' => $this->revId ),
 24+ __METHOD__ );
 25+ $this->loadFromResult( $res );
2626 }
2727
2828 public function loadFromResult( $res ) {
@@ -49,6 +49,42 @@
5050 public function getAuthors() {
5151 return $this->authors;
5252 }
 53+
 54+ public function save( $comment, $minor = false ) {
 55+ $dbw = $this->file->getRepo()->getMasterDB();
 56+
 57+ $rev = Revision::newNullRevision( $dbw,
 58+ $this->file->getTitle()->getArticleId( Article::GAID_FOR_UPDATE ),
 59+ $comment, $minor );
 60+ $rev->insertOn( $dbw );
 61+
 62+ $id = $rev->getId();
 63+
 64+ $insert = array();
 65+ foreach ( $this->authors as $author ) {
 66+ $a = array(
 67+ 'fp_rev_id' => $id,
 68+ 'fp_key' => 'author',
 69+ 'fp_value_int' => $author->getId()
 70+ );
 71+
 72+ $text = $author->getRawText();
 73+ if ( $text ) {
 74+ $a['fp_value_text'] = $text;
 75+ }
 76+ $insert[] = $a;
 77+ }
 78+ foreach ( $this->licenses as $license ) {
 79+ $insert[] = array(
 80+ 'fp_rev_id' => $id,
 81+ 'fp_key' => 'license',
 82+ 'fp_value_int' => $license->getId(),
 83+ );
 84+ }
 85+
 86+
 87+ $dbw->insert( 'file_props', $insert, __METHOD__ );
 88+ }
5389 }
5490
5591 class FileAuthor {
@@ -69,6 +105,9 @@
70106 }
71107 return User::newFromId( $this->id )->getName();
72108 }
 109+ public function getRawText() {
 110+ return $this->text;
 111+ }
73112 }
74113
75114 class FileLicense {
@@ -79,5 +118,49 @@
80119 public function __construct( $id ) {
81120 $this->id = $id;
82121 }
 122+ public function getId() {
 123+ return $this->id;
 124+ }
 125+ public function getName() {
 126+ return $this->name;
 127+ }
 128+ public function getUrl() {
 129+ return $this->url;
 130+ }
 131+ public function getCount() {
 132+ return $this->count;
 133+ }
83134
 135+ public static function loadArray( &$licenses ) {
 136+ $licenseIds = array();
 137+ foreach ( $licenses as $license ) {
 138+ $licenseIds[] = $license->getId();
 139+ }
 140+
 141+ $dbr = wfGetDB( DB_SLAVE );
 142+ $res = $dbr->select( 'licenses',
 143+ array( 'lic_id', 'lic_name', 'lic_url', 'lic_count' ),
 144+ array( 'lic_id' => $licenseIds ),
 145+ __METHOD__ );
 146+
 147+ $licenseData = array();
 148+ foreach ( $res as $row ) {
 149+ $licenseData[$row->lic_id] = $row;
 150+ }
 151+ foreach ( $licenses as $key => $license ) {
 152+ if ( isset( $licenseData[$license->getId()] ) ) {
 153+ $license->loadFromLicenseRow( $licenseData[$license->getId()] );
 154+ } else {
 155+ unset( $licenses[$key] );
 156+ }
 157+ }
 158+ }
 159+
 160+
 161+ public function loadFromLicenseRow( $row ) {
 162+ $this->name = $row->lic_name;
 163+ $this->url = $row->lic_url;
 164+ $this->count = $row->lic_count;
 165+ }
 166+
84167 }
Index: branches/license-work/phase3/includes/Revision.php
@@ -258,8 +258,7 @@
259259 'rev_minor_edit',
260260 'rev_deleted',
261261 'rev_len',
262 - 'rev_parent_id',
263 - 'rev_fileprops_id',
 262+ 'rev_parent_id'
264263 );
265264 }
266265
@@ -302,7 +301,6 @@
303302 $this->mMinorEdit = intval( $row->rev_minor_edit );
304303 $this->mTimestamp = $row->rev_timestamp;
305304 $this->mDeleted = intval( $row->rev_deleted );
306 - $this->mFileProps = intval( $row->rev_file_props );
307305
308306 if( !isset( $row->rev_parent_id ) )
309307 $this->mParentId = is_null($row->rev_parent_id) ? null : 0;
@@ -344,7 +342,6 @@
345343 $this->mDeleted = isset( $row['deleted'] ) ? intval( $row['deleted'] ) : 0;
346344 $this->mSize = isset( $row['len'] ) ? intval( $row['len'] ) : null;
347345 $this->mParentId = isset( $row['parent_id'] ) ? intval( $row['parent_id'] ) : null;
348 - $this->mFileProps = isset( $row['file_props'] ) ? intval( $row['file_props'] ) : 0;
349346
350347 // Enforce spacing trimming on supplied text
351348 $this->mComment = isset( $row['comment'] ) ? trim( strval( $row['comment'] ) ) : null;
@@ -438,10 +435,6 @@
439436 public function getPage() {
440437 return $this->mPage;
441438 }
442 -
443 - public function getFilePropsVersion() {
444 - return $this->mFileProps;
445 - }
446439
447440 /**
448441 * Fetch revision's user id if it's available to the specified audience.
@@ -861,8 +854,7 @@
862855 'rev_deleted' => $this->mDeleted,
863856 'rev_len' => $this->mSize,
864857 'rev_parent_id' => is_null($this->mParentId) ?
865 - $this->getPreviousRevisionId( $dbw ) : $this->mParentId,
866 - 'rev_file_props' => $this->mFileProps,
 858+ $this->getPreviousRevisionId( $dbw ) : $this->mParentId
867859 ), __METHOD__
868860 );
869861

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r80282Initial mostly broken read only file properties fetchingbtongminh17:02, 14 January 2011
r80290license-work: After discussion with Krinkle and Bryan, remove rev_fileprops_i...catrope18:42, 14 January 2011

Status & tagging log