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
19 function ArchivedFile( $title, $id=0, $key='' ) {
20 if( !is_object( $title ) ) {
21 throw new MWException( 'ArchivedFile constructor given bogus title.' );
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',
46 'fa_name' => $title->getDbKey(),
49 array( 'ORDER BY' => 'fa_timestamp DESC' ) );
51 if ( $dbr->numRows( $res ) == 0 ) {
52 // this revision does not exist?
55 $ret = $dbr->resultObject( $res );
56 $row = $ret->fetchObject();
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
;
76 throw new MWException( 'This title does not correspond to an image page.' );
83 * int $field one of DELETED_* bitfield constants
84 * for file or revision rows
87 function isDeleted( $field ) {
88 return ($this->mDeleted
& $field) == $field;
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.
97 function userCan( $field ) {
98 if( isset($this->mDeleted
) && ($this->mDeleted
& $field) == $field ) {
101 $permission = ( $this->mDeleted
& File
::DELETED_RESTRICTED
) == File
::DELETED_RESTRICTED
104 wfDebug( "Checking for $permission due to $field match on $this->mDeleted\n" );
105 return $wgUser->isAllowed( $permission );