Commit graph

1392 commits

Author SHA1 Message Date
C. Scott Ananian
9dbce134c6 Allow ApiParse to use the ArticleParserOptions hook
Extensions can use the ArticleParserOptions hook to customize the
parser options used for article read views, and Visual Editor uses
ApiParse to regenerate the article read view HTML after edit.  In
order for VE to remain consistent with the original parse options,
provide a `usearticle` option to the parse API to allow it to invoke
the ArticleParserOptions hook.

Bug: T373212
Change-Id: I906affc8d2335b7bb48dff3a4b061fcf86b71cee
2024-08-29 11:33:35 -04:00
thiemowmde
ba36bf46a1 tests: Make use of ??= and ?? operators in various tests
The main benefit is that this syntax avoids repeating the variable
name. It does the same as before.

Change-Id: I2040be889c749f4e2416ca9948ba261345858af2
2024-08-15 11:44:46 +02:00
jenkins-bot
b10ab6be6e Merge "use setGroupPermissions instead of mergeMwGlobalArrayValue" 2024-08-13 14:49:45 +00:00
James D. Forrester
bc662aec9b Move Language and friends into Language namespace
Bug: T353458
Change-Id: Id3202c0c4f4a2043bf97b7caee081acab684155c
2024-08-10 13:36:30 +02:00
jenkins-bot
22163e47a7 Merge "Add MediaWiki\Registration namespace to registration classes" 2024-08-10 11:33:27 +00:00
Ebrahim Byagowi
697e19e461 Add MediaWiki\Registration namespace to registration classes
Bug: T353458
Change-Id: Ifa3b6a6e0353bb4ce21a3f4456f1fc696c8d377c
2024-08-10 10:08:22 +00:00
C. Scott Ananian
8212f8c67d Hard-deprecate ParserOutput::addJsConfigVars(), deprecated in 1.38
It is difficult to distinguish this method from OutputPage::addJsConfigVars()
in code search:

  https://codesearch.wmcloud.org/search/?q=%5BOo%5Dut%28put%29%3F%28%5C%28%5C%29%29%3F-%3EaddJsConfigVars%5C%28

We generally try to replace $output with $parserOutput or $pOutput
as we touch code, to improve the ability of codesearch to dig up
deprecated ParserOutput methods.

A future project will unify those parts of OutputPage which duplicate
ParserOutput: T301020.

Bug: T300307
Bug: T305161
Depends-On: I39ae7d7a40190eedaa024097a6442cd02b6a02e7
Depends-On: I2c660972b289bbad730ceee1325d70d5ba75d27e
Change-Id: I53c28ee7c80b889c893c1d00f37678e716e55783
2024-08-09 14:04:38 +02:00
jenkins-bot
a03b19a19b Merge "ApiBase: Deprecate unused ApiBase::errorArrayToStatus()" 2024-08-08 10:10:20 +00:00
Fomafix
c532f8954d use setGroupPermissions instead of mergeMwGlobalArrayValue
Change-Id: Ibda0fc63681e0bc0acbb290474b2d2bea87cfb6d
2024-08-07 21:50:00 +00:00
Ebrahim Byagowi
4c270a72ac Add namespace to WikitextContent
It adds MediaWiki\Content namespace to WikitextContent
and two classes related.

Change-Id: Ib74e4c5b3edac6aa0e35d3b2093ce1d0b794cb6d
2024-08-06 17:42:51 +03:30
jenkins-bot
c434d89688 Merge "Replace gettype() with get_debug_type() in exception messages" 2024-08-04 21:18:48 +00:00
Bartosz Dziewoński
c045fa0291 Replace gettype() with get_debug_type() in exception messages
get_debug_type() does the same thing but better (spelling type names
in the same way as in type declarations, and including names of
object classes and resource types). It was added in PHP 8, but the
symfony/polyfill-php80 package provides it while we still support 7.4.

