Commit graph

864 commits

Author SHA1 Message Date
Timo Tijhof
f3ef7f7f23 language: Autoload normalize data and remove transformUsingPairFile compat
* Turn normalize data into an autoloadable class and use the class name
  as key instead of a partial file name with a base directory.

* This protected function is not aimed at re-use in extensions,
  has no other usage known to Codesearch. Mark it internal,
  and remove the compat introduced by 31283f34bf.

* Update the now ten-year-old documentation comments that described
  this as "Temporary". The functionality and comment were introduced
  in 2010 by Tim with r60599 (ad19c032b0).
  Ref <https://bash.toolforge.org/search?p=0&q=temporary>.

* Replace the broken wikitech-l archive link with a working one,
  and describe the thread for easier future reference.

Bug: T225756
Change-Id: I004da1f25c19e1095d0917349f2ba8461f9f0715
2021-08-10 21:03:13 +00:00
jenkins-bot
9cf0f3cd39 Merge "UserNameUtilsTest: avoid duplication in testGetCanonical_interwiki" 2021-08-10 03:49:37 +00:00
jenkins-bot
3c34f7f684 Merge "Use DummyServicesTrait for BadFileLookupTest TitleParser" 2021-08-10 03:44:11 +00:00
jenkins-bot
8d5ed3572d Merge "IPTCTest: use a data provider" 2021-08-06 12:49:36 +00:00
jenkins-bot
e89e7aa8b0 Merge "Revert "Use CsrfTokenSet as CSRF token source"" 2021-08-05 23:37:31 +00:00
jenkins-bot
8dde9906e8 Merge "build: Suppress ObjectTypeHintReturn for upcoming sniff change" 2021-08-05 23:23:04 +00:00
Umherirrender
baf4d01efa build: Suppress ObjectTypeHintReturn for upcoming sniff change
The abstract function gets validated with a new version of codesniffer
(since I4a17c2d965c277e7f8862e0e98228839022e0a01),
suppress the new error for the future version

Change-Id: I48c9151d24306822113c0305133a4984a8391f02
2021-08-05 23:01:55 +00:00
Kunal Mehta
a85f569dd1 Revert "Use CsrfTokenSet as CSRF token source"
This reverts commit 0d75fdb4f7.

Bug: T287542
Change-Id: Iedd3461869f973f8d621a39e6ad4674cbb577551
2021-08-05 15:48:26 -07:00
DannyS712
15e640bce0 IPTCTest: use a data provider
Change-Id: Iaff66f9030a38f7da7637e52d89ec4c1fc0df9d6
2021-08-05 05:40:25 +00:00
jenkins-bot
593c333ab1 Merge "parser: Replace deprecated MWHttpRequest::factory" 2021-08-04 23:13:56 +00:00
jenkins-bot
fc925ec724 Merge "Inject services into InfoAction" 2021-08-04 22:44:54 +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
DannyS712
0450da0f52 Inject services into InfoAction
Bug: T253078
Change-Id: I23022089f20695f88665a2990627e8f655266efa
2021-08-04 18:04:37 +00:00
Umherirrender
d1950d924a parser: Replace deprecated MWHttpRequest::factory
Change-Id: Id5fe298209cfbc09037799a2cdc117c9b7119172
2021-08-04 13:22:50 +00:00
jenkins-bot
41ca1816f1 Merge "Add a hook 'GetActionName' to allow overriding the action name" 2021-08-03 15:27:07 +00:00
James D. Forrester
1d71fd91d6 ILoadBalancer and IDatabase: Rename getMasterPos to getPrimaryPos
Bug: T282894
Change-Id: I30a600335af735a13a6ad2d3df56a5f17e05bfab
2021-08-02 18:14:41 +00:00
James D. Forrester
d11c59538a Rename DB primary position interfaces to DBPrimaryPos and MySQLPrimaryPos
And replace all uses.

