Commit graph

116 commits

Author SHA1 Message Date
Aaron Schulz
99d5d2e8cc rdbms: cleanup getServer() and connection parameter fields in Database
Make getServer() always return a string, as documented, even with new
Database::NEW_UNCONNECTED handles that have yet to call open(). If the
'host' parameter to __construct() is ''/null, getServer() now returns
'localhost' instead of null. This avoids problems like fatal errors in
calls to TransactionProfiler::recordConnection().

Use Database constants for "connectionParams" field keys for better
static analysis.

Also:
* Add Database::getServerName() method that returns "readable" server
  names in the style of LoadBalancer::getServerName(). Note that the
  "hostName" field is already passed in from LoadBalancer.
* Migrate most getServer() callers to getServerName() for easier
  debugging and more readable logging.
* Also, normalize Database/LoadBalancer SPI logging context to use
  "db_server" and reduce logging code duplication in LoadBalancer.

Bug: T277056
Change-Id: I00ed4049ebb45edab1ea07561c47e226a423ea3b
2021-05-05 19:44:02 +00:00
jenkins-bot
23d5d441c9 Merge "Replace uses of DB_MASTER with DB_PRIMARY" 2021-04-29 19:04:17 +00: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
daniel
46e877d182 RevisionStore: don't die on mismatching Titles
When we find that a revision we loaded doesn't belong to the expected
title, log the error and continue, instead of failing hard.

This could happen if a caller to e.g. getRevisionById supplied a Title that is
plain wrong. In this case, we should ideally throw an IllegalArgumentException.
However, it is more likely that we encountered a race condition during a page
move (T268910, T279832) or database corruption (T263340). That situation
should not be ignored, but we can allow the request to continue in a reasonable
manner without breaking things for the user.

Note that this patch does not resolve the mentioend bugs. It only
reduces impact for users. We still need to find out when and why we are
gettign mismatching titles.

Bug: T259022
Bug: T268910
Bug: T263340
Bug: T279832
Change-Id: Ia64ad3b8a6e3c3348bc0a276d528ead127c6b0e0
2021-04-28 11:23:15 +02:00
Thiemo Kreuz
b95a07380a Remove meaningless ->expects( $this->any() ) from all tests
It is not entirely meaningless. It might be an indicator that
the number of calls to a method is intentionally unlimited.
This is similar to e.g. an @inheritDoc PHPDoc comment that
marks a method as being "intentionally undocumented".

However, what's the meaning of being "intentionally
unconstrained"? Let's just not have any constraint then.

I feel all these ->expects( $this->any() ) bloat the test
code so much that it's never worth it.

Change-Id: I9925e7706bd03e1666f6eb0b284cb42b0dd3be23
2021-04-23 11:58:58 +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
37ab31298c Merge "Remove $actor field from UsererIdentityValue" 2021-04-14 14:40:12 +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
daniel
fe9430947d Use PageStore in RevisionStore
This introduces PageStoreFactory as well.

Change-Id: I7abd3c6a8ea70a68e8f8e9460d3bdd8c6f45338a
2021-04-05 20:58:54 +02: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
daniel
ed7e42e42e RevisionStore: create getPage, deprecate getTitle
The new getPage() handles cross-wiki access correctly. It's not a direct
replacement for getTitle(), since it is private.

getTitle() cannot work properly for RevisionStore instances connected to
a sister-wiki. It was already discouraged, and is nearly unused outside
of RevisionStore. Remainign usages should be replaced with
RevisionRecord::getPage().

Note that PageIdentityValue is not lazy loading, while Title is.
Code in newRevisionFromRowAndSlots() was adjusted to take advantage of
any fields from the page table that may already be present from a join,
to avoid an additional query to the page table.