Also remove uses of get_class() and get_resource_type() where the new
method already provides the same information.

For reference:
https://www.php.net/manual/en/function.get-debug-type.php
https://www.php.net/manual/en/function.gettype.php

To keep this safe and simple to review, I'm only changing cases where
the type is immediately used in an exception message.

Change-Id: I325efcddcb58be63b1592b9c20ac0845393c15e2
2024-07-31 19:24:39 +02:00
Reedy
b52a8addf5 Drop writeapi userright
Bug: T294397
Depends-On: Ib34228a18917e404517d45e539bd786419d9c401
Change-Id: Ifad2edc782b36d21c8c67fecde7f011dce02c11b
2024-07-31 11:10:50 +00:00
STran
311774c033 Filter temporary accounts as anonymous in ApiQueryRecentChanges
Edits from temporary accounts are considered anonymous edits.
ApiQueryRecentChanges doesn't correctly reflect this and needs to be
updated to correctly return temporary account edits as anonymous (and
similarly, not to return them when requesting !anon)

- Update the anon|!anon query to accomodate temporary accounts

Bug: T370803
Change-Id: Ica5225422ea53d2aa3a84b86d9c2f14832a34ed4
2024-07-29 11:00:22 +01:00
Bartosz Dziewoński
c9f73efd5a Namespace MessageSpecifier under Wikimedia\Message\
In change I625a48a6ecd3fad5c2ed76b23343a0fef91e1b83 I am planning to
make Wikimedia\Message\MessageValue use it, and we try to pretend that
it is a library separate from MediaWiki, so it makes sense to move
MessageSpecifier to the same namespace under Wikimedia\.

Bug: T353458
Change-Id: I9ff4ff7beb098b60c92f564591937c7d789c6684
2024-07-28 14:21:32 +02:00
Umherirrender
2e6b634176 api: Hard-deprecate ApiPageSet::get*Titles
The following functions are now hard-deprected:
- ApiPageSet::getTitles
- ApiPageSet::getGoodTitles
- ApiPageSet::getMissingTitles
- ApiPageSet::getGoodAndMissingTitles
- ApiPageSet::getRedirectTitles
- ApiPageSet::getSpecialTitles

Bug: T339384
Depends-On: Ie117ac8417e7f62ef3f199312a7f57df205900b2
Change-Id: I9533f89bbd370bcec43ca37200b2fedd0610183f
2024-07-20 00:11:55 +02:00
Umherirrender
856947391f api: Add a ratelimit test for action=purge
Follow-Up: Ifb19cc195a51f5521f8365ab26b3cdb56429e0fb
Change-Id: Ie1179a046d7d4dd68aca938593e83aadc578d23b
2024-07-12 22:32:22 +02:00
jenkins-bot
71285104f5 Merge "Add namespace to the root classes of ObjectCache" 2024-07-10 11:58:53 +00:00
jenkins-bot
3fc5ec3616 Merge "RecentChange: Replace use of legacy error arrays" 2024-07-10 11:40:11 +00:00
Bartosz Dziewoński
02fe59f058 ApiBase: Deprecate unused ApiBase::errorArrayToStatus()
This method has become unnecessary after we introduced interfaces that
return StatusValue objects directly instead of legacy error arrays.

Depends-On: I2311d1fa3772ba6be378ad6f497ed4c0df9b7aa8
Depends-On: I3af555c31320d8e9b1362dfc8bf0d8315539ba4f
Depends-On: I1d9e1c94b814b22a7691b710ed033526cc823032
Change-Id: Ifa67cf4e05a318539f6254a631de14156c41d462
2024-07-09 23:55:44 +02:00
Bartosz Dziewoński
252bacff34 RecentChange: Replace use of legacy error arrays
Replace uses of soon-to-be-deprecated methods:
* ApiBase::errorArrayToStatus
* PermissionStatus::toLegacyErrorArray

Deprecate and replace uses of:
* RecentChange::doMarkPatrolled

