Commit graph

310 commits

Author SHA1 Message Date
daniel
855988fd0e LinkCache: soft deprecate addGoodLinkObj()
addGoodLinkObj() has many optional arguments, but omitting them actually
means corrupting the cache.

Nearly all existing callers are in tests.
So LinkCacheTestTrait::addGoodLinkObject() was created only
for testing. It is better to have this method in the
trait, because building the row directly in each test
would make these tests brittle against schema changes.

The only usage in WMF production code was in WikiPage and has been
fixed.

Bug: T284955
Change-Id: I03a2bd9ed64fcc0281ee29a286c8db395a9e03d9
2021-09-10 16:00:02 +02:00
jenkins-bot
6ae92c0c73 Merge "Improve DeletePage tests" 2021-09-09 21:10:39 +00:00
jenkins-bot
1efeefe017 Merge "PageStore: Use LinkCache" 2021-09-09 20:04:47 +00:00
Daimona Eaytoy
1f86010f0f Improve DeletePage tests
Should have decent coverage now.

Bug: T288758
Change-Id: I2342f2072cd9c6d50831b9c3e7dd36f4a5e1c8e4
2021-09-08 17:37:52 +00:00
Daimona Eaytoy
73f0ae36a3 Make DeletePage a real service
- Switch do actual DI
- Add some more parameters for needed dependencies
- Create a factory interface, implement it in PageCommandFactory and add
  wiring for it.
- Add new unit tests for DeletePage; unfortunately, this requires
  conditionally disabling some code during tests due to dependencies on
  legacy code that hasn't been migrated yet. I believe that these
  temporary hacks are acceptable, since they allow us to use real unit
  tests immediately.
- Adjust WikiPageDbTest: the two logging tests were identical as of
  Ie0d9da2c8d273c93301921e1e108d9ffb381b8a5; and then the logging part
  could just be part of the "main" test.
- Add integration tests for DeletePage. For now, these are all copying
  their WikiPageDbTest counterpart. More tests will be added soon™.

Bug: T288758
Change-Id: I2fb79ed905ce621cb87f0658983d97148948da28
2021-09-08 11:43:04 +00:00
daniel
3b6345ca16 PageStore: Use LinkCache
This makes the data stored by LinkCache compatible with PageStoreRecord,
so we can use LinkCache inside PageStore.

This causes PageStore to make use of local caching as well as WANObjectCache.

Note that getPageById() does not yet benefit from cache, but does
populate the cache.

Bug: T278940
Change-Id: Icc27a0d9299a3e4ce45521daef87ad06ec06f064
2021-09-01 08:24:34 +00:00
Daimona Eaytoy
6a3b9daf29 Make WikiPage a ProperPageIdentity
Bug: T272424
Change-Id: I1dbcf1192390cbdfd6faaa60f9831f62ec1eff0d
2021-08-30 13:05:18 +00: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
jenkins-bot
fe93ad5273 Merge "Add DummyServicesTrait::getDummyReadOnlyMode()" 2021-07-20 04:00:25 +00:00
DannyS712
ae4efe66c6 Don't pass unneeded variables into anonymous functions
Change-Id: Iad4d1dc4727828f9e0120c8bf99dc245a29ee14d
2021-07-13 19:48:26 +00:00
DannyS712
d290b63153 Add DummyServicesTrait::getDummyReadOnlyMode()
Returns an actual working ReadOnlyMode object
based on a ConfiguredReadOnlyMode and a mock
load balancer

Change-Id: I429c8e81343c24c536718b3fc112e797afbc05a2
2021-07-05 07:16:13 +00:00
DannyS712
8217a1a253 Hard deprecate WikiPage::doEditContent
Bug: T255507
Change-Id: I8f4e5a579b787f94963f0c0dded30b374f5b4e3a
2021-07-04 00:03:38 +00:00
jenkins-bot
afb4ea82af Merge "WikiPage: update mTitle in updateRevisionOn()" 2021-07-01 20:47:02 +00:00
DannyS712
e6bf7a4e9a Hard deprecate WikiPage::prepareContentForEdit() without a UserIdentity
Bug: T285447
Change-Id: I59b6998edf9c54dd725147430c6242ff37ecb5e7
2021-06-28 23:17:34 +00:00
DannyS712
b45ddb2ab3 Use WikiPage::doUserEditContent() instead of ::doEditContent()
Results in passing a user where previously the fallback
to $wgUser was being used, mostly in tests.

