Commit graph

35 commits

Author SHA1 Message Date
thiemowmde
4e7c3ca094 Use native str_contains/str_starts_with in a few more places
This makes the code quit a bit more readable, I believe.

strpos is especially confusing because it can return false when a
string doesn't contain the needle, as well as 0 when the string
starts with the needle. This is sometimes used as a feature (i.e. to
check if a string contains the needle, but doesn't start with it),
but that's not the case here.

A slightly more complicated change is made in TitleTest. But this is
only in a test and should verify itself when the test still succeeds.

Change-Id: I355ad1dc8e1725ae7a1eb652ec047ce7ff589cdf
2024-01-25 12:17:27 +01:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
Amir Sarabadani
73e11b8745 Tests: Only skip tests related to the temp table reopen issue in MySQL
This is fixed in MariaDB so we can keep it running in majority of our CI
without any issues

Bug: T256006
Change-Id: If68883969f8762c761b152cd18bdeb19d3a6c40d
2023-06-09 02:31:03 +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
jenkins-bot
1d045146d0 Merge "Make use of the new PageUpdateStatus" 2022-12-01 10:45:32 +00:00
daniel
166b569444 Make use of the new PageUpdateStatus
PageUpdateStatus provides clean access the the newly created
RevisionRecord.

Depends-On: Ia08c586198082ea47e8313d0d41835f9830fb29e
Change-Id: Id6963842321c4eaa3d7d029ad0b769f73433c103
2022-11-30 17:56:58 +00:00
Umherirrender
c6fecd5ab0 tests: Replace assertEmpty with assertSame
assertSame avoids use of loose comparisons and
allows to check the expected type

Change-Id: If821d1be2bc1ff9f8b70968a339f33c7a8e8880a
2022-11-25 00:42:53 +01:00
Thiemo Kreuz
29aca66975 Fix visibility of setUp methods in tests
Change-Id: Iefc05b4f4a9c258a385a22fc8d87b29648900e44
2022-05-17 14:11:22 +02:00
Alexander Vorwerk
decbaf4f38 phpunit: use ->getServiceContainer() in integration tests
Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
2022-01-27 22:04:16 +01:00
Umherirrender
db9e0391d7 Fix signature of DatabasePostgres::buildGroupConcatField
The method in the postgres layer has an extra argument in the middle,
making the last parameter unused and the join condition is not passed to
build the subquery.
For usage of that function with a join the join condition are missing
and making the subquery returning a cartesian product, in case of change
tags with all existing tags in the wiki.

The code is there since the addition of the function in a974025
It is first used in a in a5500e7 for the change tags

Bug: T195807
Bug: T256401
Change-Id: I4e73e37d176a6368e65aeb21e5dbed14edd24f19
2022-01-22 11:40:28 +01:00
Reedy
6e29611642 Remove or replace usages of "sanity"
Still some more to go...

Bug: T254646
Change-Id: Ia117f01e443c35b4765f3275cab4f2707e1be96f
2021-11-21 16:42:31 +00:00
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
DannyS712
b876af50cc Fix order of parameters in assertions
Should be expected, and then actual

Switched some assertEquals to assertSame to fix failing
phpcs sniffs

Change-Id: I7257c5afacd22fed78a58f3cc918b721ac11a46d
2021-05-03 15:50:53 +00:00
daniel
fed7f0b179 Remove $actor field from UsererIdentityValue
Code that needs to store an actor ID in the database to
represent a UserIdentity, or needs to construct a UserIdentity based on
an actor ID loaded from the database, should use the ActorNormalization
service.

Note: The getActorId() method is removed from the UserIdentity interface,
but all concrete classes continue to support it for now.
UsererIdentityValue::getActorId() is hard deprecated and should
be removed in 1.37. It always returns 0.
User::getActorId() is not deprecated at this point.

Bug: T274179
Depends-On: Id2b3ddf6a2a7cdf90f8936a69148d2cce6fde237
Change-Id: I9925906d11e47efaec3c1f48d5cb3f9896a982c1
2021-04-13 18:18:06 +00:00
DannyS712
e0c2f363e0 ContributionsLookupTest: reduce duplication
Instead of using MediaWikiServices to retrieve all
of the dependencies, and then manually creating the
ContributionsLookup object, just retrieve the
ContributionsLookup from MediaWikiServices, which
does the same thing without the duplication.

Implement a helper method to simplify
potential future switch to unit tests

Change-Id: Icbb6d92553146a559768f01ae7087f30e22f1e6a
2021-03-14 19:57:28 +00:00
Umherirrender
a1de8b8700 Tests: Mark more more closures as static
Result of a new sniff I25a17fb22b6b669e817317a0f45051ae9c608208

Bug: T274036
Change-Id: I695873737167a75f0d94901fa40383a33984ca55
2021-02-09 02:55:57 +00:00
Reedy
eb41565a9a Tests: Start marking some closures as static
Bug: T274036
Change-Id: Ib738ecd3bc23d34900bc268c8246702ac3655746
2021-02-06 19:57:42 +00:00
jenkins-bot
cd2c210302 Merge "Convert RevisionRecord to Authority and PageIdentity" 2021-01-21 21:46:23 +00:00
Petr Pchelko
816e02ae51 Convert RevisionRecord to Authority and PageIdentity
As we convert the RevisionRecord to using Authority,
we no longer need Title instances, so we can convert
that to PageIdentity.

Ideally, we'd part away from using Title at all, but:
1. For foreign wikis PageIdentity has stronger validation,
so calling PageIdentity getId() on Title will break things.
There's still a lot of code depending on lax Title guarantees,
so we keep it.
2. A lot of code still depends on Title, so we try to pass it
through even if we don't nesessarily need to, to save cost
on recreating it later on.

Bug: T271458
Depends-On: I287400b967b467ea18bebbb579e881a785a19158
Change-Id: I63d9807264d7e2295afef51fc9d982447f92fcbd
2021-01-21 13:37:01 -06:00
Petr Pchelko
2dd374f038 Make ContributionsLookup use Authority
Change-Id: Idcddff0f9c1968e24dc8d7d767e3233e368ec029
2021-01-21 13:45:18 +00:00
Umherirrender
7f03231ace Inject services into SpecialContributions/SpecialDeletedContributions
This covers only directly used services by this special page and pager
Services used by the base class are not part of this patch set

Have to change another service to avoid global state

Bug: T259960
Depends-On: I07203e22f4b254df5c8cd6180d915a1537b7de30
Change-Id: Ifed2cbd2eee7166daf2e7d9bab017786247f88f6
2020-11-24 17:18:40 +00:00
Nikki Nikkhoui
c26d64fc18 UserContributions endpoint add tags 'display' property
Add a property to the 'tags' object in the /user/{name}/contributions
REST endpoint named 'display' which shows the display
HTML for the tag which is either defined in i18n .json
files or overriden at MediaWiki:tag-$name

Bug: T259716
Depends-On: I57e2a7253944a3fde3f52f52bbf5fe8473c8a415
Change-Id: Id755adcab8b0115e19df2a6046643ebe97881e28
2020-08-19 06:04:50 -07:00
Nikki Nikkhoui
43f2d5440f Rename 'revisions' to 'contributions'
Extensions have the ability to inject their own idea of what
a contribution is into the ContribsPager query resultset (via
the ContribsPager__reallyDoQueryHook). Because of this,
stable chronological ordering of ContribsPager results
becomes virtually impossible

For the purpose of the User Contribution REST endpoints, we will
restrict the resultset to ONLY mediawiki revisions for now.

This patch renames 'revisions' to 'contributions' and adds the
'type' field to future-proof work on adding different kinds of
contributions to the User Contribution REST endpoints.

Bug: T257838
Change-Id: I1e6de1c14a5f47e0310df86325fa6d791833addb
2020-07-22 18:29:29 +02:00
Nikki Nikkhoui
268400fbde Add option to not call onContribsPager__reallyDoQuery hook
For some use cases (e.g. UserContributions endpoints (T235073) )
we do not want extensions to be able to inject their own
contributions into the result set of ContribsPager.

This is because extensions may not be adding revisions, but
other types of 'contributions'. With the hook enabled,
we are unable to reliably enforce strict chronological
ordering of contributions. (See T200259 for explanation).

Disabling the hook provides a consistent set of revisions for the
User Contribution endpoints.

Bug: T257839
Change-Id: I239395c572d4cb32a4d9ee871ffa02accfdce837
2020-07-22 18:00:51 +02:00
daniel
afdcacbfd5 REST /me/contributions/count filter by tag
Bug: T251806
Change-Id: Ib071ebb91f20a0ca1c0e14b4a271fc17f343a648
2020-07-06 19:56:17 +02:00
daniel
c1a73e64e1 REST me/contributions/count endpoint
Introduce endpoint for getting a uer's contribution count.

Bug: T251805
Change-Id: I409b7943941437f46dd8cdb2194fca9b7404f185
2020-07-06 09:28:33 +00:00
daniel
2cf5a251b9 me/contributions: filter by tag
Bug: T251803
Change-Id: I5ba4164abe414df4b24858422f2a601e00516d7f
2020-07-02 22:27:21 +02:00
daniel
01b959fb83 UserContributions endpoint: return deltas
Bug: T252202
Change-Id: Ie38c658bddb974ded85a532b2fc556af5706275e
2020-06-26 11:44:57 +02:00
Nikki Nikkhoui
7452d8c067 REST /me/contributions: return change tags
The endpoint for user contributions should include change tags in the
result. Bump the version of npm module api-testing.

Bug: T252202
Change-Id: Iccc0c378bc65d0f34b38557f4c78f424d95a951f
2020-06-25 19:28:02 +02:00
Nikki Nikkhoui
b28ec056f9 Rename ContributionsLookup::getRevisionsByUser
ContributionsLookup::getRevisionsByUser() returns a ContributionSegment,
but the function name was misleading. Renamed to getContributions()
to more accurately reflect the return value.

Change-Id: Id94549f1f8d2dc5ca5769fcb4696a454fdb851ac
2020-06-22 14:58:13 -07:00
daniel
96aacab20b UserContributions endpoint: filter suppressed revisions
ContributionsLookup needs to have the acting user (the authority) passde
in explicitly, so suppressed user contributions can be filtered according
to the user's permissions.

Bug: T252202
Change-Id: I94098f87ae45cd4e1db4a7168bf6e9478e9e32fc
2020-06-16 08:20:32 -07:00
daniel
5601152836 REST /me/contributions: implement backwards paging
This is part of a chain of patches that implement the user
contributions endpoint. This patch adds the ability to navigate
towards newer newer contributions from a response listign older
contributions.

Bug: T252202
Change-Id: I54c43f3c7bd5d2fa55431eda733291a7067bfc75
2020-06-15 11:41:36 -07:00
Nikki Nikkhoui
fbe321166e REST /me/contributions: allow paging forward
This is part of a chain of patches that implement the
user contributions endpoint.

In this patch, we add the ability to page through changes,
from latest to oldest only.

Bug: T252202
Change-Id: If1e862e419ce86b68606ddf28a78304461d3a6d8
2020-06-12 13:50:16 +02:00
daniel
5ac84ffd12 REST /me/contributions: return revisions
This is part of a chain of patches to complete the REST User Contributions
endpoint. This change returns a list of the 2 (hard-coded for now) most
recent revisions for a given user.

Package.json was also updated for new api-testing module (v 1.1.0)

Bug: T252202
Change-Id: I42a5dfc0e1ff7600848e89ac2c4b002e8a3612df
2020-06-09 08:19:45 -07:00
Nikki Nikkhoui
300fcfd00b REST me/contributions: Returns 401 Unauthorized
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
2020-06-09 15:00:25 +00:00