Coding style
[lhc/web/wiklou.git] / includes / filerepo / ForeignAPIRepo.php
index 00020ff..094258b 100644 (file)
@@ -1,4 +1,10 @@
 <?php
+/**
+ * Foreign repository accessible through api.php requests.
+ *
+ * @file
+ * @ingroup FileRepo
+ */
 
 /**
  * A foreign repository with a remote MediaWiki with an API thingy
@@ -25,7 +31,10 @@ class ForeignAPIRepo extends FileRepo {
 
        function __construct( $info ) {
                parent::__construct( $info );
-               $this->mApiBase = $info['apibase']; // http://commons.wikimedia.org/w/api.php
+               
+               // http://commons.wikimedia.org/w/api.php               
+               $this->mApiBase = isset( $info['apibase'] ) ? $info['apibase'] : null; 
+
                if( isset( $info['apiThumbCacheExpiry'] ) ) {
                        $this->apiThumbCacheExpiry = $info['apiThumbCacheExpiry'];
                }
@@ -106,14 +115,17 @@ class ForeignAPIRepo extends FileRepo {
        function fetchImageQuery( $query ) {
                global $wgMemc;
 
-               $url = $this->mApiBase .
-                       '?' .
-                       wfArrayToCgi(
-                               array_merge( $query,
-                                       array(
-                                               'format' => 'json',
-                                               'action' => 'query',
-                                               'redirects' => 'true' ) ) );
+               $query = array_merge( $query,
+                       array(
+                               'format' => 'json',
+                               'action' => 'query',
+                               'redirects' => 'true' 
+                       ) );
+               if ( $this->mApiBase ) {
+                       $url = wfAppendQuery( $this->mApiBase, $query );
+               } else {
+                       $url = $this->makeUrl( $query, 'api' );
+               }
 
                if( !isset( $this->mQueryCache[$url] ) ) {
                        $key = $this->getLocalCacheKey( 'ForeignAPIRepo', 'Metadata', md5( $url ) );
@@ -149,11 +161,15 @@ class ForeignAPIRepo extends FileRepo {
        function findBySha1( $hash ) {
                $results = $this->fetchImageQuery( array(
                                                                                'aisha1base36' => $hash,
-                                                                               'aiprop'       => 'timestamp|user|comment|url|size|sha1|metadata|mime',
+                                                                               'aiprop'       => ForeignAPIFile::getProps(),
                                                                                'list'         => 'allimages', ) );
                $ret = array();
                if ( isset( $results['query']['allimages'] ) ) {
                        foreach ( $results['query']['allimages'] as $img ) {
+                               // 1.14 was broken, doesn't return name attribute
+                               if( !isset( $img['name'] ) ) {
+                                       continue;
+                               }
                                $ret[] = new ForeignAPIFile( Title::makeTitle( NS_FILE, $img['name'] ), $this, $img );
                        }
                }