ForeignAPIRepo fixes:
* Now supports thumbnails! * SVG seems to work * Comments now working in version info * Can fetch description pages without extra configuration (assuming standard script layout) * Asks server for mime type, but doesn't get it back yet
This commit is contained in:
parent
554ff3f6a6
commit
98fa355b11
2 changed files with 68 additions and 19 deletions
|
|
@ -27,15 +27,19 @@ class ForeignAPIFile extends File {
|
|||
public function getPath() {
|
||||
return false;
|
||||
}
|
||||
|
||||
function getThumbPath( $suffix = false ) {
|
||||
return false; // hrmmm
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
function getThumbUrl( $suffix = false ) {
|
||||
return false; // FLKDSJLKFDJS
|
||||
}
|
||||
|
||||
|
||||
// Info we can get from API...
|
||||
public function getWidth( $page = 1 ) {
|
||||
return intval( $this->mInfo['width'] );
|
||||
|
|
@ -46,7 +50,7 @@ class ForeignAPIFile extends File {
|
|||
}
|
||||
|
||||
public function getMetadata() {
|
||||
return $this->mInfo['metadata'];
|
||||
return serialize( (array)$this->mInfo['metadata'] );
|
||||
}
|
||||
|
||||
public function getSize() {
|
||||
|
|
@ -61,7 +65,7 @@ class ForeignAPIFile extends File {
|
|||
return $this->mInfo['user'];
|
||||
}
|
||||
|
||||
public function getComment() {
|
||||
public function getDescription() {
|
||||
return $this->mInfo['comment'];
|
||||
}
|
||||
|
||||
|
|
@ -73,4 +77,10 @@ class ForeignAPIFile extends File {
|
|||
function getMediaType() {
|
||||
return $this->mInfo['media_type'];
|
||||
}
|
||||
|
||||
function getDescriptionUrl() {
|
||||
return isset( $this->mInfo['descriptionurl'] )
|
||||
? $this->mInfo['descriptionurl']
|
||||
: false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,16 @@
|
|||
/**
|
||||
* 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
|
||||
*/
|
||||
|
|
@ -11,6 +20,10 @@ class ForeignAPIRepo extends 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 ) {
|
||||
|
|
@ -32,25 +45,51 @@ class ForeignAPIRepo extends FileRepo {
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue