Commit graph

37 commits

Author SHA1 Message Date
Amir Sarabadani
830c51f0a2 Specials: Mass switch everything to IConnectionProvider from LB
Bug: T330641
Change-Id: Ie1772da59f92213fea598f02385c3e0ac6d200a7
2023-04-19 19:19:16 +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
Amir Sarabadani
cb18d1007e Reorg: Move ActorMigration and ActorMigrationBase to user/
This may seem a bit weird but anything else related to actor is already
under user/ including ActorCache, ActorNormalization, ActorStore and
ActorStoreFactory.

Bug: T321882
Change-Id: I7072b374bba7a0cd9d905e399c822bf30bd5c0d8
2022-12-16 13:44:33 +01:00
Derick Alangi
d4ae3e8839 tests: Migrate away from setMwGlobals() to overrideConfigValue(s)()
Change-Id: I1b0e8e2cf4d85ae5ce8ad090cfc47f5086350702
2022-08-14 22:23:25 +01:00
Umherirrender
68cef1ab99 Various whitespace changes
Change-Id: I31f316c66b3066461b9297c7b6f9845ade99f0df
2022-07-12 20:07:23 +02:00
Umherirrender
047c184bfe tests: Use Title::makeTitle instead of Title::newFromText
Avoid parsing known titles in tests to improve performance

Change-Id: Ibfccfe696f0b8bfda0b99abae324e60bbecef7d8
2022-07-06 00:44:00 +02:00
Umherirrender
f01a391f0d tests: Fix types in documentation by adding use statements
Some types used in @param/@return are not correct,
because the class is not used with namespace

Change-Id: Ic2643687378a6addabc2c9cd402224e442257f86
2022-05-29 07:11:15 +00:00
Umherirrender
770f905900 tests: Use namespaced IDatabase class
Change-Id: I7171ff26faee00d9eaabc33c2f3d91049ea0b40d
2022-05-28 00:09:55 +02:00
Alexander Vorwerk
decbaf4f38 phpunit: use ->getServiceContainer() in integration tests
Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
2022-01-27 22:04:16 +01:00
Tim Starling
f7f84dddb3 Introduce CommentFormatter
CommentParser:

* Move comment formatting backend from Linker to a CommentParser service.
  Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
  was used for.
* Rename the "autocomment" concept to "section link" in public
  interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
  static analysis and code review.

CommentFormatter:

* Add CommentFormatter and RowCommentFormatter services as a usable
  frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.

Linker:

* Remove Linker::makeCommentLink() without deprecation -- nothing calls
  it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
  commentBlock() and revComment().

Caller migration:

* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
  ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
  ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
  ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager

Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-09-28 11:13:03 -07:00
Tim Starling
ba5c3039ce Reduce Special:Contributions query count
ContribsPager was doing an actor table query from User::load() for
every row. Instead pass a UserIdentity to the constructor which can
cache the user ID. Most callers already had a UserIdentity with the
data already cached.

There are some weird kinds of targets which are not really users, but
UserIdentity was constructed unconditionally already, so I'm not
changing that. I did allow the target option to still be used in case
there is any future problem with round tripping strings through
UserIdentity.

Add integration tests.

Change-Id: Ifd05103fa648d0778ef5185fc73128d38d5fce74
2021-08-25 16:19:10 +10:00
Tim Starling
088a313fec ContribsPager row filtering with RevisionStore::isRevisionRow
Flow hooks into ContribsPager, causing formatRow() to be called with
FormatterRow objects instead of stdClass objects. formatRow() is
expected to silently decline to format such objects, leaving formatting
up to a subsequent hook.

Instead of calling newRevisionFromRow with all warnings suppressed and
all exceptions caught, provide isRevisionRow() which determines whether
the row is valid. Thus, unexpected exceptions will be visible and the
code does not depend on details of how newRevisionFromRow() validates
its arguments.

Bug: T288563
Change-Id: Id0316886d770cd905897d515b3eb658a5875bd80
2021-08-10 17:59:30 -07:00
Umherirrender
134045b9aa tests: Swap assertion order in unit tests
Changes from patch set Icb93c79f4843b59dae80d3eda1a880457a1a68f2
Also some swaps from assertEquals to assertSame/True/False/Null

