MediaWiki  1.28.0
MimeMagic.php
Go to the documentation of this file.
1 <?php
22 
23 class MimeMagic extends MimeAnalyzer {
29  public static function singleton() {
30  return MediaWikiServices::getInstance()->getMIMEAnalyzer();
31  }
32 
38  public static function applyDefaultParameters( array $params, Config $mainConfig ) {
39  $logger = LoggerFactory::getInstance( 'Mime' );
40  $params += [
41  'typeFile' => $mainConfig->get( 'MimeTypeFile' ),
42  'infoFile' => $mainConfig->get( 'MimeInfoFile' ),
43  'xmlTypes' => $mainConfig->get( 'XMLMimeTypes' ),
44  'guessCallback' =>
45  function ( $mimeAnalyzer, &$head, &$tail, $file, &$mime ) use ( $logger ) {
46  // Also test DjVu
47  $deja = new DjVuImage( $file );
48  if ( $deja->isValid() ) {
49  $logger->info( __METHOD__ . ": detected $file as image/vnd.djvu\n" );
50  $mime = 'image/vnd.djvu';
51 
52  return;
53  }
54  // Some strings by reference for performance - assuming well-behaved hooks
55  Hooks::run(
56  'MimeMagicGuessFromContent',
57  [ $mimeAnalyzer, &$head, &$tail, $file, &$mime ]
58  );
59  },
60  'extCallback' => function ( $mimeAnalyzer, $ext, &$mime ) {
61  // Media handling extensions can improve the MIME detected
62  Hooks::run( 'MimeMagicImproveFromExtension', [ $mimeAnalyzer, $ext, &$mime ] );
63  },
64  'initCallback' => function ( $mimeAnalyzer ) {
65  // Allow media handling extensions adding MIME-types and MIME-info
66  Hooks::run( 'MimeMagicInit', [ $mimeAnalyzer ] );
67  },
68  'logger' => $logger
69  ];
70 
71  if ( $params['infoFile'] === 'includes/mime.info' ) {
72  $params['infoFile'] = __DIR__ . "/libs/mime/mime.info";
73  }
74 
75  if ( $params['typeFile'] === 'includes/mime.types' ) {
76  $params['typeFile'] = __DIR__ . "/libs/mime/mime.types";
77  }
78 
79  $detectorCmd = $mainConfig->get( 'MimeDetectorCommand' );
80  if ( $detectorCmd ) {
81  $params['detectCallback'] = function ( $file ) use ( $detectorCmd ) {
82  return wfShellExec( "$detectorCmd " . wfEscapeShellArg( $file ) );
83  };
84  }
85 
86  return $params;
87  }
88 }
static applyDefaultParameters(array $params, Config $mainConfig)
Definition: MimeMagic.php:38
the array() calling protocol came about after MediaWiki 1.4rc1.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static singleton()
Get an instance of this class.
Definition: MimeMagic.php:29
if($ext== 'php'||$ext== 'php5') $mime
Definition: router.php:65
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
wfShellExec($cmd, &$retval=null, $environ=[], $limits=[], $options=[])
Execute a shell command, with time and memory limits mirrored from the PHP configuration if supported...
get($name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".
Support for detecting/validating DjVu image files and getting some basic file metadata (resolution et...
Definition: DjVuImage.php:36
$params
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
LoggerInterface $logger
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
MediaWiki Logger LoggerFactory implements a PSR[0] compatible message logging system Named Psr Log LoggerInterface instances can be obtained from the MediaWiki Logger LoggerFactory::getInstance() static method.MediaWiki\Logger\LoggerFactory expects a class implementing the MediaWiki\Logger\Spi interface to act as a factory for new Psr\Log\LoggerInterface instances.The"Spi"in MediaWiki\Logger\Spi stands for"service provider interface".An SPI is an API intended to be implemented or extended by a third party.This software design pattern is intended to enable framework extension and replaceable components.It is specifically used in the MediaWiki\Logger\LoggerFactory service to allow alternate PSR-3 logging implementations to be easily integrated with MediaWiki.The service provider interface allows the backend logging library to be implemented in multiple ways.The $wgMWLoggerDefaultSpi global provides the classname of the default MediaWiki\Logger\Spi implementation to be loaded at runtime.This can either be the name of a class implementing the MediaWiki\Logger\Spi with a zero argument const ructor or a callable that will return an MediaWiki\Logger\Spi instance.Alternately the MediaWiki\Logger\LoggerFactory MediaWiki Logger LoggerFactory
Definition: logger.txt:5
wfEscapeShellArg()
Version of escapeshellarg() that works better on Windows.