Commit graph

54 commits

Author SHA1 Message Date
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
2915e0bbbf DefaultPreferencesFactory: inject and use UserOptionsManager
Inject a UserOptionsManager instead of UserOptionsLookup, and
update deprecated calls to user options methods

Bug: T277600
Bug: T277818
Change-Id: Ifdf491c3fd6b5b16246f33012f1db21f2cbc1f3e
2021-06-17 17:27:40 -07:00
DannyS712
fcad1b9e44 DefaultPreferencesFactory: inject all services needed
Inject LanguageConverterFactory, Parser, and SkinFactory,
plus remove use of UserOptionsLookup from MediaWikiServices
in favor of the existing injected one

Change-Id: Id8635a7a982f84828f3c0ba71f8446dd3d666a25
2021-06-04 23:51:59 +00:00
DannyS712
7c59cb3a8a DefaultPreferencesFactory: inject a UserGroupManager
Has a fallback in case one is not provided, so as to not
break the GlobalPreferences extension

Includes fixing the expectations in the tests
for the underlying code in testUserGroupMemberships

Change-Id: Ia539e48c305787f7e2a9a3a0b42891b7a8e2912b
2021-06-02 19:06:27 +00:00
jenkins-bot
c60ccf4e6d Merge "preferences: Move complex creation of infos for usergroups into closure" 2021-05-27 19:52:04 +00:00
DannyS712
779bd0aae8 Migrate DefaultPreferencesFactory to authority
Use authority methods instead of the injected PermissionManager;
not removing the PermissionManager yet since it would break
the GlobalPreferencesFactory which extends the class

Change-Id: Ia804fa7e536d0746f49f51792a48af9f4834183c
2021-05-26 06:39:45 +00:00
Umherirrender
215431bfd4 preferences: Move complex creation of infos for usergroups into closure
The HTMLInfoField allows the default part to be a closure.
This delays the message parse until the messages are needed on a gui.
This avoids the message parse on save or api calls and hopefully makes
that faster.

The message prefs-memberingroups is now parsed as all the other label
messages. This is another fix as done for T142882 / 116063f

Bug: T58633
Change-Id: I860501fe3df1ee330460f04ffe8493dd16421c8d
2021-05-25 18:17:37 +02:00
DannyS712
26dec11987 Use DummyServicesTrait::getDummyNamespaceInfo in more places
Make it possible for callers to override config as needed

Change-Id: I54e7ba8d56d7d168248aca85c2e4e973b012806a
2021-05-05 01:53:30 +00:00
DannyS712
6c4c09c715 DefaultPreferencesFactoryTest: add helper for PermissionManager
Change-Id: If852c3de90513a0b6e103e89661c1d1c38611ab6
2021-05-03 16:24:21 +00:00
vladshapik
9cc797695b Hard deprecate User ::isIP, ::getOptions
Bug: T275602
Change-Id: Id4be13751ca0a900e51214c1855a4624077a5a62
2021-04-26 16:10:24 +00:00
Bartosz Dziewoński
444e28f907 Check for line breaks in user signatures
Bug: T272322
Change-Id: Ieac8be8839915a1ec4d547c2fc15d5fa9b27aca9
2021-04-23 19:55:38 +00: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
jenkins-bot
b57ace7aee Merge "Replace PHPUnit ->returnValue() with ->willReturn() shortcut" 2021-04-22 15:47:14 +00:00
Thiemo Kreuz
f10f4e05de Remove some meaningless $this->equalTo() from tests
This is the default behavior anyway when using ->with().

Change-Id: I64b6474280eb7da122eb22fc0afa28cca81e96c5
2021-04-22 10:47:54 +02: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
Peter Ovchyn
45140daa29 Avoid using User ::getDefaultOption, ::getDefaultOptions
This patch hard-deprecates the methods above

Bug: T276035
Change-Id: Ic36b0702f7547acce0d162d6e0b54bbd4ecf4d81
2021-03-16 17:24:17 +02:00
Umherirrender
7691dbeca9 Add missing @param and @return to documentation in tests
Change-Id: Ic663e81cca0bf007804a70772250914a85f1fef4
2021-01-22 19:57:25 +01: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
jenkins-bot
3ea0a9068a Merge "preferences: Signature validation (lint errors, user links, nested subst)" 2020-06-24 22:14:57 +00:00
Bartosz Dziewoński
df7231ad89 preferences: Signature validation (lint errors, user links, nested subst)
Three new checks are now applied to user signatures in preferences:

