2018-08-03 08:25:15 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* 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 Parser
|
|
|
|
|
*/
|
2019-04-12 09:50:30 +00:00
|
|
|
|
2024-10-03 18:39:06 +00:00
|
|
|
namespace MediaWiki\Parser;
|
|
|
|
|
|
2023-02-09 18:59:23 +00:00
|
|
|
use MediaWiki\Category\TrackingCategories;
|
2019-04-12 09:50:30 +00:00
|
|
|
use MediaWiki\Config\ServiceOptions;
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
use MediaWiki\HookContainer\HookContainer;
|
2021-08-04 12:56:30 +00:00
|
|
|
use MediaWiki\Http\HttpRequestFactory;
|
2024-10-03 18:39:06 +00:00
|
|
|
use MediaWiki\Language\Language;
|
2020-02-04 12:42:03 +00:00
|
|
|
use MediaWiki\Languages\LanguageConverterFactory;
|
2023-12-27 19:44:12 +00:00
|
|
|
use MediaWiki\Languages\LanguageNameUtils;
|
2018-08-08 14:57:31 +00:00
|
|
|
use MediaWiki\Linker\LinkRendererFactory;
|
2023-02-22 17:51:26 +00:00
|
|
|
use MediaWiki\Page\File\BadFileLookup;
|
2022-04-07 23:52:05 +00:00
|
|
|
use MediaWiki\Preferences\SignatureValidatorFactory;
|
2020-02-21 00:01:43 +00:00
|
|
|
use MediaWiki\SpecialPage\SpecialPageFactory;
|
2021-02-18 16:51:12 +00:00
|
|
|
use MediaWiki\Tidy\TidyDriverBase;
|
2023-09-18 14:17:28 +00:00
|
|
|
use MediaWiki\Title\NamespaceInfo;
|
2023-09-18 14:26:53 +00:00
|
|
|
use MediaWiki\Title\TitleFormatter;
|
2023-11-29 10:21:43 +00:00
|
|
|
use MediaWiki\User\Options\UserOptionsLookup;
|
2021-03-16 18:31:27 +00:00
|
|
|
use MediaWiki\User\UserFactory;
|
2022-04-11 01:26:51 +00:00
|
|
|
use MediaWiki\User\UserNameUtils;
|
2022-04-28 13:33:39 +00:00
|
|
|
use MediaWiki\Utils\UrlUtils;
|
2019-06-27 03:35:50 +00:00
|
|
|
use Psr\Log\LoggerInterface;
|
2024-09-27 18:13:02 +00:00
|
|
|
use Wikimedia\ObjectCache\WANObjectCache;
|
2018-08-15 01:11:59 +00:00
|
|
|
|
2018-08-03 08:25:15 +00:00
|
|
|
/**
|
|
|
|
|
* @since 1.32
|
|
|
|
|
*/
|
|
|
|
|
class ParserFactory {
|
2019-04-12 09:50:30 +00:00
|
|
|
/** @var ServiceOptions */
|
|
|
|
|
private $svcOptions;
|
2018-08-03 08:25:15 +00:00
|
|
|
|
|
|
|
|
/** @var MagicWordFactory */
|
|
|
|
|
private $magicWordFactory;
|
|
|
|
|
|
|
|
|
|
/** @var Language */
|
|
|
|
|
private $contLang;
|
|
|
|
|
|
2022-04-28 13:33:39 +00:00
|
|
|
/** @var UrlUtils */
|
|
|
|
|
private $urlUtils;
|
2018-08-03 08:25:15 +00:00
|
|
|
|
2018-08-15 01:11:59 +00:00
|
|
|
/** @var SpecialPageFactory */
|
|
|
|
|
private $specialPageFactory;
|
|
|
|
|
|
2018-08-08 14:57:31 +00:00
|
|
|
/** @var LinkRendererFactory */
|
|
|
|
|
private $linkRendererFactory;
|
|
|
|
|
|
2018-08-05 12:50:01 +00:00
|
|
|
/** @var NamespaceInfo */
|
|
|
|
|
private $nsInfo;
|
|
|
|
|
|
2019-06-27 03:35:50 +00:00
|
|
|
/** @var LoggerInterface */
|
|
|
|
|
private $logger;
|
|
|
|
|
|
2019-08-18 18:19:05 +00:00
|
|
|
/** @var BadFileLookup */
|
|
|
|
|
private $badFileLookup;
|
|
|
|
|
|
2020-02-04 12:42:03 +00:00
|
|
|
/** @var LanguageConverterFactory */
|
|
|
|
|
private $languageConverterFactory;
|
|
|
|
|
|
2023-12-27 19:44:12 +00:00
|
|
|
/** @var LanguageNameUtils */
|
|
|
|
|
private $languageNameUtils;
|
|
|
|
|
|
2021-03-16 18:31:27 +00:00
|
|
|
/** @var UserOptionsLookup */
|
|
|
|
|
private $userOptionsLookup;
|
|
|
|
|
|
|
|
|
|
/** @var UserFactory */
|
|
|
|
|
private $userFactory;
|
|
|
|
|
|
2021-04-25 17:29:33 +00:00
|
|
|
/** @var TitleFormatter */
|
|
|
|
|
private $titleFormatter;
|
|
|
|
|
|
2021-08-04 12:56:30 +00:00
|
|
|
/** @var HttpRequestFactory */
|
|
|
|
|
private $httpRequestFactory;
|
|
|
|
|
|
2021-10-08 16:37:26 +00:00
|
|
|
/** @var TrackingCategories */
|
|
|
|
|
private $trackingCategories;
|
|
|
|
|
|
2022-04-07 23:52:05 +00:00
|
|
|
/** @var SignatureValidatorFactory */
|
|
|
|
|
private $signatureValidatorFactory;
|
|
|
|
|
|
2022-04-11 01:26:51 +00:00
|
|
|
/** @var UserNameUtils */
|
|
|
|
|
private $userNameUtils;
|
|
|
|
|
|
2020-04-16 14:46:00 +00:00
|
|
|
/**
|
|
|
|
|
* Track calls to Parser constructor to aid in deprecation of direct
|
|
|
|
|
* Parser invocation. This is temporary: it will be removed once the
|
|
|
|
|
* deprecation notice period is over and the underlying method calls
|
|
|
|
|
* are refactored.
|
|
|
|
|
* @internal
|
|
|
|
|
* @var int
|
|
|
|
|
*/
|
|
|
|
|
public static $inParserFactory = 0;
|
|
|
|
|
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
/** @var HookContainer */
|
|
|
|
|
private $hookContainer;
|
|
|
|
|
|
2021-02-18 16:51:12 +00:00
|
|
|
/** @var TidyDriverBase */
|
|
|
|
|
private $tidy;
|
|
|
|
|
|
2021-02-19 17:26:39 +00:00
|
|
|
/** @var WANObjectCache */
|
|
|
|
|
private $wanCache;
|
|
|
|
|
|
2022-06-20 03:48:44 +00:00
|
|
|
/** @var Parser|null */
|
|
|
|
|
private $mainInstance;
|
|
|
|
|
|
2018-08-03 08:25:15 +00:00
|
|
|
/**
|
2020-02-04 12:42:03 +00:00
|
|
|
* @param ServiceOptions $svcOptions
|
2018-08-03 08:25:15 +00:00
|
|
|
* @param MagicWordFactory $magicWordFactory
|
|
|
|
|
* @param Language $contLang Content language
|
2022-04-28 13:33:39 +00:00
|
|
|
* @param UrlUtils $urlUtils
|
2018-08-15 01:11:59 +00:00
|
|
|
* @param SpecialPageFactory $spFactory
|
2018-08-08 14:57:31 +00:00
|
|
|
* @param LinkRendererFactory $linkRendererFactory
|
2020-02-04 12:42:03 +00:00
|
|
|
* @param NamespaceInfo $nsInfo
|
|
|
|
|
* @param LoggerInterface $logger
|
|
|
|
|
* @param BadFileLookup $badFileLookup
|
|
|
|
|
* @param LanguageConverterFactory $languageConverterFactory
|
2023-12-27 19:44:12 +00:00
|
|
|
* @param LanguageNameUtils $languageNameUtils
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
* @param HookContainer $hookContainer
|
2021-02-18 16:51:12 +00:00
|
|
|
* @param TidyDriverBase $tidy
|
2021-02-19 17:26:39 +00:00
|
|
|
* @param WANObjectCache $wanCache
|
2021-03-16 18:31:27 +00:00
|
|
|
* @param UserOptionsLookup $userOptionsLookup
|
|
|
|
|
* @param UserFactory $userFactory
|
2021-04-25 17:29:33 +00:00
|
|
|
* @param TitleFormatter $titleFormatter
|
2021-08-04 12:56:30 +00:00
|
|
|
* @param HttpRequestFactory $httpRequestFactory
|
2021-10-08 16:37:26 +00:00
|
|
|
* @param TrackingCategories $trackingCategories
|
2022-04-07 23:52:05 +00:00
|
|
|
* @param SignatureValidatorFactory $signatureValidatorFactory
|
2022-04-11 01:26:51 +00:00
|
|
|
* @param UserNameUtils $userNameUtils
|
2018-08-03 08:25:15 +00:00
|
|
|
* @since 1.32
|
2021-02-18 16:51:12 +00:00
|
|
|
* @internal
|
2018-08-03 08:25:15 +00:00
|
|
|
*/
|
|
|
|
|
public function __construct(
|
2020-02-04 12:42:03 +00:00
|
|
|
ServiceOptions $svcOptions,
|
2019-06-27 03:35:50 +00:00
|
|
|
MagicWordFactory $magicWordFactory,
|
|
|
|
|
Language $contLang,
|
2022-04-28 13:33:39 +00:00
|
|
|
UrlUtils $urlUtils,
|
2019-06-27 03:35:50 +00:00
|
|
|
SpecialPageFactory $spFactory,
|
2020-02-04 12:42:03 +00:00
|
|
|
LinkRendererFactory $linkRendererFactory,
|
|
|
|
|
NamespaceInfo $nsInfo,
|
|
|
|
|
LoggerInterface $logger,
|
|
|
|
|
BadFileLookup $badFileLookup,
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
LanguageConverterFactory $languageConverterFactory,
|
2023-12-27 19:44:12 +00:00
|
|
|
LanguageNameUtils $languageNameUtils,
|
2021-02-18 16:51:12 +00:00
|
|
|
HookContainer $hookContainer,
|
2021-02-19 17:26:39 +00:00
|
|
|
TidyDriverBase $tidy,
|
2021-03-16 18:31:27 +00:00
|
|
|
WANObjectCache $wanCache,
|
|
|
|
|
UserOptionsLookup $userOptionsLookup,
|
2021-04-25 17:29:33 +00:00
|
|
|
UserFactory $userFactory,
|
2021-08-04 12:56:30 +00:00
|
|
|
TitleFormatter $titleFormatter,
|
2021-10-08 16:37:26 +00:00
|
|
|
HttpRequestFactory $httpRequestFactory,
|
2022-04-07 23:52:05 +00:00
|
|
|
TrackingCategories $trackingCategories,
|
2022-04-11 01:26:51 +00:00
|
|
|
SignatureValidatorFactory $signatureValidatorFactory,
|
|
|
|
|
UserNameUtils $userNameUtils
|
2018-08-03 08:25:15 +00:00
|
|
|
) {
|
2019-10-08 18:30:42 +00:00
|
|
|
$svcOptions->assertRequiredOptions( Parser::CONSTRUCTOR_OPTIONS );
|
2019-04-12 09:50:30 +00:00
|
|
|
|
2020-06-01 05:00:39 +00:00
|
|
|
wfDebug( __CLASS__ . ": using default preprocessor" );
|
2019-04-12 09:50:30 +00:00
|
|
|
|
|
|
|
|
$this->svcOptions = $svcOptions;
|
2018-08-03 08:25:15 +00:00
|
|
|
$this->magicWordFactory = $magicWordFactory;
|
|
|
|
|
$this->contLang = $contLang;
|
2022-04-28 13:33:39 +00:00
|
|
|
$this->urlUtils = $urlUtils;
|
2018-08-15 01:11:59 +00:00
|
|
|
$this->specialPageFactory = $spFactory;
|
2018-08-08 14:57:31 +00:00
|
|
|
$this->linkRendererFactory = $linkRendererFactory;
|
2018-08-05 12:50:01 +00:00
|
|
|
$this->nsInfo = $nsInfo;
|
2020-02-04 12:42:03 +00:00
|
|
|
$this->logger = $logger;
|
|
|
|
|
$this->badFileLookup = $badFileLookup;
|
|
|
|
|
$this->languageConverterFactory = $languageConverterFactory;
|
2023-12-27 19:44:12 +00:00
|
|
|
$this->languageNameUtils = $languageNameUtils;
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
$this->hookContainer = $hookContainer;
|
2021-02-18 16:51:12 +00:00
|
|
|
$this->tidy = $tidy;
|
2021-02-19 17:26:39 +00:00
|
|
|
$this->wanCache = $wanCache;
|
2021-03-16 18:31:27 +00:00
|
|
|
$this->userOptionsLookup = $userOptionsLookup;
|
|
|
|
|
$this->userFactory = $userFactory;
|
2021-04-25 17:29:33 +00:00
|
|
|
$this->titleFormatter = $titleFormatter;
|
2021-08-04 12:56:30 +00:00
|
|
|
$this->httpRequestFactory = $httpRequestFactory;
|
2021-10-08 16:37:26 +00:00
|
|
|
$this->trackingCategories = $trackingCategories;
|
2022-04-07 23:52:05 +00:00
|
|
|
$this->signatureValidatorFactory = $signatureValidatorFactory;
|
2022-04-11 01:26:51 +00:00
|
|
|
$this->userNameUtils = $userNameUtils;
|
2018-08-03 08:25:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-02-04 12:42:03 +00:00
|
|
|
* Creates a new parser
|
|
|
|
|
*
|
2023-10-07 20:57:53 +00:00
|
|
|
* @note Use this function to get a new Parser instance to store
|
|
|
|
|
* in a local class property. Where possible use lazy creation and
|
|
|
|
|
* create the Parser only when needed, not directly in service wiring.
|
|
|
|
|
*
|
2018-08-03 08:25:15 +00:00
|
|
|
* @return Parser
|
|
|
|
|
* @since 1.32
|
|
|
|
|
*/
|
2021-07-22 03:11:47 +00:00
|
|
|
public function create(): Parser {
|
2020-04-16 14:46:00 +00:00
|
|
|
self::$inParserFactory++;
|
|
|
|
|
try {
|
|
|
|
|
return new Parser(
|
|
|
|
|
$this->svcOptions,
|
|
|
|
|
$this->magicWordFactory,
|
|
|
|
|
$this->contLang,
|
|
|
|
|
$this,
|
2022-04-28 13:33:39 +00:00
|
|
|
$this->urlUtils,
|
2020-04-16 14:46:00 +00:00
|
|
|
$this->specialPageFactory,
|
|
|
|
|
$this->linkRendererFactory,
|
|
|
|
|
$this->nsInfo,
|
|
|
|
|
$this->logger,
|
|
|
|
|
$this->badFileLookup,
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
$this->languageConverterFactory,
|
2023-12-27 19:44:12 +00:00
|
|
|
$this->languageNameUtils,
|
2021-02-18 16:51:12 +00:00
|
|
|
$this->hookContainer,
|
2021-02-19 17:26:39 +00:00
|
|
|
$this->tidy,
|
2021-03-16 18:31:27 +00:00
|
|
|
$this->wanCache,
|
|
|
|
|
$this->userOptionsLookup,
|
2021-04-25 17:29:33 +00:00
|
|
|
$this->userFactory,
|
2021-08-04 12:56:30 +00:00
|
|
|
$this->titleFormatter,
|
2021-10-08 16:37:26 +00:00
|
|
|
$this->httpRequestFactory,
|
2022-04-07 23:52:05 +00:00
|
|
|
$this->trackingCategories,
|
2022-04-11 01:26:51 +00:00
|
|
|
$this->signatureValidatorFactory,
|
|
|
|
|
$this->userNameUtils
|
2020-04-16 14:46:00 +00:00
|
|
|
);
|
|
|
|
|
} finally {
|
|
|
|
|
self::$inParserFactory--;
|
|
|
|
|
}
|
2018-08-03 08:25:15 +00:00
|
|
|
}
|
2022-06-20 03:48:44 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the main shared instance. This is unsafe when the caller is not in
|
|
|
|
|
* a top-level context, because re-entering the parser will throw an
|
|
|
|
|
* exception.
|
|
|
|
|
*
|
2023-10-07 20:57:53 +00:00
|
|
|
* @note This function is used to get metadata from the parser. Avoid
|
|
|
|
|
* using this function to parse wikitext. (Generally avoid using this
|
|
|
|
|
* function at all in new code.)
|
|
|
|
|
*
|
2022-06-20 03:48:44 +00:00
|
|
|
* @since 1.39
|
|
|
|
|
* @return Parser
|
|
|
|
|
*/
|
|
|
|
|
public function getMainInstance() {
|
|
|
|
|
if ( $this->mainInstance === null ) {
|
|
|
|
|
$this->mainInstance = $this->create();
|
|
|
|
|
}
|
|
|
|
|
return $this->mainInstance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the main shared instance, or if it is locked, get a new instance
|
|
|
|
|
*
|
2023-10-07 20:57:53 +00:00
|
|
|
* @note This function was used to parse wikitext. The instance it
|
|
|
|
|
* returned should be used only in local scope. Do not hold a
|
|
|
|
|
* reference to this parser in class properties. In general,
|
|
|
|
|
* avoid using this method and use ::create() instead.
|
|
|
|
|
*
|
2022-06-20 03:48:44 +00:00
|
|
|
* @since 1.39
|
|
|
|
|
* @return Parser
|
|
|
|
|
*/
|
|
|
|
|
public function getInstance() {
|
|
|
|
|
$instance = $this->getMainInstance();
|
|
|
|
|
if ( $instance->isLocked() ) {
|
|
|
|
|
$instance = $this->create();
|
|
|
|
|
}
|
|
|
|
|
return $instance;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-03 08:25:15 +00:00
|
|
|
}
|
2024-10-03 18:39:06 +00:00
|
|
|
|
|
|
|
|
/** @deprecated class alias since 1.43 */
|
|
|
|
|
class_alias( ParserFactory::class, 'ParserFactory' );
|