Commit graph

27 commits

Author SHA1 Message Date
vladshapik
c7e6c67dc5 Hard deprecate User group methods
1) The following methods were hard deprecated:
- User::addAutopromoteOnceGroups
- User::getEffectiveGroups
- User::getAutomaticGroups
- User::getFormerGroups

2) User ::getGroups, ::getGroupMemberships, ::addGroup,
::removeGroup were replaced in the production code,
but they were not hard deprecated because of conflict
with UserRightsProxy class.

Bug: T275148
Change-Id: Ia69598316f5dc5dd9511f6112b5b13e1aa07575a
2021-07-23 15:00:16 +03: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
b45ddb2ab3 Use WikiPage::doUserEditContent() instead of ::doEditContent()
Results in passing a user where previously the fallback
to $wgUser was being used, mostly in tests.

Bug: T255507
Change-Id: Iabe24315b23c0ad1272353186425e71974528d23
2021-06-28 00:11:30 -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
Petr Pchelko
1f11b88f35 Convert PageEditStash to PageIdentity/UserIdentity
One tricky piece left when we get the Request from user
to check whether it was posted, needs a more thorrow
investigation.

Depends-On: Iab96a35be8f50fdbc66194bd8956d98b5b6b0032
Change-Id: I7164b914299441bd0f82e764252c8b5d30b45fbe
2021-04-14 09:12:04 -07:00
Thiemo Kreuz
ac205fa84c Fix incomplete/bogus PHPDoc tags in various tests
Most of these are found by the not yet released I10559d8.

I remove the type MockObject in some cases when the calling
code really does not need to know if he get's a mock or the
real thing. However, I do this only in places that are very
closely related to the fixes.

Change-Id: I26a4c3c5a8ae141bf56161b52b54bce7e68f2e30
2021-01-14 19:02:00 +00:00
Umherirrender
b64d838062 Skip undo related phpunit tests when diff3 is missing
Change-Id: I7fcbcfcd191805c00bdac07f681d266fe3e1fccb
2020-12-12 20:22:17 +00:00
jenkins-bot
2ed425f39e Merge "PHPUnit integration tests: fix handling of null user in editPage()" 2020-09-13 09:24:18 +00:00
Ostrzyciel
81ac2fc852 PHPUnit integration tests: fix handling of null user in editPage()
The PHPDoc for the editPage method stated that if $user is null,
the test sysop user will be used instead. This is not the case in
practice, as the method simply passes null to the doEditContent
method.

As Ammarpad has pointed out in a comment, this confusion is due to
I5a10163 assuming the sysop would be used, which is incorrect.
It's also probably better for the default user to be a "regular"
user, not a sysop, so I changed it to getTestUser() and noted this
in the doc block.

Depends-On: I7a79e0eaa1617e4d87a8d615a5391723c0e30b6a
Change-Id: I9f77474f40e0f6901aa2c6f846e471b822636aa5
2020-09-13 09:42:52 +02:00
Ammar Abdulhamid
7af5678847 API: Handle ContentHandler exception for content model mismatch
Ensure the content we are trying to save and the base content have
identical content models before proceeding to save so as to forestall
Exception that may be thrown by ContentHandler if it founds they're not.

There are two cases where the models are allowed to differ: Edit that
undoes content model change or edit that's meant to explicitly change
the model. The logic for these is handled separately and may succeed
or fail, but exception will not be thrown.

Bug: T255700
Change-Id: I8782732bb0fc3059693cd7035b7ebb43fd71d333
2020-09-04 03:41:58 +01:00
Thiemo Kreuz
5f3a92385b Fix visibility of setUp/tearDown
Change-Id: I636be48eb9f713680abac35d46091f7b49374696
2020-06-16 21:02:05 +02:00
DannyS712
c595f2fd7e Remove use of the Revision object returned in WikiPage::doEditContent (2)
Each file's changes are independent and can be reviewed separately

Bug: T251853
Bug: T254952
Change-Id: Ifdc192796f0989c12fda7c0317bf2458874d6e19
2020-06-10 01:15:45 +00:00
DannyS712
25a90e8009 Remove unneeded ::setUp and ::tearDown methods that only call parent
Change-Id: I2a12859cfc56059bb71afa2aac08a8f86e746612
2020-06-07 10:09:32 +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
6b2a4dd1fe MediaWikiIntegrationTestCase: Remove use of Revision objects
Only support passing RevisionRecord or int, remove use of
Revision::newFromId

Bug: T249021
Bug: T249561
Change-Id: Id4a8f64f239d0664865056887fe0a11c7e468d5f
2020-04-21 23:20:25 +00:00
James D. Forrester
4f2d1efdda Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUse
Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
2020-01-10 09:32:25 -08:00
Daimona Eaytoy
7b946ffb4b Fixes for PHPUnit 8 compat in DB suite
Once again, this fixes all issues aside from assertArraySubset.