* Disallow invalid HTML and lint errors (T140606)

  Since 15e0e9bb4b we can rely on Parsoid to check the signature for
  lint errors. (The old PHP Parser doesn't have this capability.)

  Most importantly, this will disallow unclosed HTML tags. Unclosed
  formatting tags like `<i>` (and also wikitext markup like `''`)
  could affect the entire page with the bad markup.

  New configuration variable $wgSignatureAllowedLintErrors is added
  to allow ignoring some errors. The default value ignores the
  'obsolete-tag' error (caused by HTML tags like `<font>` and `<tt>`.)

* Require a link to user page, talk page or contributions (T237700)

  Various tools don't work correctly when such a link is missing. For
  example, Echo notifications are not sent, DiscussionTools will not
  allow replying to these comments, English Wikipedia's SineBot treats
  these comments as unsigned.

  Such requirement has been present for a long time in many Wikimedia
  wikis' policies, but it was not enforced by software.

* Disallow "nested" substitution in signature (T230652)

  Clever abuse of "subst" markup and tildes allows users to save edits
  containing wikitext in which substitution occurs again when the page
  is next saved. Disallow this in signatures, at least.

New configuration variable $wgSignatureValidation is added to control
what we do about the result of the validation described above. The
options are:

* 'warning':
  Only displays a warning near the field on Special:Preferences if
  the current signature is invalid. Signatures can still be changed
  regardless of validity and will be used when signing comments.

* 'new':
  In addition to the above, if a user tries to change their signature,
  the new one must be valid. Existing invalid signatures are still
  used when signing comments.

* 'disallow':
  In addition to the above, existing invalid signatures are no longer
  used when signing comments.

Bug: T140606
Bug: T237700
Bug: T230652
Change-Id: I07c575c2d9d2afe7a89c4847d16ac044417297bf
2020-06-24 01:20:05 +02:00
Umherirrender
fd666afbb0 Use MediaWikiServices::getAuthManager instead of AuthManager::singleton
Change-Id: I92c31b963095eab751df9f8c1715e8e23b7e8485
2020-06-22 00:57:08 +00:00
Thiemo Kreuz
5f3a92385b Fix visibility of setUp/tearDown
Change-Id: I636be48eb9f713680abac35d46091f7b49374696
2020-06-16 21:02:05 +02:00
Sam Wilson
5e0fd6d664 Remove PreferencesFactory::setUser()
This method was recently added and was to result in the deprecation
of a few places where User objects were being passed to the factory.
This has now been reconsidered and this patch reverts to the
previous behaviour. It is largely a revert of Ie1bed9e9537cabc836992ccfa7fb127885ea3e11

Bug: T238466
Depends-On: Idc9f33fd5ab55bde88cc306ca63adead286380a8
Change-Id: I3653559704ccfd9bca0946f5a865be93bdf5ceb6
2020-06-08 00:27:04 +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
jenkins-bot
4a5c7b4e84 Merge "Deprecate no LanguageNameUtils constructing DefaultPrederencesFactory" 2020-05-11 21:13:20 +00:00
Sam Wilson
36defc20eb Add PreferencesFactory::setUser()
Add a new setUser() method to PreferencesFactory so that a User
object doesn't have to be passed around so much. This is how
GlobalPreferencesFactory has done it, and so after this change
that code can be removed from GlobalPreferences.

Bug: T238466
Change-Id: Ie1bed9e9537cabc836992ccfa7fb127885ea3e11
2020-05-06 09:04:08 +08:00
Petr Pchelko
2501625352 Deprecate no LanguageNameUtils constructing DefaultPrederencesFactory
Depends-On: I3e30bc01ec9333d03e1282a21ae8953ae1f7c770
Change-Id: Ifd9628469bf72ffaa6ab75415ee18edd416cffe2
2020-05-05 16:41:31 -07:00
Peter Ovchyn
50e3bd4fac parser: Inject a LanguageConverterFactory through DI containers:
1. into class Parser
2. into class LinkHoderArray
3. into class DefaultPreferencesFactory

Add more tests for DefaultPreferencesFactory:
1. testVariantsSupport verifies that converter with variants is used correctly.
2. Test testUserGroupMemberships verifies that membership is used correctly

Bug: T243320, T243321, T243317
Change-Id: I1e5c37e18332d0d32391c74c06e3d84862e48df8
2020-02-04 14:42:03 +02:00
James D. Forrester
5e9fca47b9 Coding style: Auto-fix MediaWiki.Usage.PHPUnit*
Change-Id: I86fc55a4fc8ceafe368692173211bbcd6d8581d7
2020-01-10 10:17:12 +00:00
Cormac Parle
c4eae0dad4 Search: Provide new preference to control redirects on search matches
To avoid preference bloat, this preference is hidden unless the new
sysadmin config $wgSearchMatchRedirectPreference is set.

Bug: T235263
Change-Id: Ic16f53a4e6ddb6da071d63cd5da28d937d4692c8
2019-11-06 15:37:56 +00: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
James D. Forrester
17f3f9cee3 Services: Convert DefaultPreferencesFactory's static to a const now HHVM is gone
Change-Id: If24c5f120cb96311b50750c5b3022664dc6b20e5
2019-10-08 11:28:15 -07:00
Petr Pchelko
57cffc9e57 Break PreferencesFormOOUI->PermissionManager dependency
Depends-On: Id0f0bdb39b9e0be4d7c38c229371be04bb5aec5c
Change-Id: I9209cf26a27ab66306f61937b620bfe05c2045b0
2019-09-17 08:34:53 -07:00
Petr Pchelko
5ccb1a42c7 Make DefaultPreferencesFactory depend on PermissionManager.
Bug: T220191
Change-Id: I3f5c4340501d59b5ca63b096364b5cc8388cff80
2019-09-11 15:34:26 -07:00
Aryeh Gregor
b058a0e562 Test that classes use all their ServiceOptions
Classes that use ServiceOptions need to declare a list of keys that they
use, typically in self::$constructorOptions. If keys are missing from
that list that are supposed to be present, an exception will be thrown
when someone tries to access them. If keys are present on the list that
are never used, no error is flagged. This means if a dependency on a
given configuration option is removed and nobody updates the list, the
service will keep thinking it depends on that option when it doesn't.
This is messy at best, like an unused variable.

A new and easy-to-use TestAllServiceOptionsUsed trait fixes that
problem. It will log all the ServiceOptions accesses while the test
class runs and raise an error if there are any keys that were never
accessed.

In retrospect, it was probably not worth the time to write this, but
it's a sunk cost now.

Change-Id: Idcaf9a0e2f687069869e6f8057908ffee7dd5f11
2019-08-19 20:42:28 +03:00
Máté Szabó
344481f60d Move trivially compatible tests to the unit tests suite
This changeset resumes work on T89432 and related tickets
by porting an initial set of tests to the new unit test suite
separated out in I69b92db3e70093570e05cc0a64c7780a278b321a.
The tests were only ported if they worked immediately without
requiring any changes other than changing the test case class
to MediaWikiUnitTestCase and moving the test to the new suite.
If a test failed for any reason (even trivial misconfiguration),
it was NOT ported.

With this change, the unit tests suite now consits of a total
of 455 tests. As before, you can run these tests via the following
command:
$ composer phpunit:unit

Bug: T84948
Bug: T89432
Bug: T87781
Change-Id: Ibb8175981092d7f41864e641cc3c118af70a5c76
2019-06-30 15:23:53 +02:00
Legoktm
4e35134f7a Revert "Separate MediaWiki unit and integration tests"
This reverts commit 0a2b996278.

Reason for revert: Broke postgres tests.

Change-Id: I27d8e0c807ad5f0748b9611a4f3df84cc213fbe1
2019-06-13 23:00:08 +00:00
Máté Szabó
0a2b996278 Separate MediaWiki unit and integration tests
This changeset implements T89432 and related tickets and is based on exploration
done at the Prague Hackathon. The goal is to identify tests in MediaWiki core
that can be run without having to install & configure MediaWiki and its dependencies,
and provide a way to execute these tests via the standard phpunit entry point,
allowing for faster development and integration with existing tooling like IDEs.

The initial set of tests that met these criteria were identified using the work Amir did in
I88822667693d9e00ac3d4639c87bc24e5083e5e8. These tests were then moved into a new subdirectory
under phpunit/ and organized into a separate test suite. The environment for this suite
is set up via a PHPUnit bootstrap file without a custom entry point.

You can execute these tests by running:
$ vendor/bin/phpunit -d memory_limit=512M -c tests/phpunit/unit-tests.xml

Bug: T89432
Bug: T87781
Bug: T84948
Change-Id: Iad01033a0548afd4d2a6f2c1ef6fcc9debf72c0d
2019-06-13 22:56:31 +02:00
Aryeh Gregor
3860a8d9b4 Update DefaultPreferencesFactory to use NamespaceInfo
Depends-On: I552264714de7227965f978f20f932f41cf96042e
Change-Id: I0568e7f4c7223208001f378a03fef395df8bff69
2019-05-06 12:19:13 +03:00
Aryeh Gregor
18ec468633 Don't pass Config to service constructors
We don't want to depend on the entire site configuration when we only
need a few specific settings.

This change additionally means that these services no longer see a live
version of the settings, but rather a copy. This means in tests you
really do have to call overrideMwServices() if you want services to pick
up your config changes.

ResourceLoader and SearchEngineConfig will need more work to port,
because they expose their member Config in a getter, and the getter is
actually used.

Parser and NamespaceInfo are also relatively complicated, so I split
them into separate patches.

Tested with 100% code coverage. \o/

Depends-On: If6534b18f6657ec1aba7327463f2661037f995b3
Change-Id: I1a3f358e8659b49de4502dc8216ecb6f35f4e02a
2019-05-02 11:33:56 +03:00
Reedy
571a44a4be Replace PreferencesFormLegacy usages with PreferencesFormOOUI
Change-Id: I4fc2a609ebb0f93b0767dddc343c3ff93ca8a39c
2019-04-14 00:51:05 +00:00
tzhelyazkova
aca802509e Add a user preference to opt in or out of a confirmation prompt for rollbacks.
Bug: T199537
Change-Id: I2f08ef5f8c38f23b282e130d040681fc060b6b00
2019-03-21 09:05:27 +01:00
Tim Eulitz
07c0c40978 Remove rollback confirmation user preference
Due to a delay in the rollout of this feature, this part of the code has
to be temporarily removed again to prevent an unused setting from
popping up in the user settings.

Bug: T218556
Change-Id: I0f4e822fc25fddc2bc3c0b55b0792799a1e4c4ba
2019-03-19 13:49:51 +00:00
tzhelyazkova
9c4d596dbc Add a user preference to opt in or out of a confirmation prompt for rollbacks.
This should not be visible on production until the feature of rollback confirmation prompt has been deployed.

Bug: T199537

Change-Id: I8a49143f662b8412f74c06627c2285ab3c3b8cff
2019-03-06 16:44:09 +01:00
Antoine Musso
eb8e2ba234 test: disable hook when testing default preferences
The GetPreferences hook lets extensions register additional user
preferences.  They show up on the form and that breaks the hardcoded
assertion that exactly 5 preferences are available.

Disable the hook in case the test is run with extensions loaded in (ex:
BetaFeatures).

Change-Id: I78b11e989110407cd721e8a3fbbe81d28ca4be5b
2018-09-10 10:25:22 +02:00
Aryeh Gregor
bca6085920 Use ParserFactory in a bunch of places
I wasn't sure how to convert the rest of the occurrences in core (there
are a significant number).

