Commit graph

914 commits

Author SHA1 Message Date
jenkins-bot
e831aa9c8b Merge "Namespace includes/context" 2024-02-08 18:04:34 +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
242c6d2cf9 Introduce ParserOutput:setFromParserOptions() and use for preview flag
Bug: T341010
Co-Authored-by: cananian <cananian@wikimedia.org>
Co-Authored-by: ihurbain <ihurbainpalatin@wikimedia.org>
Change-Id: I03125fdaa7dd71ba57d593e85ecb98be6806f3f6
2024-02-07 21:22:06 -05:00
C. Scott Ananian
52320c0902 Move ParsoidRenderID to MediaWiki\Edit
This class belongs with the rest of the Parsoid output stash code.

This class has been marked @unstable since 1.39 and thus the move
does not need release notes.

Change-Id: I16061c0c28b1549fbe90ea082cc717fee4a09a6e
2024-02-07 21:22:06 -05:00
C. Scott Ananian
1858e1cdd7 Rename ParserOutput::{get,set}Timestamp() to ::{get,set}RevisionTimestamp()
This avoids confusion with the "render timestamp" held by the cache,
and is consistent with ::get*RevisionId() etc.

The old ::getTimestamp() and ::setTimestamp() methods have been
deprecated.

Change-Id: Idb5e687709c98086c5d3075d31885c58a0723197
2024-02-07 21:22:06 -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
jenkins-bot
d023c7fb99 Merge "Move creation of BlockErrorFormatter into FormatterFactory" 2024-02-02 22:29:47 +00:00
jenkins-bot
fb09ec21ff Merge "Use the instanceof and ::class features instead of strings" 2024-02-02 16:01:15 +00:00
thiemowmde
7e70b8042c Use the instanceof and ::class features instead of strings
This makes it much easier for IDEs and tools like Phan to understand
what's going on. Note this syntax is perfectly valid even if a class
is undefined. Language features like `use`, `instanceof`, and
`class_exists` work perfectly fine. We do this a lot in existing
code.

Change-Id: I4d397621ebcc6a7e842150f7641c1b23d082b730
2024-02-02 14:50:15 +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
Umherirrender
a3a9cf99cb tests: Use namespaced class names in @covers annotations
Assist from 8c9cb701e56226cac43fee2fa24b0d0e586f1733

Change-Id: I47897c499028d9e24c00ad0bc6ba7fd8002d9bc1
2024-01-27 01:11:07 +01: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
8f8e1d6f85 Merge "Change more uses of getDBLoadBalancerFactory() to getConnectionProvider()" 2024-01-23 17:59:21 +00:00
Daimona Eaytoy
7acfa6a0a5 Replace more instances of unchecked MWException
Most (all?) of the remaining usages are caught somewhere and will be
migrated later.

Bug: T328220
Change-Id: I5c36693a5361dd75b4f1e7a0bab5ad48626ed75c
2024-01-23 16:20:53 +00:00
Bartosz Dziewoński
4aebcfe097 Change more uses of getDBLoadBalancerFactory() to getConnectionProvider()
Some less trivial cases. Also update variable names.

This doesn't really change anything, but I hope it helps promote
getConnectionProvider() as the common way to do this.

Follow-up to 8604c384f6.

Change-Id: I6657d783375fac5c7fa856b884ff1fb09285e94c
2024-01-23 16:34:45 +01:00
jenkins-bot
37dcd4adf8 Merge "Allow temporary accounts to be blocked with 'hideuser' enabled" 2024-01-23 10:24:29 +00:00
jenkins-bot
903c17c8a2 Merge "Add wfDeprecated call to RealTempUserConfig::getMatchPattern" 2024-01-22 20:53:06 +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
3739272ed4 Merge "GrantsLocalization: Move grant risk level labels from CSS to HTML" 2024-01-19 06:31:49 +00:00
Dreamy Jazz
4fcf7c46ba Add wfDeprecated call to RealTempUserConfig::getMatchPattern
Why:
* The TempUserConfig::getMatchPattern method was deprecated in
  7f588780a0 with a replacement of
  TempUserConfig::getMatchPatterns.
* All existing usages on WMF deployed extensions have been replaced
  so a call to wfDeprecated can be added.

What:
* Add a wfDeprecated call in RealTempUserConfig::getMatchPattern.
  The other implementation of this method calls this method, so
  this is the only call needed.
* Update the tests to expect the deprecation of ::getMatchPattern.

Depends-On: I122f001ab24e879a573b19468d642b8f579d1024
Bug: T354619
Change-Id: I74ea85429d083737c325c978e1cad04beb6a9325
2024-01-18 20:25:17 +00:00
Alexander Vorwerk
cd6ac532ce tests: Replace usages of wfGetDB
Change-Id: I4f57ef084da8f0404e7bc2b4c466b7512e89670f
2024-01-18 00:12:59 +00:00
jenkins-bot
fa50123c38 Merge "Update tests for PHPUnit 9.6 (part 2)" 2024-01-17 19:22:23 +00:00
Daimona Eaytoy
c8e2f99211 Update tests for PHPUnit 9.6 (part 2)
- Avoid withConsecutive()

