[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/media/ -> Tiff.php (source)

   1  <?php
   2  /**
   3   * Handler for Tiff images.
   4   *
   5   * This program is free software; you can redistribute it and/or modify
   6   * it under the terms of the GNU General Public License as published by
   7   * the Free Software Foundation; either version 2 of the License, or
   8   * (at your option) any later version.
   9   *
  10   * This program is distributed in the hope that it will be useful,
  11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13   * GNU General Public License for more details.
  14   *
  15   * You should have received a copy of the GNU General Public License along
  16   * with this program; if not, write to the Free Software Foundation, Inc.,
  17   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18   * http://www.gnu.org/copyleft/gpl.html
  19   *
  20   * @file
  21   * @ingroup Media
  22   */
  23  
  24  /**
  25   * Handler for Tiff images.
  26   *
  27   * @ingroup Media
  28   */
  29  class TiffHandler extends ExifBitmapHandler {
  30      const EXPENSIVE_SIZE_LIMIT = 10485760; // TIFF files over 10M are considered expensive to thumbnail
  31  
  32      /**
  33       * Conversion to PNG for inline display can be disabled here...
  34       * Note scaling should work with ImageMagick, but may not with GD scaling.
  35       *
  36       * Files pulled from an another MediaWiki instance via ForeignAPIRepo /
  37       * InstantCommons will have thumbnails managed from the remote instance,
  38       * so we can skip this check.
  39       *
  40       * @param File $file
  41       * @return bool
  42       */
  43  	function canRender( $file ) {
  44          global $wgTiffThumbnailType;
  45  
  46          return (bool)$wgTiffThumbnailType
  47              || $file->getRepo() instanceof ForeignAPIRepo;
  48      }
  49  
  50      /**
  51       * Browsers don't support TIFF inline generally...
  52       * For inline display, we need to convert to PNG.
  53       *
  54       * @param File $file
  55       * @return bool
  56       */
  57  	function mustRender( $file ) {
  58          return true;
  59      }
  60  
  61      /**
  62       * @param string $ext
  63       * @param string $mime
  64       * @param array $params
  65       * @return bool
  66       */
  67  	function getThumbType( $ext, $mime, $params = null ) {
  68          global $wgTiffThumbnailType;
  69  
  70          return $wgTiffThumbnailType;
  71      }
  72  
  73      /**
  74       * @param File $image
  75       * @param string $filename
  76       * @throws MWException
  77       * @return string
  78       */
  79  	function getMetadata( $image, $filename ) {
  80          global $wgShowEXIF;
  81          if ( $wgShowEXIF ) {
  82              try {
  83                  $meta = BitmapMetadataHandler::Tiff( $filename );
  84                  if ( !is_array( $meta ) ) {
  85                      // This should never happen, but doesn't hurt to be paranoid.
  86                      throw new MWException( 'Metadata array is not an array' );
  87                  }
  88                  $meta['MEDIAWIKI_EXIF_VERSION'] = Exif::version();
  89  
  90                  return serialize( $meta );
  91              } catch ( MWException $e ) {
  92                  // BitmapMetadataHandler throws an exception in certain exceptional
  93                  // cases like if file does not exist.
  94                  wfDebug( __METHOD__ . ': ' . $e->getMessage() . "\n" );
  95  
  96                  return ExifBitmapHandler::BROKEN_FILE;
  97              }
  98          } else {
  99              return '';
 100          }
 101      }
 102  
 103  	public function isExpensiveToThumbnail( $file ) {
 104          return $file->getSize() > static::EXPENSIVE_SIZE_LIMIT;
 105      }
 106  }


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1