Change-Id: I2311d1fa3772ba6be378ad6f497ed4c0df9b7aa8
2024-07-09 21:48:34 +00:00
Ebrahim Byagowi
fab78547ad Add namespace to the root classes of ObjectCache
And deprecated aliases for the the no namespaced classes.

ReplicatedBagOStuff that already is deprecated isn't moved.

Bug: T353458
Change-Id: Ie01962517e5b53e59b9721e9996d4f1ea95abb51
2024-07-10 00:14:54 +03:30
Bartosz Dziewoński
b5fb2b724a ApiFormatTestBase: Fix test failures with extensions
Many tests were failing for me locally with CentralAuth installed.

Change-Id: I3e4e28c49e7b7906e81ca9b78ddc20b6de2ca7d3
2024-07-08 00:14:20 +02:00
Kosta Harlan
37306f5efb
ApiEditPageTest#testCreateImageRedirectAnon: Disable temp user feature
Why:

- The test checks for anon edit functionality specifically

What:

- Disable temp user feature for this test

Bug: T365669
Change-Id: I856ff3cb5ed64fd2d46a7cffc5084415f66ee536
2024-06-27 13:42:52 +02:00
jenkins-bot
78f6e3a602 Merge "ApiParseTest: Set a user in method call that generates log entry" 2024-06-26 12:54:45 +00:00
Kosta Harlan
0332b96e51 ApiParseTest: Set a user in method call that generates log entry
Why:

- Anon authority will generate manual log entries with an anonymous
  actor, which won't work with temp accounts enabled

What:

- Set the context user to a regular account before calling
  ::setVisibility on a list from RevisionDeleter

Bug: T365669
Change-Id: I3a813c69abcc715eec5048acc316d1fb43242b01
2024-06-26 11:37:48 +00:00
Kosta Harlan
638117c424
ApiQueryWatchlistIntegrationTest: Disable temp account in anon edit
Why:

- The test class does anonymous edits, but did not first disable temp
  user creation

What:

- Disable temp user creation before attempting an anonymous edit
- Enable temp account feature when calling doTempPageEdit
  - Remove call to enableAutoCreateTempUser in testShowAnonParamsTemp, as
    it's no longer needed

Bug: T365669
Change-Id: I2ce83d5703ecc75fe680d7ddb44aa406c26c4df5
2024-06-26 13:13:54 +02:00
Kosta Harlan
059d155dd3 ApiQueryRecentChangesIntegrationTest: Fixes for temp accounts
Why:

- This test does not pass when temp accounts are enabled

What:

- Set disableAutoCreateTempUser when doing an anon page edit
- Set a valid pattern for the temp user name

This patch does not fix testUserPropParameter but does solve the other
failures for this class.

Bug: T365669
Change-Id: I24b3ff10c6275a9c13c3f07d97ea14581f975067
2024-06-26 10:55:32 +00:00
Kosta Harlan
c7c1404d27 ApiQueryUserContribsTest: Disable temp account feature
Why:

- This test exercises code that checks for IP edits

What:

- Disable temp user feature for this test class

Bug: T365669
Change-Id: If385b71b76c16f9276c3973a02ca0c888b47d3a3
2024-06-26 10:55:32 +00:00
Kosta Harlan
a64e3d6c3a ApiRevisionDeleteTest: Use registered authority for tests
Why:

- Anon authority will generate manual log entries with an anonymous
  actor, which won't work with temp accounts enabled

What:

- Switch test cases to use registered authority mock

Bug: T365669
Change-Id: I4d3a79506d2f1fc744fc32b75e560f084738bdd7
2024-06-26 10:55:32 +00:00
Kosta Harlan
534ecdd49c ApiTestCase: Set request context user to session user
Why:

- In some situations (e.g. tests in ApiRevisionDeleteTest),
  the context user ID / name was being unset by code in Session

What:

- Set the session user to the request context user

