8 function ArchivedFile( $title, $id=0, $key='' ) {
9 if( !is_object( $title ) ) {
10 throw new MWException( 'ArchivedFile constructor given bogus title.' );
13 $this->title
= $title;
14 $this->name
= $title->getDBKey();
22 $this->mime
= "unknown/unknown";
24 $this->description
= '';
27 $this->timestamp
= NULL;
29 # BC, load if these are specified
36 * Loads a file object from the filearchive table
37 * @return ResultWrapper
40 if( !is_object( $this->title
) ) {
41 throw new MWException( 'ArchivedFile constructor given bogus title.' );
43 $conds = ($this->id
) ?
"fa_id = {$this->id}" : "fa_storage_key = '{$this->key}'";
44 if( $this->title
->getNamespace() == NS_IMAGE
) {
45 $dbr = wfGetDB( DB_SLAVE
);
46 $res = $dbr->select( 'filearchive',
67 'fa_name' => $this->title
->getDBKey(),
70 array( 'ORDER BY' => 'fa_timestamp DESC' ) );
72 if ( $dbr->numRows( $res ) == 0 ) {
73 // this revision does not exist?
76 $ret = $dbr->resultObject( $res );
77 $row = $ret->fetchObject();
79 // initialize fields for filestore image object
80 $this->id
= intval($row->fa_id
);
81 $this->name
= $row->fa_name
;
82 $this->archive_name
= $row->fa_archive_name
;
83 $this->group
= $row->fa_storage_group
;
84 $this->key
= $row->fa_storage_key
;
85 $this->size
= $row->fa_size
;
86 $this->bits
= $row->fa_bits
;
87 $this->width
= $row->fa_width
;
88 $this->height
= $row->fa_height
;
89 $this->metaData
= $row->fa_metadata
;
90 $this->mime
= "$row->fa_major_mime/$row->fa_minor_mime";
91 $this->type
= $row->fa_media_type
;
92 $this->description
= $row->fa_description
;
93 $this->user
= $row->fa_user
;
94 $this->userText
= $row->fa_user_text
;
95 $this->timestamp
= $row->fa_timestamp
;
96 $this->deleted
= $row->fa_deleted
;
98 throw new MWException( 'This title does not correspond to an image page.' );
105 * Loads a file object from the filearchive table
106 * @return ResultWrapper
108 public static function newFromRow( $row ) {
109 $file = new ArchivedFile( Title
::makeTitle( NS_IMAGE
, $row->fa_name
) );
111 $file->id
= intval($row->fa_id
);
112 $file->name
= $row->fa_name
;
113 $file->archive_name
= $row->fa_archive_name
;
114 $file->group
= $row->fa_storage_group
;
115 $file->key
= $row->fa_storage_key
;
116 $file->size
= $row->fa_size
;
117 $file->bits
= $row->fa_bits
;
118 $file->width
= $row->fa_width
;
119 $file->height
= $row->fa_height
;
120 $file->metaData
= $row->fa_metadata
;
121 $file->mime
= "$row->fa_major_mime/$row->fa_minor_mime";
122 $file->type
= $row->fa_media_type
;
123 $file->description
= $row->fa_description
;
124 $file->user
= $row->fa_user
;
125 $file->userText
= $row->fa_user_text
;
126 $file->timestamp
= $row->fa_timestamp
;
127 $file->deleted
= $row->fa_deleted
;
133 * int $field one of DELETED_* bitfield constants
134 * for file or revision rows
137 function isDeleted( $field ) {
138 return ($this->deleted
& $field) == $field;
142 * Determine if the current user is allowed to view a particular
143 * field of this FileStore image file, if it's marked as deleted.
147 function userCan( $field ) {
148 if( isset($this->deleted
) && ($this->deleted
& $field) == $field ) {
151 $permission = ( $this->deleted
& File
::DELETED_RESTRICTED
) == File
::DELETED_RESTRICTED
154 wfDebug( "Checking for $permission due to $field match on $this->deleted\n" );
155 return $wgUser->isAllowed( $permission );