Bug: T275531
Bug: T273284
Change-Id: If4525d76a578b92dbcfe1f5150028f7a28811119
2021-03-17 10:53:40 +00:00
Petr Pchelko
eb5eca11b6 Deprecate constructing revision with non-proper page
Bug: T275531
Change-Id: If641a5a901210ba1a1ea6a41fa6a18c08f4183db
2021-03-10 22:05:06 +01: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
Petr Pchelko
4d8dc6b992 Use ActorStore in RevisionStore
Bug: T273290
Change-Id: Iff9b67455d337ea03cb728dd570c4ce760c39e49
2021-02-10 14:37:54 -06:00
Peter Ovchyn
8a06301738 Update RevisionStore public interface to be using PageIdentity
The following methods have beed converted:
::getRevisionByTitle
::getRevisionByTimestamp
::newRevisionFromArchiveRow
::newRevisionsFromBatch
::getKnownCurrentRevision
::getFirstRevision
Appropriate tests were adjusted to test both old interface (with
Title) and new interface (with PageIdentityValue)

Bug: T272886
Change-Id: Ica8da21d2413df885365475eaa498214edbcfd1d
2021-02-08 18:33:25 +02: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
jenkins-bot
eb4b304ed8 Merge "Add missing @param and @return to documentation in tests" 2021-01-30 15:22:33 +00:00
vladshapik
117982da96 RevisionRecord: make RevisionRecord::getId() take a wiki ID
Bug: T272485
Change-Id: Ic1a8a406c2163844b14aa34ab259f0836687887e
2021-01-29 15:01:31 +02:00
Umherirrender
7691dbeca9 Add missing @param and @return to documentation in tests
Change-Id: Ic663e81cca0bf007804a70772250914a85f1fef4
2021-01-22 19:57:25 +01: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
b655f382db Remove broken/outdated @param/@throws tags from @dataProviders
My personal best practice is to not document @params when there
is a @dataProvider. I mean, these test…() functions are not
meant to be called from anywhere. They do not really need
documentation. @param tags don't do much but duplicate what the
@dataProvider does. This is error-prone, as demonstrated by the
examples in this patch.

This patch also removes @throws tags from tests. A test…() can
never throw an exception. Otherwise the test would fail.

Most of these are found by the not yet released I10559d8.

Change-Id: I3782bca43f875687cd2be972144a7ab6b298454e
2021-01-21 03:42:42 +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
Máté Szabó
aa847d5369 tests: Fix queryFlags parameter type in RevisionStoreDbTestBase
RevisionStoreDbTestBase is mistakenly passing an array instead of an integer as
a query flags parameter in many places, which eventually gets passed to
DBAccessObjectUtils that uses it with a bitwise operator. PHP < 8 handles this
silently, but PHP >= 8 throws "TypeError: Unsupported operand types: array &
int" here.

Bug: T248925
Change-Id: I4e29b2709fe5e6d583727d45e005b3f16a1e3f4d
2020-11-26 19:39:34 +01:00
Ostrzyciel
13dfd35895 RevisionStore: add INCLUDE_* constants
As the same string values are used by multiple methods in
RevisionStore, factoring them out to constants would make sense.

The only other appearances of these strings in core are some
long-deprecated methods that are probably not worth updating.

Change-Id: I85fe6ab96716f237291202dbb1ebefb90bb9f0da
2020-08-17 20:22:17 +02:00
Ostrzyciel
38d19b6fbe RevisionStore: add getRevisionIdsBetween method
Motivation:
This method would be useful to many extensions and other parts of
code that want to obtain a list of revisions in a given range. This
is quite hard to do properly, as the limit conditions are rather
complicated, so it would be useful to have a tested, working method
that does this.

This would be especially useful when obtaining a list of reverted
revisions. Currently extensions are provided with the newest and
oldest reverted revision ids, so this method could be used in such
a case. I think at least Echo, FlaggedRevs and EventBus could make
use of it. I also plan to use it in code marking reverted edits with
mw-reverted change tag.

Design:
I've decided for this method to return only ids, as this would suit
many (but not all) use cases and is far simpler than returning entire
revisions. If the method was to return RevisionRecords, it'd have to
have a few extra parameters (which parts of the revision should we
load? which slots should be loaded? should the content be loaded as
well?) and it would quickly grow to a huge supermethod that has way
too many responsibilities and is extremely hard to test reliably.

Bug: T258951
Change-Id: I0b82e8fa8bd7cb8aa599376a72ebc0a3b320c0e9
2020-08-05 12:46:23 +02:00
daniel
a67cad6d0f Create fallback for undefined content models.
This causes RevisionStore to use FallbackContent instances to represent
content for which no content handler is defined.

