Commit graph

79 commits

Author SHA1 Message Date
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
daniel
071ce36abd Add findBadBlobs script.
This script scans for content blobs that can't be loaded due to
database corruption, and can change their entry in the content table
to an address starting with "bad:". Such addresses cause the content
to be read as empty, with no log entry. This is useful to avoid
errors and log spam due to known bad revisions.

The script is designed to scan a limited number of revisions from a
given start date. The assumption is that database corruption is
generally caused by an intermedia bug or system failure which will
affect many revisions over a short period of time.

Bug: T205936
Change-Id: I6f513133e90701bee89d63efa618afc3f91c2d2b
2020-04-17 15:04:59 +02:00
Timo Tijhof
cdd2f47d9c Revision: Use setFakeTime() instead of sleep() in unit tests
Before:
> 1. 1140ms to run …McrRevisionStoreDbTest:testLoadRevisionFromTimestamp
> 2. 1140ms to run …McrRevisionStoreDbTest:testGetRevisionByTimestamp
> …

After:
> …
> 36. 137ms to run …McrRevisionStoreDbTest:testGetRevisionByTimestamp
> 40. 135ms to run …McrRevisionStoreDbTest:testLoadRevisionFromTimestamp

Bug: T225730
Change-Id: I716bcf127761ef01d7ccfe10a79c08bea33ebc97
2020-04-02 21:12:48 +01:00
DannyS712
a96fd717a7 Hard deprecate Revision::getRecentChange and ::getTextId, both unused
Bug: T246284
Change-Id: I10197231642b45ad60e4588f94edad2bacf2f46e
2020-03-31 02:38:27 +00:00
jenkins-bot
7fa2b595c5 Merge "phpunit: Change optional params before required params to also be required" 2020-03-30 21:29:45 +00:00
Max Semenik
84f15a0a79 phpunit: Change optional params before required params to also be required
Bug: T248078
Change-Id: I7e1d4229d84f5960fd496f281084dbec4739da4c
2020-03-29 15:45:17 +00:00
jenkins-bot
5268ed3543 Merge "Hard deprecate Revision::loadFromTimestamp" 2020-03-25 19:44:45 +00:00
jenkins-bot
1576ae0c5a Merge "Deprecate Revision::loadFromPageId" 2020-03-25 19:24:01 +00:00
Petr Pchelko
aa1ea49a51 Hard deprecate Revision::loadFromTimestamp
Bug: T246284
Depends-On: Ia8d49b3158baf578ccd3476d6537be36dcea7e13
Change-Id: Ic4df02a7e21d4d1c0140e0f5a985a90f66983fab
2020-03-25 12:21:02 -07:00
Petr Pchelko
b3ab937939 Deprecate Revision::loadFromPageId
Bug: T246284
Depends-On: Id4ec83cc0ac0685857064486697a7daed979ea69
Change-Id: I5de750322e30052700f509d2908456ebd5be95ef
2020-03-25 12:10:48 -07:00
DannyS712
cf2c2a0778 Tests: Replace ::doDeleteArticle with WikiPage::doDeleteArticleReal
Not including WikiPageDbTestBase, which is testing the method

Bug: T248000
Change-Id: I1848a79be9e25759654053e88ef956269342f588
2020-03-25 11:34:17 -07:00
jenkins-bot
bdd722e310 Merge "Remove compat code for pre-MCR schema." 2020-03-25 18:19:33 +00:00
Petr Pchelko
a749000d39 Deprecate Title and WikiPage getFirstRevision methods
They naturally belong in RevisionLookup. They return Revision,
so should be replaced anyway.

Bug: T246284
Change-Id: Ie5c478e4667ca0e773186b9cb8a319cd09145112
2020-03-24 11:56:08 -07:00
daniel
495323c063 Remove compat code for pre-MCR schema.
NOTE: This was manually tested to ensure it does not
break updates, see T242764.

