Commit graph

17 commits

Author SHA1 Message Date
Amir Sarabadani
8e183495e1 Stop using LoadBalancer::getConnectionRef() so it can be hard-deprecated
Bug: T326274
Change-Id: I90493d7cd4c21fdc022bcc19765fc04d986a9c8f
2024-04-30 13:31:08 +01:00
Umherirrender
01eb29b691 tests: Return FakeResultWrapper from mocked IReadableDatabase::select
To match the return type documentation of IReadableDatabase::select

Change-Id: Ib8b93a22182d8dd82ecec467fba6889f249c04b2
2024-04-19 21:30:23 +02:00
Timo Tijhof
a2b9e84c22 Permissions: Widen @covers tags in tests
> We lose useful coverage and waste valuable time on keeping tags
> accurate through refactors (or worse, forget to do so).
>
> Tracking tiny per-method details wastes time in realizing (and
> fixing) when people inevitably don't keep them in sync, and time
> lost in finding uncovered code to write tests to realize it was
> already covered but "not yet claimed".
>
> Given all used methods are de-facto and liberally claimed, and
> that we keep the coverage limited to the subject class, this
> maintains the spirit and intent. PHPUnit offers a more precise
> tool when you need it (i.e. when testing legacy monster classes),
> but for well-written code, the class-wide tag suffices.

Ref https://gerrit.wikimedia.org/r/q/owner:Krinkle+is:merged+message:Widen

Change-Id: I89f510232554fddeaff90e264e3b396448623888
2024-04-11 22:11:56 +01:00
Máté Szabó
aa3b388b5b Permissions: Avoid RestrictionStore lookup for unsupported actions
When rendering Special:RecentChanges for an user with rollback rights,
the software checks whether the user has permission to perform the
rollback action on each entry via User::probablyCan(), which
delegates to PermissionManager. This in turn checks for each entry
whether the title has protections (e.g. from action=protect) against the
"rollback" action, which is unlikely to be the case since by default
wgRestrictionTypes only supports create/edit/move/upload.

This triggers noticeable memcached I/O and overhead.[1]

So, as an optimization, avoid fetching page restrictions in
RestrictionStore for action types that are known to not be restrictable
via page protection. In the unlikely event that wgRestrictionTypes is
customised to offer separate restrictions for "rollback", this will
work continue to work as expected and is covered by tests.

-
[1] acd6281072/recentchanges.speedscope.json

Bug: T341319
Change-Id: I912e4ef2fa3d48238c01631d4f35940aea93ab03
2024-04-11 21:02:53 +00:00
James D. Forrester
35b2542895 Namespace includes/cache
Bug: T353458
Change-Id: Ic3f3168ef17113f5fb3ec11e0a47f52d65eefba9
2024-02-20 10:28:03 -05:00
Reedy
a1144dc7c5 mark various anonymous functions as static
Change-Id: Iefe896769359f0d32e52bf20aa03e1c3715d5074
2023-08-22 19:38:38 +00:00
Umherirrender
fe40101587 Replace IDatabase::delete with DeleteQueryBuilder
Change-Id: Ie0c1c955ca1a7028f75f24563fdeb9f94285af30
2023-06-21 17:50:31 +02:00
Umherirrender
d36073cdcf tests: Make some PHPUnit data providers static
Initally used a new sniff with autofix (T333745),
but some provide are defined non-static in TestBase class
and need more work to make them static in a compatible way

Bug: T332865
Change-Id: I889d33424f0c01fb26f2d86f8d4fc3de3e568843
2023-05-20 01:05:27 +02:00
Tim Starling
5e30a927bc tests: Make some PHPUnit data providers static
Just methods where adding "static" to the declaration was enough, I
didn't do anything with providers that used $this.

Initially by search and replace. There were many mistakes which I
found mostly by running the PHPStorm inspection which searches for
$this usage in a static method. Later I used the PHPStorm "make static"
action which avoids the more obvious mistakes.

Bug: T332865
Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
2023-03-24 02:53:57 +00:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00
Umherirrender
607dde7c0c permissions: Check cascade protection only if page can exists
No need to ask the database for special pages

Set valid title in tests to pass canExists check

Change-Id: Ic6db74cf671484db475a0a646b372c814ea41918
2023-02-10 20:11:07 +00:00
Amir Sarabadani
d9e00a3ead RestrictionStore: Migrate Database::select usages to SelectQueryBuilder
Bug: T311866
Change-Id: I420d3904cbda6997b63bd0b2fce47926d94811d8
2022-09-30 17:48:07 +02:00
jenkins-bot
d2a8287ed4 Merge "RestrictionStore: Do not return upload as a restriction for non-existent titles" 2022-09-06 16:56:50 +00:00
Umherirrender
167fb2a979 unit tests: Use MainConfigNames constant to refer configs
When creating ServiceOptions objects or fake HashConfigs use the
constant to refer the config name

Change-Id: I59a29f25b76e896c07e82156c6cc4494f98e64cc
2022-08-17 22:33:58 +02:00
Amir Sarabadani
244127fc5d RestrictionStore: Add support for templatelinks migration
For checking cascade protection.

Bug: T308207
Change-Id: Ia7a3ec84e8de11a77f3addc05e3de0bab2cb51a6
2022-05-13 23:45:24 +00:00
Dylsss
d7574546a8 RestrictionStore: Do not return upload as a restriction for non-existent titles
WikiPage::doUpdateRestrictions only allows create protection for non-existent pages, so do not return upload as an available restriction for non-existent titles.

Bug: T298453
Change-Id: I5ed84a5a6213035afc9cc8710bb72bedfd9756ce
2022-01-03 16:19:15 +00:00
Aryeh Gregor
cf818256fb New RestrictionStore service
This allows checking restrictions without a dependency on Title, based
only on a PageIdentity.

Additional fixes along the way:

* Correctly return false instead of 'infinity' for
  getRestrictionExpiry( 'create' ) on an existing page
* Correctly handle non-special pages that can't exist (like media pages)
  in listApplicableRestrictionTypes() (return empty array instead of
  'create')
* Improve readability of isProtected()

The expectation change in TitleTest::testIsProtected() is because the
test was formerly broken, since it set mRestrictions without setting
mRestrictionsLoaded. (Which illustrates how this approach to testing is
essentially broken.)

Co-authored-by: Vedmaka <god.vedmaka@gmail.com>
Bug: T218395
Change-Id: Ia73ea587586cb69eb53265b2f8f7a296a2573dd0
2021-08-28 16:01:06 +00:00