This may happen when loading revisions using a model that was defined
by an extension that has since been uninstalled.

Bug: T220594
Bug: T220793
Bug: T228921
Change-Id: I5cc9e61223ab22406091479617b077512aa6ae2d
2020-07-22 19:59:09 +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
a6d16bd03d Remove unneeded creation of revision objects
Clean up some technical debt; use MutableRevisionRecord instead of
manually constructing a Revision from an array, remove last uses of
RevisionStoreDbTestBase::revisionToRow and remove the method.

Each file can be reviewed separately (except that the removal of
revisionToRow depends on replacing its usage)

Bug: T246284
Change-Id: I0bdc069b21a5c41ef8f9e972c5b17ff189d4a741
2020-06-10 09:09:55 +00:00
DannyS712
f04d825a8b Hard deprecate Revision::getSize
Bug: T254964
Change-Id: I79ff1671921f4d63829338d22126f8c0821bb16c
2020-06-10 05:19:20 +00:00
DannyS712
f8cc519222 Hard deprecate Revision::getPage and ::getComment
Bug: T251853
Bug: T254960
Change-Id: I09fadbebd839a16b46a027f64eaac9a435622321
2020-06-10 04:10:41 +00:00
DannyS712
970fbda0d4 McrRevisionStoreDbTest: Don't create a Revision object
Use assertRevisionRecordsEqual, not assertRevisionRecordMatchesRevision
also revisionRecordToRow, not revisionToRow

RevisionStoreDbTestBase::assertRevisionRecordMatchesRevision can thus
be removed

Bug: T254952
Change-Id: If5d7d4e01947d9f8a2ed51c950e750e82380930c
2020-06-10 03:10:43 +00:00
DannyS712
3a1513a5b5 RevisionStoreDbTestBase: Reduce use of Revision from WikiPage::doEditContent
Bug: T251853
Bug: T254952
Change-Id: Ib4b7dba7cb8c4277c9135558e6a21646f1a75249
2020-06-10 03:10:31 +00:00
DannyS712
df7906cd0f Hard deprecate Revision::getContent
Bug: T254703
Change-Id: I50e82d29f87725a2d583a0fc1ebacc467ffee935
2020-06-08 02:44:21 +00:00
DannyS712
b4d8adab32 Hard deprecate Revision::getContent(Model|Handler|Format)
Bug: T250981
Change-Id: I5b93e65f7a5b12e910c1e36fc39f60f498edf6c4
2020-06-03 23:52:49 +00:00
Tim Starling
68c433bd23 Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.

General principles:
* Use DI if it is already used. We're not changing the way state is
  managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
  is a service, it's a more generic interface, it is the only
  thing that provides isRegistered() which is needed in some cases,
  and a HookRunner can be efficiently constructed from it
  (confirmed by benchmark). Because HookContainer is needed
  for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
  SpecialPage and ApiBase have getHookContainer() and getHookRunner()
  methods in the base class, and classes that extend that base class
  are not expected to know or care where the base class gets its
  HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
  getHookRunner() methods, getting them from the global service
  container. The point of this is to ease migration to DI by ensuring
  that call sites ask their local friendly base class rather than
  getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
  methods did not seem warranted, there is a private HookRunner property
  which is accessed directly. Very rarely (two cases), there is a
  protected property, for consistency with code that conventionally
  assumes protected=private, but in cases where the class might actually
  be overridden, a protected accessor is preferred over a protected
  property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
  global code. In a few cases it was used for objects with broken
  construction schemes, out of horror or laziness.

Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore

Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router

setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine

Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-05-30 14:23:28 +00:00
DannyS712
511fd87645 Hard deprecate Revision::getParentId and ::getVisibility
Bug: T250980
Bug: T250714
Change-Id: I8084607090266687395612be26ad2c06f9a60baa
2020-05-27 23:35:18 +00:00
DannyS712
1e36b2c12f Hard deprecate Revision::getUserText, ::isMinor, and ::isCurrent
Bug: T250579
Bug: T250580
Bug: T250608
Change-Id: I89ac77c436245cad3e746b33aec5a42247fda67d
2020-05-26 22:19:54 +00:00
jenkins-bot
67d6d6d14a Merge "Revision: Ensure getRevisionByTitle() works for foreign wikis" 2020-05-25 01:59:01 +00:00
jenkins-bot
69011218a7 Merge "RevisionStore: improve error handling in newRevisionsFromBatch" 2020-05-08 17:51:45 +00:00
Brad Jorsch
c04732b987 Alter revision for actor, comment, and MCR
We're finally to the point of making the massive alter to the `revision`
table that we've been building up to for 2.5 years now.