Bug: T198557
Change-Id: I1d9f5465018bae10124514bc38169e23e0e613e6
2020-03-24 19:45:47 +01:00
Petr Pchelko
ebd35bdc85 Hard deprecate Revision::getParentLengths
As well hard-deprecate RevisionStore::listRevisionSizes.
It was marked as @deprecated, but the release for the
deprecation was not specified. Let's say it's 1.35.

Additionally, in order to avoid temporary code duplication,
listRevisionSizes now uses getRevisionSizes and ignores the
database object injected into it. This is ok since we're
hard-deprecating the method and all the usages have been
removed.

Bug: T246284
Change-Id: Ifad1c25a0af892b88fce492b2d34c8cf71279b70
2020-03-18 12:26:26 -07:00
jenkins-bot
44354f45eb Merge "rdbms: inject replLogger into Database and consolidate duplicated logging" 2020-03-04 21:29:23 +00:00
jenkins-bot
fe13074a7b Merge "Remove Revision::loadFromId(), deprecated and unused" 2020-03-03 11:49:13 +00:00
Thiemo Kreuz
e1dd371e11 Make use of PHPUnit's assertCount feature where possible
… and avoid assertEmpty() on arrays, in favor of a much more strict
assertSame( [] ).

Change-Id: I20266b0b1fc38a3a87666ba1b0793cb2b37d94a9
2020-03-02 15:58:41 +00:00
DannyS712
77d503db09 Remove Revision::loadFromId(), deprecated and unused
Bug: T242311
Change-Id: I0c8fe834da79cb6db3c2268df50ba460fa97d981
2020-03-01 09:12:30 +00:00
DannyS712
2efa4b69a9 Hard deprecate Revision::loadFromTitle
Part of the soft deprecated revision class, no known callers outside
of EditPage, which is updated, and tests, which hide the deprecation

Bug: T246284
Change-Id: I099cb93a12f3a1d9a720e18e3236374321ce7b0c
2020-02-28 19:10:17 -08:00
Aaron Schulz
6c5d937adb rdbms: inject replLogger into Database and consolidate duplicated logging
Bug: T235244
Change-Id: I9397f6f74f703a395ef1be4713702247060d8bd4
2020-02-23 00:33:33 +00:00
Aaron Schulz
160370afcd rdbms: dependency inject domain aliases into LBFactory
Add new ILBFactory::setDomainAliases() method for injection database
domain aliases and call it in MWLBFactory::setDomainAliases().

Also:
* Remove overkill "last db/section" caching in LBFactoryMulti
* Clean up some LBFactoryMulti code comments
* Split out separate MWLBFactoryTest test file

Change-Id: If180a58c61178969ca7587c4a06b8786574c7254
2020-02-15 22:34:38 +00:00
ArtBaltai
30e54b3962 Introduce ContentHandlerFactory
Added:
- ContentHandlerFactory
Tests:
- PHPUnit
Changed
- Calls of changed and deprecated
- DI for some service/api
Deprecated:
- ContentHandler::* then similar to ContentHandlerFactory
- ContentHandler::getForTitle
- ContentHandler::$handlers

Bug: T235165
Change-Id: I59246938c7ad7b3e70e46c9e698708ef9bc672c6
2020-02-07 00:53:51 +03:00
jenkins-bot
7c6ec9a895 Merge "RevisionStore: fail on mismatching hash or size." 2020-02-03 20:25:36 +00:00
Thiemo Kreuz
9c57ea2b7f Replace complicated assertions with assertIsString() and such
This patch tries to make assertions in tests more readable by using more
self-documenting assertions as provided by modern PHPUnit versions. Among
a few others, these two main changes are done:

* I found a lot of assertions with the expected value being the *second*
parameter. I did not changed all of them. Only some that can be replaced
with assertNull() and such.

* I try to replace all `assertTrue( is_…() )` with dedicated assertions.

