[MediaWiki-commits] [Gerrit] mediawiki/core[master]: MediaHandlerFactory: Don't use any global state

2016-08-04 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: MediaHandlerFactory: Don't use any global state
..


MediaHandlerFactory: Don't use any global state

Instead inject the configured MediaHandlers in the service constructor.

Change-Id: I039c01ef531389c74524cb7adcb8cf1229d9a95d
---
M includes/ServiceWiring.php
M includes/media/MediaHandlerFactory.php
M tests/phpunit/mocks/media/MockMediaHandlerFactory.php
3 files changed, 18 insertions(+), 6 deletions(-)

Approvals:
  Addshore: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php
index 438f667..21c6377 100644
--- a/includes/ServiceWiring.php
+++ b/includes/ServiceWiring.php
@@ -159,7 +159,9 @@
},
 
'MediaHandlerFactory' => function( MediaWikiServices $services ) {
-   return new MediaHandlerFactory();
+   return new MediaHandlerFactory(
+   $services->getMainConfig()->get( 'MediaHandlers' )
+   );
},
 
'LinkCache' => function( MediaWikiServices $services ) {
diff --git a/includes/media/MediaHandlerFactory.php 
b/includes/media/MediaHandlerFactory.php
index 1deecd7..543dc80 100644
--- a/includes/media/MediaHandlerFactory.php
+++ b/includes/media/MediaHandlerFactory.php
@@ -50,18 +50,24 @@
];
 
/**
+* @var array
+*/
+   private $registry;
+
+   /**
 * Instance cache of MediaHandler objects by mimetype
 *
 * @var MediaHandler[]
 */
private $handlers;
 
-   protected function getHandlerClass( $type ) {
-   global $wgMediaHandlers;
+   public function __construct( array $registry ) {
+   $this->registry = $registry + self::$coreHandlers;
+   }
 
-   $registry = $wgMediaHandlers + self::$coreHandlers;
-   if ( isset( $registry[$type] ) ) {
-   return $registry[$type];
+   protected function getHandlerClass( $type ) {
+   if ( isset( $this->registry[$type] ) ) {
+   return $this->registry[$type];
} else {
return false;
}
diff --git a/tests/phpunit/mocks/media/MockMediaHandlerFactory.php 
b/tests/phpunit/mocks/media/MockMediaHandlerFactory.php
index 0bcc6eb..54d46b0 100644
--- a/tests/phpunit/mocks/media/MockMediaHandlerFactory.php
+++ b/tests/phpunit/mocks/media/MockMediaHandlerFactory.php
@@ -36,6 +36,10 @@
'application/ogg' => MockOggHandler::class,
];
 
+   public function __construct() {
+   // override parent
+   }
+
protected function getHandlerClass( $type ) {
if ( isset( self::$overrides[$type] ) ) {
return self::$overrides[$type];

-- 
To view, visit https://gerrit.wikimedia.org/r/301729
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I039c01ef531389c74524cb7adcb8cf1229d9a95d
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm 
Gerrit-Reviewer: Aaron Schulz 
Gerrit-Reviewer: Addshore 
Gerrit-Reviewer: jenkins-bot <>

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki/core[master]: MediaHandlerFactory: Don't use any global state

2016-07-28 Thread Legoktm (Code Review)
Legoktm has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/301729

Change subject: MediaHandlerFactory: Don't use any global state
..

MediaHandlerFactory: Don't use any global state

Instead inject the configured MediaHandlers in the service constructor.

Change-Id: I039c01ef531389c74524cb7adcb8cf1229d9a95d
---
M includes/ServiceWiring.php
M includes/media/MediaHandlerFactory.php
M tests/phpunit/mocks/media/MockMediaHandlerFactory.php
3 files changed, 18 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/29/301729/1

diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php
index 438f667..21c6377 100644
--- a/includes/ServiceWiring.php
+++ b/includes/ServiceWiring.php
@@ -159,7 +159,9 @@
},
 
'MediaHandlerFactory' => function( MediaWikiServices $services ) {
-   return new MediaHandlerFactory();
+   return new MediaHandlerFactory(
+   $services->getMainConfig()->get( 'MediaHandlers' )
+   );
},
 
'LinkCache' => function( MediaWikiServices $services ) {
diff --git a/includes/media/MediaHandlerFactory.php 
b/includes/media/MediaHandlerFactory.php
index d87e730..4bfd9e4 100644
--- a/includes/media/MediaHandlerFactory.php
+++ b/includes/media/MediaHandlerFactory.php
@@ -50,18 +50,24 @@
];
 
/**
+* @var array
+*/
+   private $registry;
+
+   /**
 * Instance cache of MediaHandler objects by mimetype
 *
 * @var MediaHandler[]
 */
private $handlers;
 
-   protected function getHandlerClass( $type) {
-   global $wgMediaHandlers;
+   public function __construct( array $registry ) {
+   $this->registry = $registry + self::$coreHandlers;
+   }
 
-   $registry = $wgMediaHandlers + self::$coreHandlers;
-   if ( isset( $registry[$type] ) ) {
-   return $registry[$type];
+   protected function getHandlerClass( $type) {
+   if ( isset( $this->registry[$type] ) ) {
+   return $this->registry[$type];
} else {
return false;
}
diff --git a/tests/phpunit/mocks/media/MockMediaHandlerFactory.php 
b/tests/phpunit/mocks/media/MockMediaHandlerFactory.php
index 0bcc6eb..54d46b0 100644
--- a/tests/phpunit/mocks/media/MockMediaHandlerFactory.php
+++ b/tests/phpunit/mocks/media/MockMediaHandlerFactory.php
@@ -36,6 +36,10 @@
'application/ogg' => MockOggHandler::class,
];
 
+   public function __construct() {
+   // override parent
+   }
+
protected function getHandlerClass( $type ) {
if ( isset( self::$overrides[$type] ) ) {
return self::$overrides[$type];

-- 
To view, visit https://gerrit.wikimedia.org/r/301729
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I039c01ef531389c74524cb7adcb8cf1229d9a95d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits