Commit graph

1005 commits

Author SHA1 Message Date
Kosta Harlan
6efd008f33 TempAccounts: Rate limit acquisition of temp account names
Why:

- We don't want to allow unlimited acquisition of temp account names.
  These should be rate limited in similar way to how we limit the
  creation of temp accounts

What:

- Provide a TempAccountNameAcquisitionThrottle, and use it in the
  acquireName() method
- Set a default that is 10 times the limit of
  TempAccountNameCreationThrottle

Depends-On: If660aad1d0f04f366414084aff3f88484a19d416
Bug: T343101
Change-Id: I99d5973498a89ac227847de5837c0a8e895c28fb
2024-04-23 13:33:57 +00:00
Derick Alangi
e2f6161980
objectcache: Inject DBLoadBalancerFactory into ObjectCacheFactory
This patch does the follow with a few gotchas:

* Properly inject LBFactory service into ObjectCacheFactory to be
  used where needed.

* doc: Pull in relevant documentation from ObjectCache class into
  the ObjectCacheFactory class and also update docs in the OCF
  class to be more accurate with the code.

* This patch also resolves an issue that caused an infinite loop in
  SqlBagOStuff making connections to the DB not to be reused within
  a request there by crashing the application (when the index.php
  entry-point) is accessed directly and every cache type is set to
  CACHE_ANYTHING. Meaning in LocalSettings, only `$wgMainCacheType`
  is set and its relatives (ParserCache, MessageCache, etc) aren't
  set.

NOTES
=====
-> A circular dependency would occur in OCF when injecting LBFactory:

   DBLoadBalancerFactory->DBLoadBalancerFactoryConfigBuilder
   ->LocalServerObjectCache->ObjectCacheFactory->DBLoadBalancerFactory

   directly, so in order to resolve this, we'll inject a closure instead
   and call that to retrieve the service when needed. The solution above
   is already used in other services today in the code. As an example,
   you can see SignatureValidatorFactory.

-> In MainConfigSchema.php, the CACHE_ANYTHING key got removed
   in https://gerrit.wikimedia.org/r/c/mediawiki/core/+/955771
   and this is a change in behavior. So we need to recompute the
   value of CACHE_ANYTHING's ID via service wiring for DB operations.

Test plan
=========

This patch is fairly straight forward, all it does is do some DI of
a service into OCF (via a callable). No change in behavior should be
expected in your local wiki.

So if your local wiki is still running smoothly when you hit the
`/index.php` entry-point directly and other cases, then everything
should be working fine.

Bug: T362686
Change-Id: I305ef0c377a023236b8ed9a101762813f32e6cd0
2024-04-18 22:04:16 +01:00
Derick Alangi
791cb9f676
search: Use ServiceOptions not full config object
This patch uses the recommended MW practice for injecting
settings into MW services. Instead of passing in the full
config object, pass in service options which MW service wiring
will use to lookup settings/options from config sources.

So in this patch, the various options have been identified
and put into `CONSTRUCTOR_OPTIONS` constant and inject via
service wiring.

Test plan
=========
Ensure that the special page: `Special:Search` still works
with this patch checkout on your local test wiki.

When you visit `Special:Search` on your local wiki, you should
see a search form view. Type in something like: "Main Page" and
then hit search. If everything works well, then local test passes.

NOTE
====
This patch also resolves a TODO which mentions the removal of
the `getConfig()` method from the SearchEngineConfig class.

Change-Id: Ib5dfc10f3f210c6c35247f4f30f9549dd60e0af7
2024-04-16 15:50:43 +01:00
Thalia
14a2ec687b Remove ContributionsLookup service
This was added in 300fcfd00b
for an experimental REST endpoint that was removed in
c3fe4b037d, and is now unused.

Bug: T305506
Change-Id: I900c00747f77af6b0844105e9681c9d4acfe1ad5
2024-04-15 16:29:47 +00:00
jenkins-bot
b3affdea7e Merge "LogFormatterFactory: Inject LinkRenderer too" 2024-04-03 18:30:14 +00:00
jenkins-bot
62da79f197 Merge "Add new conditional default conditions for user options: anon and named" 2024-04-03 13:24:41 +00:00
Steph Toyofuku
1e26f420dc Add new conditional default conditions for user options: anon and named
Adds two new conditional user option default conditions CUDCOND_ANON and
CUDCOND_NAMED, for the purpose of allowing the specification of a
separate default user option for logged-out users.  We're taking two
different approaches to the targeting of logged-out users (anon vs
named) because of the temporary users project - anon will not include
temporary users while named will allow us to target only fully created
user accounts.  This will be ultimately be used for the rollout of the
reading accessibility settings menu