Change-Id: I1fc72188fbd0edacf13886e7f9a9eacbd85f13c2
2020-01-28 19:17:58 +00:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
James D. Forrester
4f2d1efdda Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUse
Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
2020-01-10 09:32:25 -08:00
James D. Forrester
5e9fca47b9 Coding style: Auto-fix MediaWiki.Usage.PHPUnit*
Change-Id: I86fc55a4fc8ceafe368692173211bbcd6d8581d7
2020-01-10 10:17:12 +00:00
daniel
9a7990dea9 RevisionStore: fail on mismatching hash or size.
The SlotRecord passed to RevisionStore::insertRevisionOn may have its sha1 and size
already set by the caller. This is useful when restoring archived re
visions, but apparently sometimes goes wrong, leading to a revision
being recorded with the hash and size of its parent revision.

This patch introduces a sanity check that ensures that the revision's
hash and size matches the main slot's hash and size. If there are
additional slots, the check is skipped.

This does not fix the bug as reported, but should prevent any new
revisions to be inserted with mismatching meta-data, and provide us with
a stack trace that should help with finding the original cause of the
issue.

Bug: T239717
Change-Id: I4947731364925fef1c77cabcfd144fd2c07bf9db
2020-01-06 14:20:16 +01:00
Brad Jorsch
152376376e Remove hacks for lack of index on rc_this_oldid
In several places, we're including rc_timestamp or other fields in a
query selecting on rc_this_oldid because there was historically no index
on the column.

The needed index was created by I0ccfd26d and deployed by T202167, so
let's remove the hacks.

Bug: T139012
Bug: T239772
Change-Id: Ic99760075bde6603c9f2ab3ee262f5a2878205c7
2019-12-04 16:00:02 -05:00
daniel
bb43130314 RevisionStore: force "Unknown user" instead of empty user name
When restoring revisions that have an empty user name associated with
them, force "Unknown user" to be used instead, even if the actor table
has an entry for the empty user name.

Bug: T236624
Change-Id: I31edd5f7d89d9b43806ad18e96f5e93cff0f8c6f
2019-11-26 22:16:56 +01:00
Umherirrender
97ed35e2e8 Add missing @param and @return to documentation
Change-Id: I48ee838a7ebf4f25a4883d4c7886b39c2d3916af
2019-11-16 13:45:55 +01:00
Petr Pchelko
7fef88e7cc REST: Implement from and to for editors count handler.
* Move Title::{get,count}AuthorsBetween to RevisionStore
* Use it in REST count handler to to provide 'from' and 'to'
support for editors count.

Bug: T235896
Bug: T235666
Change-Id: Ib7947ae64b82871ceb4a3097a0ea03c0ba218c7c
2019-11-05 07:48:38 -08:00
Petr Pchelko
d951e6ccb6 REST: Add 'from' and 'to' parameters to historycount endpoint.
* Add 'from' and 'to' query parameters to history count endpoint,
in case we are counting 'edits'. The support for parameters will be
expanded in the future, given that 'editors' is on the way.

* Refactor RevisionStore::countRevisionsBetween to be able to omit
starting or ending revision.

Bug: T235666
Change-Id: I1fc3f2d4e422f17ccfc99664ea35e210c13ade5f
2019-11-04 15:21:22 -08: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
Petr Pchelko
6eb67c752e Move countRevisionsBetween from Title to RevisionStore
Bug: T235666
Change-Id: Ib404d29a662de7736b50a1d07380f651d332ad6b
2019-10-17 08:02:26 -07:00
Aaron Schulz
fb621c26a3 rdbms: various cleanups to LoadBalancer::reallyOpenConnection()
Move the DBO_TRX init logic out of Database::__construct() and into
LoadBalancer since the later already handles setting and clearing this
flag based on transaction rounds starting and ending.

Add 'lazyMasterHandle', 'topologyRole', and 'topologicalMaster' parameters
to Database::factory() and inject them via LoadBalancer all at once in order
to avoid worrying about call order. Move some type casting code to
Database::__construct().

Add IDatabase::getTopologyRole()/getTopologicalMaster().

Use constants for getLBInfo()/setLBInfo() for better usage tracking and
typo resistance.

Change-Id: I437ce434326601e6ba36d9aedc55db396dfe4452
2019-10-11 11:35:02 -07:00
jenkins-bot
59a0942376 Merge "Kill the remaining usages of PHPUnit4And6Compat methods" 2019-10-06 10:47:37 +00:00