Commit graph

85 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Petr Pchelko
46db19ecdf Factor out rollback logic from WikiPage
Change-Id: I95da91875fcf2f53143c315560e35ccd5ffbf4b3
2021-04-14 11:49:07 -07: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
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
daniel
c0825f38f2 WikiPage: keep touch date consistent
WikiPage::getTouched() must return the updated touched date
after the WIkiPage was used to make an edit.

Change-Id: I40060d6932d6d715bb549932439c9b8c0521f4b3
2021-03-24 12:02:05 +01:00
daniel
f37ebf4478 Introduce PageRecord interface
PageRecord is intended as a lightweight alternative to WikiPage,
similar to RevisionRecord.

Bug: T272421
Bug: T272422
Depends-On: Ia34cc8fa795b6b27832982fc22fa237ee36339b4
Depends-On: I39a984c9f3132f755f7d8984b789d05ad080d7b4
Change-Id: Ib3c9b22e0c0b7c97e6c230f2fecf0663b4c68cc6
2021-03-22 12:41:29 -06:00
Petr Pchelko
1f691267a6 Convert WikiPage public interface to UserIdentity
Change-Id: I18dc3ad597f65972add10a700602a811f4060022
2021-03-18 15:10:55 -06:00
jenkins-bot
b62ff2eb18 Merge "Safer WikiPage redirect functions" 2021-03-14 21:17:53 +00:00
Tim Starling
6feea17779 Safer WikiPage redirect functions
MediaWiki::initializeArticle() would copy the title from
WikiPage::getRedirectTarget() into the RequestContext. But if the
redirect table contained an invalid title, an object would be returned
anyway, and the invalid title would later break various callers.

Many callers were assuming that if WikiPage::isRedirect() returns true,
then WikiPage::getRedirectTarget() will return a Title. Fair enough, it
is confusing to have two levels of rigor for a data value within a
class.

So:

* Make WikiPage::isRedirect() simply call getRedirectTarget()
* Add a new method WikiPage::getPageIsRedirectField() which preserves
  the old behaviour. Call its associated property mPageIsRedirectField.
* Make getRedirectTarget() use makeTitleSafe() instead of makeTitle().
* Remove the call to Title::isRedirect(). We have our own cache of page
  data and don't need Title's help with this.
* Remove mIsRedirect without deprecation. CodeSearch finds no usages.
  Instead we have a lazy-loaded validity flag mHasRedirectTarget paired
  with mRedirectTarget.
* page_is_redirect is now a necessary but not sufficient condition for a
  page to be a redirect by WikiPage's definition of the concept.

Bug: T261347
Change-Id: I12542fc899cdec39694440c5cf2505c115e4635d
2021-03-10 16:30:21 +11:00
DannyS712
24afc63e49 Remove constructors from test classes
Tests should put their setup code in ::setUp(),
rather than __construct

Change-Id: I622f017f3c78a72acc65310f37d61dbec2a5da79
2021-03-08 03:31:25 +00:00
jenkins-bot
5d66187122 Merge "Make WikiPage a (non-proper) PageIdentity" 2021-02-16 15:51:49 +00:00
jenkins-bot
5ea464b234 Merge "Use static closures where safe to use" 2021-02-14 23:05:48 +00:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
Thiemo Kreuz
947a8cfc00 Use ?? instead of isset/array_key_exists where possible
This patch touches all uncontroversial (I hope) places where a chain
of isset(), array_key_exist() and the ternary ?: operator can be
replaced with the much shorter ?? feature from PHP 7.

?? does the same. It checks if the element before the ?? is set and
not null. When this check fails, the element after the ?? is used.

Change-Id: Id612e2782ae928164b26b6f0de676c6c7d8302f3
2021-02-10 20:32:25 +01:00
Daniel Kinzler
65f89072e3 Make WikiPage a (non-proper) PageIdentity
This is a step towards introducing PageRecord.

We allow WikiPage to be a "non-proper" PageIdentity for now,
but this should be changed to a ProperPageIdentity as soon as
possible.