Bug: T365669
Change-Id: Ife2cc31133bafb6a2c0adfeebcb2e1a139f25f48
2024-06-26 10:55:32 +00:00
jenkins-bot
291aab76dd Merge "ApiEditPageTest: Set a user in method call that generates log entry" 2024-06-26 10:54:41 +00:00
Kosta Harlan
6a938585b3 ApiEditPageTest: Set a user in method call that generates log entry
Why:

- When temp accounts are enabled, creation of new log entries needs to
  be associated with a named user account or temp account

What:

- Set the context user to a regular account before calling
  ::setVisibility on a list from RevisionDeleter

Bug: T365669
Change-Id: I1be6924a92309ea5da75df37910949440e23c937
2024-06-26 10:27:51 +00:00
Bartosz Dziewoński
0c2fb030e2 Message: Rename 'interface' prop because of syntax highlighting
Some syntax highlighters, in particular Gerrit's, incorrectly handle
code that uses a property named 'interface' (which is a PHP keyword).
https://phabricator.wikimedia.org/F55884039

Rename it to avoid problems.

Message isn't '@stable to extend', so this is not a breaking change.
I couldn't find any extensions that refer to it anyway.

Change-Id: I6676421222921b7bb1aeeefef79dd06072c1c2ac
2024-06-26 02:04:59 +00:00
jenkins-bot
a1d3e66790 Merge "ApiChangeContentModelTest: Disable temp accounts for anon test" 2024-06-25 21:53:55 +00:00
jenkins-bot
1436e324e7 Merge "ApiComparePagesTest: Disable temp accounts for anon tests" 2024-06-25 21:42:55 +00:00
Kosta Harlan
5042215d85
ApiComparePagesTest: Disable temp accounts for anon tests
Bug: T365669
Change-Id: I3b641fe8e93e3a302092c5097e87b4c3de2e7225
2024-06-25 22:05:28 +02:00
Kosta Harlan
60310c37d0
ApiChangeContentModelTest: Disable temp accounts for anon test
Bug: T365669
Change-Id: Ib6e789f0b2363118890c8ccc04316d9cd08fcf5b
2024-06-25 22:01:56 +02:00
Wandji69
c257e2276c Replace db with getDb for Tests
Bug: T316841
Change-Id: I29e535e8ee9b5641a4546d53b98cd5060d39681d
2024-06-23 23:47:56 +01:00
jenkins-bot
52e66c8aa8 Merge "api: Rewrite adrto/from/prefix handling to use expression builder" 2024-06-18 14:16:23 +00:00
Umherirrender
883b3f08fb api: Rewrite adrto/from/prefix handling to use expression builder
For a deduplication the raw sql is used as string key in an array.
Now only the search term is part of the key, build the sql a bit later,
as objects not usable in array keys.

The deduplication is needed when namespaces have different first letter
configs as happen with $wgCapitalLinks = false for all namespaces except
the hard coded like user and mediawiki with talk.
Searching for lower case titles splits the query

Bug: T361023
Change-Id: Ia4e29d1d4d816f354318ef443ae19c954fd52274
2024-06-17 22:36:10 +02:00
jenkins-bot
5f49cafa64 Merge "ApiQuerySiteinfo: Use TempUserConfig class" 2024-06-14 14:25:24 +00:00
jenkins-bot
a0fd50682e Merge "TempUserTestTrait: Use an array for config overrides when disabling" 2024-06-14 14:03:49 +00:00
Kosta Harlan
2ed2467a7a
ApiQuerySiteinfo: Use TempUserConfig class
Why:

- Using TempUserConfig is more flexible as it doesn't require us to know
  about the internal details of the AutoCreateTempUser config object

What:

- Use TempUserConfig service instead of loading the AutoCreateTempUser
  object
- Remove properties from ApiQuerySiteInfo that don't already have
  getters. If someone has a need for more this information to be exposed
  in ApiQuerySiteInfo, they can be added in a separate patch
  - This seems compatible with the goals of T335532 which was about
    making it possible to discover via the API if an action would result
    in a temp account
