Create a Special:Redirect page.
[lhc/web/wiklou.git] / includes / filerepo / ForeignAPIRepo.php
index ba574da..5cd6fc2 100644 (file)
@@ -61,21 +61,21 @@ class ForeignAPIRepo extends FileRepo {
                // http://commons.wikimedia.org/w/api.php
                $this->mApiBase = isset( $info['apibase'] ) ? $info['apibase'] : null;
 
-               if( isset( $info['apiThumbCacheExpiry'] ) ) {
+               if ( isset( $info['apiThumbCacheExpiry'] ) ) {
                        $this->apiThumbCacheExpiry = $info['apiThumbCacheExpiry'];
                }
-               if( isset( $info['fileCacheExpiry'] ) ) {
+               if ( isset( $info['fileCacheExpiry'] ) ) {
                        $this->fileCacheExpiry = $info['fileCacheExpiry'];
                }
-               if( !$this->scriptDirUrl ) {
+               if ( !$this->scriptDirUrl ) {
                        // hack for description fetches
                        $this->scriptDirUrl = dirname( $this->mApiBase );
                }
                // If we can cache thumbs we can guess sane defaults for these
-               if( $this->canCacheThumbs() && !$this->url ) {
+               if ( $this->canCacheThumbs() && !$this->url ) {
                        $this->url = $wgLocalFileRepo['url'];
                }
-               if( $this->canCacheThumbs() && !$this->thumbUrl ) {
+               if ( $this->canCacheThumbs() && !$this->thumbUrl ) {
                        $this->thumbUrl = $this->url . '/thumb';
                }
        }
@@ -105,7 +105,7 @@ class ForeignAPIRepo extends FileRepo {
                        if ( isset( $this->mFileExists[$k] ) ) {
                                $results[$k] = true;
                                unset( $files[$k] );
-                       } elseif( self::isVirtualUrl( $f ) ) {
+                       } elseif ( self::isVirtualUrl( $f ) ) {
                                # @todo FIXME: We need to be able to handle virtual
                                # URLs better, at least when we know they refer to the
                                # same repo.
@@ -120,9 +120,9 @@ class ForeignAPIRepo extends FileRepo {
 
                $data = $this->fetchImageQuery( array( 'titles' => implode( $files, '|' ),
                                                                                        'prop' => 'imageinfo' ) );
-               if( isset( $data['query']['pages'] ) ) {
+               if ( isset( $data['query']['pages'] ) ) {
                        $i = 0;
-                       foreach( $files as $key => $file ) {
+                       foreach ( $files as $key => $file ) {
                                $results[$key] = $this->mFileExists[$key] = !isset( $data['query']['pages'][$i]['missing'] );
                                $i++;
                        }
@@ -147,8 +147,8 @@ class ForeignAPIRepo extends FileRepo {
 
                $query = array_merge( $query,
                        array(
-                               'format'    => 'json',
-                               'action'    => 'query',
+                               'format' => 'json',
+                               'action' => 'query',
                                'redirects' => 'true'
                        ) );
                if ( $this->mApiBase ) {
@@ -157,10 +157,10 @@ class ForeignAPIRepo extends FileRepo {
                        $url = $this->makeUrl( $query, 'api' );
                }
 
-               if( !isset( $this->mQueryCache[$url] ) ) {
+               if ( !isset( $this->mQueryCache[$url] ) ) {
                        $key = $this->getLocalCacheKey( 'ForeignAPIRepo', 'Metadata', md5( $url ) );
                        $data = $wgMemc->get( $key );
-                       if( !$data ) {
+                       if ( !$data ) {
                                $data = self::httpGet( $url );
                                if ( !$data ) {
                                        return null;
@@ -168,7 +168,7 @@ class ForeignAPIRepo extends FileRepo {
                                $wgMemc->set( $key, $data, 3600 );
                        }
 
-                       if( count( $this->mQueryCache ) > 100 ) {
+                       if ( count( $this->mQueryCache ) > 100 ) {
                                // Keep the cache from growing infinitely
                                $this->mQueryCache = array();
                        }
@@ -182,9 +182,9 @@ class ForeignAPIRepo extends FileRepo {
         * @return bool|array
         */
        function getImageInfo( $data ) {
-               if( $data && isset( $data['query']['pages'] ) ) {
-                       foreach( $data['query']['pages'] as $info ) {
-                               if( isset( $info['imageinfo'][0] ) ) {
+               if ( $data && isset( $data['query']['pages'] ) ) {
+                       foreach ( $data['query']['pages'] as $info ) {
+                               if ( isset( $info['imageinfo'][0] ) ) {
                                        return $info['imageinfo'][0];
                                }
                        }
@@ -198,14 +198,15 @@ class ForeignAPIRepo extends FileRepo {
         */
        function findBySha1( $hash ) {
                $results = $this->fetchImageQuery( array(
-                                                                               'aisha1base36' => $hash,
-                                                                               'aiprop'       => ForeignAPIFile::getProps(),
-                                                                               'list'         => 'allimages', ) );
+                       'aisha1base36' => $hash,
+                       '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'] ) ) {
+                               if ( !isset( $img['name'] ) ) {
                                        continue;
                                }
                                $ret[] = new ForeignAPIFile( Title::makeTitle( NS_FILE, $img['name'] ), $this, $img );
@@ -228,11 +229,11 @@ class ForeignAPIRepo extends FileRepo {
                        'iiprop' => 'url|timestamp',
                        'iiurlwidth' => $width,
                        'iiurlheight' => $height,
-                       'iiurlparam'  => $otherParams,
+                       'iiurlparam' => $otherParams,
                        'prop' => 'imageinfo' ) );
                $info = $this->getImageInfo( $data );
 
-               if( $data && $info && isset( $info['thumburl'] ) ) {
+               if ( $data && $info && isset( $info['thumburl'] ) ) {
                        wfDebug( __METHOD__ . " got remote thumb " . $info['thumburl'] . "\n" );
                        $result = $info;
                        return $info['thumburl'];
@@ -268,11 +269,11 @@ class ForeignAPIRepo extends FileRepo {
 
                /* Get the array of urls that we already know */
                $knownThumbUrls = $wgMemc->get( $key );
-               if( !$knownThumbUrls ) {
+               if ( !$knownThumbUrls ) {
                        /* No knownThumbUrls for this file */
                        $knownThumbUrls = array();
                } else {
-                       if( isset( $knownThumbUrls[$sizekey] ) ) {
+                       if ( isset( $knownThumbUrls[$sizekey] ) ) {
                                wfDebug( __METHOD__ . ': Got thumburl from local cache: ' .
                                        "{$knownThumbUrls[$sizekey]} \n" );
                                return $knownThumbUrls[$sizekey];
@@ -283,14 +284,14 @@ class ForeignAPIRepo extends FileRepo {
                $metadata = null;
                $foreignUrl = $this->getThumbUrl( $name, $width, $height, $metadata, $params );
 
-               if( !$foreignUrl ) {
+               if ( !$foreignUrl ) {
                        wfDebug( __METHOD__ . " Could not find thumburl\n" );
                        return false;
                }
 
                // We need the same filename as the remote one :)
                $fileName = rawurldecode( pathinfo( $foreignUrl, PATHINFO_BASENAME ) );
-               if( !$this->validateFilename( $fileName ) ) {
+               if ( !$this->validateFilename( $fileName ) ) {
                        wfDebug( __METHOD__ . " The deduced filename $fileName is not safe\n" );
                        return false;
                }
@@ -298,15 +299,14 @@ class ForeignAPIRepo extends FileRepo {
                $localFilename = $localPath . "/" . $fileName;
                $localUrl = $this->getZoneUrl( 'thumb' ) . "/" . $this->getHashPath( $name ) . rawurlencode( $name ) . "/" . rawurlencode( $fileName );
 
-               if( $backend->fileExists( array( 'src' => $localFilename ) )
-                       && isset( $metadata['timestamp'] ) )
-               {
+               if ( $backend->fileExists( array( 'src' => $localFilename ) )
+                       && isset( $metadata['timestamp'] ) ) {
                        wfDebug( __METHOD__ . " Thumbnail was already downloaded before\n" );
                        $modified = $backend->getFileTimestamp( array( 'src' => $localFilename ) );
                        $remoteModified = strtotime( $metadata['timestamp'] );
                        $current = time();
                        $diff = abs( $modified - $current );
-                       if( $remoteModified < $modified && $diff < $this->fileCacheExpiry ) {
+                       if ( $remoteModified < $modified && $diff < $this->fileCacheExpiry ) {
                                /* Use our current and already downloaded thumbnail */
                                $knownThumbUrls[$sizekey] = $localUrl;
                                $wgMemc->set( $key, $knownThumbUrls, $this->apiThumbCacheExpiry );
@@ -315,7 +315,7 @@ class ForeignAPIRepo extends FileRepo {
                        /* There is a new Commons file, or existing thumbnail older than a month */
                }
                $thumb = self::httpGet( $foreignUrl );
-               if( !$thumb ) {
+               if ( !$thumb ) {
                        wfDebug( __METHOD__ . " Could not download thumb\n" );
                        return false;
                }
@@ -323,7 +323,7 @@ class ForeignAPIRepo extends FileRepo {
                # @todo FIXME: Delete old thumbs that aren't being used. Maintenance script?
                $backend->prepare( array( 'dir' => dirname( $localFilename ) ) );
                $params = array( 'dst' => $localFilename, 'content' => $thumb );
-               if( !$backend->quickCreate( $params )->isOK() ) {
+               if ( !$backend->quickCreate( $params )->isOK() ) {
                        wfDebug( __METHOD__ . " could not write to thumb path '$localFilename'\n" );
                        return $foreignUrl;
                }