Index: branches/license-work/phase3/includes/filerepo/LocalFile.php |
— | — | @@ -1283,6 +1283,11 @@ |
1284 | 1284 | $dbw = $this->repo->getMasterDB(); |
1285 | 1285 | $dbw->rollback(); |
1286 | 1286 | } |
| 1287 | + |
| 1288 | + public function properties() { |
| 1289 | + return new FileProperties( $this ); |
| 1290 | + } |
| 1291 | + |
1287 | 1292 | } // LocalFile class |
1288 | 1293 | |
1289 | 1294 | # ------------------------------------------------------------------------------ |
Index: branches/license-work/phase3/includes/filerepo/FileProperties.php |
— | — | @@ -12,16 +12,16 @@ |
13 | 13 | } |
14 | 14 | |
15 | 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 ); |
| 16 | + if ( !$this->revId ) { |
| 17 | + $this->revId = $this->file->getTitle()->getLatestRevID(); |
25 | 18 | } |
| 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 ); |
26 | 26 | } |
27 | 27 | |
28 | 28 | public function loadFromResult( $res ) { |
— | — | @@ -49,6 +49,42 @@ |
50 | 50 | public function getAuthors() { |
51 | 51 | return $this->authors; |
52 | 52 | } |
| 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 | + } |
53 | 89 | } |
54 | 90 | |
55 | 91 | class FileAuthor { |
— | — | @@ -69,6 +105,9 @@ |
70 | 106 | } |
71 | 107 | return User::newFromId( $this->id )->getName(); |
72 | 108 | } |
| 109 | + public function getRawText() { |
| 110 | + return $this->text; |
| 111 | + } |
73 | 112 | } |
74 | 113 | |
75 | 114 | class FileLicense { |
— | — | @@ -79,5 +118,49 @@ |
80 | 119 | public function __construct( $id ) { |
81 | 120 | $this->id = $id; |
82 | 121 | } |
| 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 | + } |
83 | 134 | |
| 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 | + |
84 | 167 | } |
Index: branches/license-work/phase3/includes/Revision.php |
— | — | @@ -258,8 +258,7 @@ |
259 | 259 | 'rev_minor_edit', |
260 | 260 | 'rev_deleted', |
261 | 261 | 'rev_len', |
262 | | - 'rev_parent_id', |
263 | | - 'rev_fileprops_id', |
| 262 | + 'rev_parent_id' |
264 | 263 | ); |
265 | 264 | } |
266 | 265 | |
— | — | @@ -302,7 +301,6 @@ |
303 | 302 | $this->mMinorEdit = intval( $row->rev_minor_edit ); |
304 | 303 | $this->mTimestamp = $row->rev_timestamp; |
305 | 304 | $this->mDeleted = intval( $row->rev_deleted ); |
306 | | - $this->mFileProps = intval( $row->rev_file_props ); |
307 | 305 | |
308 | 306 | if( !isset( $row->rev_parent_id ) ) |
309 | 307 | $this->mParentId = is_null($row->rev_parent_id) ? null : 0; |
— | — | @@ -344,7 +342,6 @@ |
345 | 343 | $this->mDeleted = isset( $row['deleted'] ) ? intval( $row['deleted'] ) : 0; |
346 | 344 | $this->mSize = isset( $row['len'] ) ? intval( $row['len'] ) : null; |
347 | 345 | $this->mParentId = isset( $row['parent_id'] ) ? intval( $row['parent_id'] ) : null; |
348 | | - $this->mFileProps = isset( $row['file_props'] ) ? intval( $row['file_props'] ) : 0; |
349 | 346 | |
350 | 347 | // Enforce spacing trimming on supplied text |
351 | 348 | $this->mComment = isset( $row['comment'] ) ? trim( strval( $row['comment'] ) ) : null; |
— | — | @@ -438,10 +435,6 @@ |
439 | 436 | public function getPage() { |
440 | 437 | return $this->mPage; |
441 | 438 | } |
442 | | - |
443 | | - public function getFilePropsVersion() { |
444 | | - return $this->mFileProps; |
445 | | - } |
446 | 439 | |
447 | 440 | /** |
448 | 441 | * Fetch revision's user id if it's available to the specified audience. |
— | — | @@ -861,8 +854,7 @@ |
862 | 855 | 'rev_deleted' => $this->mDeleted, |
863 | 856 | 'rev_len' => $this->mSize, |
864 | 857 | '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 |
867 | 859 | ), __METHOD__ |
868 | 860 | ); |
869 | 861 | |