Merged filerepo-work branch:
[lhc/web/wiklou.git] / includes / filerepo / ArchivedFile.php
1 <?php
2
3 /**
4 * @addtogroup Media
5 */
6 class ArchivedFile
7 {
8 /**
9 * Returns a file object from the filearchive table
10 * In the future, all current and old image storage
11 * may use FileStore. There will be a "old" storage
12 * for current and previous file revisions as well as
13 * the "deleted" group for archived revisions
14 * @param $title, the corresponding image page title
15 * @param $id, the image id, a unique key
16 * @param $key, optional storage key
17 * @return ResultWrapper
18 */
19 function ArchivedFile( $title, $id=0, $key='' ) {
20 if( !is_object( $title ) ) {
21 throw new MWException( 'ArchivedFile constructor given bogus title.' );
22 }
23 $conds = ($id) ? "fa_id = $id" : "fa_storage_key = '$key'";
24 if( $title->getNamespace() == NS_IMAGE ) {
25 $dbr = wfGetDB( DB_SLAVE );
26 $res = $dbr->select( 'filearchive',
27 array(
28 'fa_id',
29 'fa_name',
30 'fa_storage_key',
31 'fa_storage_group',
32 'fa_size',
33 'fa_bits',
34 'fa_width',
35 'fa_height',
36 'fa_metadata',
37 'fa_media_type',
38 'fa_major_mime',
39 'fa_minor_mime',
40 'fa_description',
41 'fa_user',
42 'fa_user_text',
43 'fa_timestamp',
44 'fa_deleted' ),
45 array(
46 'fa_name' => $title->getDbKey(),
47 $conds ),
48 __METHOD__,
49 array( 'ORDER BY' => 'fa_timestamp DESC' ) );
50
51 if ( $dbr->numRows( $res ) == 0 ) {
52 // this revision does not exist?
53 return;
54 }
55 $ret = $dbr->resultObject( $res );
56 $row = $ret->fetchObject();
57
58 // initialize fields for filestore image object
59 $this->mId = intval($row->fa_id);
60 $this->mName = $row->fa_name;
61 $this->mGroup = $row->fa_storage_group;
62 $this->mKey = $row->fa_storage_key;
63 $this->mSize = $row->fa_size;
64 $this->mBits = $row->fa_bits;
65 $this->mWidth = $row->fa_width;
66 $this->mHeight = $row->fa_height;
67 $this->mMetaData = $row->fa_metadata;
68 $this->mMime = "$row->fa_major_mime/$row->fa_minor_mime";
69 $this->mType = $row->fa_media_type;
70 $this->mDescription = $row->fa_description;
71 $this->mUser = $row->fa_user;
72 $this->mUserText = $row->fa_user_text;
73 $this->mTimestamp = $row->fa_timestamp;
74 $this->mDeleted = $row->fa_deleted;
75 } else {
76 throw new MWException( 'This title does not correspond to an image page.' );
77 return;
78 }
79 return true;
80 }
81
82 /**
83 * int $field one of DELETED_* bitfield constants
84 * for file or revision rows
85 * @return bool
86 */
87 function isDeleted( $field ) {
88 return ($this->mDeleted & $field) == $field;
89 }
90
91 /**
92 * Determine if the current user is allowed to view a particular
93 * field of this FileStore image file, if it's marked as deleted.
94 * @param int $field
95 * @return bool
96 */
97 function userCan( $field ) {
98 if( isset($this->mDeleted) && ($this->mDeleted & $field) == $field ) {
99 // images
100 global $wgUser;
101 $permission = ( $this->mDeleted & File::DELETED_RESTRICTED ) == File::DELETED_RESTRICTED
102 ? 'hiderevision'
103 : 'deleterevision';
104 wfDebug( "Checking for $permission due to $field match on $this->mDeleted\n" );
105 return $wgUser->isAllowed( $permission );
106 } else {
107 return true;
108 }
109 }
110 }
111
112 ?>