Change-Id: Ife497ae6cb1888b77eb25e85b76df72adc65641a
2021-08-04 20:21:01 +02: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
Tim Starling
99a0ab599c Contributions: when ip_changes is the "target table", put it first
When we are using ip_changes for ORDER BY and the main query conditions,
put it first in the table list so that the MariaDB query planner doesn't
get confused. The join condition gets moved from ip_changes to revision,
but should have the same effect.

Bug: T284419
Change-Id: I7b9b48b0e78ca0a7c3849b829f9eb3cdc6e02207
2021-06-08 12:57:57 +10:00
DannyS712
c0dd682544 Start removing places using Revision objects
- EditPage::$mBaseRevision
- EditPage::getBaseRevision()
- Title::getFirstRevision()
- LinksUpdate::setRevision()
- LinksUpdate::getRevision()
- Article::$mRevision
- Article::getRevisionFetched()
- WikiPage::getOldestRevision()
- WikiPage::getRevision()
- ContribsPager::tryToCreateValidRevision()

To make things easier, instead of rewritting
the Revision tests that were using WikiPage::getRevision,
just delete them, its not worth the effort to rewrite
them since the class is going away. For the WikiPage
tests, replace uses of getRevision with getRevisionRecord,
manually converting to a Revision object where needed

Bug: T247143
Change-Id: I52bc1f49649f8bd25797e3f7a090bec9c63ac2d1
2021-04-30 12:33:15 -07:00
daniel
4dce6dd0c3 Deprecate UserIdentity::getActorId()
Note: User::getActorId() is not (yet) deprecated.

Bug: T274179
Change-Id: Ic2ca6d489db821fc2334e53bf2496c7b0d3ea5b1
2021-03-13 19:45:57 +01: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
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
Umherirrender
e7dd18b584 Fix ContribsPagerTest when running alone
When running the test in isolation or all tests from the /specials/ folder
the test is failing and internally an exception is thrown:
> Could not determine title for page ID 2 and revision ID 2
Just provide a Title object, because there is no guard that the revision
2 with a title exists on the database or such.

Change-Id: I8c251fcc5413971e52bafd09aeb6f1497cc65146
2020-10-29 20:40:46 +00: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
DannyS712
0637d80572 Hard deprecate the rest of the Revision class
Bug: T246284
Change-Id: I126d7892c90aa2200c668b5717820e729613bed8
2020-07-02 09:02:02 +00:00
addshore
959bc315f2 MediaWikiTestCase to MediaWikiIntegrationTestCase
The name change happened some time ago, and I think its
about time to start using the name name!
(Done with a find and replace)

My personal motivation for doing this is that I have started
trying out vscode as an IDE for mediawiki development, and
right now it doesn't appear to handle php aliases very well
or at all.

Change-Id: I412235d91ae26e4c1c6a62e0dbb7e7cf3c5ed4a6
2020-06-30 17:02:22 +01:00
Thiemo Kreuz
5f3a92385b Fix visibility of setUp/tearDown
Change-Id: I636be48eb9f713680abac35d46091f7b49374696
2020-06-16 21:02:05 +02:00
DannyS712
02e1285c1a Hard deprecate ContribsPager::tryToCreateValidRevision
Bug: T250431
Change-Id: Icffe4c407f46e068fb27b0632d93fcaac2b6cfa9
2020-05-01 18:30:56 +00:00
DannyS712
f456c7bfd5 Add ContribsPager::tryCreatingRevisionRecord
Soft deprecate ::tryToCreateValidRevision (to be hard deprecated once
MobileFrontend is updated)

In caller, replace use of Revision methods with corresponding
RevisionRecord calls.

Bug: T250431
Bug: T250580
Bug: T250980
Bug: T250579
Bug: T250714
Change-Id: Ic7be7d5cf5158482ee6fe08b179560460b6ccd32
2020-04-27 08:39:42 +00:00
Aaron Schulz
1238043eff Add MediaWikiIntegrationTestCase::assertArraySubmapSame()
Also fix PHPUnit 9 warning in PNGMetadataExtractorTest about $delta.

This should fix all of the integration test warning spam.