Bug: T342110
Change-Id: Iedda49765cbceeb10ccd72d0248f3cda9241da1e
2024-01-17 18:16:38 +01:00
Dreamy Jazz
7f588780a0 Support multiple matchPatterns in temp user autocreate config
Why:
* There is a need to update the generation and match pattern on
  WMF wikis to a new format that includes the year and starts with
  `~`. As such, the 'matchPattern' key needs to be updated.
* Removing the old 'matchPattern' from the wgAutoCreateTempUser
  config currently leaves existing temporary accounts as no longer
  recongnised as temporary accounts.
* Instead, the 'matchPattern' needs to be able to take an array of
  string patterns so that old patterns can still be used for matching.

What:
* Update the MainConfigSchama to indicate that 'matchPattern' in the
  wgAutoCreateTempUser config can be an array of strings.
* Add TempUserConfig::getMatchPatterns and deprecate TempUserConfig::
  getMatchPattern. This is needed because ::getMatchPattern was typed
  to only ever return one Pattern, which is no longer the case with this
  config change.
* Update the RealTempUserConfig to support multiple patterns defined in
  the 'matchPattern' key. The RealTempUserConfig::getMatchPattern method
  returns the pattern or first pattern if multiple are defined to allow
  time for existing usages of this deprecated method to be updated.
* Update the RealTempUserConfig to rely on other methods instead of checking
  object property values where possible (e.g. use ::isEnabled instead of
  checking $this->enabled) to allow easier unit testing.
* Update UserSelectQueryBuilder and ChangesListSpecialPage to use TempUserConfig
  ::getMatchPatterns instead of ::getMatchPattern.
* Update mediawiki.util/util.js to be able to parse the 'matchPattern' value
  when it is an array of strings.
* Update maintenance/userOptions.php to use ::getMatchPatterns instead of
  ::getMatchPattern.
* Add and update unit and integration tests for the new code, as well as
  expanding coverage over existing code that was indirectly affected.

Bug: T354619
Change-Id: I3763daefe4dc7c76370bd934fb20452591c9c762
2024-01-17 11:24:26 +00:00
jenkins-bot
2f8e379744 Merge "BotPasswords: Show risk level of grants" 2024-01-17 02:53:47 +00:00
Bartosz Dziewoński
f85ebfb1df GrantsLocalization: Move grant risk level labels from CSS to HTML
Change-Id: I6c4ed496cd74f0d59e6b71e5d6d37abcc80a4914
2024-01-16 23:55:48 +01:00
Gergő Tisza
a74230cc6b BotPasswords: Show risk level of grants
* Make GrantsLocalization add CSS classes indicating risk level
  to grant names.
* On Special:BotPasswords, unlink the grant names. Instead, fix
  formatting of the tooltips (containing the same information)
  and move the help text (linking to the same page) above the
  checkmatrix so the user notices it before starting to check
  things.
* Color grant names by risk level; add color legend to the help
  text.

Bug: T290790
Change-Id: I9f21273d5a1db92d8656fdf8b656b5ea8161bb23
2024-01-16 23:55:48 +01:00
Daimona Eaytoy
605d12b9b3 Update tests for PHPUnit 9.6 (part 1)
- Avoid defining abstract test classes (ending in "Test")
- Avoid withConsecutive()
- Avoid getMockClass()

Bug: T342110
Change-Id: I131e0d85bd14e75aaebd6f212b2e64a45d4c73a2
2024-01-16 23:36:15 +01:00
jenkins-bot
0b1b808267 Merge "UserOptionsManager: Do not consider null to be equal to anything but a null" 2024-01-16 02:37:04 +00:00
Martin Urbanec
0afe7f7c99 UserOptionsManager: Do not consider null to be equal to anything but a null
Previously, UserOptionsManager:.isValueEqual considered null to be
equal to certain non-null values (such as an empty string). This
resulted in UserOptionsManager::saveOptionsInternal ignoring
any attempts to set any option to an empty string when
there was no pre-existing user_properties row.

Bug: T355086
Change-Id: Ib145efbd337b7f09eed86d2873228a1b503d02f3
2024-01-15 21:37:41 +01:00
Dreamy Jazz
037e7a6b49 Add TempUserTestTrait to easily control temp user config in tests
Why:
* The temporary account configuration settings, which are
  controlled via wgAutoCreateTempUser have many options
  and so defining the config for a test is difficult without
  keeping a private array for the default array value.