Bug: T360098
Change-Id: I316d231330159770f05234dd2f5fdb7d07531002
2024-04-02 14:46:53 -07:00
Bartosz Dziewoński
0b0ebabea2 LogFormatterFactory: Inject LinkRenderer too
Change-Id: I1edfc9cc4e2ad794b226b4f8be03c3846bbeb84d
2024-04-02 21:24:49 +02:00
Gergő Tisza
ce836dae7c logging: Add LogFormatterFactory
Bug: T356468
Change-Id: I8dc2ec7993d8d5268877518c86df8c604380c8a0
2024-03-30 11:37:38 +01:00
jenkins-bot
861c3c4af7 Merge "SignatureValidator: Don't fail signature validation on hidden lints" 2024-03-30 02:41:30 +00:00
C. Scott Ananian
8b922a64b1 SignatureValidator: Don't fail signature validation on hidden lints
Bug: T360809
Bug: T360796
Change-Id: Ia3512b5e7bb6eae6bfa9b9ae67611a9f977e6bb3
2024-03-29 15:55:02 -04:00
Derick Alangi
e0c34987eb
objectcache: Restore default keyspace for LocalServerCache service
* Fix main makeLocalServerCache() call in ObjectCacheFactory::newFromId
  to include a default keyspace, since wgCachePrefix is false by default
  (including at WMF).
* Idem for ExtensionRegistry.
* Dependency inject the domain ID so that service wiring does the
  correct thing when doing cross-wiki operations.

This is a followup on: I3179a387486377c6a575d173f39f82870c49c321.

Bug: T358346
Bug: T361177
Change-Id: Ibbb250465529810b8593f90bbb8330af0a2c3dbd
2024-03-28 19:47:44 +01:00
Timo Tijhof
f60c46485a phpunit: Use StaticUserOptionsLookup when storage is disabled
This is an alternate for the workaround in I5987c4f1c3 (c98aeff078).
The service class should not need awareness of MW_PHPUNIT_TEST, or
otherwise have a mixed kind-of-yes/kind-of-not DB dependency.

With this patch, DefaultOptionsLookup is reverted to remove the
test-specific workaround in favour of using StaticUserOptionsLookup
in MediaWikiServices::disableStorage.

This is already called by MediaWikiIntegrationTestCase for tests
that don't enable the database.

Bug: T155147
Depends-On: I906450a4ac2dc51cdc536fbc978661b06f62f0a4
Change-Id: I8720d32fcfb18f7468e2c4b82412fe8664e28ddc
2024-03-27 03:40:14 +00:00
Derick Alangi
d372626b97
objectcache: Introduce ObjectCacheFactory MW service
ObjectCache is already doing a lot of factory pattern logic like
creating instances of the various BagOStuff, this should really be
the responsibility of the factory servicet.

This patch introduces a proper factory (ObjectCacheFactory) to handle
the responsibility of creating various instances of BagOStuff. Since
`newFromParams()` is a static function that gets passed in configuration
of $wgObjectCaches, that can stay that way (to keep supporting how we do
this in prod today).

Technical Breaking Change: `ObjectCache::makeLocalServerCache()` now has
a parameter and requires it but there are no callers of this method outside
MW core hence it is safe to change (and this patch update all callers) to
work correctly. Cache prefix is gotten from global state because sometimes
at this stage, the services container is not available.

Bug: T358346
Change-Id: I3179a387486377c6a575d173f39f82870c49c321
2024-03-19 12:38:39 +03:00
Cole White
d9eafc96bb ServiceWiring: pass StatsFactory instance to ParserCacheFactory
Bug: T356815
Change-Id: Iaee83b48ffb44b9d67bd8f203a9d92dcf2032be1
2024-03-15 10:16:48 +00:00
jenkins-bot
83432c36db Merge "REST: HTML endpoints should support all content models" 2024-03-13 09:57:15 +00:00
daniel
36b0c8a048 REST: HTML endpoints should support all content models
This allows HtmlOutputRendererHelper to function for all kinds of
content.