Bug: T282894
Change-Id: I5222a8568255ac9fa5e2350e2264b8d2ee5eb968
2021-08-02 17:59:39 +00:00
Bartosz Dziewoński
6d361d61bd Add a hook 'GetActionName' to allow overriding the action name
The use case is to change action=edit into action=view in some
scenarios where we want to offer a more limited interface or a
gentler introduction to editing than MediaWiki provides, for example
I2e7b2682da7beb3c1c469bb784a9a8ec3998aeb9 in DiscussionTools.

Bug: T282204
Change-Id: Ib9302e2fda7dadf1edc43c0107db7234eb4bdf7a
2021-08-02 09:44:27 -05:00
jenkins-bot
f91965a992 Merge "SpecialPageAction: inject action name and SpecialPageFactory" 2021-08-02 01:16:16 +00:00
DannyS712
4a82f51d17 Inject JobQueueGroup into UserGroupManager
UserGroupManagerFactory takes care of getting the
correct JobQueueGroup for the domain.

Bug: T287808
Change-Id: I548f0c52b298bfcae386ca1a427521c81dc802fe
2021-07-31 07:09:27 +00:00
DannyS712
5b5763e230 SpecialPageAction: inject action name and SpecialPageFactory
Instead of trying to figure out the name based on the
context, which duplicates the handling in ActionFactory,
make use of ObjectFactory specs' `args` feature to inject
the name.

Also inject the SpecialPageFactory service.

