d0add602b6a08af4b7d02f53d80eece3637fd107
4 * Very hacky and inefficient
9 class ForeignAPIFile
extends File
{
10 function __construct( $title, $repo, $info ) {
11 parent
::__construct( $title, $repo );
15 static function newFromTitle( $title, $repo ) {
16 $info = $repo->getImageInfo( $title );
18 return new ForeignAPIFile( $title, $repo, $info );
25 public function exists() {
29 public function getPath() {
33 function transform( $params, $flags = 0 ) {
35 $thumbUrl = $this->repo
->getThumbUrl(
37 isset( $params['width'] ) ?
$params['width'] : -1,
38 isset( $params['height'] ) ?
$params['height'] : -1 );
40 if ( $this->repo
->useLocalCache
) {
41 wfDebug("Attempting to get the thumb from the cache...");
42 $key = md5($thumbUrl);
43 $obj = $wgMemc->get($key);
45 wfDebug("success!\n");
50 $res = $this->handler
->getTransform( $this, 'bogus', $thumbUrl, $params );;
51 if ( $res && $this->repo
->useLocalCache
) $wgMemc->set( $key, $res, $this->repo
->localCacheExpiry
);
52 wfDebug( __METHOD__
. " got remote thumb $thumbUrl\n" );
58 // Info we can get from API...
59 public function getWidth( $page = 1 ) {
60 return intval( @$this->mInfo
['width'] );
63 public function getHeight( $page = 1 ) {
64 return intval( @$this->mInfo
['height'] );
67 public function getMetadata() {
68 return serialize( (array)@$this->mInfo
['metadata'] );
71 public function getSize() {
72 return intval( @$this->mInfo
['size'] );
75 public function getUrl() {
76 return strval( @$this->mInfo
['url'] );
79 public function getUser( $method='text' ) {
80 return strval( @$this->mInfo
['user'] );
83 public function getDescription() {
84 return strval( @$this->mInfo
['comment'] );
88 return wfBaseConvert( strval( @$this->mInfo
['sha1'] ), 16, 36, 31 );
91 function getTimestamp() {
92 return wfTimestamp( TS_MW
, strval( @$this->mInfo
['timestamp'] ) );
95 function getMimeType() {
96 if( empty( $info['mime'] ) ) {
97 $magic = MimeMagic
::singleton();
98 $info['mime'] = $magic->guessTypesForExtension( $this->getExtension() );
100 return $info['mime'];
103 /// @fixme May guess wrong on file types that can be eg audio or video
104 function getMediaType() {
105 $magic = MimeMagic
::singleton();
106 return $magic->getMediaType( null, $this->getMimeType() );
109 function getDescriptionUrl() {
110 return isset( $this->mInfo
['descriptionurl'] )
111 ?
$this->mInfo
['descriptionurl']