Changes here are:
* Drop `rev_text_id`, `rev_content_model`, and `rev_content_format` that
  MCR obsoleted.
* Drop `ar_text_id`, `ar_content_model`, and `ar_content_format` that
  MCR obsoleted.
* Replace `rev_comment` with `rev_comment_id`.
* Replace `rev_user` and `rev_user_text` with `rev_actor`, plus
  associated index changes.

Future patches will make the code changes to migrate data from
`revision_actor_temp` and `revision_comment_temp` into the new
`revision` columns.

Bug: T251343
Bug: T184615
Bug: T215466
Change-Id: I18071a2fe45907a0cf1b0fefebd96a97a2dacb7b
2020-05-08 15:26:56 +00:00
Máté Szabó
e987ba3a58 Revision: Ensure getRevisionByTitle() works for foreign wikis
Change Ic6f98d8fb changed RevisionStore::getRevisionByTitle to convert
the passed LinkTarget to a Title using Title::newFromLinkTarget, to
address bug T206498.

Unfortunately, this breaks when RevisionStore is operating in the context
of a foreign wiki. In this scenario, when RevisionStoreRecord::__construct
calls Title::getArticleID on the Title instance to perform a sanity check
of the page ID against the page ID reference stored in the revision table
for the given revision record, then Title::getArticleID will lazily fetch
the page ID on the local, rather than the foreign wiki. This results in
an InvalidArgumentException thrown by RevisionStoreRecord::__construct.

This patch changes the logic to only resolve the LinkTarget to a Title
when operating in the context of the local wiki, similar to the checks
that RevisionStore::getTitle and friends are already performing.

It also adds a regression test to verify that
RevisionStore::getRevisionByTitle does not try to access the local wiki
DBLoadBalancer when called in the context of a foreign wiki.

Bug: T248756
Change-Id: I76090fa2907c2db8e23a62959346db531c6d9cb2
2020-05-05 00:58:06 +00:00
daniel
d351bb7e39 RevisionStore: improve error handling in newRevisionsFromBatch
When for some reason we can't determine the title for a revision
in the batch, this should not trigger a fatal TypeError, but handled
gracefully, with helpful information included in the error message.

Bug: T205936
Change-Id: I0c7d2c1fee03d1c9208669a9b5ad66612494a47c
2020-05-03 21:54:02 +02:00
DannyS712
8a88d51536 WikiPage::updateRevisionOn - replace uses, hard deprecate Revision use
See codesearch - only deployed call outside of core is in flaggedrevs,
and already passes a RevisionRecord:
https://codesearch.wmflabs.org/deployed/?q=-%3EupdateRevisionOn%5C(&i=nope&files=&repos=

Also fixed a use of Revision::newFromId in orphans.php

Bug: T249561
Bug: T249021
Change-Id: I5933a278de8645b7005c11026c87ae27c0373770
2020-05-01 04:54:37 +00:00
DannyS712
28cb11e8ca Replace uses and hard deprecate Revision::getSha1
Bug: T251233
Change-Id: I815db5120094909b2820b8ca56d65a62f6af82d1
2020-04-30 17:44:11 +00:00
jenkins-bot
9a939d38d0 Merge "RevisionStore and PageUpdater: handle stale page ID" 2020-04-27 21:16:52 +00:00
daniel
1fcd23878c RevisionStore and PageUpdater: handle stale page ID
Sometimes, an edit is done with a Title object that has gone
out of sync with the database after a page move. In this case,
we should re-load the current page ID from the database,
instead of failing the update hard.

Bug: T246720
Bug: T204793
Bug: T221763
Bug: T225366
Change-Id: If7701205ec2bf4d4495349d3e67cf53d32ee8357
2020-04-20 18:11:45 +02:00
jenkins-bot
260403b83a Merge "Add findBadBlobs script." 2020-04-17 13:32:17 +00:00