public function getPath() {
return false;
}
-
- function getThumbPath( $suffix = false ) {
- return false; // hrmmm
- }
-
- function getThumbUrl( $suffix = false ) {
- return false; // FLKDSJLKFDJS
+
+ function transform( $params, $flags = 0 ) {
+ $thumbUrl = $this->repo->getThumbUrl(
+ $this->getName(),
+ isset( $params['width'] ) ? $params['width'] : -1,
+ isset( $params['height'] ) ? $params['height'] : -1 );
+ if( $thumbUrl ) {
+ wfDebug( __METHOD__ . " got remote thumb $thumbUrl\n" );
+ return $this->handler->getTransform( $this, 'bogus', $thumbUrl, $params );;
+ }
+ return false;
}
-
+
// Info we can get from API...
public function getWidth( $page = 1 ) {
return intval( $this->mInfo['width'] );
}
public function getMetadata() {
- return $this->mInfo['metadata'];
+ return serialize( (array)$this->mInfo['metadata'] );
}
public function getSize() {
return $this->mInfo['user'];
}
- public function getComment() {
+ public function getDescription() {
return $this->mInfo['comment'];
}
function getMediaType() {
return $this->mInfo['media_type'];
}
+
+ function getDescriptionUrl() {
+ return isset( $this->mInfo['descriptionurl'] )
+ ? $this->mInfo['descriptionurl']
+ : false;
+ }
}
/**
* A foreign repository with a remote MediaWiki with an API thingy
* Very hacky and inefficient
- * do not use :D
+ * do not use except for testing :D
+ *
+ * Example config:
+ *
+ * $wgForeignFileRepos[] = array(
+ * 'class' => 'ForeignAPIRepo',
+ * 'name' => 'shared',
+ * 'apibase' => 'http://en.wikipedia.org/w/api.php',
+ * 'fetchDescription' => true, // Optional
+ * );
*
* @ingroup FileRepo
*/
function __construct( $info ) {
parent::__construct( $info );
$this->mApiBase = $info['apibase']; // http://commons.wikimedia.org/w/api.php
+ if( !$this->scriptDirUrl ) {
+ // hack for description fetches
+ $this->scriptDirUrl = dirname( $this->mApiBase );
+ }
}
function storeBatch( $triplets, $flags = 0 ) {
function newFile( $title, $time = false ) {
return false;
}
- function findFile( $title, $time = false ) {
+
+ protected function queryImage( $query ) {
$url = $this->mApiBase .
'?' .
- wfArrayToCgi( array(
- 'format' => 'json',
- 'action' => 'query',
- 'titles' => $title, // fixme -- canonical namespacea
- 'prop' => 'imageinfo',
- 'iiprop' => 'timestamp|user|comment|url|size|sha1|metadata' ) );
+ wfArrayToCgi(
+ array_merge( $query,
+ array(
+ 'format' => 'json',
+ 'action' => 'query',
+ 'prop' => 'imageinfo' ) ) );
$json = Http::get( $url );
$data = json_decode( $json, true );
if( isset( $data['query']['pages'] ) ) {
foreach( $data['query']['pages'] as $pageid => $info ) {
if( isset( $info['imageinfo'][0] ) ) {
- return new ForeignAPIFile( $title, $this, $info['imageinfo'][0] );
+ return $info['imageinfo'][0];
}
}
}
return false;
}
+
+ function findFile( $title, $time = false ) {
+ $info = $this->queryImage( array(
+ 'titles' => 'Image:' . $title->getText(),
+ 'prop' => 'imageinfo',
+ 'iiprop' => 'timestamp|user|comment|url|size|sha1|metadata|mimetype' ) );
+ if( $info ) {
+ return new ForeignAPIFile( $title, $this, $info );
+ } else {
+ return false;
+ }
+ }
+
+ function getThumbUrl( $name, $width=-1, $height=-1 ) {
+ $info = $this->queryImage( array(
+ 'titles' => 'Image:' . $name,
+ 'iiprop' => 'url',
+ 'iiurlwidth' => $width,
+ 'iiurlheight' => $height ) );
+ if( $info ) {
+ return $info['thumburl'];
+ } else {
+ return false;
+ }
+ }
}