]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/filerepo/ArchivedFile.php
MediaWiki 1.11.0
[autoinstalls/mediawiki.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          * @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
14          */
15         function ArchivedFile( $title, $id=0, $key='' ) {
16                 if( !is_object( $title ) ) {
17                         throw new MWException( 'ArchivedFile constructor given bogus title.' );
18                 }
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',
23                                 array(
24                                         'fa_id',
25                                         'fa_name',
26                                         'fa_storage_key',
27                                         'fa_storage_group',
28                                         'fa_size',
29                                         'fa_bits',
30                                         'fa_width',
31                                         'fa_height',
32                                         'fa_metadata',
33                                         'fa_media_type',
34                                         'fa_major_mime',
35                                         'fa_minor_mime',
36                                         'fa_description',
37                                         'fa_user',
38                                         'fa_user_text',
39                                         'fa_timestamp',
40                                         'fa_deleted' ),
41                                 array( 
42                                         'fa_name' => $title->getDbKey(),
43                                         $conds ),
44                                 __METHOD__,
45                                 array( 'ORDER BY' => 'fa_timestamp DESC' ) );
46                                 
47                         if ( $dbr->numRows( $res ) == 0 ) {
48                         // this revision does not exist?
49                                 return;
50                         }
51                         $ret = $dbr->resultObject( $res );
52                         $row = $ret->fetchObject();
53         
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;             
71                 } else {
72                         throw new MWException( 'This title does not correspond to an image page.' );
73                         return;
74                 }
75                 return true;
76         }
77
78         /**
79          * int $field one of DELETED_* bitfield constants
80          * for file or revision rows
81          * @return bool
82          */
83         function isDeleted( $field ) {
84                 return ($this->mDeleted & $field) == $field;
85         }
86         
87         /**
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.
90          * @param int $field                                    
91          * @return bool
92          */
93         function userCan( $field ) {
94                 if( isset($this->mDeleted) && ($this->mDeleted & $field) == $field ) {
95                 // images
96                         global $wgUser;
97                         $permission = ( $this->mDeleted & File::DELETED_RESTRICTED ) == File::DELETED_RESTRICTED
98                                 ? 'hiderevision'
99                                 : 'deleterevision';
100                         wfDebug( "Checking for $permission due to $field match on $this->mDeleted\n" );
101                         return $wgUser->isAllowed( $permission );
102                 } else {
103                         return true;
104                 }
105         }
106 }
107
108