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