summaryrefslogtreecommitdiff
path: root/includes/filerepo/file/ArchivedFile.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/filerepo/file/ArchivedFile.php')
-rw-r--r--includes/filerepo/file/ArchivedFile.php165
1 files changed, 120 insertions, 45 deletions
diff --git a/includes/filerepo/file/ArchivedFile.php b/includes/filerepo/file/ArchivedFile.php
index 749f11a5..5b0d8e2b 100644
--- a/includes/filerepo/file/ArchivedFile.php
+++ b/includes/filerepo/file/ArchivedFile.php
@@ -27,40 +27,73 @@
* @ingroup FileAbstraction
*/
class ArchivedFile {
- /**#@+
- * @private
- */
- var $id, # filearchive row ID
- $name, # image name
- $group, # FileStore storage group
- $key, # FileStore sha1 key
- $size, # file dimensions
- $bits, # size in bytes
- $width, # width
- $height, # height
- $metadata, # metadata string
- $mime, # mime type
- $media_type, # media type
- $description, # upload description
- $user, # user ID of uploader
- $user_text, # user name of uploader
- $timestamp, # time of upload
- $dataLoaded, # Whether or not all this has been loaded from the database (loadFromXxx)
- $deleted, # Bitfield akin to rev_deleted
- $sha1, # sha1 hash of file content
- $pageCount,
- $archive_name;
+ /** @var int Filearchive row ID */
+ private $id;
- /**
- * @var MediaHandler
- */
- var $handler;
- /**
- * @var Title
+ /** @var string File name */
+ private $name;
+
+ /** @var string FileStore storage group */
+ private $group;
+
+ /** @var string FileStore SHA-1 key */
+ private $key;
+
+ /** @var int File size in bytes */
+ private $size;
+
+ /** @var int Size in bytes */
+ private $bits;
+
+ /** @var int Width */
+ private $width;
+
+ /** @var int Height */
+ private $height;
+
+ /** @var string Metadata string */
+ private $metadata;
+
+ /** @var string MIME type */
+ private $mime;
+
+ /** @var string Media type */
+ private $media_type;
+
+ /** @var string Upload description */
+ private $description;
+
+ /** @var int User ID of uploader */
+ private $user;
+
+ /** @var string User name of uploader */
+ private $user_text;
+
+ /** @var string Time of upload */
+ private $timestamp;
+
+ /** @var bool Whether or not all this has been loaded from the database (loadFromXxx) */
+ private $dataLoaded;
+
+ /** @var int Bitfield akin to rev_deleted */
+ private $deleted;
+
+ /** @var string SHA-1 hash of file content */
+ private $sha1;
+
+ /** @var string Number of pages of a multipage document, or false for
+ * documents which aren't multipage documents
*/
- var $title; # image title
+ private $pageCount;
+
+ /** @var string Original base filename */
+ private $archive_name;
- /**#@-*/
+ /** @var MediaHandler */
+ protected $handler;
+
+ /** @var Title */
+ protected $title; # image title
/**
* @throws MWException
@@ -162,13 +195,13 @@ class ArchivedFile {
/**
* Loads a file object from the filearchive table
*
- * @param $row
- *
+ * @param stdClass $row
* @return ArchivedFile
*/
public static function newFromRow( $row ) {
$file = new ArchivedFile( Title::makeTitle( NS_FILE, $row->fa_name ) );
$file->loadFromRow( $row );
+
return $file;
}
@@ -204,7 +237,7 @@ class ArchivedFile {
/**
* Load ArchivedFile object fields from a DB row.
*
- * @param $row Object database row
+ * @param stdClass $row Object database row
* @since 1.21
*/
public function loadFromRow( $row ) {
@@ -231,6 +264,9 @@ class ArchivedFile {
// old row, populate from key
$this->sha1 = LocalRepo::getHashFromKey( $this->key );
}
+ if ( !$this->title ) {
+ $this->title = Title::makeTitleSafe( NS_FILE, $row->fa_name );
+ }
}
/**
@@ -239,6 +275,9 @@ class ArchivedFile {
* @return Title
*/
public function getTitle() {
+ if ( !$this->title ) {
+ $this->load();
+ }
return $this->title;
}
@@ -248,6 +287,10 @@ class ArchivedFile {
* @return string
*/
public function getName() {
+ if ( $this->name === false ) {
+ $this->load();
+ }
+
return $this->name;
}
@@ -256,6 +299,7 @@ class ArchivedFile {
*/
public function getID() {
$this->load();
+
return $this->id;
}
@@ -264,6 +308,7 @@ class ArchivedFile {
*/
public function exists() {
$this->load();
+
return $this->exists;
}
@@ -273,6 +318,7 @@ class ArchivedFile {
*/
public function getKey() {
$this->load();
+
return $this->key;
}
@@ -298,6 +344,7 @@ class ArchivedFile {
*/
public function getWidth() {
$this->load();
+
return $this->width;
}
@@ -307,6 +354,7 @@ class ArchivedFile {
*/
public function getHeight() {
$this->load();
+
return $this->height;
}
@@ -316,6 +364,7 @@ class ArchivedFile {
*/
public function getMetadata() {
$this->load();
+
return $this->metadata;
}
@@ -325,6 +374,7 @@ class ArchivedFile {
*/
public function getSize() {
$this->load();
+
return $this->size;
}
@@ -334,15 +384,17 @@ class ArchivedFile {
*/
public function getBits() {
$this->load();
+
return $this->bits;
}
/**
- * Returns the mime type of the file.
+ * Returns the MIME type of the file.
* @return string
*/
public function getMimeType() {
$this->load();
+
return $this->mime;
}
@@ -354,12 +406,14 @@ class ArchivedFile {
if ( !isset( $this->handler ) ) {
$this->handler = MediaHandler::getHandler( $this->getMimeType() );
}
+
return $this->handler;
}
/**
* Returns the number of pages of a multipage document, or false for
* documents which aren't multipage documents
+ * @return bool|int
*/
function pageCount() {
if ( !isset( $this->pageCount ) ) {
@@ -369,6 +423,7 @@ class ArchivedFile {
$this->pageCount = false;
}
}
+
return $this->pageCount;
}
@@ -379,6 +434,7 @@ class ArchivedFile {
*/
public function getMediaType() {
$this->load();
+
return $this->media_type;
}
@@ -389,6 +445,7 @@ class ArchivedFile {
*/
public function getTimestamp() {
$this->load();
+
return wfTimestamp( TS_MW, $this->timestamp );
}
@@ -400,29 +457,40 @@ class ArchivedFile {
*/
function getSha1() {
$this->load();
+
return $this->sha1;
}
/**
- * Return the user ID of the uploader.
+ * Returns ID or name of user who uploaded the file
*
- * @return int
+ * @note Prior to MediaWiki 1.23, this method always
+ * returned the user id, and was inconsistent with
+ * the rest of the file classes.
+ * @param string $type 'text' or 'id'
+ * @return int|string
+ * @throws MWException
*/
- public function getUser() {
+ public function getUser( $type = 'text' ) {
$this->load();
- if ( $this->isDeleted( File::DELETED_USER ) ) {
- return 0;
- } else {
+
+ if ( $type == 'text' ) {
+ return $this->user_text;
+ } elseif ( $type == 'id' ) {
return $this->user;
}
+
+ throw new MWException( "Unknown type '$type'." );
}
/**
* Return the user name of the uploader.
*
+ * @deprecated since 1.23 Use getUser( 'text' ) instead.
* @return string
*/
public function getUserText() {
+ wfDeprecated( __METHOD__, '1.23' );
$this->load();
if ( $this->isDeleted( File::DELETED_USER ) ) {
return 0;
@@ -452,6 +520,7 @@ class ArchivedFile {
*/
public function getRawUser() {
$this->load();
+
return $this->user;
}
@@ -462,6 +531,7 @@ class ArchivedFile {
*/
public function getRawUserText() {
$this->load();
+
return $this->user_text;
}
@@ -472,6 +542,7 @@ class ArchivedFile {
*/
public function getRawDescription() {
$this->load();
+
return $this->description;
}
@@ -481,29 +552,33 @@ class ArchivedFile {
*/
public function getVisibility() {
$this->load();
+
return $this->deleted;
}
/**
* for file or revision rows
*
- * @param $field Integer: one of DELETED_* bitfield constants
+ * @param int $field One of DELETED_* bitfield constants
* @return bool
*/
public function isDeleted( $field ) {
$this->load();
+
return ( $this->deleted & $field ) == $field;
}
/**
* Determine if the current user is allowed to view a particular
* field of this FileStore image file, if it's marked as deleted.
- * @param $field Integer
- * @param $user User object to check, or null to use $wgUser
+ * @param int $field
+ * @param null|User $user User object to check, or null to use $wgUser
* @return bool
*/
public function userCan( $field, User $user = null ) {
$this->load();
- return Revision::userCanBitfield( $this->deleted, $field, $user );
+
+ $title = $this->getTitle();
+ return Revision::userCanBitfield( $this->deleted, $field, $user, $title ? : null );
}
}