4 * Very hacky and inefficient
9 class ForeignAPIFile
extends File
{
10 function __construct( $title, $repo, $info ) {
11 parent
::__construct( $title, $repo );
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'] );
22 static function newFromTitle( $title, $repo ) {
23 $info = $repo->getImageInfo( $title );
25 return new ForeignAPIFile( $title, $repo, $info );
32 public function exists() {
36 public function getPath() {
40 function transform( $params, $flags = 0 ) {
41 $thumbUrl = $this->repo
->getThumbUrl(
43 isset( $params['width'] ) ?
$params['width'] : -1,
44 isset( $params['height'] ) ?
$params['height'] : -1 );
46 wfDebug( __METHOD__
. " got remote thumb $thumbUrl\n" );
47 return $this->handler
->getTransform( $this, 'bogus', $thumbUrl, $params );;
52 // Info we can get from API...
53 public function getWidth( $page = 1 ) {
54 return intval( $this->mInfo
['width'] );
57 public function getHeight( $page = 1 ) {
58 return intval( $this->mInfo
['height'] );
61 public function getMetadata() {
62 return serialize( (array)$this->mInfo
['metadata'] );
65 public function getSize() {
66 return intval( $this->mInfo
['size'] );
69 public function getUrl() {
70 return $this->mInfo
['url'];
73 public function getUser( $method='text' ) {
74 return $this->mInfo
['user'];
77 public function getDescription() {
78 return $this->mInfo
['comment'];
82 return wfBaseConvert( $this->mInfo
['sha1'], 16, 36, 31 );
85 function getTimestamp() {
86 return wfTimestamp( TS_MW
, $this->mInfo
['timestamp'] );
89 // Info we had to guess...
90 function getMimeType() {
91 return $this->mInfo
['mime'];
94 function getMediaType() {
95 return $this->mInfo
['media_type'];
98 function getDescriptionUrl() {
99 return isset( $this->mInfo
['descriptionurl'] )
100 ?
$this->mInfo
['descriptionurl']