Bug: T311728
Bug: T311648
Bug: T359426
Change-Id: Ib32af7cf2a7ad989eb0b13ecca37c857fc9199ec
2024-03-13 04:32:59 -05:00
jenkins-bot
e57ce5a8f7 Merge "TempUserCreator: Use separate rate limit for temp account creations" 2024-03-06 14:07:15 +00:00
Kosta Harlan
08fef95627
TempUserCreator: Use separate rate limit for temp account creations
Why:

- The pathway to creating a regular account is different from that of a
  temporary account. It makes sense to rate limiting creation of these
  two types of accounts at different rates.

What:

- Add a TempAccountCreationThrottle config with a restrictive default
  that matches the existing production configuration of
  AccountCreationThrottle (6 creations per day)
- Update resetAuthenticationThrottle.php to support resetting the temp
  account creation throttle
- For now, not adding an equivalent hook for account creation throttle's
  ExemptFromAccountCreationThrottle

Bug: T357777
Change-Id: Ibf36ac96f717107bace6f0a3326f79ed129a1dfe
2024-03-06 14:41:15 +01:00
jenkins-bot
428a1a171e Merge "Revert "Output: Add IframeSandbox class"" 2024-03-06 02:44:15 +00:00
jenkins-bot
0f84f77448 Merge "PoolCounter: Adopt PSR logger in PoolCounter objects" 2024-03-05 22:01:45 +00:00
Gergő Tisza
038ec7be40 Revert "Output: Add IframeSandbox class"
This reverts commit cb09a27cc2.