* Providing methods to easily disable and enable temporary account
  creation in a one-line call is useful to fix existing tests
  for temporary account creation.

What:
* Add the trait named TempUserTestTrait which provides two methods
  that disable and enable temporary account autocreation.
* This trait is designed for use in integration tests as it modifies
  configuration values.
* The ::enableAutoCreateTempUser method optionally takes an array
  that can be used to override the default wgAutoCreateTempUser
  configuration.
* The ::disableAutoCreateTempUser method optionally takes a value
  for the reservedPattern key as this is still used if the 'enabled'
  key is set to false.

Bug: T352693
Change-Id: I21c5c7d61370b9ce96059341e0744abc61545e09
2024-01-15 13:33:02 +00:00
jenkins-bot
2e9d3e68d0 Merge "Check warnings from INSERT during tests" 2024-01-15 10:18:52 +00:00
Reedy
72df6cb8da libs/composer: Namespace under Wikimedia\Composer
Change-Id: I5ffedacf31e60fb0f38e308f8dcf010e577f919e
2024-01-13 20:10:25 +00:00
RazeSoldier
20e77793b8 Refactor checkComposerLockUpToDate.php logic out to reuseable class
Introduce LockFileChecker that used to check whether
composer-installed dependencies (no-dev) are up-to-date.

Bug: T283389
Change-Id: I0d56f235604d5c856bae5d170230f8c7ca0729c6
2024-01-13 18:35:07 +00:00
jenkins-bot
5dca00526a Merge "Use class @covers annotation in some tests" 2024-01-13 09:12:24 +00:00
jenkins-bot
1239150d95 Merge "DummyServicesTrait: add an ITextFormatter" 2024-01-12 23:21:00 +00:00
Thalia
07bf3bf93a Use class @covers annotation in some tests
* ImportableOldRevisionImporterTest
* ActorStoreTest

Bug: T354968
Change-Id: Iac20a48df28b3cc1d6afed1b78e43cc1c3cd7da7
2024-01-12 20:54:17 +00:00
Tim Starling
551ec29ea6 Check warnings from INSERT during tests
INSERT IGNORE when inserting NULL into a non-nullable field will succeed
with a warning on MySQL but fail on PostgreSQL. In any case, it's
probably harmful and unintended. But to check the error code of MySQL
warnings, you need to query the server with SHOW WARNINGS, so there is a
performance cost.

So, add a configuration variable which, when enabled, checks warnings
after INSERT to see if there were any null type constraint errors. Set
it to true in DevelopmentSettings.php and TestSetup.php.

Change-Id: I5e47e2d3cc7e0f804036e11b512b1e3b76804432
2024-01-12 09:33:05 +11:00
jenkins-bot
2accd5c8ed Merge "Add phpunit test for RootSpecHandler" 2024-01-09 15:28:41 +00:00
DannyS712
f11bee20d4 DummyServicesTrait: add an ITextFormatter
To avoid duplicating the creation of mocks/implementations

Change-Id: Id1094a9009acd100092f1b7cd55016d78900ce5f
2024-01-09 13:16:59 +00:00
jenkins-bot
7057d995bc Merge "Add support for conditional user defaults" 2024-01-09 04:42:53 +00:00
Martin Urbanec
6c8b696020 Add support for conditional user defaults
Why:
Sometimes, it is necessary to have different behavior
for newly registered and existing users. For example,
this happens in the Echo or GrowthExperiments extensions.
As of now, this behavior is implemented by inserting
user_properties rows in onLocalUserCreated.

Over time, this results in a singificant amount of rows
inserted, which contributes to the user_properties table bloat,
which is already overly large (cf. T54777). This patch makes it
possible to remove such rows by supporting conditional defaults
for user properties.

What:
Add support for conditional defaults of user properties. This can be
configured via `ConditionalUserOptions` config option.

Bug: T321527
Change-Id: I1549c3137e66801c85e03e46427e27da333d68e2
2024-01-09 02:33:17 +00:00
jenkins-bot
1121ea90d0 Merge "Use year in temporary user names and restart index each year" 2024-01-05 22:59:47 +00:00
Thalia
caf9912323 Use year in temporary user names and restart index each year
Why:

* Part of a temporary user name is generated from an index that
  increments, which is stored in the database.
* As specified in T345855, the index will be restarted each year.
* Also specified in T345855, the year will be included in
  generated temporary user names.

What:
* Since the year must be included in the name in order to avoid
  naming conflicts if the index is restarted each year, both are
  implemented together and controlled by a single config.
* Add a new config option that, when true, restarts the name
  generation index at the start of each year and add the year into
  the user name: $wgAutoCreateTempUser['serialProvider']['useYear']
* Add a uas_year column to the user_autocreate_serial table, which
  is unique in combination with uas_shard, so the index can be
  stored for each shard/year combination.
