Replace WikiPage::factory with a proper factory object with dependency
injection (only for dependencies needed by the factory methods,
not WikiPage itself).
Change-Id: Ie7d6e40d8387d8bc4f8592a31fdd70d0aad510ae
This causes some IDE warnings with tools that cannot understand the conditional logic.
These warnings are also very annoying because ::getInstance() is used in lots of places.
Change-Id: I00eb86c3e318b2f4c2c64388f7db52e5f9603893
Makes it possible to mock static User methods in tests;
actually introducing dependency injection to the User class is left for
the future.
New class has 100% code coverage
Bug: T253432
Change-Id: I0b93da09124d95beafd84e932b214909ce920230
This intentionally doesn't change the usages of SpecialBlock
method nor does it mark it as deprecated, because that is planned
to be done in follow-up patches:
* Ide31da469297f4582ad0e3f7f1a7c40d542923f8
* Ifdced735b694b85116cb0e43dadbfa8e4cdb8cab
Bug: T189073
Bug: T251861
Change-Id: Ib230f1cdb745937fac7512924f1d79e7b3542ab0
This is the first in a chain of patches that iteratively create
the me/contributions endpoint that returns a list
of contributions by the currently logged in user.
This patch contains stubs for major classes needed
as well as implementation and test just for returning
a 401 Unauthorized for anonymous users.
Bug:T252202
Change-Id: Ib75711bb015f476e9d486cb3008eb7b06b148d00
Introduce a UserGroupManagerFactory and UserGroupManager.
The factory utilizes the same pattern as RevisionStore
for access to user groups of a foreign wiki.
Some user group related methods were ported from User
and UserGroupMembership and deprecated, more methods to
be moved over in future patches, not to make this one to large.
Eventually as all the group-related methods are moved and their
usages are replaced, the need for the UserRightsProxy will disappear,
thus it also will be deprecated and removed. Currently for backwards
compatibility, I've had to create artificial UserIdentityValue
objects in some of the deprecated methods to avoid making transitional
temporary methods in the UserGroupManager that would take user ID
instead of the UserIdentity. All of this will go away once migration
to UserGroupManager is completed.
Bug: T234921
Change-Id: If29c6a03dfdbb80b2e846243f7e384b334da9f07
Replaces watchlist notification methods in Title and User classes:
* Title::getNotificationTimestamp -> ::getTitleNotificationTimestamp
* User::clearNotification -> ::clearTitleUserNotifications
* User::clearAllNotifications -> ::clearAllUserNotifications
New service has 67.90% code coverage with pure Unit tests; as well
as integration tests for the DeferredUpdates part
A follow-up patch will deprecate the replaced methods, as well
as document that the `UserClearNewTalkNotification` hook now only
provides a UserIdentity (typehint added in T253435 but until now
a full User was still provided).
Bug: T208777
Change-Id: I6f388c04cb9dc65b20ff028ece607c3dc131dfc5
Moved to the new service are the following User:: methods:
* ::getEditCount
* ::getFirstEditTimestamp
* ::getLatestEditTimestamp
* ::getEditTimestamp
* ::initEditCountInternal
A subsequent patch will replace existing uses in core and deprecate the
User methods.
The new service has 100% test coverage with pure Unit tests.
Bug: T253431
Change-Id: If96f9d41026aa358c0fe269a3e078af5f6f058f2
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
Move handling of the different services that are created with
NameTableStoreFactory to ServiceWiring, so that MediaWikiServices
can just call $this->getService() and nothing else.
For objects created from specs via ObjectFactory, services are retrieved
via ContainerInterface::get( 'ServiceName' ), an alias for ::getService.
Since the different stores created with NameTableStoreFactory were not
individually defined as services, they would not have been usable
with an ObjectFactory spec.
Change-Id: I8f862efeffe91a8ca1c4cbc48a5c429d6c78973c
For checks against `$wgSpamRegex` and `$wgSummarySpamRegex`.
EditPage methods will be deprecated in a separate follow-up patch,
as well as making use of the service where needed.
Bug: T251015
Change-Id: I12120b51073c31680713204cfeb5c61c0ca8c52c
* The hook that's being deprecated is not used anywhere
in MW ecosystem.
* The getNewMessageLinks/getNewMessageRevisionId wasn't
ported to the service, only the DB lookup. The interface
of these two methods is extremelly weird, the idea is that
they should eventually be able to do cross-wiki lookups.
This doesn't belong in the service - with only a single caller,
these methods should be moved out of User and inlined into the
caller instead.
* There's been a little bit of preparation done to T146585#4233276
as the interface of setNewTalk was split into set and remove
with the idea that we gotta require Revision to be passed to
setUserHasNewMessages eventually. B/C is still maintained though
since service-conversion patches are not a right place for making
behavioural changes
* The tests are only integration tests since most of the logic
in the manager is tied up to the database anyway.
Bug: T239640
Change-Id: Ia0a52865970c11066d1089196251f62ffeaa53bb
Per 0adc5f3, this method was added in MediaWiki 1.35. It's important
to add this indicator for extension developers when requiring certain
MW versions so they don't assume.
Change-Id: Iaebf127be14e0346f6ef7e520102b466a407ce9b
It makes even less sense now that HookRunner has been modularized, with
API hooks being split out to ApiHookRunner. HookRunner is inherently
local and private and doesn't deserve to be a namespace.
Change-Id: I97ddc56e96c7bfeb1594f4a84619665aee9c401c
This converts user options management to a separate
service for use in DI context.
User options are accessed quite early on in installation
process and full-on options management depends on the
database. Prior we have protected from accessing the DB
by setting a hacky $wgUser with 0 id, and relying on the
implementation that it doesn't go into the database to
get the default user options. Now we can't really do that
since DBLoadBalancer is required to instantiate the options
manager. Instead, we redefine the options manager with
a DefaultOptionsManager, that only provides access to
default options and doesn't require DB access.
UserOptionsManager uses PreferencesFactory, however
injecting it will produce a cyclic dependency. The problem
is that we separate options to different kinds, which are
inferred from the PreferencesFactory declaration for those
options (e.g. if it's a radio button in the UI declaration,
the option is of multiselect kind). This is plain wrong,
the dependency should be wise versa. This will be addressed
separately, since it's requires larger refactoring. For now
the PreferencesFactory is obtained on demand. This will be
addressed in a followup.
Bug: T248527
Change-Id: I74917c5eaec184d188911a319895b941ed55ee87
New classes and modificatons to existing classes to support the new Hooks system. All changes are documented in RFC https://phabricator.wikimedia.org/T240307.
- HookContainer.php: Class for doing much of what Hooks.php has historically done, but enabling new-style hooks to be processed and registered. Changes include new ways of defining hook handler functions as an object with defined dependencies in extension.json, removing runWithoutAbort() and addit it to an $options parameter to be passed to HookContainer::run(), being able to decipher whether a hook handler is legacy or non-legacy style and run them in the appropriate way, etc.
- DeprecatedHooks.php: For marking hooks deprecated and verifying if one is deprecated
- DeprecatedHooksTest.php: Unit tests for DeprecatedHooks.php
- Hooks.php: register() will now additionally register hooks with handlers in new HooksContainer.php. getHandlers() will be a legacy wrapper for calling the newer HookContainer::getHandlers()
- MediaWikiServices.php: Added getHookContainer() for retrieving HookContainer singleton
- ExtensionProcessor.php: modified extractHooks() to be able to extract new style handler objects being registered in extension.json
- ServiceWiring.php: Added HookContainer to list of services to return
- HookContainerTest.php: Unit tests for HookContainer.php
- ExtensionProcessorTest.php: Moved file out of /unit folder and now extends MediaWikiTestCase instead of MediaWikiUnitTestCase (as the tests are not truly unit tests). Modified existing tests for ExtensionProcessor::extractHooks() to include a test case for new style handler
Bug: T240307
Change-Id: I432861d8995cfd7180e77e115251d8055b7eceec
This is a re-submit of 35da1bbd7c, which was accidentally merged before
CR (and reverted with aa4da3c2e8).
The purge() method handles purging of both file cache and CDN, using
a PRESEND deferred update. This avoids code duplication and missing
file cache purge calls.
Also:
* Migrate HTMLCacheUpdate callers to just directly using HTMLCacheUpdateJob
* Add HtmlFileCacheUpdate class and defer such updates just like with CDN
* Simplify HTMLCacheUpdate constructor parameters
* Remove BacklinkCache::clear() calls which do nothing since the backlink
query does not actually happen until the job runs
Bug: T230025
Change-Id: Ic1005e70e2c22d5bd1ca36dcdb618108ebe290f3
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.
Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.
UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.
User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated
A follow up patch will add this to the release notes, to avoid merge
conflicts.
Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
In order to test functionality dependant on sending emails
Emailer should be introduced as service
Bug: T247229
Change-Id: I4fcceb7860a9a4dda091fb4cffcd2f6950fffaf8
Follows-up d4045035b0.
This class was added to the MediaWiki\Special namespace, contrary to the
plan in T166010 which reserves that namespace for core special pages.
Instead, use MediaWiki\SpecialPage, following the directory in which it
is located.
Also, fix two bugs which prevented the introduction of a namespaced
class alias.
Bug: T166010
Change-Id: I6e31340aaae32a89beb7e45b79d76a7fea9808d2
Added:
- ContentHandlerFactory
Tests:
- PHPUnit
Changed
- Calls of changed and deprecated
- DI for some service/api
Deprecated:
- ContentHandler::* then similar to ContentHandlerFactory
- ContentHandler::getForTitle
- ContentHandler::$handlers
Bug: T235165
Change-Id: I59246938c7ad7b3e70e46c9e698708ef9bc672c6
Done:
* Replace LanguageConverter::newConverter by LanguageConverterFactory::getLanguageConverter
* Remove LanguageConverter::newConverter from all subclasses
* Add LanguageConverterFactory integration tests which covers all languages by their code.
* Caching of LanguageConverters in factory
* Make all tests running (hope that's would be enough)
* Uncomment the deprecated functions.
* Rename FakeConverter to TrivialLanguageConverter
* Create ILanguageConverter to have shared ancestor
* Make the LanguageConverter class abstract.
* Create table with mapping between lang code and converter instead of using name convention
* ILanguageConverter @internal
* Clean up code
Change-Id: I0e4d77de0f44e18c19956a1ffd69d30e63cf51bf
Bug: T226833, T243332
All services required by LinkBatch are now injected by the
LinkBatchFactory. The constructor for LinkBatch has been
soft-deprecated, but the required services are still optional.
Bug: T239855
Depends-On: If49cbb730d4ac48586b891908cf24601efbc5d6a
Change-Id: I93d931ab60305ad49a6e419f8269c77791a3938d
There is no reason this should be necessary. Resetting services should
do the trick, together with Language::$mLangObjCache while it exists.
Resetting only a subset of services is fragile and shouldn't be done,
because one of the reset services might later be injected into a service
that's not reset, resulting in bugs.
Change-Id: I8c72b466ba7337649f9256ee6c078c76163f9785
Languages with variants no longer can override the parent's constructor
(which is now used for injecting services). Instead, they need to
override Language::newConverter().
Bug: T201405
Change-Id: I923400d61763cf1db88cb0c3f684c9c10e58032d
Makes it possible to mock static Title methods in tests, where
they are one of the more common reasons for not being able to
use MediaWikiUnitTestCase.
Actually introducing dependency injection to Title is left for
the future.
Change-Id: I959ba87f8e283da9549b6bfcefd338e60b00be8f
This replaces the static Language methods getFallbackFor(),
getFallbacksFor(), and getFallbacksIncludingSiteLanguage(). There is
100% unit and integration test coverage for the new class.
One deliberate functional change: I changed one place where we threw
MWException to InvalidArgumentException.
Bug: T201405
Depends-On: Ie7a89f6ed7d52a0bc01672019ff92e7ee105a1f3
Change-Id: I49222eb55f1feec5b1dcd40f364cffe0c8801855
The main reasons for adding this service layer are:
* It allows error messages to be more consistent, by defining
a set of reportable information that can describe any block
type and is consistently formatted.
* It decouples formatting from the block classes, removing
their dependency on language, for the most part.
The service provides one public method, getMessage, which
returns a Message object whose key and parameters are
determined by the type of block. This should be used instead
of the deprecated AbstractBlock::getPermissionsError and
AbstractBlock::getBlockErrorParams.
Calls to AbstractBlock::getPermissionsError are replaced in
this patch.
Bug: T227174
Change-Id: I8caae7e30a46ef7120a86a4e5e6f30ae00855063
These are static methods that have to do with processing language names
and codes. I didn't include fallback behavior, because that would mean a
circular dependency with LocalisationCache.
In the new class, I renamed AS_AUTONYMS to AUTONYMS, and added a class
constant DEFINED for 'mw' to match the existing SUPPORTED and ALL. I
also renamed fetchLanguageName(s) to getLanguageName(s).
There is 100% test coverage for the code in the new class.
This was previously committed as 2e52f48c2e and reverted because it
depended on e4468a1d6b, which had to be reverted for performance
issues. There should be no changes other than rebasing.
Bug: T201405
Change-Id: Ifa346c8a92bf1eb57dc5e79458b32b7b26f1ee8a
This removes Language::$dataCache without deprecation, because 1) I
don't know of a way to properly simulate it in the new paradigm, and 2)
I found no direct access to the member outside of the Language and
LanguageTest classes.
An earlier version of this patch (e4468a1d6b) had to be reverted
because of a massive slowdown on test runs. Based on some local testing,
this should fix the problem. Running all tests in languages is slowed
down by only around 20% instead of a factor of five, and memory usage is
actually reduced greatly (~350 MB -> ~200 MB). The slowdown is still not
great, but I assume it's par for the course for converting things to
services and is acceptable. If not, I can try to optimize further.
Bug: T231220
Bug: T231198
Bug: T231200
Bug: T201405
Change-Id: Ieadbd820379a006d8ad2d2e4a1e96241e172ec5a