ForeignAPIRepo fixes:
[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 // Dummy functions...
23 public function exists() {
24 return true;
25 }
26
27 public function getPath() {
28 return false;
29 }
30
31 function transform( $params, $flags = 0 ) {
32 $thumbUrl = $this->repo->getThumbUrl(
33 $this->getName(),
34 isset( $params['width'] ) ? $params['width'] : -1,
35 isset( $params['height'] ) ? $params['height'] : -1 );
36 if( $thumbUrl ) {
37 wfDebug( __METHOD__ . " got remote thumb $thumbUrl\n" );
38 return $this->handler->getTransform( $this, 'bogus', $thumbUrl, $params );;
39 }
40 return false;
41 }
42
43 // Info we can get from API...
44 public function getWidth( $page = 1 ) {
45 return intval( $this->mInfo['width'] );
46 }
47
48 public function getHeight( $page = 1 ) {
49 return intval( $this->mInfo['height'] );
50 }
51
52 public function getMetadata() {
53 return serialize( (array)$this->mInfo['metadata'] );
54 }
55
56 public function getSize() {
57 return intval( $this->mInfo['size'] );
58 }
59
60 public function getUrl() {
61 return $this->mInfo['url'];
62 }
63
64 public function getUser( $method='text' ) {
65 return $this->mInfo['user'];
66 }
67
68 public function getDescription() {
69 return $this->mInfo['comment'];
70 }
71
72 // Info we had to guess...
73 function getMimeType() {
74 return $this->mInfo['mime'];
75 }
76
77 function getMediaType() {
78 return $this->mInfo['media_type'];
79 }
80
81 function getDescriptionUrl() {
82 return isset( $this->mInfo['descriptionurl'] )
83 ? $this->mInfo['descriptionurl']
84 : false;
85 }
86 }