From 4e94b88f9943c5a9932fc854ec0c31db7dda3430 Mon Sep 17 00:00:00 2001 From: Umherirrender Date: Tue, 30 Jan 2024 23:36:55 +0100 Subject: [PATCH] Remove the VisualEditorHookRunner service The HookRunner class is a lightweight class and not designed to be a service, the needed HookContainer should be injected instead and a hook runner created when needed. The overhead from the service wiring is the same as using new objects when needed. This follows practice from core and the documentation in core/docs/Hooks.md in the section "Hook runner classes" Change-Id: Ib42281dfae8a5a260005d82ed3bb7da12e1b645e --- extension.json | 2 +- includes/ApiVisualEditorEdit.php | 5 +++-- includes/ServiceWiring.php | 4 ---- includes/VisualEditorHookRunner.php | 2 -- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/extension.json b/extension.json index af7116eae4..db1ae0885a 100644 --- a/extension.json +++ b/extension.json @@ -179,7 +179,7 @@ "visualeditoredit": { "class": "MediaWiki\\Extension\\VisualEditor\\ApiVisualEditorEdit", "services": [ - "VisualEditorHookRunner", + "HookContainer", "StatsdDataFactory", "PageEditStash", "SkinFactory", diff --git a/includes/ApiVisualEditorEdit.php b/includes/ApiVisualEditorEdit.php index 376484f4a2..0a092e8d76 100644 --- a/includes/ApiVisualEditorEdit.php +++ b/includes/ApiVisualEditorEdit.php @@ -21,6 +21,7 @@ use ExtensionRegistry; use FlaggablePageView; use IBufferingStatsdDataFactory; use IDBAccessObject; +use MediaWiki\HookContainer\HookContainer; use MediaWiki\Logger\LoggerFactory; use MediaWiki\Page\WikiPageFactory; use MediaWiki\Request\DerivativeRequest; @@ -51,7 +52,7 @@ class ApiVisualEditorEdit extends ApiBase { public function __construct( ApiMain $main, string $name, - VisualEditorHookRunner $hookRunner, + HookContainer $hookContainer, IBufferingStatsdDataFactory $statsdDataFactory, PageEditStash $pageEditStash, SkinFactory $skinFactory, @@ -62,7 +63,7 @@ class ApiVisualEditorEdit extends ApiBase { parent::__construct( $main, $name ); $this->setLogger( LoggerFactory::getInstance( 'VisualEditor' ) ); $this->setStats( $statsdDataFactory ); - $this->hookRunner = $hookRunner; + $this->hookRunner = new VisualEditorHookRunner( $hookContainer ); $this->pageEditStash = $pageEditStash; $this->skinFactory = $skinFactory; $this->wikiPageFactory = $wikiPageFactory; diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index 63e7f55f44..5f8b21c6e8 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -14,10 +14,6 @@ namespace MediaWiki\Extension\VisualEditor; use MediaWiki\MediaWikiServices; return [ - VisualEditorHookRunner::SERVICE_NAME => static function ( MediaWikiServices $services ): VisualEditorHookRunner { - return new VisualEditorHookRunner( $services->getHookContainer() ); - }, - VisualEditorParsoidClientFactory::SERVICE_NAME => static function ( MediaWikiServices $services ): VisualEditorParsoidClientFactory { diff --git a/includes/VisualEditorHookRunner.php b/includes/VisualEditorHookRunner.php index 462edd7b07..d19a674086 100644 --- a/includes/VisualEditorHookRunner.php +++ b/includes/VisualEditorHookRunner.php @@ -23,8 +23,6 @@ class VisualEditorHookRunner implements VisualEditorBeforeEditorHook { - public const SERVICE_NAME = 'VisualEditorHookRunner'; - /** @var HookContainer */ private $hookContainer;