81d28f8633bab907d74907264c621eb73a4ee1aa
[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
13 // For some reason API doesn't currently provide type info
14 $magic = MimeMagic::singleton();
15 $info['mime'] = $magic->guessTypesForExtension( $this->getExtension() );
16 list( $info['major_mime'], $info['minor_mime'] ) = self::splitMime( $info['mime'] );
17 $info['media_type'] = $magic->getMediaType( null, $info['mime'] );
18
19 $this->mInfo = $info;
20 }
21
22 static function newFromTitle( $title, $repo ) {
23 $info = $repo->getImageInfo( $title );
24 if( $info ) {
25 return new ForeignAPIFile( $title, $repo, $info );
26 } else {
27 return null;
28 }
29 }
30
31 // Dummy functions...
32 public function exists() {
33 return true;
34 }
35
36 public function getPath() {
37 return false;
38 }
39
40 function transform( $params, $flags = 0 ) {
41 $thumbUrl = $this->repo->getThumbUrl(
42 $this->getName(),
43 isset( $params['width'] ) ? $params['width'] : -1,
44 isset( $params['height'] ) ? $params['height'] : -1 );
45 if( $thumbUrl ) {
46 wfDebug( __METHOD__ . " got remote thumb $thumbUrl\n" );
47 return $this->handler->getTransform( $this, 'bogus', $thumbUrl, $params );;
48 }
49 return false;
50 }
51
52 // Info we can get from API...
53 public function getWidth( $page = 1 ) {
54 return intval( $this->mInfo['width'] );
55 }
56
57 public function getHeight( $page = 1 ) {
58 return intval( $this->mInfo['height'] );
59 }
60
61 public function getMetadata() {
62 return serialize( (array)$this->mInfo['metadata'] );
63 }
64
65 public function getSize() {
66 return intval( $this->mInfo['size'] );
67 }
68
69 public function getUrl() {
70 return $this->mInfo['url'];
71 }
72
73 public function getUser( $method='text' ) {
74 return $this->mInfo['user'];
75 }
76
77 public function getDescription() {
78 return $this->mInfo['comment'];
79 }
80
81 function getSha1() {
82 return wfBaseConvert( $this->mInfo['sha1'], 16, 36, 31 );
83 }
84
85 function getTimestamp() {
86 return wfTimestamp( TS_MW, $this->mInfo['timestamp'] );
87 }
88
89 // Info we had to guess...
90 function getMimeType() {
91 return $this->mInfo['mime'];
92 }
93
94 function getMediaType() {
95 return $this->mInfo['media_type'];
96 }
97
98 function getDescriptionUrl() {
99 return isset( $this->mInfo['descriptionurl'] )
100 ? $this->mInfo['descriptionurl']
101 : false;
102 }
103 }