*cough* thx
[lhc/web/wiklou.git] / includes / filerepo / ForeignAPIRepo.php
1 <?php
2
3 /**
4 * A foreign repository with a remote MediaWiki with an API thingy
5 * Very hacky and inefficient
6 * do not use :D
7 *
8 * @ingroup FileRepo
9 */
10 class ForeignAPIRepo extends FileRepo {
11 function __construct( $info ) {
12 parent::__construct( $info );
13 $this->mApiBase = $info['apibase']; // http://commons.wikimedia.org/w/api.php
14 }
15
16 function storeBatch( $triplets, $flags = 0 ) {
17 return false;
18 }
19
20 function storeTemp( $originalName, $srcPath ) {
21 return false;
22 }
23 function publishBatch( $triplets, $flags = 0 ) {
24 return false;
25 }
26 function deleteBatch( $sourceDestPairs ) {
27 return false;
28 }
29 function getFileProps( $virtualUrl ) {
30 return false;
31 }
32 function newFile( $title, $time = false ) {
33 return false;
34 }
35 function findFile( $title, $time = false ) {
36 $url = $this->mApiBase .
37 '?' .
38 wfArrayToCgi( array(
39 'format' => 'json',
40 'action' => 'query',
41 'titles' => $title, // fixme -- canonical namespacea
42 'prop' => 'imageinfo',
43 'iiprop' => 'timestamp|user|comment|url|size|sha1|metadata' ) );
44 $json = Http::get( $url );
45 $data = json_decode( $json, true );
46
47 if( isset( $data['query']['pages'] ) ) {
48 foreach( $data['query']['pages'] as $pageid => $info ) {
49 if( isset( $info['imageinfo'][0] ) ) {
50 return new ForeignAPIFile( $title, $this, $info['imageinfo'][0] );
51 }
52 }
53 }
54 return false;
55 }
56 }