Bug: T255507
Change-Id: Iabe24315b23c0ad1272353186425e71974528d23
2021-06-28 00:11:30 -07:00
Petr Pchelko
d6b3cd1a12 Remove hard-deprecated methods from RevisionStore
Bug: T274209
Change-Id: I1cdc9f2d4445cd5a32d90e9bbbfe16c65f1167ff
2021-06-24 12:42:49 -07:00
Lucas Werkmeister
b4a57a7353 WikiPage: update mTitle in updateRevisionOn()
After we updated the page row in WikiPage::updateRevisionOn(), some
fields in our mTitle – specifically, mLatestID, mLength, mRedirect,
mContentModel – are probably outdated. Use Title::loadFromRow() to
update them.

I put the loadFromRow() call very early in the block – specifically,
before the updateRedirectOn() call – because updateRedirectOn() already
potentially passes the WikiPage’s title into another class (LocalRepo),
and I want to minimize the risk of other code observing the outdated
Title (even though LocalRepo doesn’t currently use any fields that might
have become outdated).

Bug: T283654
Change-Id: Iacdacfd58a3e336e2d58dd7508d42d5afbb74500
2021-06-22 18:11:41 +02:00
Roman Stolar
dbe594a3ce Replace RecentChange::getPerformer with RecentChange::getPerformerIdentity
Preparing replace in core (DifferenceEngine.php, Article.php, ChangesListSpecialPage.php)

Bug: T276412
Change-Id: I4fd9cbd9404879d082179b68a9993e7203e43a8d
2021-05-27 11:45:17 +03:00
Marius Hoch
c20d6764b0 ArticleViewTest: Make timestamp tests deterministic
These tests can be unstable as subsequent revision
may or may not have the same timestamp. This can
be problematic as we have tests that make sure Article
correctly uses the timestamp from the older revisions.

