Fixed coding convention issue
[lhc/web/wiklou.git] / includes / filerepo / File.php
index 0e634eb..ede98b6 100644 (file)
@@ -264,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
@@ -499,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
         *
@@ -511,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 );
        }
 
        /**
@@ -524,7 +529,7 @@ abstract class File {
         * @return MediaTransformOutput
         */
        function transform( $params, $flags = 0 ) {
-               global $wgUseSquid, $wgIgnoreImageErrors;
+               global $wgUseSquid, $wgIgnoreImageErrors, $wgThumbnailEpoch;
 
                wfProfileIn( __METHOD__ );
                do {
@@ -556,10 +561,14 @@ abstract class File {
 
                        wfDebug( __METHOD__.": Doing stat for $thumbPath\n" );
                        $this->migrateThumbFile( $thumbName );
-                       if ( file_exists( $thumbPath ) ) {
-                               $thumb = $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
-                               break;
-                       }
+                       if ( file_exists( $thumbPath ))
+                               $thumbTime = filemtime( $thumbPath );
+                               if ( $thumbTime !== FALSE &&
+                                    gmdate( 'YmdHis', $thumbTime ) >= $wgThumbnailEpoch ) { 
+       
+                                       $thumb = $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
+                                       break;
+                               }
                        $thumb = $this->handler->doTransform( $this, $thumbPath, $thumbUrl, $params );
 
                        // Ignore errors if requested
@@ -575,13 +584,13 @@ 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);
 
                wfProfileOut( __METHOD__ );
-               return $thumb;
+               return is_object( $thumb ) ? $thumb : false;
        }
 
        /**
@@ -678,8 +687,9 @@ abstract class File {
         * @param $limit integer Limit of rows to return
         * @param $start timestamp Only revisions older than $start will be returned
         * @param $end timestamp Only revisions newer than $end will be returned
+        * @param $inc bool Include the endpoints of the time range
         */
-       function getHistory($limit = null, $start = null, $end = null) {
+       function getHistory($limit = null, $start = null, $end = null, $inc=true) {
                return array();
        }
 
@@ -740,15 +750,6 @@ abstract class File {
                return $path;
        }
 
-       /** Get relative path for a thumbnail file */
-       function getThumbRel( $suffix = false ) {
-               $path = 'thumb/' . $this->getRel();
-               if ( $suffix !== false ) {
-                       $path .= '/' . $suffix;
-               }
-               return $path;
-       }
-
        /** Get the path of the archive directory, or a particular file if $suffix is specified */
        function getArchivePath( $suffix = false ) {
                return $this->repo->getZonePath('public') . '/' . $this->getArchiveRel( $suffix );
@@ -756,7 +757,11 @@ abstract class File {
 
        /** Get the path of the thumbnail directory, or a particular file if $suffix is specified */
        function getThumbPath( $suffix = false ) {
-               return $this->repo->getZonePath('public') . '/' . $this->getThumbRel( $suffix );
+               $path = $this->repo->getZonePath('thumb') . '/' . $this->getRel();
+               if ( $suffix !== false ) {
+                       $path .= '/' . $suffix;
+               }
+               return $path;
        }
 
        /** Get the URL of the archive directory, or a particular file if $suffix is specified */
@@ -772,7 +777,7 @@ abstract class File {
 
        /** Get the URL of the thumbnail directory, or a particular file if $suffix is specified */
        function getThumbUrl( $suffix = false ) {
-               $path = $this->repo->getZoneUrl('public') . '/thumb/' . $this->getUrlRel();
+               $path = $this->repo->getZoneUrl('thumb') . '/' . $this->getUrlRel();
                if ( $suffix !== false ) {
                        $path .= '/' . rawurlencode( $suffix );
                }
@@ -792,7 +797,7 @@ abstract class File {
 
        /** Get the virtual URL for a thumbnail file or directory */
        function getThumbVirtualUrl( $suffix = false ) {
-               $path = $this->repo->getVirtualUrl() . '/public/thumb/' . $this->getUrlRel();
+               $path = $this->repo->getVirtualUrl() . '/thumb/' . $this->getUrlRel();
                if ( $suffix !== false ) {
                        $path .= '/' . rawurlencode( $suffix );
                }
@@ -859,22 +864,23 @@ abstract class File {
         *
         * @deprecated Use HTMLCacheUpdate, this function uses too much memory
         */
-       function getLinksTo( $options = '' ) {
+       function getLinksTo( $options = array() ) {
                wfProfileIn( __METHOD__ );
 
                // Note: use local DB not repo DB, we want to know local links
-               if ( $options ) {
+               if ( count( $options ) > 0 ) {
                        $db = wfGetDB( DB_MASTER );
                } else {
                        $db = wfGetDB( DB_SLAVE );
                }
                $linkCache = LinkCache::singleton();
 
-               list( $page, $imagelinks ) = $db->tableNamesN( 'page', 'imagelinks' );
                $encName = $db->addQuotes( $this->getName() );
-               $sql = "SELECT page_namespace,page_title,page_id,page_len,page_is_redirect,
-                       FROM $page,$imagelinks WHERE page_id=il_from AND il_to=$encName $options";
-               $res = $db->query( $sql, __METHOD__ );
+               $res = $db->select( array( 'page', 'imagelinks'), 
+                                                       array( 'page_namespace', 'page_title', 'page_id', 'page_len', 'page_is_redirect' ),
+                                                       array( 'page_id' => 'il_from', 'il_to' => $encName ),
+                                                       __METHOD__,
+                                                       $options );
 
                $retVal = array();
                if ( $db->numRows( $res ) ) {
@@ -936,6 +942,14 @@ abstract class File {
        function isDeleted( $field ) {
                return false;
        }
+       
+       /**
+        * Return the deletion bitfield
+        * STUB
+        */     
+       function getVisibility() {
+               return 0;
+       }
 
        /**
         * Was this file ever deleted from the wiki?
@@ -944,7 +958,7 @@ abstract class File {
         */
        function wasDeleted() {
                $title = $this->getTitle();
-               return $title && $title->isDeleted() > 0;
+               return $title && $title->isDeletedQuick();
        }
 
        /**
@@ -1000,8 +1014,9 @@ abstract class File {
        }
 
        /**
-        * Returns 'true' if this image is a multipage document, e.g. a DJVU
-        * document.
+        * 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
         */
@@ -1062,15 +1077,16 @@ abstract class File {
         * Get the HTML text of the description page, if available
         */
        function getDescriptionText() {
-               global $wgMemc;
+               global $wgMemc, $wgLang;
                if ( !$this->repo->fetchDescription ) {
                        return false;
                }
-               $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName() );
+               $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $wgLang->getCode() );
                if ( $renderUrl ) {
-                       if ( $this->repo->useLocalCache ) {
-                               wfDebug("Attempting to get the description from the transwiki cache...");
-                               $key = md5($renderUrl);
+                       if ( $this->repo->descriptionCacheExpiry > 0 ) {
+                               wfDebug("Attempting to get the description from cache...");
+                               $key = $this->repo->getLocalCacheKey( 'RemoteFileDescription', 'url', $wgLang->getCode(), 
+                                                                       $this->getName() );
                                $obj = $wgMemc->get($key);
                                if ($obj) {
                                        wfDebug("success!\n");
@@ -1080,7 +1096,9 @@ abstract class File {
                        }
                        wfDebug( "Fetching shared description from $renderUrl\n" );
                        $res = Http::get( $renderUrl );
-                       if ( $res && $this->repo->useLocalCache ) $wgMemc->set( $key, $res, $this->repo->localCacheExpiry );
+                       if ( $res && $this->repo->descriptionCacheExpiry > 0 ) {
+                               $wgMemc->set( $key, $res, $this->repo->descriptionCacheExpiry );
+                       }
                        return $res;
                } else {
                        return false;
@@ -1114,6 +1132,19 @@ abstract class File {
                return self::sha1Base36( $this->getPath() );
        }
 
+       /**
+        * Get the deletion archive key, <sha1>.<ext>
+        */
+       function getStorageKey() {
+               $hash = $this->getSha1();
+               if ( !$hash ) {
+                       return false;
+               }
+               $ext = $this->getExtension();
+               $dotExt = $ext === '' ? '' : ".$ext";
+               return $hash . $dotExt;                         
+       }
+
        /**
         * Determine if the current user is allowed to view a particular
         * field of this file, if it's marked as deleted.
@@ -1212,7 +1243,7 @@ abstract class File {
                if ( $handler ) {
                        return $handler->getLongDesc( $this );
                } else {
-                       return MediaHandler::getLongDesc( $this );
+                       return MediaHandler::getGeneralLongDesc( $this );
                }
        }
 
@@ -1221,7 +1252,7 @@ abstract class File {
                if ( $handler ) {
                        return $handler->getShortDesc( $this );
                } else {
-                       return MediaHandler::getShortDesc( $this );
+                       return MediaHandler::getGeneralShortDesc( $this );
                }
        }
 
@@ -1241,7 +1272,7 @@ abstract class File {
        function getRedirectedTitle() {
                if ( $this->redirected ) {
                        if ( !$this->redirectTitle )
-                               $this->redirectTitle = Title::makeTitle( NS_IMAGE, $this->redirected );
+                               $this->redirectTitle = Title::makeTitle( NS_FILE, $this->redirected );
                        return $this->redirectTitle;
                }
        }
@@ -1249,6 +1280,10 @@ abstract class File {
        function redirectedFrom( $from ) {
                $this->redirected = $from;
        }
+
+       function isMissing() {
+               return false;
+       }
 }
 /**
  * Aliases for backwards compatibility with 1.6