/**
* Loads a file object from the filearchive table
+ *
+ * @param $row
+ *
* @return ArchivedFile
*/
public static function newFromRow( $row ) {
/**
* Return the associated title object
+ *
+ * @return Title
*/
public function getTitle() {
return $this->title;
/**
* Return the file name
+ *
+ * @return string
*/
public function getName() {
return $this->name;
}
+ /**
+ * @return int
+ */
public function getID() {
$this->load();
return $this->id;
}
+ /**
+ * @return bool
+ */
public function exists() {
$this->load();
return $this->exists;
/**
* Return the FileStore key
+ * @return string
*/
public function getKey() {
$this->load();
/**
* Return the FileStore key (overriding base File class)
+ * @return string
*/
public function getStorageKey() {
return $this->getKey();
/**
* Return the FileStore storage group
+ * @return string
*/
public function getGroup() {
return $this->group;
/**
* Return the width of the image
+ * @return int
*/
public function getWidth() {
$this->load();
/**
* Return the height of the image
+ * @return int
*/
public function getHeight() {
$this->load();
/**
* Get handler-specific metadata
+ * @return string
*/
public function getMetadata() {
$this->load();
/**
* Return the size of the image file, in bytes
+ * @return int
*/
public function getSize() {
$this->load();
/**
* Return the bits of the image file, in bytes
+ * @return int
*/
public function getBits() {
$this->load();
/**
* Returns the mime type of the file.
+ * @return string
*/
public function getMimeType() {
$this->load();
/**
* Return the type of the media in the file.
* Use the value returned by this function with the MEDIATYPE_xxx constants.
+ * @return string
*/
public function getMediaType() {
$this->load();
/**
* Return upload timestamp.
+ *
+ * @return string
*/
public function getTimestamp() {
$this->load();
/**
* Return the user ID of the uploader.
+ *
+ * @return int
*/
public function getUser() {
$this->load();
/**
* Return the user name of the uploader.
+ *
+ * @return string
*/
public function getUserText() {
$this->load();
/**
* Return upload description.
+ *
+ * @return string
*/
public function getDescription() {
$this->load();
/**
* Return the user ID of the uploader.
+ *
+ * @return int
*/
public function getRawUser() {
$this->load();
/**
* Return the user name of the uploader.
+ *
+ * @return string
*/
public function getRawUserText() {
$this->load();
/**
* Return upload description.
+ *
+ * @return string
*/
public function getRawDescription() {
$this->load();
*/
protected $handler;
+ protected $url, $extension, $name, $path, $hashPath, $pageCount, $transformScript;
+
+ /**
+ * @var bool
+ */
+ protected $canRender, $isSafeFile;
+
/**
* Call this constructor from child classes
+ *
+ * @param $title
+ * @param $repo
*/
function __construct( $title, $repo ) {
$this->title = $title;
*
* @param $old File Old file
* @param $new string New name
- *
+ *
* @return bool|null
*/
static function checkExtensionCompatibility( File $old, $new ) {
public function getFullUrl() {
return wfExpandUrl( $this->getUrl(), PROTO_RELATIVE );
}
-
+
+ /**
+ * @return string
+ */
public function getCanonicalUrl() {
return wfExpandUrl( $this->getUrl(), PROTO_CANONICAL );
}
* STUB
* Overridden by LocalFile, UnregisteredLocalFile
*
+ * @param $page int
+ *
* @return false|number
*/
public function getHeight( $page = 1 ) {
/**
* Accessor for __get()
- *
+ *
* @return bool
*/
protected function getIsSafeFile() {
/**
* Get the relative path for an archived file
- *
+ *
* @param $suffix bool|string if not false, the name of an archived thumbnail file
*
- * @return string
+ * @return string
*/
function getArchiveRel( $suffix = false ) {
$path = 'archive/' . $this->getHashPath();
/**
* Get the relative path for an archived file's thumbs directory
* or a specific thumb if the $suffix is given.
- *
+ *
* @param $archiveName string the timestamped name of an archived image
* @param $suffix bool|string if not false, the name of a thumbnail file
+ *
+ * @return string
*/
function getArchiveThumbRel( $archiveName, $suffix = false ) {
$path = 'archive/' . $this->getHashPath() . $archiveName . "/";
* $findItem = array( 'title' => $title, 'private' => true );
* $findBatch = array( $findItem );
* $repo->findFiles( $findBatch );
+ *
+ * @return array
*/
function findFiles( $items ) {
$result = array();
/**
* Returns true if the repository can transform files via a 404 handler
+ *
+ * @return bool
*/
function canTransformVia404() {
return $this->transformVia404;
return $name;
}
+ /**
+ * @param $name
+ * @param $levels
+ * @return string
+ */
static function getHashPathForLevel( $name, $levels ) {
if ( $levels == 0 ) {
return '';
/**
* Get a relative path including trailing slash, e.g. f/fa/
* If the repo is not hashed, returns an empty string
+ *
+ * @param $name string
+ *
+ * @return string
*/
function getHashPath( $name ) {
return self::getHashPathForLevel( $name, $this->hashLevels );
*/
abstract function publishBatch( $triplets, $flags = 0 );
+ /**
+ * @param $file
+ * @param int $flags
+ * @return bool
+ */
function fileExists( $file, $flags = 0 ) {
$result = $this->fileExistsBatch( array( $file ), $flags );
return $result[0];
* Get properties of a file with a given virtual URL
* The virtual URL must refer to this repo
* Properties should ultimately be obtained via File::getPropsFromPath()
+ *
+ * @param $virtualUrl string
*/
abstract function getFileProps( $virtualUrl );
/**
* Determine if a relative path is valid, i.e. not blank or involving directory traveral
+ *
+ * @param $filename string
+ *
+ * @return bool
*/
function validateFilename( $filename ) {
if ( strval( $filename ) == '' ) {
* Use the same traversal protection as Title::secureAndSplit()
*/
if ( strpos( $filename, '.' ) !== false &&
- ( $filename === '.' || $filename === '..' ||
- strpos( $filename, './' ) === 0 ||
- strpos( $filename, '../' ) === 0 ||
- strpos( $filename, '/./' ) !== false ||
- strpos( $filename, '/../' ) !== false ) )
+ ( $filename === '.' || $filename === '..' ||
+ strpos( $filename, './' ) === 0 ||
+ strpos( $filename, '../' ) === 0 ||
+ strpos( $filename, '/./' ) !== false ||
+ strpos( $filename, '/../' ) !== false ) )
{
return false;
} else {
* Path disclosure protection functions
*/
function paranoidClean( $param ) { return '[hidden]'; }
+
+ /**
+ * @param $param
+ * @return
+ */
function passThrough( $param ) { return $param; }
/**
/**
* Create a new good result
+ *
+ * @return FileRepoStatus
*/
function newGood( $value = null ) {
return FileRepoStatus::newGood( $this, $value );
return $this->getName() == 'local';
}
-
/**
* Get a key on the primary cache for this repository.
* Returns false if the repository's cache is not accessible at this site.
* @ingroup FileRepo
*/
class ForeignAPIFile extends File {
-
+
private $mExists;
/**
- * @param $title
- * @param $repo ForeignApiRepo
- * @param $info
+ * @param $title
+ * @param $repo ForeignApiRepo
+ * @param $info
* @param bool $exists
*/
function __construct( $title, $repo, $info, $exists = false ) {
}
/**
- * @param $title Title
- * @param $repo ForeignApiRepo
+ * @param $title Title
+ * @param $repo ForeignApiRepo
* @return ForeignAPIFile|null
*/
static function newFromTitle( $title, $repo ) {
return null;
}
}
-
+
/**
* Get the property string for iiprop and aiprop
*/
static function getProps() {
return 'timestamp|user|comment|url|size|sha1|metadata|mime';
}
-
+
// Dummy functions...
public function exists() {
return $this->mExists;
}
-
+
public function getPath() {
return false;
}
public function getWidth( $page = 1 ) {
return isset( $this->mInfo['width'] ) ? intval( $this->mInfo['width'] ) : 0;
}
-
+
+ /**
+ * @param $page int
+ * @return int
+ */
public function getHeight( $page = 1 ) {
return isset( $this->mInfo['height'] ) ? intval( $this->mInfo['height'] ) : 0;
}
-
+
public function getMetadata() {
if ( isset( $this->mInfo['metadata'] ) ) {
return serialize( self::parseMetadata( $this->mInfo['metadata'] ) );
}
return null;
}
-
+
public static function parseMetadata( $metadata ) {
if( !is_array( $metadata ) ) {
return $metadata;
}
return $ret;
}
-
+
public function getSize() {
return isset( $this->mInfo['size'] ) ? intval( $this->mInfo['size'] ) : null;
}
-
+
public function getUrl() {
return isset( $this->mInfo['url'] ) ? strval( $this->mInfo['url'] ) : null;
}
public function getUser( $method='text' ) {
return isset( $this->mInfo['user'] ) ? strval( $this->mInfo['user'] ) : null;
}
-
+
public function getDescription() {
return isset( $this->mInfo['comment'] ) ? strval( $this->mInfo['comment'] ) : null;
}
function getSha1() {
- return isset( $this->mInfo['sha1'] ) ?
- wfBaseConvert( strval( $this->mInfo['sha1'] ), 16, 36, 31 ) :
+ return isset( $this->mInfo['sha1'] ) ?
+ wfBaseConvert( strval( $this->mInfo['sha1'] ), 16, 36, 31 ) :
null;
}
-
+
function getTimestamp() {
- return wfTimestamp( TS_MW,
+ return wfTimestamp( TS_MW,
isset( $this->mInfo['timestamp'] ) ?
- strval( $this->mInfo['timestamp'] ) :
+ strval( $this->mInfo['timestamp'] ) :
null
);
}
-
+
function getMimeType() {
if( !isset( $this->mInfo['mime'] ) ) {
$magic = MimeMagic::singleton();
}
return $this->mInfo['mime'];
}
-
+
/// @todo FIXME: May guess wrong on file types that can be eg audio or video
function getMediaType() {
$magic = MimeMagic::singleton();
return $magic->getMediaType( null, $this->getMimeType() );
}
-
+
function getDescriptionUrl() {
return isset( $this->mInfo['descriptionurl'] )
? $this->mInfo['descriptionurl']
: false;
}
-
+
/**
* Only useful if we're locally caching thumbs anyway...
*/
return null;
}
}
-
+
function getThumbnails() {
$files = array();
$dir = $this->getThumbPath( $this->getName() );
}
return $files;
}
-
+
function purgeCache() {
$this->purgeThumbnails();
$this->purgeDescriptionPage();
}
-
+
function purgeDescriptionPage() {
global $wgMemc, $wgContLang;
$url = $this->repo->getDescriptionRenderUrl( $this->getName(), $wgContLang->getCode() );
$key = $this->repo->getLocalCacheKey( 'RemoteFileDescription', 'url', md5($url) );
$wgMemc->delete( $key );
}
-
+
function purgeThumbnails() {
global $wgMemc;
$key = $this->repo->getLocalCacheKey( 'ForeignAPIRepo', 'ThumbUrl', $this->getName() );
* @param $dstUrl String: destination URL to use in output HTML
* @param $params Array: arbitrary set of parameters validated by $this->validateParam()
* @param $flags Integer: a bitfield, may contain self::TRANSFORM_LATER
+ *
+ * @return MediaTransformOutput
*/
abstract function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 );