Add JavaScript variable wgContentNamespaces
[lhc/web/wiklou.git] / includes / filerepo / ForeignAPIRepo.php
index e64c88a..bb16c8b 100644 (file)
@@ -52,13 +52,17 @@ class ForeignAPIRepo extends FileRepo {
                'timestamp',
        );
 
-       var $fileFactory = array( 'ForeignAPIFile', 'newFromTitle' );
-       /* Check back with Commons after a day */
-       var $apiThumbCacheExpiry = 86400; /* 24*60*60 */
-       /* Redownload thumbnail files after a month */
-       var $fileCacheExpiry = 2592000; /* 86400*30 */
+       protected $fileFactory = array( 'ForeignAPIFile', 'newFromTitle' );
+       /** @var int Check back with Commons after a day (24*60*60) */
+       protected $apiThumbCacheExpiry = 86400;
 
-       protected $mQueryCache = array();
+       /** @var int Redownload thumbnail files after a month (86400*30) */
+       protected $fileCacheExpiry = 2592000;
+
+       /** @var array  */
+       private $mQueryCache = array();
+
+       /** @var array  */
        protected $mFileExists = array();
 
        /**
@@ -110,6 +114,7 @@ class ForeignAPIRepo extends FileRepo {
                if ( $time ) {
                        return false;
                }
+
                return parent::newFile( $title, $time );
        }
 
@@ -136,8 +141,11 @@ class ForeignAPIRepo extends FileRepo {
                        }
                }
 
-               $data = $this->fetchImageQuery( array( 'titles' => implode( $files, '|' ),
-                                                                                       'prop' => 'imageinfo' ) );
+               $data = $this->fetchImageQuery( array(
+                       'titles' => implode( $files, '|' ),
+                       'prop' => 'imageinfo' )
+               );
+
                if ( isset( $data['query']['pages'] ) ) {
                        # First, get results from the query. Note we only care whether the image exists,
                        # not whether it has a description page.
@@ -161,6 +169,7 @@ class ForeignAPIRepo extends FileRepo {
                                $results[$key] = $this->mFileExists[$file];
                        }
                }
+
                return $results;
        }
 
@@ -211,6 +220,7 @@ class ForeignAPIRepo extends FileRepo {
                                }
                        }
                }
+
                return false;
        }
 
@@ -234,6 +244,7 @@ class ForeignAPIRepo extends FileRepo {
                                $ret[] = new ForeignAPIFile( Title::makeTitle( NS_FILE, $img['name'] ), $this, $img );
                        }
                }
+
                return $ret;
        }
 
@@ -258,6 +269,7 @@ class ForeignAPIRepo extends FileRepo {
                if ( $data && $info && isset( $info['thumburl'] ) ) {
                        wfDebug( __METHOD__ . " got remote thumb " . $info['thumburl'] . "\n" );
                        $result = $info;
+
                        return $info['thumburl'];
                } else {
                        return false;
@@ -286,6 +298,7 @@ class ForeignAPIRepo extends FileRepo {
 
                if ( $data && $info && isset( $info['thumberror'] ) ) {
                        wfDebug( __METHOD__ . " got remote thumb error " . $info['thumberror'] . "\n" );
+
                        return new MediaTransformError(
                                'thumbnail_error_remote',
                                $width,
@@ -307,7 +320,8 @@ class ForeignAPIRepo extends FileRepo {
         * @param string $name is a dbkey form of a title
         * @param $width
         * @param $height
-        * @param string $params Other rendering parameters (page number, etc) from handler's makeParamString.
+        * @param string $params Other rendering parameters (page number, etc)
+        *   from handler's makeParamString.
         * @return bool|string
         */
        function getThumbUrlFromCache( $name, $width, $height, $params = "" ) {
@@ -332,6 +346,7 @@ class ForeignAPIRepo extends FileRepo {
                        if ( isset( $knownThumbUrls[$sizekey] ) ) {
                                wfDebug( __METHOD__ . ': Got thumburl from local cache: ' .
                                        "{$knownThumbUrls[$sizekey]} \n" );
+
                                return $knownThumbUrls[$sizekey];
                        }
                        /* This size is not yet known */
@@ -342,6 +357,7 @@ class ForeignAPIRepo extends FileRepo {
 
                if ( !$foreignUrl ) {
                        wfDebug( __METHOD__ . " Could not find thumburl\n" );
+
                        return false;
                }
 
@@ -349,14 +365,17 @@ class ForeignAPIRepo extends FileRepo {
                $fileName = rawurldecode( pathinfo( $foreignUrl, PATHINFO_BASENAME ) );
                if ( !$this->validateFilename( $fileName ) ) {
                        wfDebug( __METHOD__ . " The deduced filename $fileName is not safe\n" );
+
                        return false;
                }
                $localPath = $this->getZonePath( 'thumb' ) . "/" . $this->getHashPath( $name ) . $name;
                $localFilename = $localPath . "/" . $fileName;
-               $localUrl = $this->getZoneUrl( 'thumb' ) . "/" . $this->getHashPath( $name ) . rawurlencode( $name ) . "/" . rawurlencode( $fileName );
+               $localUrl = $this->getZoneUrl( 'thumb' ) . "/" . $this->getHashPath( $name ) .
+                       rawurlencode( $name ) . "/" . rawurlencode( $fileName );
 
                if ( $backend->fileExists( array( 'src' => $localFilename ) )
-                       && isset( $metadata['timestamp'] ) ) {
+                       && isset( $metadata['timestamp'] )
+               ) {
                        wfDebug( __METHOD__ . " Thumbnail was already downloaded before\n" );
                        $modified = $backend->getFileTimestamp( array( 'src' => $localFilename ) );
                        $remoteModified = strtotime( $metadata['timestamp'] );
@@ -366,6 +385,7 @@ class ForeignAPIRepo extends FileRepo {
                                /* Use our current and already downloaded thumbnail */
                                $knownThumbUrls[$sizekey] = $localUrl;
                                $wgMemc->set( $key, $knownThumbUrls, $this->apiThumbCacheExpiry );
+
                                return $localUrl;
                        }
                        /* There is a new Commons file, or existing thumbnail older than a month */
@@ -373,6 +393,7 @@ class ForeignAPIRepo extends FileRepo {
                $thumb = self::httpGet( $foreignUrl );
                if ( !$thumb ) {
                        wfDebug( __METHOD__ . " Could not download thumb\n" );
+
                        return false;
                }
 
@@ -381,11 +402,13 @@ class ForeignAPIRepo extends FileRepo {
                $params = array( 'dst' => $localFilename, 'content' => $thumb );
                if ( !$backend->quickCreate( $params )->isOK() ) {
                        wfDebug( __METHOD__ . " could not write to thumb path '$localFilename'\n" );
+
                        return $foreignUrl;
                }
                $knownThumbUrls[$sizekey] = $localUrl;
                $wgMemc->set( $key, $knownThumbUrls, $this->apiThumbCacheExpiry );
                wfDebug( __METHOD__ . " got local thumb $localUrl, saving to cache \n" );
+
                return $localUrl;
        }
 
@@ -416,6 +439,7 @@ class ForeignAPIRepo extends FileRepo {
                if ( in_array( $zone, $supported ) ) {
                        return parent::getZonePath( $zone );
                }
+
                return false;
        }