Bug: T244095
Change-Id: I0e2a76d5df2685ae5ad1498864e0b5f9db60c0cc
2020-03-19 15:53:59 -07:00
Max Semenik
48a323f702 tests: Add explicit return type void to setUp() and tearDown()
Bug: T192167
Depends-On: I581e54278ac5da3f4e399e33f2c7ad468bae6b43
Change-Id: I3a21fb55db76bac51afdd399cf40ed0760e4f343
2019-10-30 14:31:22 -07:00
Umherirrender
5bd311b1a2 Add public as visibility in tests folder
Add public, protected or private to function missing a visibility
Enable the tests folder for the phpcs sniff

Change-Id: Ibefce76ea9984c47e08c94889ea2eafca7565e2c
2019-10-10 21:55:37 +02:00
Umherirrender
e3c9107089 Use the existing link renderer in the special page pagers
Use SpecialPage::getLinkRenderer and pass it to the pagers
Since I082152b64141f1a9a4085bba23fe81a99ec8d886 it is a property in the
IndexPager and can be used by getLinkRenderer

Change-Id: I2be8a8b9f2b0b8c04fe9e18aa1959987fc125f50
2019-09-01 20:32:30 +02:00
Brad Jorsch
c1db9d7443 ContribsPager: Fix slow queries
When ContribsPager is using an auxiliary table like ip_changes or
revision_actor_temp for the main action of the query, we already had
code in place to let it use the auxiliary table's denormalized timestamp
field for the ordering. What we didn't have was code to let it also use
the auxiliary table's denormalized timestamp field for *continuation*.

With the schema defined in tables.sql, the simplest thing to do would be
to be to add a redundant JOIN condition between rev_timestamp and the
denormalized timestamp field which would be enough to allow
MySQL/MariaDB to propagate the continuation conditional on rev_timestamp
to the denormalized timestamp field.

Unfortunately many Wikimedia wikis have rev_timestamp defined
differently from table.sql (P8433), and that difference is enough to
break that propagation. So we need to take a more difficult route,
restructuring the code tell IndexPager to explicitly use the
denormalized fields for ordering and continuation.

On the plus side, since we're doing that anyway we can get rid of the
code mentioned in the first paragraph.

Bug: T221380
Change-Id: Iad6c0c2f1ac5e1c610de15fe6e85a637c287bcd8
2019-04-30 21:07:32 -04:00
Thiemo Kreuz
a88be858ee Fix order on Special:Contributions when timestamps are identical
Please see T200259#4827781 for a longer explanation why this is needed.

Bug: T200259
Change-Id: I1678f7ec994328a96eed208483421be2f82be0ce
2018-12-20 18:12:07 +01:00
Kunal Mehta
8956885666 Add @covers tags to specials tests
Change-Id: I626155b890580af38c09795b2b31f625fe942358
2017-12-24 23:29:00 -08:00
MusikAnimal
d09554b6ef Add basic IP range support to Special:Contributions
This works by using the new table introduced with T156318.

The only thing that differs from normal Special:Contribs is we are
showing the IP address next to each entry. This is it how it is
displayed if you request to see newbie contributions:
https://en.wikipedia.org/wiki/Special:Contributions?contribs=newbie

For the time being, Special:DeletedContributions does not support
IP ranges. Various other irrelevant links such as Uploads and Logs
are also hidden.

Refer to P4725 for a way to automate creation of edits by random
IPs in your dev environment.

IP::isValidBlock() has been deprecated with this dependent change:
https://gerrit.wikimedia.org/r/#/c/373165/

Bug: T163562
Change-Id: Ice1bdae3d16cf365da14c6df0e8d91d2b914e064
2017-09-05 16:15:33 -04:00
Geoffrey Mon
287ddb4c9a Fix action=feedcontributions date filtering parameters
* Convert year/month date filter parameters to use start/end so that
  ApiFeedContributions still works as expected after b668887
* Move SpecialContributions::processDateFilter (used to convert
  year/month parameters to start/end parameters) to ContribsPager
  since ApiFeedContributions also uses it now

Bug: T166859
Change-Id: I34fc8388a29e4cd36474934e6266127d0e3253cd
2017-06-06 10:41:40 -04:00
Renamed from tests/phpunit/includes/specials/SpecialContributionsTest.php (Browse further)