* The year is added into the username just after the prefix, as
  specified in T345855. This is based on research that having the
  year near the start of the name aids understanding that the
  names are not IP addresses. The position of the year within the
  name is therefore not configurable (though whether to include
  it is). See T345855 for the research.

Bug: T349494
Bug: T349501
Depends-On: I6b3c640a4e74f52fd4a4f46de5a2cbe80fe3b665
Change-Id: If51acb3f4efa361ce36d919c862a52501a5a7d24
2024-01-05 17:14:19 +00:00
jenkins-bot
5a9a717b56 Merge "REST: Add tests for handling file description pages" 2024-01-03 20:12:00 +00:00
daniel
be5b9e23ec REST: Add tests for handling file description pages
This adds high level test that ensure that the page HTML endpoint
behaves correctly for file description pages on wikis that make use of a
remote file repo.

Bug: T353688
Change-Id: Ied774b885be08a7db9e78aacb6bb56382fd8c2c0
2024-01-02 19:15:09 +00:00
Tim Starling
c23829db2b Improve ChangedTablesTracker domain handling
* Have ChangedTablesTracker take a domain as a parameter. Getting the ID
  out of it is deferred to save some nanoseconds in production.
* Split getTablesAndStop() into getTables() and stopTracking(). Make
  getTables() take a domain ID parameter.

Change-Id: I52ade87e2f0305e6f2be541df5b38c7d76c409a7
2024-01-02 17:23:05 +11:00
jenkins-bot
99c571c52f Merge "Handle collisions from SerialProvider::acquireIndex" 2023-12-21 15:49:07 +00:00
Dreamy Jazz
3b3f1d7851 Handle collisions from SerialProvider::acquireIndex
Why:
* When using the TempUserCreator::create or ::acquireAndStashName to
  get temporary account when the chosen username already existed, that
  temporary account is treated as if it doesn't exist. This causes
  confusing "userexists" errors and also causes the user to be logged
  into an already existing temporary account.
* Furthermore, because the user existence check in AuthManager::auto
  CreateUser only checks the local wiki, if an existing temporary
  account exists globally but not on the local wiki then the code
  sign a new user into an existing temporary account.
* This is very bad behaviour, though shouldn't happen unless the
  serialMapping configuration uses a SerialMapping class that could
  provide duplicates and/or the configuration has been changed to
  use a different SerialMapping class.
* There is a need to change the SerialMapping class in use to a
  different class, which means that the code will attempt to use
  temporary account usernames which already exist.
* As such, the code that is generating the temporary account usernames
  based on the SerialMapping and SerialProvider should be aware that
  it may produce an already existing temporary account username, even
  if the SerialMapping class being used is asserted to never provide
  duplicates.
* Therefore, the code that generates temporary account usernames
  should always attempt to verify that a automatically generated
  temporary account name does not already exist on the wiki.

What:
* Update TempUserCreator::acquireName to check to see if the username
  it generates already exists centrally using the CentralIdLookup.
  If it does, then the method returns null. Otherwise, the username
  that hasn't been used yet is returned.
* Create the private method TempUserCreator::attemptAutoCreate that
  attempts an autocreate for a temporary account name, and optionally
  logs the account in.
* Update TempUserCreator::create to use ::attemptAutoCreate to
  first to check if the account can be created and then again once
  the account is created to actually login to that temporary account.
  This is done to prevent logins to existing temporary accounts on
  the local wiki. The second call to actually perform the login is
  necessary as there is no other way to login to a temporary account.
* Update TempUserCreator::acquireAndStashName to respond to the changes
  to ::acquireName, such that it returns null if ::acquireName returns
  null and also does not modify the session.
* Update EditPage::maybeActivateTempUserCreate to return a Status and
  return a good status in all cases except when a temporary account
  name could not be acquired.
* Add IEditObject::AS_UNABLE_TO_ACQUIRE_TEMP_ACCOUNT, and use it as
  the value of the fatal status returned by EditPage
  ::internalAttemptSave if a temporary account name could not be
  acquired. This will cause the display of a useful error to the
  user on edit.
* Update ApiEditPage and ApiAcquireTempUserName to die with an error
  if a temporary account username was unable to be acquired.
* Provide tests for the untested ApiAcquireTempUserName.php file
  including testing the new behaviour.
* Add and update tests for TempUserCreator.php

Bug: T353390
Change-Id: Id3a316ea0eba544d51d4ffcdfb03e35f4b3c54cc
2023-12-21 14:49:42 +00:00
Amir Sarabadani
b7c5d05813 PoolCounter: Namespace classes
Two of the classes in this directory have already namespaced to
MediaWiki\PoolCounter.

Bug: T353458
Change-Id: Ie41f8d935f7623bb40040a5eb78f99c6d7b7b75e
2023-12-20 09:32:19 +00:00