Bug: T200881
Change-Id: I114bba946cd3ea8a293121e275588c3c4d174f94
2018-08-11 00:16:17 -06:00
RazeSoldier
af2346f3d2 Fix octal escape sequence overflow in FiltersTest.php
The octal escape sequence must be less than or equal to 377.
Change \666 to \377.

Bug: T200004
Change-Id: I3804a0c0fab7ec74bc9dd1281d800fffd53f05fa
2018-07-19 22:09:15 +08:00
Max Semenik
e6b4944dbf Introduce preference filters
This normalizes handling of transformations on the boundaries between
preferences and generic form controls and removes the special case
where email-blacklist is passed around as an array internally, leaking
into the API.

As a result of this normalization, meta=userinfo no longer returns an
array of users, using the internal representation like action=options.

Bug: T198935
Change-Id: Iff63da0d215585cfcf083e7f7ec8ed45d5b77301
2018-07-17 13:19:14 -07:00
Reedy
6b6c71558e Fix PreferencesForm alias
Change-Id: I6f24c6283b4165b9209e53f8fc3b8ecb5feb9ca4
2018-05-29 21:44:18 +00:00
jenkins-bot
cfd378774e Merge "Special:Preferences: Create flag to enable OOjs UI" 2018-05-08 21:32:01 +00:00