Bug: T253078
Change-Id: Iec223583f93d45184152862d9eee735737453417
2021-07-31 03:43:56 +00:00
DannyS712
20293e4c99 Add an ActionFactory and start converting to DI
$wgActions used to map string action names to true,
false, a string, a callable, or an object. Now it can also
be an array (that isn't a callable) corresponding to an
ObjectFactory spec for DI.

This patch converts the revisiondelete and rollback actions to
use DI, with the rest to be converted later. The new structure
of $wgActions is fully backwards-compatible.

We don't yet deprecate Action::factory(), ::getActionName(),
and ::exists(), those will be deprecated in a follow-up.

Additionally, we no longer impose a rule that only some
actions can be overridden on a per-article basis via
Article::getActionOverrides().

Bug: T253078
Change-Id: I0fc3c53d671eced1758458f9a0148180b40c6c9b
2021-07-29 01:32:43 +00:00
DannyS712
bbbc66f1ab UserNameUtilsTest: avoid duplication in testGetCanonical_interwiki
Merge as another case in provideGetCanonical now that we don't
need separate configuration because 'interwiki' is configured as an
interwiki prefix for all of the tests.

Follow-up: I3b54909e33e69fea8bb5ec55c99848c196859185
Change-Id: I5cc358be8a4f037d4bf336aeecc6fa1b157aeeb6
2021-07-28 21:20:13 +00:00
DannyS712
d62a398a78 Use DummyServicesTrait for BadFileLookupTest TitleParser
Possible now that we can tell the service to throw mock
exceptions. Requires telling DummyServicesTrait to
include "Image" and "Image talk" alias support (these
are included in MessagesEn.php and so always available).

Follow-up: I11ae4c6292465626ad1e432f7c6e9754c8ef36c2
Change-Id: Ic995aeebcd2b9c8d2c43cb17258363eef81429ad
2021-07-28 20:50:20 +00:00
jenkins-bot
5790e3d9ce Merge "Make MailAddressTest a unit test" 2021-07-28 19:31:08 +00:00
Petr Pchelko
339fd93f67 Make MovePageTest actually test valid moves
Before MovePageTest was skipped if the move was valid,
claiming we can't test actual moves. Now we can.

Additionally, use MediaTestTrait for file and repo
mocking.

Change-Id: Ie8a1edbdb2f22432919f03a60c2dacc5d4528615
2021-07-28 09:18:59 -07:00
jenkins-bot
03cdd6af12 Merge "Narrow PageUpdater dependency from Title" 2021-07-27 21:38:53 +00:00
jenkins-bot
713d81d62a Merge "Move EditResultBuilder::findIdenticalRevision to RevStore" 2021-07-27 21:25:20 +00:00
DannyS712
91ac8a717d Add UserNameUtils to DummyServicesTrait, and use it
Allows us to reduce direct mocking in individual tests, or relying
on MediaWikiServices, by having a reusable service instead that
can be used in unit tests.

Make use of it in a few places.

This dummy service is also less coupled to individual tests;
in the rest handler tests, replacing mocks that report that
only a specific string is an ip address with the actual implementation
that accepts other ip address, and in BlockUtilsTest use
an actually invalid user name instead of making the mock
UserNameUtils complain about a perfectly valid name.

Change-Id: Iaa3195002ac4ae7e0c9c58ed57c80c02762d4070
2021-07-27 12:17:06 +00:00
DannyS712
edd9ae23be Allow using MediaWikiTitleCodec with errors in unit tests
MediaWikiTitleCodec can throw MalformedTitleException,
which cannot be created in unit tests (see T281935). Until
that changes, add a helper callback
MediaWikiTitleCodec::$createMalformedTitleException
that will by default return a MalformedTitleException, but
tests can override this to return a mock.

We add this as an option to DummyServicesTrait to throw
generic `MalformedTitleException`s without regard to the
specifics of the message or parameters provided, this
can be used if no finer control is needed, or callers
can manually change the callback.

Demonstrate using it by moving the tests for UserNameUtils
to be unit tests - the only thing blocking this was the
creation of `MalformedTitleException`s.

Change-Id: I11ae4c6292465626ad1e432f7c6e9754c8ef36c2
2021-07-27 11:27:56 +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
DannyS712
6e46d72309 Make CentralIdLookupTest a unit test
Mock the UserIdentityLookup (might be worth adding
to DummyServicesTrait soon) and pass UserIdentityValue
instead of full User objects.

The tests for the factory methods are removed, those
just wrap around CentralIdLookupFactory which has
its own tests already.

Change-Id: Ieea548aae46e3dd5a71518e7381dd40ce19c94ec
2021-07-26 20:52:14 +00: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
DannyS712
c8ebb7113a Make MailAddressTest a unit test
Requires a bit of manual manipulation of globals, but
other than than no reason to make an integration test.

Change-Id: I56342770f856092992660e104e06aa65a24e0e20
2021-07-23 10:30:04 +00:00
DannyS712
4f3b6eae63 Reduce duplication in NoWriteWatchedItemStoreUnitTest
Plus, fix implementation of
NoWriteWatchedItemStore::countWatchersMultiple, which
should call the same method on the actual store

A follow-up will convert to using data providers
to further reduce duplication

Change-Id: I82682c37b404110e1537aec8ca859044953a0f0a
2021-07-23 08:07:46 +00:00
jenkins-bot
f7e6e6bcd2 Merge "Simplify and reduce duplication in PingbackTest" 2021-07-23 04:16:56 +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
85fa5602e3 Simplify and reduce duplication in PingbackTest
MediaWikiTestCaseTrait provides a helper method,
createNoOpMock, that covers the case of wanting
to assert that no methods or no methods except
those in a list get called.

Add a helper method for the repeated logic
of creating cache and config, and creating
and running the pingback.

Merge the two test cases for when a pingback
should actually be sent (no prior pingback in the
database, or the prior pingback is from more than a
month ago) to use a data provider.

Rename variables to be sligthly clearer.

Change-Id: I25daf4d78b7bea12a6bc68ace3827985e435d21d
2021-07-21 15:50:25 +00:00
Tim Starling
bc76602493 DBMS-specific ResultWrapper subclasses
Cleanup after the switch of Database::query() to return ResultWrapper
instead of resource.

* Soft-deprecate the IResultWrapper accessors in IDatabase.
* Move relevant DBMS-specific functionality to ResultWrapper subclasses.
  The deprecated methods in IResultWrapper become short and simple.
  ResultWrapper is now abstract (b/c break).
* Move the implementation of fieldName(), numFields() and one of the
  fieldInfo() implementations to the ResultWrapper subclass in order to
  avoid ResultWrapper::unwrap() calls.
* Make Database::doQuery() return a ResultWrapper subclass instead of
  underlying result data, so that the Database parent class does not
  need to be aware of wrapper construction.
* Hard-deprecate ResultWrapper::unwrap(),
  DatabaseMysqlBase::fieldType(), DatabasePostgres::fieldType().
* Fix the inefficient seeking method in SQLite.
* Make FakeResultWrapper extend ResultWrapper with an implementation
  similar to the SQLite one. This is possible because ResultWrapper does
  not depend on IDatabase anymore.
* Resolve fixme in DatabasePostgres: from studying the source,
  neither pg_fetch_object() nor pg_num_rows() can set an error
  retrievable with pg_last_error(). Removed unnecessary warning
  suppression.
* ResultWrapperTest didn't make sense as a unit test anymore, so I
  adapted it as an integration test against the current DBMS.

This change also means that ResultWrapper::key() always gives the
correct offset, even if Iterator methods are not being used.

Bug: T286694
Change-Id: I935835316c0bd7d3d061bd8fde9c9ce99ce756ec
2021-07-21 06:54:26 -07:00
Petr Pchelko
4f4822119d Convert CentralIdLookup to UserIdentity.
NOTE: this is a backwards incompatible change which will
need to have corresponding changes implemented in CentralAuth
and probably force-merged.

Depends-On: I4c2170a25ea8b1cf5410a4648ebec66a3ab253f3
Depends-On: I612460ec2c6a038b7155b3f38f3261757ba63b4e
Depends-On: I3b91b333753a877aceb177b7d38f9272a044f055
Depends-On: I9ae86c9a5da66d5857fcea9967012c6bbbfc4d45
Depends-On: I4a08af2227d0dfd833e16469df3f76e397dce669
Change-Id: I67bf4f2442269b8aa1002868ede9a71a5ca43a84
2021-07-21 06:18:59 -07:00
jenkins-bot
7a79548ac7 Merge "Convert BlockUtils::parseBlockTarget to UserIdentity" 2021-07-20 21:54:33 +00:00
Alexander Vorwerk
825ac0232c Convert BlockUtils::parseBlockTarget to UserIdentity
Bug: T286490
Change-Id: Ice96180690828bcf2efd60faf6ad10d64307713d
2021-07-20 22:12:26 +02:00
jenkins-bot
b283b2a1d0 Merge "Cleanup to PageUpdaterFactory and tests" 2021-07-20 19:41:39 +00:00
jenkins-bot
f560abe9e7 Merge "Simplifications to RevertedTagUpdateTest" 2021-07-20 19:38:46 +00:00
DannyS712
e16e6c4ab8 WatchedItemStore: use UserFactory::newFromUserIdentity()
Currently, we have a UserIdentity, we retrieve the user id,
and then we create a User object based on the id. Instead,
create the User object based on the UserIdentity directly,
so that if the UserIdentity happens to already be a full User
object no change is needed.

This allows us to simplify WatchedItemStoreUnitTest by
not needing to tailor the mock UserFactory to the specific
user ids that we are using in each test case.

Change-Id: I52918b4f4c7d44086ea4fcdabdbfe14197c06373
2021-07-20 12:10:20 +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
jenkins-bot
fe93ad5273 Merge "Add DummyServicesTrait::getDummyReadOnlyMode()" 2021-07-20 04:00:25 +00:00
jenkins-bot
13d9240610 Merge "VueComponentParser: Don't crash on top-level comments" 2021-07-19 16:40:45 +00:00
daniel
1829057944 Introduce includes/Storage/PageUpdaterFactory
Change-Id: I2a060bfa8ac098edf24fc4d51212eeb7ddf3942d
2021-07-19 12:15:26 +02:00