The class is not very useful as it is now, due to performance issues
(T169027#9342985). The Graph extension is not going to use iframes
(T334940#9537862) and that was the only concrete feature for this, so
making the class usable in practice is unlikely to get prioritized.
No point in leaving the code in its current halfway state.

Bug: T222807
Bug: T169027
Change-Id: Id1b5193975435b58aebc225528e30f04456d0c41
2024-03-04 12:32:23 -05:00
Thalia
0b7a4b049a Group temporary users with IP users in ApiQueryWatchlist filters
Why

* ApiQueryWatchList allows filtering anon users or not-anon users.
  It is not obvious wether temporary users should be considered
  anon for these purposes.
* The equivalent filters in recent changes group temporary users
  with anonymous users (T343322).
* Since ApiQueryWatchlist queries the recentchanges table, and
  shares many filters with recent changes, it makes sense to
  filter the same way in both, and therefore to group temporary
  users with anonymous users.

What

* Update queries in WatchedItemQueryService to group temporary
  users with anonymous users for FILTER_ANON and FILTER_NOT_ANON.
* Don't change the 'anon' flag, because the other APIs flag
  temporary users with anon=false.
* Instead add a 'temp' flag for temporary users.

Bug: T358693
Change-Id: I4cd3a4d0c5f4f488933cf3f06dee62a9beb85440
2024-03-03 06:26:03 +00:00
Timo Tijhof
4e40bcdd8f PoolCounter: Adopt PSR logger in PoolCounter objects
* Inject from ServiceWiring via PoolCounterFactory.

* In production we use PoolCounterClient (which is backed by
  our poolcounterd service), we also offer PoolCounterRedis for
  third parties. Replace the local logger in the Redis variant in
  favour of the built-in one.

* Update PoolCounterWork to adopt this as well. Expose it via getter
  to here, so that DI works all the way, including for the existing
  test.

Bug: T358901
Change-Id: I5413825a0172b186d58e85bbc3cc93697b174c27
2024-03-02 00:41:11 +00:00
jenkins-bot
845e69cb2e Merge "Namespace includes/cache" 2024-02-28 15:10:38 +00:00
James D. Forrester
35b2542895 Namespace includes/cache
Bug: T353458
Change-Id: Ic3f3168ef17113f5fb3ec11e0a47f52d65eefba9
2024-02-20 10:28:03 -05:00
Derick Alangi
64d02c830f
preferences: Avoid injecting entire config object, use ServiceOptions
We're already constructing service options with the list of options the
service needs. Let's stick to the light-weight version and avoid injecting
the entire MainConfig object just to get 2 settings when we can just list
it them in CONSTRUCTOR_OPTIONS.

Change-Id: I0612ca1c129c55664f29e178959c017d849eb218
2024-02-19 15:30:26 +03:00
Subramanya Sastry
e55cc517da Move Parser to Mediawiki\Parser namespace
Bug: T166010
Co-Authored-By: Daimona Eaytoy <daimona.wiki@gmail.com>
Co-Authored-By: James Forrester <jforrester@wikimedia.org>
Co-Authored-By: Subramanya Sastry <ssastry@wikimedia.org>
Change-Id: I79b4e732c45095eedbaa80afa5eb7479b387ed8a
2024-02-16 09:18:38 -05:00
DannyS712
58015e0030 IntroMessageBuilder: inject connection provider
Follow-up: I6d30af6ff9f667e367d39befb80c2bb0bf5fb29e
Change-Id: Ib739b83ed376c38c5c6e756c54b397a5a33ad836
2024-02-14 17:22:02 +00:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
C. Scott Ananian
0de13d7662 Add ParserOutput::{get,set}RenderId() and set render id in ContentRenderer
Set the render ID for each parse stored into cache so that we are able
to identify a specific parse when there are dependencies (for example
in an edit based on that parse).  This is recorded as a property added
to the ParserOutput, not the parent CacheTime interface.  Even though
the render ID is /related/ to the CacheTime interface, CacheTime is
also used directly as a parser cache key, and the UUID should not be
part of the lookup key.

In general we are trying to move the location where these cache
properties are set as early as possible, so we check at each location
to ensure we don't overwrite a previously-set value.  Eventually we
can convert most of these checks into assertions that the cache
properties have already been set (T350538).  The primary location for
setting cache properties is the ContentRenderer.

Moved setting the revision timestamp into ContentRenderer as well, as
it was set along the same code paths.  An extra parameter was added to
ContentRenderer::getParserOutput() to support this.

Added merge code to ParserOutput::mergeInternalMetaDataFrom() which
should ensure that cache time, revision, timestamp, and render id are
all set properly when multiple slots are combined together in MCR.

In order to ensure the render ID is set on all codepaths we needed to
plumb the GlobalIdGenerator service into ContentRenderer, ParserCache,
ParserCacheFactory, and RevisionOutputCache.  Eventually (T350538) it
should only be necessary in the ContentRenderer.

Bug: T350538
Bug: T349868
Followup-To: Ic9b7cc0fcf365e772b7d080d76a065e3fd585f80
Change-Id: I72c5e6f86b7f081ab5ce7a56f5365d2f75067a78
2024-02-07 21:22:06 -05:00
Alexander Vorwerk
d9713bf6a6 RevisionStore: Remove usage of ActorMigration
Bug: T227047
Change-Id: Ie877b578b5760d3592afd7654df524fe4d20a6ff
2024-02-05 00:29:44 +00:00
jenkins-bot
d023c7fb99 Merge "Move creation of BlockErrorFormatter into FormatterFactory" 2024-02-02 22:29:47 +00:00
jenkins-bot
3140725166 Merge "Always allow local IP actors to be created when importing" 2024-01-31 20:30:36 +00:00
jenkins-bot
e6eb387e4a Merge "Make ExtensionRegistry available via MediaWikiServices" 2024-01-31 20:05:59 +00:00
Thalia
6909b2016e Always allow local IP actors to be created when importing
Why:

* Following T345578, the ActorStore throws an error on
  attempting to create an actor whose name is their IP address
  if temporary accounts are enabled.
* For the specific case of importing old revisions, we need to
  be able to create new actors whose name is their IP address,
  while still generally disallowing it.

What:

* Add $allowCreateIpActors flag to ActorStore, and check for
  it during actor name validation.
* Set the flag from ActorStoreFactory::getActorStore depending
  on whether temporary users are enabled.
* Add ActorStoreFactory::getActorStoreForImport, which sets
  flag to true.
* Add RevisionStoreFactory::getRevisionStoreForImport, which
  uses getActorStoreForImport. Use this from classes handling
  imports, so that IP actors can always be created.
* Add $forImport flag on ActorMigration, since RevisionStore
  uses an actor store obtained via ActorMigration.

Bug: T354207
Change-Id: I0715bd0d23089fd8156e579913e6e823089809be
2024-01-29 19:35:14 +00:00
daniel
3d55397207 Move creation of BlockErrorFormatter into FormatterFactory
The idea is that all formatters that need the user language or
other request specific context should be instantiated by
FormatterFactory.

Change-Id: I8334cc89dcf0f293298b82e004116be50a90f0d1
2024-01-26 13:03:44 -05:00
jenkins-bot
37dcd4adf8 Merge "Allow temporary accounts to be blocked with 'hideuser' enabled" 2024-01-23 10:24:29 +00:00
jenkins-bot
4db4b4e87f Merge "CentralId: Use UserFactory::newAnonymous" 2024-01-22 21:34:55 +00:00
Umherirrender
a616847791 CentralId: Use UserFactory::newAnonymous
Bug: T325686
Change-Id: Ia8ed50e806aadec15cb78eabf3c52ee4f73578ec
2024-01-22 21:48:20 +01:00
Umherirrender
b155f52dbc Output: Use UserFactory::newAnonymous in IframeSandbox
Bug: T325686
Change-Id: Id3608ab07d61658244dac8a2d47e9f9a9dbda214
2024-01-22 20:37:46 +00:00
Dreamy Jazz
7440b2c22e Allow temporary accounts to be blocked with 'hideuser' enabled
Why:
* The ability to block temporary account usernames with 'hideuser'
  needs to be added so that we can hide the username of temporary
  accounts in the case of accidental logged out edits by editors.
* This brings similar behaviour how IP addresses are hidden on
  WMF wikis, as the IP addresses are hidden for logged out edits
  using the suppression tool. Blocking the account with 'hideuser'
  allows all edits to be hidden plus also prevent further editing
  using that temporary account.

What:
* This reverts commit 878602ad97.

Bug: T355430
Change-Id: I7b38d2bf0155df479a179c69c91cfe1987bd234a
2024-01-22 18:19:59 +00:00
jenkins-bot
9e9d76a820 Merge "Introduce DBAccessObjectUtils::getDBFromRecency()" 2024-01-22 05:04:53 +00:00
Alexander Vorwerk
0b8b61b9fe ActorMigration: Stop injecting useless stage value
Change-Id: I94fa756733b2d0c199131523e15d650cd953daec
2024-01-20 11:00:38 +00:00
Amir Sarabadani
72a8c3b433 Introduce DBAccessObjectUtils::getDBFromRecency()
And general clean up of db connection handling in core

Bug: T354194
Change-Id: Icb3685f1d7f8d1f4bcadf8e292ddf9450180fcdb
2024-01-19 16:54:05 +01:00
jenkins-bot
bbe9d7f397 Merge "TempUserCreator: Use cluster-local cache for throttling" 2024-01-18 23:50:44 +00:00
Gergő Tisza
aec060f345
TempUserCreator: Use cluster-local cache for throttling
ThrottlePreAuthenticationProvider uses the cluster-local object
cache, but TempUserCreator used the server-local cache. This
made throttling less effective and prevented
resetAuthenticationThrottle.php from working for temp users.

Change-Id: Ic6019767076416c5c06c2c2a119d1d416f18bca1
2024-01-17 23:10:55 -08:00
jenkins-bot
70e573df64 Merge "block: Use dbdomain to check for local in BlockUtilsFactory" 2024-01-18 01:15:58 +00:00
jenkins-bot
5d3a549326 Merge "rdbms: Add ConnectionProvider service alias" 2024-01-16 12:00:44 +00:00
Gergő Tisza
8604c384f6 rdbms: Add ConnectionProvider service alias
Reduce mental burden by exposing LBFactory also as
$services->getConnectionProvider, since it's encouraged to
type-hint this as IConnectionProvider whenever possible, this is
both more intuitive and more future-proof.

Also replace occurences in ServiceWiring where the receiving parameter
was already typehinted as IConnectionProvider.

Change-Id: I557dad3c985a1b2c43743e6b75cae57ce37d1785
2024-01-15 18:58:01 +00:00