Update and fixes.
[mediawiki.git] / includes / filerepo / ForeignAPIFile.php
blobaaf922048eaca808b071a685b5d4cff3e48f04b3
1 <?php
3 /**
4 * Very hacky and inefficient
5 * do not use :D
7 * @ingroup FileRepo
8 */
9 class ForeignAPIFile extends File {
10 function __construct( $title, $repo, $info ) {
11 parent::__construct( $title, $repo );
12 $this->mInfo = $info;
15 static function newFromTitle( $title, $repo ) {
16 $info = $repo->getImageInfo( $title );
17 if( $info ) {
18 return new ForeignAPIFile( $title, $repo, $info );
19 } else {
20 return null;
24 // Dummy functions...
25 public function exists() {
26 return true;
29 public function getPath() {
30 return false;
33 function transform( $params, $flags = 0 ) {
34 $thumbUrl = $this->repo->getThumbUrl(
35 $this->getName(),
36 isset( $params['width'] ) ? $params['width'] : -1,
37 isset( $params['height'] ) ? $params['height'] : -1 );
38 if( $thumbUrl ) {
39 wfDebug( __METHOD__ . " got remote thumb $thumbUrl\n" );
40 return $this->handler->getTransform( $this, 'bogus', $thumbUrl, $params );;
42 return false;
45 // Info we can get from API...
46 public function getWidth( $page = 1 ) {
47 return intval( @$this->mInfo['width'] );
50 public function getHeight( $page = 1 ) {
51 return intval( @$this->mInfo['height'] );
54 public function getMetadata() {
55 return serialize( (array)@$this->mInfo['metadata'] );
58 public function getSize() {
59 return intval( @$this->mInfo['size'] );
62 public function getUrl() {
63 return strval( @$this->mInfo['url'] );
66 public function getUser( $method='text' ) {
67 return strval( @$this->mInfo['user'] );
70 public function getDescription() {
71 return strval( @$this->mInfo['comment'] );
74 function getSha1() {
75 return wfBaseConvert( strval( @$this->mInfo['sha1'] ), 16, 36, 31 );
78 function getTimestamp() {
79 return wfTimestamp( TS_MW, strval( @$this->mInfo['timestamp'] ) );
82 function getMimeType() {
83 if( empty( $info['mime'] ) ) {
84 $magic = MimeMagic::singleton();
85 $info['mime'] = $magic->guessTypesForExtension( $this->getExtension() );
87 return $info['mime'];
90 /// @fixme May guess wrong on file types that can be eg audio or video
91 function getMediaType() {
92 $magic = MimeMagic::singleton();
93 return $magic->getMediaType( null, $this->getMimeType() );
96 function getDescriptionUrl() {
97 return isset( $this->mInfo['descriptionurl'] )
98 ? $this->mInfo['descriptionurl']
99 : false;