Some HipHop fixes:
[lhc/web/wiklou.git] / includes / filerepo / File.php
index 9e582ad..0b5e374 100644 (file)
@@ -52,7 +52,23 @@ abstract class File {
        /**
         * The following member variables are not lazy-initialised
         */
-       var $repo, $title, $lastError, $redirected, $redirectedTitle;
+
+       /**
+        * @var LocalRepo
+        */
+       var $repo;
+
+       /**
+        * @var Title
+        */
+       var $title;
+
+       var $lastError, $redirected, $redirectedTitle;
+
+       /**
+        * @var MediaHandler
+        */
+       protected $handler;
 
        /**
         * Call this constructor from child classes
@@ -122,10 +138,10 @@ abstract class File {
         * Split an internet media type into its two components; if not
         * a two-part name, set the minor type to 'unknown'.
         *
-        * @param $mime "text/html" etc
+        * @param string $mime "text/html" etc
         * @return array ("text", "html") etc
         */
-       static function splitMime( $mime ) {
+       public static function splitMime( $mime ) {
                if( strpos( $mime, '/' ) !== false ) {
                        return explode( '/', $mime, 2 );
                } else {
@@ -157,9 +173,10 @@ abstract class File {
 
        /**
         * Return the associated title object
+        * @return Title
         */
        public function getTitle() { return $this->title; }
-       
+
        /**
         * Return the title used to find this file
         */
@@ -212,7 +229,8 @@ abstract class File {
        * i.e. whether the files are all found in the same directory,
        * or in hashed paths like /images/3/3c.
        *
-       * May return false if the file is not locally accessible.
+       * Most callers don't check the return value, but ForeignAPIFile::getPath
+       * returns false.
        */
        public function getPath() {
                if ( !isset( $this->path ) ) {
@@ -223,8 +241,11 @@ abstract class File {
 
        /**
        * Alias for getPath()
+       *
+       * @deprecated since 1.18 Use getPath().
        */
        public function getFullPath() {
+               wfDeprecated( __METHOD__ );
                return $this->getPath();
        }
 
@@ -267,16 +288,16 @@ abstract class File {
        }
 
        /**
-         *  Return true if the file is vectorized
-         */
-        public function isVectorized() {
-                $handler = $this->getHandler();
-                if ( $handler ) {
-                        return $handler->isVectorized( $this );
-                } else {
-                        return false;
-                }
-        }
+        *  Return true if the file is vectorized
+        */
+       public function isVectorized() {
+               $handler = $this->getHandler();
+               if ( $handler ) {
+                       return $handler->isVectorized( $this );
+               } else {
+                       return false;
+               }
+       }
 
 
        /**
@@ -286,6 +307,26 @@ abstract class File {
         */
        public function getMetadata() { return false; }
 
+       /**
+       * get versioned metadata
+       *
+       * @param $metadata Mixed Array or String of (serialized) metadata
+       * @param $version integer version number.
+       * @return Array containing metadata, or what was passed to it on fail (unserializing if not array)
+       */
+       public function convertMetadataVersion($metadata, $version) {
+               $handler = $this->getHandler();
+               if ( !is_array( $metadata ) ) {
+                       //just to make the return type consistant
+                       $metadata = unserialize( $metadata );
+               }
+               if ( $handler ) {
+                       return $handler->convertMetadataVersion( $metadata, $version );
+               } else {
+                       return $metadata;
+               }
+       }
+
        /**
         * Return the bit depth of the file
         * Overridden by LocalFile
@@ -435,9 +476,8 @@ abstract class File {
         * It would be unsafe to include private images, making public thumbnails inadvertently
         *
         * @return boolean Whether file exists in the repository and is includable.
-        * @public
         */
-       function isVisible() {
+       public function isVisible() {
                return $this->exists();
        }
 
@@ -475,12 +515,22 @@ abstract class File {
         * @private -ish
         */
        function thumbName( $params ) {
+               return $this->generateThumbName( $this->getName(), $params );
+       }
+
+       /**
+        * Generate a thumbnail file name from a name and specified parameters
+        *
+        * @param string $name
+        * @param array $params Parameters which will be passed to MediaHandler::makeParamString
+        */
+       function generateThumbName( $name, $params ) {
                if ( !$this->getHandler() ) {
                        return null;
                }
                $extension = $this->getExtension();
                list( $thumbExt, $thumbMime ) = $this->handler->getThumbType( $extension, $this->getMimeType(), $params );
-               $thumbName = $this->handler->makeParamString( $params ) . '-' . $this->getName();
+               $thumbName = $this->handler->makeParamString( $params ) . '-' . $name;
                if ( $thumbExt != $extension ) {
                        $thumbName .= ".$thumbExt";
                }
@@ -512,29 +562,6 @@ abstract class File {
                return $thumb->getUrl();
        }
 
-       /**
-        * As createThumb, but returns a ThumbnailImage object. This can
-        * provide access to the actual file, the real size of the thumb,
-        * and can produce a convenient \<img\> tag for you.
-        *
-        * For non-image formats, this may return a filetype-specific icon.
-        *
-        * @param $width Integer: maximum width of the generated thumbnail
-        * @param $height Integer: maximum height of the image (optional)
-        * @param $render Integer: Deprecated
-        *
-        * @return ThumbnailImage or null on failure
-        *
-        * @deprecated use transform()
-        */
-       public function getThumbnail( $width, $height=-1, $render = true ) {
-               $params = array( 'width' => $width );
-               if ( $height != -1 ) {
-                       $params['height'] = $height;
-               }
-               return $this->transform( $params, 0 );
-       }
-
        /**
         * Transform a media file
         *
@@ -585,8 +612,8 @@ abstract class File {
                        if ( file_exists( $thumbPath )) {
                                $thumbTime = filemtime( $thumbPath );
                                if ( $thumbTime !== FALSE &&
-                                    gmdate( 'YmdHis', $thumbTime ) >= $wgThumbnailEpoch ) { 
-       
+                                       gmdate( 'YmdHis', $thumbTime ) >= $wgThumbnailEpoch ) {
+
                                        $thumb = $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
                                        break;
                                }
@@ -602,9 +629,9 @@ abstract class File {
                                        $thumb = $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
                                }
                        }
-                       
-                       // Purge. Useful in the event of Core -> Squid connection failure or squid 
-                       // purge collisions from elsewhere during failure. Don't keep triggering for 
+
+                       // 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 || $thumb->isError() || $thumb->getUrl() != $this->getURL()) ) {
                                SquidUpdate::purge( array( $thumbUrl ) );
@@ -624,6 +651,7 @@ abstract class File {
 
        /**
         * Get a MediaHandler instance for this file
+        * @return MediaHandler
         */
        function getHandler() {
                if ( !isset( $this->handler ) ) {
@@ -877,46 +905,6 @@ abstract class File {
                $this->readOnlyError();
        }
 
-       /**
-        * Get an array of Title objects which are articles which use this file
-        * Also adds their IDs to the link cache
-        *
-        * This is mostly copied from Title::getLinksTo()
-        *
-        * @deprecated Use HTMLCacheUpdate, this function uses too much memory
-        */
-       function getLinksTo( $options = array() ) {
-               wfProfileIn( __METHOD__ );
-
-               // Note: use local DB not repo DB, we want to know local links
-               if ( count( $options ) > 0 ) {
-                       $db = wfGetDB( DB_MASTER );
-               } else {
-                       $db = wfGetDB( DB_SLAVE );
-               }
-               $linkCache = LinkCache::singleton();
-
-               $encName = $db->addQuotes( $this->getName() );
-               $res = $db->select( array( 'page', 'imagelinks'), 
-                                                       array( 'page_namespace', 'page_title', 'page_id', 'page_len', 'page_is_redirect', 'page_latest' ),
-                                                       array( 'page_id' => 'il_from', 'il_to' => $encName ),
-                                                       __METHOD__,
-                                                       $options );
-
-               $retVal = array();
-               if ( $db->numRows( $res ) ) {
-                       foreach ( $res as $row ) {
-                               $titleObj = Title::newFromRow( $row );
-                               if ( $titleObj ) {
-                                       $linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redirect, $row->page_latest );
-                                       $retVal[] = $titleObj;
-                               }
-                       }
-               }
-               wfProfileOut( __METHOD__ );
-               return $retVal;
-       }
-
        function formatMetadata() {
                if ( !$this->getHandler() ) {
                        return false;
@@ -942,6 +930,7 @@ abstract class File {
        function getRepoName() {
                return $this->repo ? $this->repo->getName() : 'unknown';
        }
+
        /*
         * Returns the repository
         */
@@ -964,11 +953,11 @@ abstract class File {
        function isDeleted( $field ) {
                return false;
        }
-       
+
        /**
         * Return the deletion bitfield
         * STUB
-        */     
+        */
        function getVisibility() {
                return 0;
        }
@@ -1036,8 +1025,8 @@ abstract class File {
        }
 
        /**
-        * Returns 'true' if this file is a type which supports multiple pages, 
-        * e.g. DJVU or PDF. Note that this may be true even if the file in 
+        * Returns 'true' if this file is a type which supports multiple pages,
+        * e.g. DJVU or PDF. Note that this may be true even if the file in
         * question only has a single page.
         *
         * @return Bool
@@ -1047,7 +1036,7 @@ abstract class File {
        }
 
        /**
-        * Returns the number of pages of a multipage document, or NULL for
+        * Returns the number of pages of a multipage document, or false for
         * documents which aren't multipage documents
         */
        function pageCount() {
@@ -1097,19 +1086,8 @@ abstract class File {
 
        /**
         * Get the HTML text of the description page, if available
-        * For local files ImagePage does not use it, because it skips the parser cache.
         */
        function getDescriptionText() {
-               if( $this->isLocal() ) {
-                       global $wgParser;
-                       $revision = Revision::newFromTitle( $this->title );
-                       if ( !$revision ) return false;
-                       $text = $revision->getText();
-                       if ( !$text ) return false;
-                       $pout = $wgParser->parse( $text, $this->title, new ParserOptions() );
-                       return $pout->getText();
-               }
-
                global $wgMemc, $wgLang;
                if ( !$this->repo->fetchDescription ) {
                        return false;
@@ -1118,7 +1096,7 @@ abstract class File {
                if ( $renderUrl ) {
                        if ( $this->repo->descriptionCacheExpiry > 0 ) {
                                wfDebug("Attempting to get the description from cache...");
-                               $key = $this->repo->getLocalCacheKey( 'RemoteFileDescription', 'url', $wgLang->getCode(), 
+                               $key = $this->repo->getLocalCacheKey( 'RemoteFileDescription', 'url', $wgLang->getCode(),
                                                                        $this->getName() );
                                $obj = $wgMemc->get($key);
                                if ($obj) {
@@ -1175,7 +1153,7 @@ abstract class File {
                }
                $ext = $this->getExtension();
                $dotExt = $ext === '' ? '' : ".$ext";
-               return $hash . $dotExt;                         
+               return $hash . $dotExt;
        }
 
        /**
@@ -1310,11 +1288,12 @@ abstract class File {
        function getRedirected() {
                return $this->redirected;
        }
-       
+
        function getRedirectedTitle() {
                if ( $this->redirected ) {
-                       if ( !$this->redirectTitle )
+                       if ( !$this->redirectTitle ) {
                                $this->redirectTitle = Title::makeTitle( NS_FILE, $this->redirected );
+                       }
                        return $this->redirectTitle;
                }
        }