9 * Returns a file object from the filearchive table
10 * @param $title, the corresponding image page title
11 * @param $id, the image id, a unique key
12 * @param $key, optional storage key
13 * @return ResultWrapper
15 function ArchivedFile( $title, $id=0, $key='' ) {
16 if( !is_object( $title ) ) {
17 throw new MWException( 'ArchivedFile constructor given bogus title.' );
19 $conds = ($id) ?
"fa_id = $id" : "fa_storage_key = '$key'";
20 if( $title->getNamespace() == NS_IMAGE
) {
21 $dbr = wfGetDB( DB_SLAVE
);
22 $res = $dbr->select( 'filearchive',
42 'fa_name' => $title->getDbKey(),
45 array( 'ORDER BY' => 'fa_timestamp DESC' ) );
47 if ( $dbr->numRows( $res ) == 0 ) {
48 // this revision does not exist?
51 $ret = $dbr->resultObject( $res );
52 $row = $ret->fetchObject();
54 // initialize fields for filestore image object
55 $this->mId
= intval($row->fa_id
);
56 $this->mName
= $row->fa_name
;
57 $this->mGroup
= $row->fa_storage_group
;
58 $this->mKey
= $row->fa_storage_key
;
59 $this->mSize
= $row->fa_size
;
60 $this->mBits
= $row->fa_bits
;
61 $this->mWidth
= $row->fa_width
;
62 $this->mHeight
= $row->fa_height
;
63 $this->mMetaData
= $row->fa_metadata
;
64 $this->mMime
= "$row->fa_major_mime/$row->fa_minor_mime";
65 $this->mType
= $row->fa_media_type
;
66 $this->mDescription
= $row->fa_description
;
67 $this->mUser
= $row->fa_user
;
68 $this->mUserText
= $row->fa_user_text
;
69 $this->mTimestamp
= $row->fa_timestamp
;
70 $this->mDeleted
= $row->fa_deleted
;
72 throw new MWException( 'This title does not correspond to an image page.' );
79 * int $field one of DELETED_* bitfield constants
80 * for file or revision rows
83 function isDeleted( $field ) {
84 return ($this->mDeleted
& $field) == $field;
88 * Determine if the current user is allowed to view a particular
89 * field of this FileStore image file, if it's marked as deleted.
93 function userCan( $field ) {
94 if( isset($this->mDeleted
) && ($this->mDeleted
& $field) == $field ) {
97 $permission = ( $this->mDeleted
& File
::DELETED_RESTRICTED
) == File
::DELETED_RESTRICTED
100 wfDebug( "Checking for $permission due to $field match on $this->mDeleted\n" );
101 return $wgUser->isAllowed( $permission );