Revert r29361 -- breaks upload, calls nonexistent functions
[lhc/web/wiklou.git] / includes / filerepo / File.php
index 3b586da..7e222a0 100644 (file)
@@ -149,6 +149,21 @@ abstract class File {
                }
                return $this->url; 
        }
+       
+       /**
+        * Return a fully-qualified URL to the file.
+        * Upload URL paths _may or may not_ be fully qualified, so
+        * we check. Local paths are assumed to belong on $wgServer.
+        * @return string
+        */
+       public function getFullUrl() {
+               $url = $this->getUrl();
+               if( substr( $url, 0, 1 ) == '/' ) {
+                       global $wgServer;
+                       return $wgServer . $url;
+               }
+               return $url;
+       }
 
        function getViewURL() {
                if( $this->mustRender()) {
@@ -209,6 +224,18 @@ abstract class File {
         */
        public function getHeight( $page = 1 ) { return false; }
 
+       /**
+        * Get the duration of a media file in seconds
+        */
+       public function getLength() {
+               $handler = $this->getHandler();
+               if ( $handler ) {
+                       return $handler->getLength( $this );
+               } else {
+                       return 0;
+               }
+       }
+
        /**
         * Get handler-specific metadata
         * Overridden by LocalFile, UnregisteredLocalFile
@@ -239,7 +266,9 @@ abstract class File {
        function getMediaType() { return MEDIATYPE_UNKNOWN; }
 
        /**
-        * Checks if the file can be presented to the browser as a bitmap.
+        * Checks if the output of transform() for this file is likely 
+        * to be valid. If this is false, various user elements will 
+        * display a placeholder instead.
         *
         * Currently, this checks if the file is an image format
         * that can be converted to a format
@@ -248,7 +277,7 @@ abstract class File {
         */
        function canRender() {
                if ( !isset( $this->canRender ) ) {
-                       $this->canRender = $this->getHandler() && $this->handler->canRender();
+                       $this->canRender = $this->getHandler() && $this->handler->canRender( $this );
                }
                return $this->canRender;
        }
@@ -271,16 +300,11 @@ abstract class File {
         * @return bool
         */
        function mustRender() {
-               return $this->getHandler() && $this->handler->mustRender();
+               return $this->getHandler() && $this->handler->mustRender( $this );
        }
 
        /**
-        * Determines if this media file may be shown inline on a page.
-        *
-        * This is currently synonymous to canRender(), but this could be
-        * extended to also allow inline display of other media,
-        * like flash animations or videos. If you do so, please keep in mind that
-        * that could be a security risk.
+        * Alias for canRender()
         */
        function allowInlineDisplay() {
                return $this->canRender();
@@ -470,7 +494,7 @@ abstract class File {
 
                wfProfileIn( __METHOD__ );
                do {
-                       if ( !$this->getHandler() || !$this->handler->canRender() ) {
+                       if ( !$this->canRender() ) {
                                // not a bitmap or renderable image, don't try.
                                $thumb = $this->iconThumb();
                                break;
@@ -550,7 +574,7 @@ abstract class File {
                        $path = '/common/images/icons/' . $icon;
                        $filepath = $wgStyleDirectory . $path;
                        if( file_exists( $filepath ) ) {
-                               return new ThumbnailImage( $wgStylePath . $path, 120, 120 );
+                               return new ThumbnailImage( $this, $wgStylePath . $path, 120, 120 );
                        }
                }
                return null;
@@ -814,22 +838,11 @@ abstract class File {
                return $retVal;
        }
 
-       function getExifData() {
-               if ( !$this->getHandler() || $this->handler->getMetadataType( $this ) != 'exif' ) {
-                       return array();
-               }
-               $metadata = $this->getMetadata();
-               if ( !$metadata ) {
-                       return array();
-               }
-               $exif = unserialize( $metadata );
-               if ( !$exif ) {
-                       return array();
+       function formatMetadata() {
+               if ( !$this->getHandler() ) {
+                       return false;
                }
-               unset( $exif['MEDIAWIKI_EXIF_VERSION'] );
-               $format = new FormatExif( $exif );
-
-               return $format->getFormattedData();
+               return $this->getHandler()->formatMetadata( $this, $this->getMetadata() );
        }
 
        /**
@@ -917,7 +930,7 @@ abstract class File {
         * @return Bool
         */
        function isMultipage() {
-               return $this->getHandler() && $this->handler->isMultiPage();
+               return $this->getHandler() && $this->handler->isMultiPage( $this );
        }
 
        /**
@@ -926,7 +939,7 @@ abstract class File {
         */
        function pageCount() {
                if ( !isset( $this->pageCount ) ) {
-                       if ( $this->getHandler() && $this->handler->isMultiPage() ) {
+                       if ( $this->getHandler() && $this->handler->isMultiPage( $this ) ) {
                                $this->pageCount = $this->handler->pageCount( $this );
                        } else {
                                $this->pageCount = false;
@@ -986,7 +999,8 @@ abstract class File {
        }
 
        /**
-        * Get the 14-character timestamp of the file upload, or false if 
+        * Get the 14-character timestamp of the file upload, or false if
+        * it doesn't exist 
         */
        function getTimestamp() {
                $path = $this->getPath();
@@ -1015,7 +1029,7 @@ abstract class File {
        }
 
        /**
-        * Get an associative array containing information about a file in the local filesystem\
+        * Get an associative array containing information about a file in the local filesystem.
         *
         * @param string $path Absolute local filesystem path
         * @param mixed $ext The file extension, or true to extract it from the filename. 
@@ -1024,7 +1038,9 @@ abstract class File {
        static function getPropsFromPath( $path, $ext = true ) {
                wfProfileIn( __METHOD__ );
                wfDebug( __METHOD__.": Getting file info for $path\n" );
-               $info = array( 'fileExists' => file_exists( $path ) );
+               $info = array( 
+                       'fileExists' => file_exists( $path ) && !is_dir( $path )
+               );
                $gis = false;
                if ( $info['fileExists'] ) {
                        $magic = MimeMagic::singleton();
@@ -1040,8 +1056,8 @@ abstract class File {
                        $handler = MediaHandler::getHandler( $info['mime'] );
                        if ( $handler ) {
                                $tempImage = (object)array();
-                               $gis = $handler->getImageSize( $tempImage, $path );
                                $info['metadata'] = $handler->getMetadata( $tempImage, $path );
+                               $gis = $handler->getImageSize( $tempImage, $path, $info['metadata'] );
                        } else {
                                $gis = false;
                                $info['metadata'] = '';
@@ -1084,13 +1100,42 @@ abstract class File {
         * Returns false on failure
         */
        static function sha1Base36( $path ) {
+               wfSuppressWarnings();
                $hash = sha1_file( $path );
+               wfRestoreWarnings();
                if ( $hash === false ) {
                        return false;
                } else {
                        return wfBaseConvert( $hash, 16, 36, 31 );
                }
        }
+
+       function getLongDesc() {
+               $handler = $this->getHandler();
+               if ( $handler ) {
+                       return $handler->getLongDesc( $this );
+               } else {
+                       return MediaHandler::getLongDesc( $this );
+               }
+       }
+
+       function getShortDesc() {
+               $handler = $this->getHandler();
+               if ( $handler ) {
+                       return $handler->getShortDesc( $this );
+               } else {
+                       return MediaHandler::getShortDesc( $this );
+               }
+       }
+
+       function getDimensionsString() {
+               $handler = $this->getHandler();
+               if ( $handler ) {
+                       return $handler->getDimensionsString( $this );
+               } else {
+                       return '';
+               }
+       }
 }
 /**
  * Aliases for backwards compatibility with 1.6
@@ -1100,3 +1145,4 @@ define( 'MW_IMG_DELETED_COMMENT', File::DELETED_COMMENT );
 define( 'MW_IMG_DELETED_USER', File::DELETED_USER );
 define( 'MW_IMG_DELETED_RESTRICTED', File::DELETED_RESTRICTED );
 
+