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