Commit graph

44 commits

Author SHA1 Message Date
Derick Alangi
1854fb02d9 Storage: Warm parsoid parser cache with parsoid outputs
This patch introduces a ParsoidOutputAccess service for
getting parsoid outputs and warms the cache with pregenerated
outputs.

It also introduces a config variable in ParsoidCacheConfig that
is turned off by default for controlling the cache warming.

Bug: T301371
Change-Id: I6152c42ea765d94093d8d62598b1b4278314adec
2022-06-28 09:05:41 +00:00
Alexander Vorwerk
62a70ec7c7 Use new namespace for revision related classes
All revision related classes are namespaced MediaWiki\Revision
instead of MediaWiki\Storage since 1.32. The old namespaced
class names are deprecated and only kept for backwards-compatibility.

Bug: T305784
Change-Id: Ia0030814ce2176d06e2898acffe533d31633fccb
2022-04-09 20:22:36 +02:00
Matthias Mullie
b0bd09c939 Remove change tags for media additions/removals
This reverts commit dab7b16741.

Reason for revert: This was inaccurate/incomplete &
looks like we will not need this after all

Bug: T286362
Change-Id: I6d63d69f180d193f99986ce6878617d63cfb2b6d
2022-02-28 11:08:09 +01:00
Aaron Schulz
c433c15087 Convert various callers to LoadBalancer::getConnectionRef()
Bug: T193565
Change-Id: I2e2ef6a1d841c632d1f3e53ca3f82a720af15d47
2022-01-27 01:02:44 +00:00
daniel
cbfcf9e8a8 Introduced PreparedUpdate to replace PreparedEdit
PreparedUpdate represents an in-progress edit. It can be used to access
information about the edit from hooks that do to have access to the
PageUpdater. Ideally, the PreparedUpdate or PageUpdater would be passed
to the hook as a parameter. Handlers of legacy hooks may use
WikiPage::prepareUpdate() to access it.

Bug: T242249
Needed-By: I23324a31e06e7e6f28077085c0ade05db63e9a35
Change-Id: Id5ba40a21cc4547205adf2f3a1f725c3a69c24d8
2021-12-20 21:19:52 +01:00
Umherirrender
bcee220ad1 tests: Avoid non-namespaced aliases for Wikimedia\Rdbms namespace
Change-Id: I49cb151f64c578f41dc1236b2a8906694ca97b93
2021-09-18 20:24:08 +02:00
Petr Pchelko
2c2ffb0bef Move revert detection code from WikiPage to EditResultBuilder
WikiPage is not the right spot to compute all the revert
related stuff - we already figure out manual reverts when
building the EditResult, lets figure out rollbacks and undos
in there as well.

Change-Id: I9fdc5f24c1db1eb0452b90bf4af1ef5ffbce6cb8
2021-09-16 12:24:34 -07:00
James D. Forrester
1ca1b910c5 Drop wgAjaxEditStash, deprecated in 1.36
Bug: T274695
Change-Id: Ia51d889fff5132ff4f9a89d07bc04cc72f936f1f
2021-08-02 12:21:56 -07:00
jenkins-bot
03cdd6af12 Merge "Narrow PageUpdater dependency from Title" 2021-07-27 21:38:53 +00:00
Petr Pchelko
12997e1f14 Narrow PageUpdater dependency from Title
Note: this contains a b/c incompatible change to
SlotRoleHandler, but it's never used in any extensions
and never was used.

Change-Id: I898ab18467f7f8c605a579cc6236859b9d86c7f5
2021-07-26 19:45:11 -07:00
Petr Pchelko
3158ba5dfb Move EditResultBuilder::findIdenticalRevision to RevStore
Additionally it switches the query from DB_PRIMARY to DB_REPLICA.
I understand the idea with a quick revert, but I do not think
it can be that quick - to revert a newest revision of a page,
an editor or a bot needs to actually read it first, and reads
come from a replica. So we know at least some replicas already
had the latest revision showing to the user. Very likely by the
time revert is made, we'd have it in all replicas. If not - oh well,
we can't be perfect. But we shouldn't really do such a query on
primary - it's too heavy.

Change-Id: I2fae8dbe5f19635f4d99e26242e3b08ddad8f8af
2021-07-25 07:36:31 -07: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
jenkins-bot
b283b2a1d0 Merge "Cleanup to PageUpdaterFactory and tests" 2021-07-20 19:41:39 +00:00
DannyS712
cf849b854a Simplifications to RevertedTagUpdateTest
Inline creation of single-use variables

Use $this->createMock() and createNoOpMock()
for FutureChangeTags.

