2016-04-03 08:37:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
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;
|
|
|
|
|
use MediaWiki\HookContainer\HookRunner;
|
2019-05-14 17:00:34 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2020-11-11 22:03:32 +00:00
|
|
|
use MediaWiki\Page\WikiPageFactory;
|
2021-04-12 14:45:26 +00:00
|
|
|
use MediaWiki\User\UserNameUtils;
|
2019-05-14 17:00:34 +00:00
|
|
|
|
2016-04-03 08:37:11 +00:00
|
|
|
/**
|
|
|
|
|
* Implementation of near match title search.
|
|
|
|
|
* TODO: split into service/implementation.
|
|
|
|
|
*/
|
|
|
|
|
class SearchNearMatcher {
|
|
|
|
|
/**
|
2017-09-15 09:17:17 +00:00
|
|
|
* @var Config
|
2016-04-03 08:37:11 +00:00
|
|
|
*/
|
|
|
|
|
protected $config;
|
|
|
|
|
|
2016-04-26 22:32:13 +00:00
|
|
|
/**
|
|
|
|
|
* Current language
|
|
|
|
|
* @var Language
|
|
|
|
|
*/
|
|
|
|
|
private $language;
|
2016-04-03 08:37:11 +00:00
|
|
|
|
2020-01-23 18:39:23 +00:00
|
|
|
/**
|
|
|
|
|
* Current language converter
|
|
|
|
|
* @var ILanguageConverter
|
|
|
|
|
*/
|
|
|
|
|
private $languageConverter;
|
|
|
|
|
|
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 HookRunner
|
|
|
|
|
*/
|
|
|
|
|
private $hookRunner;
|
|
|
|
|
|
2020-11-11 22:03:32 +00:00
|
|
|
/**
|
|
|
|
|
* @var WikiPageFactory
|
|
|
|
|
*/
|
|
|
|
|
private $wikiPageFactory;
|
|
|
|
|
|
2021-04-12 14:45:26 +00:00
|
|
|
/**
|
|
|
|
|
* @var UserNameUtils
|
|
|
|
|
*/
|
|
|
|
|
private $userNameUtils;
|
|
|
|
|
|
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 Config $config
|
|
|
|
|
* @param Language $lang
|
|
|
|
|
* @param HookContainer $hookContainer
|
|
|
|
|
*/
|
|
|
|
|
public function __construct( Config $config, Language $lang, HookContainer $hookContainer ) {
|
2016-04-03 08:37:11 +00:00
|
|
|
$this->config = $config;
|
2016-04-26 22:32:13 +00:00
|
|
|
$this->language = $lang;
|
2020-11-11 22:03:32 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
$this->languageConverter = $services->getLanguageConverterFactory()
|
2020-01-23 18:39:23 +00:00
|
|
|
->getLanguageConverter( $lang );
|
2020-11-11 22:03:32 +00:00
|
|
|
$this->wikiPageFactory = $services->getWikiPageFactory();
|
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->hookRunner = new HookRunner( $hookContainer );
|
2021-04-12 14:45:26 +00:00
|
|
|
$this->userNameUtils = $services->getUserNameUtils();
|
2016-04-03 08:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If an exact title match can be found, or a very slightly close match,
|
|
|
|
|
* return the title. If no match, returns NULL.
|
|
|
|
|
*
|
|
|
|
|
* @param string $searchterm
|
|
|
|
|
* @return Title
|
|
|
|
|
*/
|
|
|
|
|
public function getNearMatch( $searchterm ) {
|
|
|
|
|
$title = $this->getNearMatchInternal( $searchterm );
|
|
|
|
|
|
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->hookRunner->onSearchGetNearMatchComplete( $searchterm, $title );
|
2016-04-03 08:37:11 +00:00
|
|
|
return $title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Do a near match (see SearchEngine::getNearMatch) and wrap it into a
|
2019-07-22 15:28:48 +00:00
|
|
|
* ISearchResultSet.
|
2016-04-03 08:37:11 +00:00
|
|
|
*
|
|
|
|
|
* @param string $searchterm
|
2019-07-22 15:28:48 +00:00
|
|
|
* @return ISearchResultSet
|
2016-04-03 08:37:11 +00:00
|
|
|
*/
|
|
|
|
|
public function getNearMatchResultSet( $searchterm ) {
|
|
|
|
|
return new SearchNearMatchResultSet( $this->getNearMatch( $searchterm ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Really find the title match.
|
|
|
|
|
* @param string $searchterm
|
|
|
|
|
* @return null|Title
|
|
|
|
|
*/
|
|
|
|
|
protected function getNearMatchInternal( $searchterm ) {
|
|
|
|
|
$allSearchTerms = [ $searchterm ];
|
|
|
|
|
|
2020-01-23 18:39:23 +00:00
|
|
|
if ( $this->languageConverter->hasVariants() ) {
|
2016-04-03 08:37:11 +00:00
|
|
|
$allSearchTerms = array_unique( array_merge(
|
|
|
|
|
$allSearchTerms,
|
2020-01-23 18:39:23 +00:00
|
|
|
$this->languageConverter->autoConvertToAllVariants( $searchterm )
|
2016-04-03 08:37:11 +00:00
|
|
|
) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$titleResult = null;
|
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
|
|
|
if ( !$this->hookRunner->onSearchGetNearMatchBefore( $allSearchTerms, $titleResult ) ) {
|
2016-04-03 08:37:11 +00:00
|
|
|
return $titleResult;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-10 20:29:08 +00:00
|
|
|
// Most of our handling here deals with finding a valid title for the search term,
|
|
|
|
|
// but almost anything starting with '#' is "valid" and points to Main_Page#searchterm.
|
|
|
|
|
// Rather than doing something completely wrong, do nothing.
|
|
|
|
|
if ( $searchterm === '' || $searchterm[0] === '#' ) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-03 08:37:11 +00:00
|
|
|
foreach ( $allSearchTerms as $term ) {
|
|
|
|
|
# Exact match? No need to look further.
|
|
|
|
|
$title = Title::newFromText( $term );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $title === null ) {
|
2016-04-03 08:37:11 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Try files if searching in the Media: namespace
|
2020-07-22 17:29:48 +00:00
|
|
|
if ( $title->getNamespace() === NS_MEDIA ) {
|
2016-04-03 08:37:11 +00:00
|
|
|
$title = Title::makeTitle( NS_FILE, $title->getText() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $title->isSpecialPage() || $title->isExternal() || $title->exists() ) {
|
|
|
|
|
return $title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# See if it still otherwise has content is some sane sense
|
2021-03-03 19:38:59 +00:00
|
|
|
if ( $title->canExist() ) {
|
|
|
|
|
$page = $this->wikiPageFactory->newFromTitle( $title );
|
|
|
|
|
if ( $page->hasViewableContent() ) {
|
|
|
|
|
return $title;
|
|
|
|
|
}
|
2016-04-03 08:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
if ( !$this->hookRunner->onSearchAfterNoDirectMatch( $term, $title ) ) {
|
2016-04-03 08:37:11 +00:00
|
|
|
return $title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Now try all lower case (i.e. first letter capitalized)
|
2020-02-10 17:47:35 +00:00
|
|
|
$title = Title::newFromText( $this->language->lc( $term ) );
|
2016-04-03 08:37:11 +00:00
|
|
|
if ( $title && $title->exists() ) {
|
|
|
|
|
return $title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Now try capitalized string
|
2020-02-10 17:47:35 +00:00
|
|
|
$title = Title::newFromText( $this->language->ucwords( $term ) );
|
2016-04-03 08:37:11 +00:00
|
|
|
if ( $title && $title->exists() ) {
|
|
|
|
|
return $title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Now try all upper case
|
2020-02-10 17:47:35 +00:00
|
|
|
$title = Title::newFromText( $this->language->uc( $term ) );
|
2016-04-03 08:37:11 +00:00
|
|
|
if ( $title && $title->exists() ) {
|
|
|
|
|
return $title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc
|
2020-02-10 17:47:35 +00:00
|
|
|
$title = Title::newFromText( $this->language->ucwordbreaks( $term ) );
|
2016-04-03 08:37:11 +00:00
|
|
|
if ( $title && $title->exists() ) {
|
|
|
|
|
return $title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Give hooks a chance at better match variants
|
|
|
|
|
$title = null;
|
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
|
|
|
if ( !$this->hookRunner->onSearchGetNearMatch( $term, $title ) ) {
|
2016-04-03 08:37:11 +00:00
|
|
|
return $title;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$title = Title::newFromText( $searchterm );
|
|
|
|
|
|
|
|
|
|
# Entering an IP address goes to the contributions page
|
|
|
|
|
if ( $this->config->get( 'EnableSearchContributorsByIP' ) ) {
|
2021-04-12 14:45:26 +00:00
|
|
|
if ( ( $title->getNamespace() === NS_USER && $this->userNameUtils->isIP( $title->getText() ) )
|
|
|
|
|
|| $this->userNameUtils->isIP( trim( $searchterm ) ) ) {
|
2016-04-03 08:37:11 +00:00
|
|
|
return SpecialPage::getTitleFor( 'Contributions', $title->getDBkey() );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Entering a user goes to the user page whether it's there or not
|
2020-07-22 17:29:48 +00:00
|
|
|
if ( $title->getNamespace() === NS_USER ) {
|
2016-04-03 08:37:11 +00:00
|
|
|
return $title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Go to images that exist even if there's no local page.
|
|
|
|
|
# There may have been a funny upload, or it may be on a shared
|
|
|
|
|
# file repository such as Wikimedia Commons.
|
2020-07-22 17:29:48 +00:00
|
|
|
if ( $title->getNamespace() === NS_FILE ) {
|
2019-05-14 17:00:34 +00:00
|
|
|
$image = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $title );
|
2016-04-03 08:37:11 +00:00
|
|
|
if ( $image ) {
|
|
|
|
|
return $title;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# MediaWiki namespace? Page may be "implied" if not customized.
|
|
|
|
|
# Just return it, with caps forced as the message system likes it.
|
2020-07-22 17:29:48 +00:00
|
|
|
if ( $title->getNamespace() === NS_MEDIAWIKI ) {
|
2020-02-10 17:47:35 +00:00
|
|
|
return Title::makeTitle( NS_MEDIAWIKI, $this->language->ucfirst( $title->getText() ) );
|
2016-04-03 08:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Quoted term? Try without the quotes...
|
|
|
|
|
$matches = [];
|
|
|
|
|
if ( preg_match( '/^"([^"]+)"$/', $searchterm, $matches ) ) {
|
2019-04-18 13:09:02 +00:00
|
|
|
return $this->getNearMatch( $matches[1] );
|
2016-04-03 08:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|