Revert thumb caching because it wasn't actually caching what I thought it was.
[lhc/web/wiklou.git] / includes / filerepo / ForeignAPIFile.php
1 <?php
2
3 /**
4 * Very hacky and inefficient
5 * do not use :D
6 *
7 * @ingroup FileRepo
8 */
9 class ForeignAPIFile extends File {
10 function __construct( $title, $repo, $info ) {
11 parent::__construct( $title, $repo );
12 $this->mInfo = $info;
13 }
14
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;
21 }
22 }
23
24 // Dummy functions...
25 public function exists() {
26 return true;
27 }
28
29 public function getPath() {
30 return false;
31 }
32
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 );;
41 }
42 return false;
43 }
44
45 // Info we can get from API...
46 public function getWidth( $page = 1 ) {
47 return intval( @$this->mInfo['width'] );
48 }
49
50 public function getHeight( $page = 1 ) {
51 return intval( @$this->mInfo['height'] );
52 }
53
54 public function getMetadata() {
55 return serialize( (array)@$this->mInfo['metadata'] );
56 }
57
58 public function getSize() {
59 return intval( @$this->mInfo['size'] );
60 }
61
62 public function getUrl() {
63 return strval( @$this->mInfo['url'] );
64 }
65
66 public function getUser( $method='text' ) {
67 return strval( @$this->mInfo['user'] );
68 }
69
70 public function getDescription() {
71 return strval( @$this->mInfo['comment'] );
72 }
73
74 function getSha1() {
75 return wfBaseConvert( strval( @$this->mInfo['sha1'] ), 16, 36, 31 );
76 }
77
78 function getTimestamp() {
79 return wfTimestamp( TS_MW, strval( @$this->mInfo['timestamp'] ) );
80 }
81
82 function getMimeType() {
83 if( empty( $info['mime'] ) ) {
84 $magic = MimeMagic::singleton();
85 $info['mime'] = $magic->guessTypesForExtension( $this->getExtension() );
86 }
87 return $info['mime'];
88 }
89
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() );
94 }
95
96 function getDescriptionUrl() {
97 return isset( $this->mInfo['descriptionurl'] )
98 ? $this->mInfo['descriptionurl']
99 : false;
100 }
101 }