Change-Id: I7d6632f61bc634279f62cefde9c7935143661c65
2021-07-20 11:43:03 +00:00
DannyS712
9d0d489412 Cleanup to PageUpdaterFactory and tests
Use one line instead of three to document variable types.

Make ContentHandlerFactory final again, no need to make
non-final.

Use MockServiceDependenciesTrait to simplify creation
of PageUpdaterFactory in unit tests.

Use Wikimedia\Rdbms\LoadBalancer instead of deprecated
alias \LoadBalancer.

Follow-up: I2a060bfa8ac098edf24fc4d51212eeb7ddf3942d
Change-Id: I63b18f71cb6e40c971511e71e8475d49ef530d71
2021-07-20 09:11:13 +00:00
daniel
1829057944 Introduce includes/Storage/PageUpdaterFactory
Change-Id: I2a060bfa8ac098edf24fc4d51212eeb7ddf3942d
2021-07-19 12:15:26 +02:00
DannyS712
043f812659 Convert BlobStoreFactoryTest to a unit test
We can create a BlobStoreFactory with mock services,
the only testing is for the domain of the blob store
being set correctly, which does not require any integration.

Change-Id: I6c4d3f53b3931e3517374ae582208910b56b64f3
2021-05-21 00:28:12 +00:00
Matthias Mullie
dab7b16741 Add change tags for media additions/removals
This introduces 2 new tags to track changes in media usage
across articles. These tags are both hidden & disabled by
default.

Bug: T266067
Change-Id: Ia230eadf7dcf6f52facab17b92293f25de38bb1c
2021-04-26 12:22:21 +02:00
DannyS712
1d5bac66c4 Reduce mocking LoggerInterface
Use TestLogger when we want to ensure specific
logged messages, or NullLogger when we don't care

Change-Id: Ifebc770933d4f5313d5b8b43a52437dbe1e24432
2021-04-23 22:35:43 +00:00
Thiemo Kreuz
c1ee8250e9 Remove unnecessary ->equalTo() from tests
This is the default anyway when using ->with(). The test code
becomes so much more readable without this, I would like to
argue. Let it just say "with these values".

Because of the way I split my changes into multiple patches
there are a few other changes in this patch I could not split,
e.g. removing unnecessary ->any(). This is the default anyway
and doesn't make the test more specific.

Change-Id: I34990799fa9258ba8dc64c7e78ec43f7903b7681
2021-04-23 12:02:42 +02:00
Daimona Eaytoy
535d7abf59 phpunit: Mass-replace setMethods with onlyMethods and adjust
Ended up using
  grep -Prl '\->setMethods\(' . | xargs sed -r -i 's/setMethods\(/onlyMethods\(/g'

special-casing setMethods( null ) -> onlyMethods( [] )

and then manual fix of failing test (from PS2 onwards).

Bug: T278010
Change-Id: I012dca7ae774bb430c1c44d50991ba0b633353f1
2021-04-16 20:15:00 +02:00
jenkins-bot
41456132c2 Merge "Revert "Add change tags for media additions/removals"" 2021-03-26 15:42:17 +00:00
Urbanecm
5519a25cf2 Revert "Add change tags for media additions/removals"
This reverts commit 5a0bfa9d98.

Reason for revert: caused a train blocker (T278429) plus Daniel says it's "super expensive"

Bug: T278429
Bug: T266067
Change-Id: I6724b4bc02d29c12c3fe18cc1e8fa17a443257d5
2021-03-26 15:16:08 +00:00
jenkins-bot
e3cdbbdbaf Merge "Add change tags for media additions/removals" 2021-03-22 17:51:04 +00:00
daniel
afa236ef53 RevisionStore: getRevisionbyId should take a PageIdentity
Providing a PageIdentity to getRevisionById removes the need
to look up page related data, and to construct a Title.

Bug: T275531
Bug: T273284
Depends-On: I8d0dc30ecd0c0c65c337170d271c2e2531914686
Change-Id: I683362ccd669acf2aadf56853afeb1ca6dee6f8c
2021-03-17 13:46:41 +00:00
Matthias Mullie
5a0bfa9d98 Add change tags for media additions/removals
This introduces 3 new tags to track changes in media usage
across articles. These tags are both hidden & disabled by
default.

Bug: T266067
Change-Id: I3e7acafe0b2266cf6e253dfef42fa6c666424469
2021-03-10 09:08:39 +00:00
Reedy
eb41565a9a Tests: Start marking some closures as static
Bug: T274036
Change-Id: Ib738ecd3bc23d34900bc268c8246702ac3655746
2021-02-06 19:57:42 +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
Thiemo Kreuz
2f66b3754f tests: Remove @param docs from test code that just repeat the signature
These are not only 100% identical to the actual code, but also:
* It's error-prone. Some are already wrong.
* These test…() functions are not meant to be called from
  anywhere. What is the target audience for this documentation?