Bug: T282648
Change-Id: Ica585818faf6948249567cd3eacd29b0b63c0d38
2021-05-12 15:35:35 +02:00
Marius Hoch
754132a4a3 Article: Use correct timestamp for OutputPage::setRevisionTimestamp
Instead of always (except when reading from ParserCache),
using the latest version.
This can also clearly be seen by visiting an old revision on
Wikipedia (https://en.wikipedia.org/w/index.php?oldid=N)
and looking for "This page was last edited on …". When first
loading the old revision, the TS of the last rev will be shown,
upon reloading, the correct time will be shown (as the output
is fetched from parser cache).

This reverts the test removals from I83a43d651.

Bug: T282648
Change-Id: I517d4970d5c682489f27a65ba01ee30db9c62276
2021-05-12 15:22:35 +02:00
Tim Starling
3f6ca47e23 Revert flaky timestamp assertion in ArticleViewTest
testViewOfOldRevision failed for me in CI, and I was able to reproduce a
2% failure rate locally using --repeat.

I also removed the assertion from testViewOfOldRevisionFromCache() for
consistency, although I wasn't able to reproduce a failure there.

Partial revert of 929dbef76d.

Bug: T282648
Change-Id: I83a43d65123304f3bac47869bbf3a9826873b397
2021-05-12 09:10:10 +00:00
Marius Hoch
929dbef76d Article::generateContentOutput: Ensure OutputPage has rev id set
This should not default to latest revision id, but
Article::getRevIdFetched() if the ParserCache doesn't
have the id set. Also set the revision id before calling
OutputPage::addParserOutput to make sure the id is
already set when the "OutputPageBeforeHTML" hook is run
(which is the case in other code paths).

Additionally I've made the tests more robust, by no
longer manually getting the revision into parser cache.

Bug: T281587
Change-Id: I999195441f9d75a7e4bde4d843ad7729cdb1bee0
2021-05-11 21:33:12 +02:00
daniel
62176bec1b PageIdentityValue: apply basic validation of titles
In order to prevent bad titles from entering the database,
PageIdentityValue should not allow instances that have obviously broken
dbeys, just like it does not allow construction for a special page.

Note however that for now, we allow PageReferenceValue to represent
thigns that are not actual pages, such as titles like "User:#1234" which
are used in the block log to represent autoblock targets. Similarly,
a PageReferenceValue can represent a special page.

This patch introduces a convenience method for constructing
PageIdentityValues in a context where it is uncertain whetehr the title
is valid, providing an opportunity to the caller to report in which
context the bad values were found.

In addition, this patch adds some documentation and testing, to clarify
the semantics of methods in PageStore with respect to invalid and non-
proper titles.

Bug: T282070
Change-Id: I8a44d9e73dda8fe38d009847332946809767d0fa
2021-05-07 17:17:45 +02:00
Petr Pchelko
4ca16e8d08 Eliminate use of Title object in REST infrastructure
Change-Id: I585f0f23cac5f6dc2a4879f69f7b83828fda3dd3
2021-05-05 18:54:58 -07:00
jenkins-bot
5127fe1b43 Merge "Add MediaWikiIntegrationTestCase::runJobs() and use it" 2021-05-05 03:15:17 +00:00
Tim Starling
0e05879d7e Add MediaWikiIntegrationTestCase::runJobs() and use it
JobRunner catches all exceptions and hides them in the status array,
meaning that it is not obvious when a job fails during a test case.
So, introduce MediaWikiIntegrationTestCase::runJobs(), which runs jobs
and asserts various things about the returned status array.

Depends-On: I4f4790c5d16a0767790eeff202e0be8fcdaeda93
Depends-On: I118f9e3f8950fd82d7b02baed6705b29fd6ab7d5
Change-Id: I63603aa158f77df4b40add096cb248f3b24979f4
2021-05-05 02:51:30 +00:00
DannyS712
f60ea069ba Remove remaining non-test uses of Revision objects
The following methods no longer support Revision parameters:
- CategoryMembershipChange::__construct
- ContentHandler::getUndoContent
- DerivedPageDataUpdater::prepareUpdate
- DifferenceEngine::getRevisionHeader

The following methods were removed entirely:
- Title::countAuthorsBetween

The following methods return arrays that formerly include
a 'revision' key that would emit deprecation warnings when
accessed and return a Revision object. The Revision object
has been removed from the arrays, and the 'revision-record'
key should be used to get the relevant RevisionRecord instead:
- PageUpdater::doModify
- PageUpdater::doCreate
- Parser::statelessFetchTemplate

The ParserOptions `templateCallback` option is a callback
that is called in Parser::fetchTemplateAndTitle() and should
return an array - the 'revision' key to that array used to
be a Revision object and was used if no 'revision-record'
was returned - it is now ignored.

Bug: T247143
Change-Id: I163ada88d649c75697aff4fa31a3a3c0bdef78b7
2021-05-04 13:10:22 -07:00
DannyS712
0dead88783 WikiPage: remove use of Revision objects
Methods no longer accepting Revision objects
as parameters:
- WikiPage::updateRevisionOn
- WikiPage::hasDifferencesOutsideMainSlot
- WikiPage::prepareContentForEdit
- WikiPage::doEditUpdates
- WikiPage::doDeleteUpdates
- WikiPage::onArticleEdit

Methods removed entirely
- WikiPage::updateIfNewerOn
- WikiPage::getUndoContent

Bug: T247143
Change-Id: I770d1937acb152a5c704ab4d43b7f7a687d9f546
2021-05-04 19:20:49 +00:00
DannyS712
604d4063ad Remove Revision from PageArchive
- PageArchive::getArchivedRevision
- PageArchive::getPreviousRevision
- PageArchive::getRevision

Bug: T247143
Change-Id: I9a2f2171ffdd284c21a4bcf58ae0589f71450c9b
2021-04-30 21:14:13 +00: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
James D. Forrester
64898405cb build: Upgrade mediawiki-codesniffer from v35.0.0 to v36.0.0
Change-Id: I8905d0d69738a1cd6997c104080fdf128d315e8b
2021-04-29 13:00:15 -07:00
James D. Forrester
df5eb22f83 Replace uses of DB_MASTER with DB_PRIMARY
Just an auto-replace from codesniffer for now.

Change-Id: I5240dc9ac5929d291b0ef1c743ea2bfd3f428266
2021-04-29 09:24:31 -07:00
Tim Starling
83e184670c Stop using legacy ActorMigration field "log_user"
Bug: T278917
Change-Id: I1b78bad7e1fa43f5f82908567a7daad9c6cc79b9
2021-04-28 16:29:04 +10:00
DannyS712
6d1703fb8e PageStoreTest: add missing parent::setUp() call
Change-Id: Ie26fe10157d5b804f56ebeb28fccf08b46ac1598
2021-04-23 21:48:29 +00:00
Thiemo Kreuz
40764d277c Replace PHPUnit ->returnValue() with ->willReturn() shortcut
It's the same and makes the test code much more readable, I
would like to argue.

Because of the was I split all the changes I made into smaller
patches this patch contains some other changes in the same
lines where I could not split them off. E.g. removal of
->any(), which is the default anyway and doesn't do anything.

Change-Id: Ib297b989d4aec33b31a4e33fe9d5032865b39be0
2021-04-22 10:37:45 +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
9c74a067c3 Merge "Factor out rollback logic from WikiPage" 2021-04-14 20:22:27 +00:00
Petr Pchelko
46db19ecdf Factor out rollback logic from WikiPage
Change-Id: I95da91875fcf2f53143c315560e35ccd5ffbf4b3
2021-04-14 11:49:07 -07:00
jenkins-bot
37ab31298c Merge "Remove $actor field from UsererIdentityValue" 2021-04-14 14:40:12 +00:00
daniel
5faa080374 Introduce PageReference
This explores the idea of a PageReference type which represents a
namespace/dbkey pair.

Every ProperPageIdentity is a PageReference. Some LinkTargets can be
mapped to a PageReference.

Bug: T279522
Change-Id: Id8b0c781fce329adcc4770f4840b2ba0108f6898
2021-04-13 23:32:20 +02: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
daniel
a4b73eb217 PageRecord: make language optional
Title::getPageLanguage has complex logic to determine the effictive
language of the page. PageRecord is a storage layer primitive and should
not haveknowledge of such logic, nor should PageStore.

The effective content language of a page needs to be determined
programmatically, see discussion on the ticket.

Bug: T278591
Change-Id: Ic26f6f7690499b3dd87982e3822881fd473cfd68
2021-04-08 20:16:36 +02:00
jenkins-bot
2f7456c731 Merge "Use PageStore in RevisionStore" 2021-04-05 19:54:40 +00:00
daniel
fe9430947d Use PageStore in RevisionStore
This introduces PageStoreFactory as well.

Change-Id: I7abd3c6a8ea70a68e8f8e9460d3bdd8c6f45338a
2021-04-05 20:58:54 +02:00
Petr Pchelko
cd66d7c335 Convert ParserOutputAccess to PageRecord.
Still needs to downcast to WikiPage in 2 places:

1. To check get a ContentHandler and check if content model
is cacheable. We probably should just make all content models
cacheable.
2. To call WikiPage::triggerOpportunisticLinksUpdate. I have
an elaborate plan for this one, but it will be done separately.

Change-Id: Ifd9ab0155dc1fad0c1608dafea05d16292afd057
2021-04-05 07:46:34 -06:00
Petr Pchelko
f642215aed Convert ParserCache to PageRecord
ParserOptions not updated cause they depend on Title::getLanguage
implementation.

Tests converted to not require a DB anymore. Can't be proper unit
tests yet due to globals in ParserOptions and fake time hacks,
but exec time does go down from 70 seconds to 9 seconds.

Page content model is still emitted in the metrics since
it was considered useful. Should be removed when we get
something like a page type concept.

Change-Id: Ib16fd0b5b87ffc3cb4d21f4aa43d1203cb7206d2
2021-04-02 21:14:54 -06:00
Umherirrender
d01d47683c Fix spacing after yield and use statements
Change-Id: Iacb93e96168ec0cd895130c5c8f66b6b44317e34
2021-03-26 23:55:58 +01:00
jenkins-bot
0949c7ac20 Merge "WikiPage: don't record bad redirects." 2021-03-25 17:10:22 +00:00
daniel
935c10f86c WikiPage: don't record bad redirects.
Bad redirects in the database led to fatal errors when attempting to
resolve the redirect when visiting the page. This patch does three
things to address this:
* change Title::isValidRedirectTarget to actually check whether the
target is a valid title.
* change WikiPage::recorddRedirectEntry to reject invalid redirect
targets
* change WikiPage::getRedirectURL to ignore invalid redirect target
that may be present in the database.

Bug: T278367
Change-Id: Ib17ebfb99fa17b846302438c675a968a1ec0f488
2021-03-24 22:15:22 +00:00