- Implement __toString for Pattern, so that it can be used in
  ApiQuerySiteInfo

Bug: T335532
Change-Id: Ica84b3e9b9865b8b83a9e9e513c99cd2e47661c9
2024-06-13 22:11:27 +02:00
Kosta Harlan
cef704c72a
TempUserTestTrait: Use an array for config overrides when disabling
Why:

- Consistency with the enableAutoCreateTempUser method
- Allows for overriding config properties (e.g. 'known')

What:

- Use an array as the parameter for `disableAutoCreateTempUser` instead
  of a string

Change-Id: I1a495cc83effcf92364fa489f779c5f4bf2d29b9
2024-06-13 21:42:35 +02:00
frankie
17b2250683 Migrate MediaWiki.editstash to statslib
Modifies incrStatsByContent in order to migrate cache_misses, cache_hits to Prometheus backend

Bug: T359465
Change-Id: I78afac7437bc2849b64f43c23477d702b94e907b
2024-06-13 17:11:33 +00:00
Tim Starling
b4591f1960 user: Add "global" parameter to ApiOptions
Add a "global" parameter to ApiOptions which allows it to update or
override global preferences.

Bug: T323076
Depends-On: I686c0091768ed330683fff89201fae4f93b8a1c4
Change-Id: Ieb2d0c0d0da5c51b2a47ed8a967a47b4e7ad4577
2024-06-13 15:22:47 +00:00
Bartosz Dziewoński
da1c476b8f Add "implements/extends Stringable" to more classes and interfaces
Follow-up to ccd423225f,
which missed some classes and all interfaces.

Change-Id: Ida0477d548c767f116eb8f465090a19f7986f7ca
2024-06-13 16:06:14 +02:00
Bartosz Dziewoński
ccd423225f Add "implements Stringable" to every class with "function __toString()"
In PHP 8, but not in PHP 7.4, every class with a __toString() function
implicitly implements the Stringable interface. Therefore, the
behavior of checks like "instanceof Stringable" differs between these
PHP versions when such classes are involved. Make every such class
implement the interface so that the behavior will be consistent.

The PHP 7.4 fallback for the Stringable interface is provided by
symfony/polyfill-php80.

Change-Id: I3f0330c2555c7d3bf99b654ed3c0b0303e257ea1
2024-06-13 00:23:39 +00:00
Tim Starling
94151fcde9 user: Move "reset kinds" concept to PreferencesFactory
Fix the dependency loop between PreferencesFactory and
UserOptionsManager by moving the concept of "reset kinds" or "option
kinds" to PreferencesFactory.

Note that this is a half-baked feature from 2013 (I5f9ba5b0dfe7c2ea)
that is not really used for anything. Apparently only the "all" and
"unused" kinds are used.

The strong dependencies on PreferencesFactory internal details show that
this feature belongs in PreferencesFactory. But UserOptionsManager can
reset "all" preferences without help from PreferencesFactory, so add a
helper for that.

The rationale for putting it in UserOptionsManager was that eventually
all preference definition information should move to UserOptionsManager
(T250822). I don't agree with that. UserOptionsManager is the key/value
store which backs PreferencesFactory. I need to refactor it further for
T323076 and it will help to have these concepts be separate.

Hard-deprecate UserOptionsManager methods resetOptions, listOptionKinds
and getOptionKinds. Add convenience methods to replace calls to
resetOptions().

I couldn't understand the logic in resetOptions(). Why was it copying
old values instead of just omitting them? Why was it assigning null but
only for "all"? setOption() had a documented method for resetting an
option to the default, so I just used that.

Bug: T323076
Depends-On: I1ed0a1a9f6492fb50254104fa4bc9f2130218323
Change-Id: I900fd4a48c96d91491eae54824e7bf02a004843d
2024-06-11 23:50:21 +00:00