Bug: T192167
Change-Id: I45c91dc1cf23f04140576dc66233558bb6021324
2019-12-15 00:27:54 +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
Vedmaka
dd6b94024c Re-apply: Factors out permissions check from User into PermissionManager service
Was reverted by I549810a4cd2e424cc4a438887d2f24614a24cc00 due to
T224607.

Original change by  Vedmaka Wakalaka was
Ia0d840b772ea5f20c9594ce151cc57adc270e48b.

Original commit message:

The following methods should are factored out of the User class into PermissionManager,
leaving only deprecated stubs:

- User::isAllowed -> PermissionManager::userHasRight
- User::getRights -> PermissionManager::getUserPermissions
- User::groupHasPermission -> PermissionManager::groupHasPermission
- User::getGroupPermissions -> PermissionManager::getGroupPermissions
 -User::getGroupsWithPermission -> PermissionManager::getGroupsWithPermission
- User::groupHasPermission -> PermissionManager::groupHasPermission
- User::isEveryoneAllowed -> PermissionManager::isEveryoneAllowed
- User::getAllRights -> PermissionManager::getAllPermissions

Depends-On: I7909e9bd6bbfbd708c0a00b861a9b22a38c6665d

Bug: T218558
Bug: T223294
Change-Id: I8899240378f636ea70f447616710516c0a3c5c31
2019-06-28 13:19:38 -07:00
Aaron Schulz
b09b3980f9 objectcache: add object segmentation support to BagOStuff
Use it for ApiStashEdit so that large PaserOutput can be stored.

Add flag to allow for value segmentation on set() in BagOStuff.
Also add a flag for immediate deletion of segments on delete().

BagOStuff now has base serialize()/unserialize() methods.

Bug: T204742
Change-Id: I0667a02612526d8ddfd91d5de48b6faa78bd1ab5
2019-06-11 16:14:17 +01:00
Aaron Schulz
2859306684 Refactor edit stashing into a PageEditStash service
Additional code cleanup:
* Call setCacheTime() in parseAndStash instead of relying
  on the one in DerivedPageDataUpdater.
* Improve the SPI logging by adding more extra fields.
* Treat requests in CLI/job mode (aside from tests) like
  those from bots with regard to checking the stash.
  This should avoid stats/logging pollution.

Change-Id: I8c6be919e399378e401a60502add0ecec7764d2d
2019-04-17 12:53:03 -07:00
Aaron Schulz
0dc015c87b Make ApiStashEdit use a separate key for the parser output due to size
Bug: T204742
Change-Id: Ibab189c8e0dee5e840770bdb0336516fdfc75e4b
2019-03-06 09:11:07 -08:00
Aaron Schulz
390fce6db1 Move user_editcount updates to a mergeable deferred update
This should reduce excess contention and lock timeouts.
Previously, it used a pre-commit hook which ran just before the
end of the DB transaction round.

Also removed unused User::incEditCountImmediate() method.

Bug: T202715
Depends-on: I6d239a5ea286afb10d9e317b2ee1436de60f7e4f
Depends-on: I0ad3d17107efc7b0e59f1dd54d5733cd1572a2b7
Change-Id: I0d6d7ddd91bbb21995142808248d162e05696d47
2018-10-25 15:32:18 -07:00
Aryeh Gregor
09eee138e1 Deprecate MediaWikiTestCase::stashMwGlobals
This method encourages directly editing configuration variables.  It's a
better idea to use setMwGlobals() (or other set wrappers) so that we can
be intelligent in the future, for instance resetting services after the
config change.  Plus, a lot of the callers come out cleaner this way
anyway.

Depends-On: I8a1e81acc5c42a8d7f30938a72cface0acea4a70
Depends-On: I4105dbcf9c5399fe7239478c460ec57c015a98d4
Depends-On: I1b220996acf2f66cf7b0f092b341584663df32f9
Depends-On: Ie2d1ea65c0cb334bbde1666d00781474b7ac4dab
Change-Id: I23d77398e401f4986b1d5bd1c9e11a8a40da16f8
2018-10-07 19:39:47 +03:00
Aryeh Gregor
ab94b63526 Improve test coverage for ApiStashEdit
Change-Id: I1b7d95e074a7f101d13398a32898b74145ab4056
2018-08-21 15:32:29 -07:00
Aryeh Gregor
ed40e8ec53 Get rid of ApiTestCase::doLogin
The function is entirely unnecessary.

Change-Id: I805520e5355119e872e602d0bfc93be26f227128
2018-04-11 20:17:52 +03:00
Antoine Musso
6fe1e2e248 test: basic test for ApiStashEdit
At least execute the main entry point.

Change-Id: I0788c9a7bf93b5365f4e510dff4e11fe6ffa3558
2016-06-16 22:26:24 +02:00