This will allow further refactoring of override logic in parser tests.
Ideally the factory class would not use $wgMediaHandlers directly, but
that ends up breaking too many tests for now.
Change-Id: I34a63ee7089ff26f86f3dd6f3cd1a37928bc4005
'MarkpatrolledAction' => __DIR__ . '/includes/actions/MarkpatrolledAction.php',
'McTest' => __DIR__ . '/maintenance/mctest.php',
'MediaHandler' => __DIR__ . '/includes/media/MediaHandler.php',
+ 'MediaHandlerFactory' => __DIR__ . '/includes/media/MediaHandlerFactory.php',
'MediaStatisticsPage' => __DIR__ . '/includes/specials/SpecialMediaStatistics.php',
'MediaTransformError' => __DIR__ . '/includes/media/MediaTransformOutput.php',
'MediaTransformInvalidParametersException' => __DIR__ . '/includes/media/MediaTransformInvalidParametersException.php',
use LinkCache;
use Liuggio\StatsdClient\Factory\StatsdDataFactory;
use LoadBalancer;
+use MediaHandlerFactory;
use MediaWiki\Linker\LinkRenderer;
use MediaWiki\Linker\LinkRendererFactory;
use MediaWiki\Services\SalvageableService;
return $this->getService( 'WatchedItemQueryService' );
}
+ /**
+ * @since 1.28
+ * @return MediaHandlerFactory
+ */
+ public function getMediaHandlerFactory() {
+ return $this->getService( 'MediaHandlerFactory' );
+ }
+
/**
* @since 1.28
* @return GenderCache
return new WatchedItemQueryService( $services->getDBLoadBalancer() );
},
+ 'MediaHandlerFactory' => function( MediaWikiServices $services ) {
+ return new MediaHandlerFactory();
+ },
+
'LinkCache' => function( MediaWikiServices $services ) {
return new LinkCache(
$services->getTitleFormatter()
* @file
* @ingroup Media
*/
+use MediaWiki\MediaWikiServices;
/**
* Base media handler class
*/
const MAX_ERR_LOG_SIZE = 65535;
- /** @var MediaHandler[] Instance cache with array of MediaHandler */
- protected static $handlers = [];
-
/**
* Get a MediaHandler for a given MIME type from the instance cache
*
* @return MediaHandler|bool
*/
static function getHandler( $type ) {
- global $wgMediaHandlers;
- if ( !isset( $wgMediaHandlers[$type] ) ) {
- wfDebug( __METHOD__ . ": no handler found for $type.\n" );
-
- return false;
- }
- $class = $wgMediaHandlers[$type];
- if ( !isset( self::$handlers[$class] ) ) {
- self::$handlers[$class] = new $class;
- if ( !self::$handlers[$class]->isEnabled() ) {
- wfDebug( __METHOD__ . ": $class is not enabled\n" );
- self::$handlers[$class] = false;
- }
- }
-
- return self::$handlers[$class];
- }
-
- /**
- * Resets all static caches
- */
- public static function resetCache() {
- self::$handlers = [];
+ return MediaWikiServices::getInstance()
+ ->getMediaHandlerFactory()->getHandler( $type );
}
/**
--- /dev/null
+<?php
+/**
+ * Media-handling base classes and generic functionality.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Media
+ */
+
+/**
+ * Class to construct MediaHandler objects
+ *
+ * @since 1.28
+ */
+class MediaHandlerFactory {
+
+ /**
+ * @var MediaHandler[]
+ */
+ private $handlers;
+
+ /**
+ * @param string $type mimetype
+ * @return bool|MediaHandler
+ */
+ public function getHandler( $type ) {
+ global $wgMediaHandlers;
+ if ( !isset( $wgMediaHandlers[$type] ) ) {
+ wfDebug( __METHOD__ . ": no handler found for $type.\n" );
+
+ return false;
+ }
+ $class = $wgMediaHandlers[$type];
+ if ( !isset( $this->handlers[$class] ) ) {
+ $this->handlers[$class] = new $class;
+ if ( !$this->handlers[$class]->isEnabled() ) {
+ wfDebug( __METHOD__ . ": $class is not enabled\n" );
+ $this->handlers[$class] = false;
+ }
+ }
+
+ return $this->handlers[$class];
+ }
+}
// TODO: move global state into MediaWikiServices
RequestContext::resetMain();
- MediaHandler::resetCache();
if ( session_id() !== '' ) {
session_write_close();
session_id( '' );
// TODO: move global state into MediaWikiServices
RequestContext::resetMain();
- MediaHandler::resetCache();
if ( session_id() !== '' ) {
session_write_close();
session_id( '' );
'DBLoadBalancer' => [ 'DBLoadBalancer', 'LoadBalancer' ],
'WatchedItemStore' => [ 'WatchedItemStore', WatchedItemStore::class ],
'WatchedItemQueryService' => [ 'WatchedItemQueryService', WatchedItemQueryService::class ],
+ 'MediaHandlerFactory' => [ 'MediaHandlerFactory', MediaHandlerFactory::class ],
'GenderCache' => [ 'GenderCache', GenderCache::class ],
'LinkCache' => [ 'LinkCache', LinkCache::class ],
'LinkRenderer' => [ 'LinkRenderer', LinkRenderer::class ],