* There is a @dataProvider. What such @param tags actually do is
  document the provider, but in an odd place. Just looking at
  the provider should give the same information.
* The MediaWiki CodeSniffer allows to skip @param when there is
  a @dataProvider, for the reasone listed.

Change-Id: I0f6f42f9a15776df944a0da48a50f9d5a2fb6349
2021-01-21 03:41:23 +00:00
Umherirrender
0347fd0631 Improve some function documentation in tests
Also fix some whitespaces

Change-Id: Ibed50a4f07442d3f299cf545c16f5dbb5f27a411
2021-01-14 22:13:55 +01:00
Thiemo Kreuz
ac205fa84c Fix incomplete/bogus PHPDoc tags in various tests
Most of these are found by the not yet released I10559d8.

I remove the type MockObject in some cases when the calling
code really does not need to know if he get's a mock or the
real thing. However, I do this only in places that are very
closely related to the fixes.

Change-Id: I26a4c3c5a8ae141bf56161b52b54bce7e68f2e30
2021-01-14 19:02:00 +00:00
Umherirrender
3f1c5d0eea Document list of change tags as string[]
Change-Id: I0ce2a8154af82a363fef126033b5819c4ee84842
2020-11-20 14:12:54 +01:00
Umherirrender
5d41326891 Use ::class together with createMock in unit tests
This makes it easier for IDEs to find usage
This works even for non-existing classes

Change-Id: I4a6389a9bc0b3c212633841d69bd4f48a7ed6f56
2020-10-30 14:45:37 +01:00
Ostrzyciel
1a27021526 Reverted tag: do not mark null revisions as reverted
This is to prevent move and protection entries from being marked
with the mw-reverted tag. Thanks to DannyS712 for a suggestion on
how to fix it :)

Bug: T265312
Change-Id: I127acdec69d37b3d0886ac1b7059bf35f1233f51
2020-10-15 19:08:28 +02:00
Ostrzyciel
a47778d5c0 Add mw-reverted change tag
The tag is added to reverted edits as described in T254074.

Functionality:
* Adding the mw-reverted tag to reverted edits (duh)
* Limiting the maximum depth of the update through a config variable
(mitigation #2 from T259014).
* Only applying the reverted tag after the edit has been somehow
approved. Only the patrol subsystem currently implements this, but
there's a hook that extensions can use (mitigation #4 from T259014, more
explanation in T259103).
* When performing the delayed update, it is checked whether the reverted
edit was reverted itself. If so, the update is ignored. This is
probably the only way to make the feature work due to the lack of an
explicit "disapproval" mechanism other than reverting.
* The update is also ignored if the revert is marked as deleted.

