Consistent casing for wfGetDB(), getDB(), and getDBKey()
[lhc/web/wiklou.git] / includes / filerepo / File.php
index ade4a24..29b63c6 100644 (file)
@@ -17,7 +17,7 @@
  * The convenience functions wfLocalFile() and wfFindFile() should be sufficient
  * in most cases.
  *
- * @addtogroup FileRepo
+ * @ingroup FileRepo
  */
 abstract class File {
        const DELETED_FILE = 1;
@@ -46,7 +46,7 @@ abstract class File {
        /**
         * The following member variables are not lazy-initialised
         */
-       var $repo, $title, $lastError, $redirected;
+       var $repo, $title, $lastError, $redirected, $redirectedTitle;
 
        /**
         * Call this constructor from child classes
@@ -79,7 +79,8 @@ abstract class File {
                        'htm' => 'html',
                        'jpeg' => 'jpg',
                        'mpeg' => 'mpg',
-                       'tiff' => 'tif' );
+                       'tiff' => 'tif',
+                       'ogv' => 'ogg' );
                if( isset( $squish[$lower] ) ) {
                        return $squish[$lower];
                } elseif( preg_match( '/^[0-9a-z]+$/', $lower ) ) {
@@ -152,6 +153,15 @@ abstract class File {
         * Return the associated title object
         */
        public function getTitle() { return $this->title; }
+       
+       /**
+        * Return the title used to find this file
+        */
+       public function getOriginalTitle() {
+               if ( $this->redirected )
+                       return $this->getRedirectedTitle();
+               return $this->title;
+       }
 
        /**
         * Return the URL of the file
@@ -254,7 +264,14 @@ abstract class File {
         * Overridden by LocalFile, UnregisteredLocalFile
         * STUB
         */
-       function getMetadata() { return false; }
+       public function getMetadata() { return false; }
+
+       /**
+        * Return the bit depth of the file
+        * Overridden by LocalFile
+        * STUB
+        */
+       public function getBitDepth() { return 0; }
 
        /**
         * Return the size of the image file, in bytes
@@ -489,8 +506,7 @@ abstract class File {
         *
         * @param integer $width        maximum width of the generated thumbnail
         * @param integer $height       maximum height of the image (optional)
-        * @param boolean $render       True to render the thumbnail if it doesn't exist,
-        *                              false to just return the URL
+        * @param boolean $render       Deprecated
         *
         * @return ThumbnailImage or null on failure
         *
@@ -501,8 +517,7 @@ abstract class File {
                if ( $height != -1 ) {
                        $params['height'] = $height;
                }
-               $flags = $render ? self::RENDER_NOW : 0;
-               return $this->transform( $params, $flags );
+               return $this->transform( $params, 0 );
        }
 
        /**
@@ -565,7 +580,7 @@ abstract class File {
                        // Purge. Useful in the event of Core -> Squid connection failure or squid 
                        // purge collisions from elsewhere during failure. Don't keep triggering for 
                        // "thumbs" which have the main image URL though (bug 13776)
-                       if ( $wgUseSquid && ($thumb->isError() || $thumb->getUrl() != $this->getURL()) ) {
+                       if ( $wgUseSquid && ( !$thumb || $thumb->isError() || $thumb->getUrl() != $this->getURL()) ) {
                                SquidUpdate::purge( array( $thumbUrl ) );
                        }
                } while (false);
@@ -670,7 +685,7 @@ abstract class File {
         * @param $end timestamp Only revisions newer than $end will be returned
         */
        function getHistory($limit = null, $start = null, $end = null) {
-               return false;
+               return array();
        }
 
        /**
@@ -904,6 +919,12 @@ abstract class File {
        function getRepoName() {
                return $this->repo ? $this->repo->getName() : 'unknown';
        }
+       /*
+        * Returns the repository
+        */
+       function getRepo() {
+               return $this->repo;
+       }
 
        /**
         * Returns true if the image is an old version
@@ -1046,13 +1067,26 @@ abstract class File {
         * Get the HTML text of the description page, if available
         */
        function getDescriptionText() {
+               global $wgMemc;
                if ( !$this->repo->fetchDescription ) {
                        return false;
                }
                $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName() );
                if ( $renderUrl ) {
+                       if ( $this->repo->descriptionCacheExpiry > 0 ) {
+                               wfDebug("Attempting to get the description from cache...");
+                               $key = wfMemcKey( 'RemoteFileDescription', 'url', md5($renderUrl) );
+                               $obj = $wgMemc->get($key);
+                               if ($obj) {
+                                       wfDebug("success!\n");
+                                       return $obj;
+                               }
+                               wfDebug("miss\n");
+                       }
                        wfDebug( "Fetching shared description from $renderUrl\n" );
-                       return Http::get( $renderUrl );
+                       $res = Http::get( $renderUrl );
+                       if ( $res && $this->repo->descriptionCacheExpiry > 0 ) $wgMemc->set( $key, $res, $this->repo->descriptionCacheExpiry );
+                       return $res;
                } else {
                        return false;
                }
@@ -1208,6 +1242,14 @@ abstract class File {
        function getRedirected() {
                return $this->redirected;
        }
+       
+       function getRedirectedTitle() {
+               if ( $this->redirected ) {
+                       if ( !$this->redirectTitle )
+                               $this->redirectTitle = Title::makeTitle( NS_IMAGE, $this->redirected );
+                       return $this->redirectTitle;
+               }
+       }
 
        function redirectedFrom( $from ) {
                $this->redirected = $from;