MediaWiki  1.23.8
ArchivedFile.php
Go to the documentation of this file.
1 <?php
29 class ArchivedFile {
31  private $id;
32 
34  private $name;
35 
37  private $group;
38 
40  private $key;
41 
43  private $size;
44 
46  private $bits;
47 
49  private $width;
50 
52  private $height;
53 
55  private $metadata;
56 
58  private $mime;
59 
61  private $media_type;
62 
64  private $description;
65 
67  private $user;
68 
70  private $user_text;
71 
73  private $timestamp;
74 
76  private $dataLoaded;
77 
79  private $deleted;
80 
82  private $sha1;
83 
87  private $pageCount;
88 
90  private $archive_name;
91 
93  protected $handler;
94 
96  protected $title; # image title
97 
104  function __construct( $title, $id = 0, $key = '' ) {
105  $this->id = -1;
106  $this->title = false;
107  $this->name = false;
108  $this->group = 'deleted'; // needed for direct use of constructor
109  $this->key = '';
110  $this->size = 0;
111  $this->bits = 0;
112  $this->width = 0;
113  $this->height = 0;
114  $this->metadata = '';
115  $this->mime = "unknown/unknown";
116  $this->media_type = '';
117  $this->description = '';
118  $this->user = 0;
119  $this->user_text = '';
120  $this->timestamp = null;
121  $this->deleted = 0;
122  $this->dataLoaded = false;
123  $this->exists = false;
124  $this->sha1 = '';
125 
126  if ( $title instanceof Title ) {
127  $this->title = File::normalizeTitle( $title, 'exception' );
128  $this->name = $title->getDBkey();
129  }
130 
131  if ( $id ) {
132  $this->id = $id;
133  }
134 
135  if ( $key ) {
136  $this->key = $key;
137  }
138 
139  if ( !$id && !$key && !( $title instanceof Title ) ) {
140  throw new MWException( "No specifications provided to ArchivedFile constructor." );
141  }
142  }
143 
149  public function load() {
150  if ( $this->dataLoaded ) {
151  return true;
152  }
153  $conds = array();
154 
155  if ( $this->id > 0 ) {
156  $conds['fa_id'] = $this->id;
157  }
158  if ( $this->key ) {
159  $conds['fa_storage_group'] = $this->group;
160  $conds['fa_storage_key'] = $this->key;
161  }
162  if ( $this->title ) {
163  $conds['fa_name'] = $this->title->getDBkey();
164  }
165 
166  if ( !count( $conds ) ) {
167  throw new MWException( "No specific information for retrieving archived file" );
168  }
169 
170  if ( !$this->title || $this->title->getNamespace() == NS_FILE ) {
171  $this->dataLoaded = true; // set it here, to have also true on miss
172  $dbr = wfGetDB( DB_SLAVE );
173  $row = $dbr->selectRow(
174  'filearchive',
175  self::selectFields(),
176  $conds,
177  __METHOD__,
178  array( 'ORDER BY' => 'fa_timestamp DESC' )
179  );
180  if ( !$row ) {
181  // this revision does not exist?
182  return null;
183  }
184 
185  // initialize fields for filestore image object
186  $this->loadFromRow( $row );
187  } else {
188  throw new MWException( 'This title does not correspond to an image page.' );
189  }
190  $this->exists = true;
191 
192  return true;
193  }
194 
201  public static function newFromRow( $row ) {
202  $file = new ArchivedFile( Title::makeTitle( NS_FILE, $row->fa_name ) );
203  $file->loadFromRow( $row );
204 
205  return $file;
206  }
207 
212  static function selectFields() {
213  return array(
214  'fa_id',
215  'fa_name',
216  'fa_archive_name',
217  'fa_storage_key',
218  'fa_storage_group',
219  'fa_size',
220  'fa_bits',
221  'fa_width',
222  'fa_height',
223  'fa_metadata',
224  'fa_media_type',
225  'fa_major_mime',
226  'fa_minor_mime',
227  'fa_description',
228  'fa_user',
229  'fa_user_text',
230  'fa_timestamp',
231  'fa_deleted',
232  'fa_deleted_timestamp', /* Used by LocalFileRestoreBatch */
233  'fa_sha1',
234  );
235  }
236 
243  public function loadFromRow( $row ) {
244  $this->id = intval( $row->fa_id );
245  $this->name = $row->fa_name;
246  $this->archive_name = $row->fa_archive_name;
247  $this->group = $row->fa_storage_group;
248  $this->key = $row->fa_storage_key;
249  $this->size = $row->fa_size;
250  $this->bits = $row->fa_bits;
251  $this->width = $row->fa_width;
252  $this->height = $row->fa_height;
253  $this->metadata = $row->fa_metadata;
254  $this->mime = "$row->fa_major_mime/$row->fa_minor_mime";
255  $this->media_type = $row->fa_media_type;
256  $this->description = $row->fa_description;
257  $this->user = $row->fa_user;
258  $this->user_text = $row->fa_user_text;
259  $this->timestamp = $row->fa_timestamp;
260  $this->deleted = $row->fa_deleted;
261  if ( isset( $row->fa_sha1 ) ) {
262  $this->sha1 = $row->fa_sha1;
263  } else {
264  // old row, populate from key
265  $this->sha1 = LocalRepo::getHashFromKey( $this->key );
266  }
267  }
268 
274  public function getTitle() {
275  return $this->title;
276  }
277 
283  public function getName() {
284  return $this->name;
285  }
286 
290  public function getID() {
291  $this->load();
292 
293  return $this->id;
294  }
295 
299  public function exists() {
300  $this->load();
301 
302  return $this->exists;
303  }
304 
309  public function getKey() {
310  $this->load();
311 
312  return $this->key;
313  }
314 
319  public function getStorageKey() {
320  return $this->getKey();
321  }
322 
327  public function getGroup() {
328  return $this->group;
329  }
330 
335  public function getWidth() {
336  $this->load();
337 
338  return $this->width;
339  }
340 
345  public function getHeight() {
346  $this->load();
347 
348  return $this->height;
349  }
350 
355  public function getMetadata() {
356  $this->load();
357 
358  return $this->metadata;
359  }
360 
365  public function getSize() {
366  $this->load();
367 
368  return $this->size;
369  }
370 
375  public function getBits() {
376  $this->load();
377 
378  return $this->bits;
379  }
380 
385  public function getMimeType() {
386  $this->load();
387 
388  return $this->mime;
389  }
390 
395  function getHandler() {
396  if ( !isset( $this->handler ) ) {
397  $this->handler = MediaHandler::getHandler( $this->getMimeType() );
398  }
399 
400  return $this->handler;
401  }
402 
407  function pageCount() {
408  if ( !isset( $this->pageCount ) ) {
409  if ( $this->getHandler() && $this->handler->isMultiPage( $this ) ) {
410  $this->pageCount = $this->handler->pageCount( $this );
411  } else {
412  $this->pageCount = false;
413  }
414  }
415 
416  return $this->pageCount;
417  }
418 
424  public function getMediaType() {
425  $this->load();
426 
427  return $this->media_type;
428  }
429 
435  public function getTimestamp() {
436  $this->load();
437 
438  return wfTimestamp( TS_MW, $this->timestamp );
439  }
440 
447  function getSha1() {
448  $this->load();
449 
450  return $this->sha1;
451  }
452 
463  public function getUser( $type = 'text' ) {
464  $this->load();
465 
466  if ( $type == 'text' ) {
467  return $this->user_text;
468  } elseif ( $type == 'id' ) {
469  return $this->user;
470  }
471 
472  throw new MWException( "Unknown type '$type'." );
473  }
474 
481  public function getUserText() {
482  wfDeprecated( __METHOD__, '1.23' );
483  $this->load();
484  if ( $this->isDeleted( File::DELETED_USER ) ) {
485  return 0;
486  } else {
487  return $this->user_text;
488  }
489  }
490 
496  public function getDescription() {
497  $this->load();
498  if ( $this->isDeleted( File::DELETED_COMMENT ) ) {
499  return 0;
500  } else {
501  return $this->description;
502  }
503  }
504 
510  public function getRawUser() {
511  $this->load();
512 
513  return $this->user;
514  }
515 
521  public function getRawUserText() {
522  $this->load();
523 
524  return $this->user_text;
525  }
526 
532  public function getRawDescription() {
533  $this->load();
534 
535  return $this->description;
536  }
537 
542  public function getVisibility() {
543  $this->load();
544 
546  }
547 
554  public function isDeleted( $field ) {
555  $this->load();
556 
557  return ( $this->deleted & $field ) == $field;
558  }
559 
567  public function userCan( $field, User $user = null ) {
568  $this->load();
569 
570  return Revision::userCanBitfield( $this->deleted, $field, $user );
571  }
572 }
ArchivedFile\loadFromRow
loadFromRow( $row)
Load ArchivedFile object fields from a DB row.
Definition: ArchivedFile.php:221
ArchivedFile\$deleted
int $deleted
Bitfield akin to rev_deleted *.
Definition: ArchivedFile.php:62
Title\makeTitle
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:398
ArchivedFile\exists
exists()
Definition: ArchivedFile.php:277
ArchivedFile\getID
getID()
Definition: ArchivedFile.php:268
ArchivedFile\$sha1
string $sha1
SHA-1 hash of file content *.
Definition: ArchivedFile.php:64
ArchivedFile\getKey
getKey()
Return the FileStore key.
Definition: ArchivedFile.php:287
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
File\DELETED_USER
const DELETED_USER
Definition: File.php:54
ArchivedFile\getTimestamp
getTimestamp()
Return upload timestamp.
Definition: ArchivedFile.php:413
ArchivedFile\$metadata
string $metadata
Metadata string *.
Definition: ArchivedFile.php:46
ArchivedFile\$dataLoaded
bool $dataLoaded
Whether or not all this has been loaded from the database (loadFromXxx) *.
Definition: ArchivedFile.php:60
ArchivedFile\$group
string $group
FileStore storage group *.
Definition: ArchivedFile.php:34
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3659
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:2483
ArchivedFile\$width
int $width
Width *.
Definition: ArchivedFile.php:42
ArchivedFile\isDeleted
isDeleted( $field)
for file or revision rows
Definition: ArchivedFile.php:532
NS_FILE
const NS_FILE
Definition: Defines.php:85
ArchivedFile\$key
string $key
FileStore SHA-1 key *.
Definition: ArchivedFile.php:36
ArchivedFile\$bits
int $bits
size in bytes *
Definition: ArchivedFile.php:40
Revision\userCanBitfield
static userCanBitfield( $bitfield, $field, User $user=null)
Determine if the current user is allowed to view a particular field of this revision,...
Definition: Revision.php:1641
ArchivedFile\getStorageKey
getStorageKey()
Return the FileStore key (overriding base File class)
Definition: ArchivedFile.php:297
LocalRepo\getHashFromKey
static getHashFromKey( $key)
Gets the SHA1 hash from a storage key.
Definition: LocalRepo.php:156
File\normalizeTitle
static normalizeTitle( $title, $exception=false)
Given a string or Title object return either a valid Title object with namespace NS_FILE or null.
Definition: File.php:161
ArchivedFile\$archive_name
string $archive_name
Original base filename *.
Definition: ArchivedFile.php:70
$dbr
$dbr
Definition: testCompression.php:48
ArchivedFile\getMetadata
getMetadata()
Get handler-specific metadata.
Definition: ArchivedFile.php:333
key
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an and does all the work of translating among various forms such as plain database key
Definition: design.txt:25
title
to move a page</td >< td > &*You are moving the page across *A non empty talk page already exists under the new or *You uncheck the box below In those you will have to move or merge the page manually if desired</td >< td > be sure to &You are responsible for making sure that links continue to point where they are supposed to go Note that the page will &a page at the new title
Definition: All_system_messages.txt:2703
ArchivedFile\getSize
getSize()
Return the size of the image file, in bytes.
Definition: ArchivedFile.php:343
ArchivedFile\load
load()
Loads a file object from the filearchive table.
Definition: ArchivedFile.php:127
ArchivedFile\getUserText
getUserText()
Return the user name of the uploader.
Definition: ArchivedFile.php:459
Title\getDBkey
getDBkey()
Get the main part with underscores.
Definition: Title.php:857
ArchivedFile\getHandler
getHandler()
Get a MediaHandler instance for this file.
Definition: ArchivedFile.php:373
MWException
MediaWiki exception.
Definition: MWException.php:26
ArchivedFile\$id
int $id
filearchive row ID *
Definition: ArchivedFile.php:30
File\DELETED_COMMENT
const DELETED_COMMENT
Definition: File.php:53
ArchivedFile\__construct
__construct( $title, $id=0, $key='')
Definition: ArchivedFile.php:82
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1127
ArchivedFile\getMimeType
getMimeType()
Returns the mime type of the file.
Definition: ArchivedFile.php:363
ArchivedFile\$mime
string $mime
MIME type *.
Definition: ArchivedFile.php:48
ArchivedFile\getTitle
getTitle()
Return the associated title object.
Definition: ArchivedFile.php:252
ArchivedFile\pageCount
pageCount()
Returns the number of pages of a multipage document, or false for documents which aren't multipage do...
Definition: ArchivedFile.php:385
ArchivedFile\getVisibility
getVisibility()
Returns the deletion bitfield.
Definition: ArchivedFile.php:520
ArchivedFile\$user
int $user
User ID of uploader *.
Definition: ArchivedFile.php:54
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
ArchivedFile\$size
int $size
File size in bytes *.
Definition: ArchivedFile.php:38
ArchivedFile\$handler
MediaHandler $handler
Definition: ArchivedFile.php:72
ArchivedFile\userCan
userCan( $field, User $user=null)
Determine if the current user is allowed to view a particular field of this FileStore image file,...
Definition: ArchivedFile.php:545
ArchivedFile\$user_text
string $user_text
User name of uploader *.
Definition: ArchivedFile.php:56
ArchivedFile\getDescription
getDescription()
Return upload description.
Definition: ArchivedFile.php:474
ArchivedFile\$title
Title $title
Definition: ArchivedFile.php:74
TS_MW
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
Definition: GlobalFunctions.php:2431
user
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same user
Definition: distributors.txt:9
ArchivedFile
Class representing a row of the 'filearchive' table.
Definition: ArchivedFile.php:29
ArchivedFile\getSha1
getSha1()
Get the SHA-1 base 36 hash of the file.
Definition: ArchivedFile.php:425
ArchivedFile\getName
getName()
Return the file name.
Definition: ArchivedFile.php:261
ArchivedFile\getGroup
getGroup()
Return the FileStore storage group.
Definition: ArchivedFile.php:305
$file
if(PHP_SAPI !='cli') $file
Definition: UtfNormalTest2.php:30
ArchivedFile\getWidth
getWidth()
Return the width of the image.
Definition: ArchivedFile.php:313
ArchivedFile\getRawUserText
getRawUserText()
Return the user name of the uploader.
Definition: ArchivedFile.php:499
ArchivedFile\getUser
getUser( $type='text')
Returns ID or name of user who uploaded the file.
Definition: ArchivedFile.php:441
ArchivedFile\$timestamp
string $timestamp
Time of upload *.
Definition: ArchivedFile.php:58
DB_SLAVE
const DB_SLAVE
Definition: Defines.php:55
Title
Represents a title within MediaWiki.
Definition: Title.php:35
ArchivedFile\$pageCount
string $pageCount
Number of pages of a multipage document, or false for documents which aren't multipage documents.
Definition: ArchivedFile.php:68
ArchivedFile\getRawDescription
getRawDescription()
Return upload description.
Definition: ArchivedFile.php:510
MediaHandler\getHandler
static getHandler( $type)
Get a MediaHandler for a given MIME type from the instance cache.
Definition: MediaHandler.php:48
ArchivedFile\$description
string $description
Upload description *.
Definition: ArchivedFile.php:52
ArchivedFile\getHeight
getHeight()
Return the height of the image.
Definition: ArchivedFile.php:323
name
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at name
Definition: design.txt:12
ArchivedFile\$name
string $name
File name *.
Definition: ArchivedFile.php:32
ArchivedFile\getBits
getBits()
Return the bits of the image file, in bytes.
Definition: ArchivedFile.php:353
ArchivedFile\selectFields
static selectFields()
Fields in the filearchive table.
Definition: ArchivedFile.php:190
ArchivedFile\$height
int $height
Height *.
Definition: ArchivedFile.php:44
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59
ArchivedFile\getRawUser
getRawUser()
Return the user ID of the uploader.
Definition: ArchivedFile.php:488
MediaHandler
Base media handler class.
Definition: MediaHandler.php:29
ArchivedFile\$media_type
string $media_type
Media type *.
Definition: ArchivedFile.php:50
ArchivedFile\newFromRow
static newFromRow( $row)
Loads a file object from the filearchive table.
Definition: ArchivedFile.php:179
ArchivedFile\getMediaType
getMediaType()
Return the type of the media in the file.
Definition: ArchivedFile.php:402
$type
$type
Definition: testCompression.php:46