Bug: T272424
Change-Id: I194c55ec757e655117bccfeb7d6f5d8487b559e5
Signed-off-by: daniel <dkinzler@wikimedia.org>
2021-02-10 11:24:05 +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
Reedy
eb41565a9a Tests: Start marking some closures as static
Bug: T274036
Change-Id: Ib738ecd3bc23d34900bc268c8246702ac3655746
2021-02-06 19:57:42 +00:00
Peter Ovchyn
e7e0db5b34 Hard deprecate RevisionStore::newMutableRevisionFromArray
Bug: T272560
Depends-On: I171537c3346a7dd4aeb4fc612d7dd9fba5d64679
Change-Id: If8d079a5d0e9bc9103cf4a6893a9c961d2728534
2021-02-03 22:29:44 +00:00
daniel
e9766994e5 WikiPage: add test for invalid titles
WikiPage should not try to create pages with invalid titles. This may
lead to data corruption.

The change in I03969883fc0b326dd2374d7f8e24c1d5a650d5fa should
make the new test pass.

Change-Id: I713c7b14dae86aa7b544bb613e6d5869a049f8b7
2021-01-20 10:14:42 -08:00
daniel
a4ec04c6df WikiPage: deprecated construction on bad titles
WikiPage represents a page that can be created and edited.
WikiPage should not be constructed on Titles that represent things like
special pages or section links. Any such usage should be deprecated.

Bug: T272424
Change-Id: I03969883fc0b326dd2374d7f8e24c1d5a650d5fa
2021-01-20 14:31:11 +01:00
James D. Forrester
a547ef3b9e Revert "Make WikiPage a ProperPageIdentity"
This reverts commit 8f46ef5ff4.

This has seemingly broken FlaggedRevs and thus a bunch of repos.

Bug: T272170
Change-Id: I67de3dbbbc9163aae937f710ecb0e40db0d483a0
2021-01-15 12:30:30 -08:00
James D. Forrester
a8fe6c9841 Revert "Define equality for PageIdentity and LinkTarget"
This reverts commit 36f1adf670.

This has seemingly broken FlaggedRevs and thus a bunch of repos.

Bug: T272170
Change-Id: I26c6fd656c75a6b209fb17965dc9109edf68642b
2021-01-15 12:30:14 -08:00
daniel
36f1adf670 Define equality for PageIdentity and LinkTarget
This allows Title and WikiPage objects to be compared with PageIdentity
and LinkTarget instances consistently.

Change-Id: I1bbd15d17d046359393ecfc1acd2778273260a95
2021-01-15 17:53:28 +01:00
daniel
8f46ef5ff4 Make WikiPage a ProperPageIdentity
This makes it so methods that take a WikiPage can be narrowed to a
PageIdentity, and prepares WikiPage for the introduction of the PageRecord
interface.

Bug: T208776
Change-Id: Iab8bd75a1948873baab9c91c76f966d606b23c0f
2021-01-15 12:34:24 +01:00
jenkins-bot
2697ba639e Merge "WikiPage: add interim replacement for WikiPage::doEditContent() requiring $user" 2020-12-17 15:11:00 +00:00
DannyS712
25db391d53 ParserOptions: Deprecate fallback to $wgUser
Emit deprecation notices in the constructor
if falling back to $wgUser, and fix core
calls

Bug: T246861
Depends-On: I51117931d527a3bdda468b48de577a7faafbcd69
Change-Id: Ibd0a8ffd0494c17a378cc43e6b6164166130adf4
2020-12-16 09:03:29 +00:00
Taavi Väänänen
0ffed5799d WikiPage: add interim replacement for WikiPage::doEditContent() requiring $user
This patch adds a method named WikiPage::doUserEditContent() as an interim
replacement to existing deprecated ::doEditContent() method. The new
method requires $user to be passed as a parameter and no longer supports
passing in the unused $serialFormat parameter. The new method otherwise
behaves identically compared to the old doEditContent() method.

Bug: T255507
Change-Id: Ibc0052b27a6d3cda3eb9663b95b4f45116dcc9f1
2020-12-15 08:59:57 +02:00