+
+ protected function fetchImageQuery( $query ) {
+ global $wgMemc;
+
+ $url = $this->mApiBase .
+ '?' .
+ wfArrayToCgi(
+ array_merge( $query,
+ array(
+ 'format' => 'json',
+ 'action' => 'query',
+ 'prop' => 'imageinfo' ) ) );
+
+ if( !isset( $this->mQueryCache[$url] ) ) {
+ $key = wfMemcKey( 'ForeignAPIRepo', $url );
+ $data = $wgMemc->get( $key );
+ if( !$data ) {
+ $data = Http::get( $url );
+ $wgMemc->set( $key, $data, 3600 );
+ }
+
+ if( count( $this->mQueryCache ) > 100 ) {
+ // Keep the cache from growing infinitely
+ $this->mQueryCache = array();
+ }
+ $this->mQueryCache[$url] = $data;
+ }
+ return json_decode( $this->mQueryCache[$url], true );
+ }
+
+ function getImageInfo( $title, $time = false ) {
+ return $this->queryImage( array(
+ 'titles' => 'Image:' . $title->getText(),
+ 'iiprop' => 'timestamp|user|comment|url|size|sha1|metadata|mime' ) );
+ }
+
+ 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;
+ }
+ }