Technical design:
* The update code is in RevertedTagUpdate.php, which is a deferrable
update, but is not used as such. It's separated to allow for better DI,
testing and better code reusability in the future.
* The update is queued / ran using the Job subsystem. The relevant job
is in RevertedTagUpdateJob.php
* PageUpdater determines whether the edit is approved or not and passes
that to the DerivedPageDataUpdater.
* The BeforeRevertedTagUpdate hook lets extensions decide whether the
update should be ran right away or await approval.
* DerivedPageDataUpdater checks whether the edit is a revert and if so
either enqueues the job (if it's auto-approved) or caches the EditResult
for later use (if it needs approval).
* RevertedTagUpdateManager allows for easy re-enqueueing of the update
for extensions. Thus, it has a very minimal interface.

Other notes:
* The unit testing setup for RevertedTagUpdate is a bit complicated,
but it was the only way I could make this class testable while using
the static ChangeTags class.

Bug: T254074
Depends-On: I86d0e660f0acd51a7351396c5c82a400d3963b94
Change-Id: I70d5b29fec6b6058613f7ac2fb49f9fad9dc8da4
2020-08-31 13:40:50 +00:00
Ostrzyciel
299cd0db9f Implement EditResultCache
EditResultCache is meant to be an easy way for storing and retrieving
EditResults associated with revisions. It stores the data in the main
object stash which is supposed to be mostly persistent. In case the
main stash method fails, it falls back to trying to find the
EditResult in the ct_params field of revert change tags.

EditResultCache is to be used for delaying the execution of
RevertedTagUpdateJob until the edit is approved. The code for that
will be in the next commit in the relation chain.

This is a separate commit just for clarity.

Bug: T259103
Change-Id: I6c0c6556b6d98fcd131beb0957230ce7c7d268da
2020-08-31 08:59:10 +02:00
Ostrzyciel
67b5a4214c EditResult: enable serialization
Serializable EditResult will be required to save it for later use by
RevertedTagUpdateJob.

Additionally I decided to save the serialization format version in
case we want to modify it in the future.

Bug: T259732
Change-Id: I0cddc9c0439c8a59b5f66cea9e7db5bb151cb53b
2020-08-05 20:38:14 +02:00
Ostrzyciel
435d5f4d55 Add mw-manual-revert change tag
Based on the patch that introduces manual revert detection, this is
to create a software-defined change tag that will be applied to all
edits that restore a page to an exact previous state. This is also
for consistency with mw-undo and mw-rollback that will make a
"reverted" tag appear on reverted edits in the future.

Note about the REST API tests: in the next patch in this chain
I encountered even more issues with comparing returned changed tags
with expectations, so I decided it'd better if we just checked the
change tags applied manually in these tests. Otherwise we can run into
nasty race conditions, as the reverted tag is processed after sending
the response to client in the deferred update. It also makes the test
hard to maintain.

Bug: T256001
Change-Id: Ic367886f39faedcb823222b7d63bf4d5cb236ae9
2020-07-16 13:29:12 +02:00
Ostrzyciel
1dc2319c1a EditResultBuilder: manual revert detection
The code for manual revert detection is ran when building the
EditResult and the edit was not marked as a revert yet. It's
based on a SELECT looking for recent edits that match the new
revision's SHA1. There is no index over rev_sha1 field, so we
limit the search to N most recent edits, in order not to cause a
full table scan.

I think this shouldn't break any extensions by setting the
originalRevisionId in situations that weren't expected, almost no
extension uses that anyway:
https://codesearch.wmflabs.org/search/?q=%5C%24originalRevId&i=nope&files=&repos=

Bug: T256001
Change-Id: I4e38b382391b42e252cb66584be1e174cdfe348c
2020-07-14 15:34:57 +02:00
Ostrzyciel
3d73bdf568 PageUpdater: create EditResult class
EditResult is an immutable object created during a page update by
the PageUpdater using a builder object, the EditResultBuilder.

EditResult is a container for information on how the edit
interacted with the page and previous revisions. It also aims to
provide a standardized way of describing reverts and reverted
edits. It is as simple as possible, with no dependencies on the DB
or global variables. Most of the logic is encapsulated in the
builder.

PageUpdater::getEditResult() replaces the following methods:
* getOriginalRevisionId()
* getUndidRevisionId()
They are both available in the EditResult object.

PageUpdater::markAsRevert() replaces
PageUpdater::setUndidRevisionId()

Bug: T254074
Change-Id: Ie04c38043d9c295552e488109436ec1df20bb2ca
2020-06-23 11:49:02 +02: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
Máté Szabó
344481f60d Move trivially compatible tests to the unit tests suite
This changeset resumes work on T89432 and related tickets
by porting an initial set of tests to the new unit test suite
separated out in I69b92db3e70093570e05cc0a64c7780a278b321a.
The tests were only ported if they worked immediately without
requiring any changes other than changing the test case class
to MediaWikiUnitTestCase and moving the test to the new suite.
If a test failed for any reason (even trivial misconfiguration),
it was NOT ported.

With this change, the unit tests suite now consits of a total
of 455 tests. As before, you can run these tests via the following
command:
$ composer phpunit:unit

Bug: T84948
Bug: T89432
Bug: T87781
Change-Id: Ibb8175981092d7f41864e641cc3c118af70a5c76
2019-06-30 15:23:53 +02:00
Legoktm
4e35134f7a Revert "Separate MediaWiki unit and integration tests"
This reverts commit 0a2b996278.

Reason for revert: Broke postgres tests.

Change-Id: I27d8e0c807ad5f0748b9611a4f3df84cc213fbe1
2019-06-13 23:00:08 +00:00
Máté Szabó
0a2b996278 Separate MediaWiki unit and integration tests
This changeset implements T89432 and related tickets and is based on exploration
done at the Prague Hackathon. The goal is to identify tests in MediaWiki core
that can be run without having to install & configure MediaWiki and its dependencies,
and provide a way to execute these tests via the standard phpunit entry point,
allowing for faster development and integration with existing tooling like IDEs.

The initial set of tests that met these criteria were identified using the work Amir did in
I88822667693d9e00ac3d4639c87bc24e5083e5e8. These tests were then moved into a new subdirectory
under phpunit/ and organized into a separate test suite. The environment for this suite
is set up via a PHPUnit bootstrap file without a custom entry point.

You can execute these tests by running:
$ vendor/bin/phpunit -d memory_limit=512M -c tests/phpunit/unit-tests.xml

Bug: T89432
Bug: T87781
Bug: T84948
Change-Id: Iad01033a0548afd4d2a6f2c1ef6fcc9debf72c0d
2019-06-13 22:56:31 +02:00