Commit graph

90 commits

Author SHA1 Message Date
Reedy
12a3883a7b Fix SingleSpaceBeforeSingleLineComment
Change-Id: I285af438ce484af40741489797f20455726ec110
2020-05-11 00:57:11 +00:00
jenkins-bot
637f4ec411 Merge "Revert "Replace weird stdClass mock with class actually expected"" 2020-03-03 23:09:07 +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
Daimona Eaytoy
3e8374219a Revert "Replace weird stdClass mock with class actually expected"
This reverts commit 8d57c5e32c.

Reason for revert: 'Session' is a final class and cannot be mocked.
Added a comment to explain this.

Change-Id: Ic8bbd82aa668916766ab8434018299a22d31224d
2020-03-02 13:39:19 +00:00
Thiemo Kreuz
8d57c5e32c Replace weird stdClass mock with class actually expected
Change-Id: I7abc014b6c82f5f5a62b807a43a623ef7d1fe721
2020-02-28 21:07:43 +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
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
Umherirrender
4680496455 Set visibility on PermissionManager RIGOR_ constant
Use the constant instead of strings in some places

Change-Id: Ic14456ec9e863def05ec4dfbccb2fa8bd828e639
2019-12-06 22:18:01 +01:00
jenkins-bot
1bc7bc958c Merge "tests: Add explicit return type void to setUp() and tearDown()" 2019-11-01 02:08:24 +00:00
Dayllan Maza
e774df240a Remove blocker dependency for System and Composite blocks
The motivations behind this change is T227892 and that a blocker for a System or
Composite block provides no useful information for the end user.

Here is what's changing:
* Move the $blocker property to DatabaseBlock, since this is the only type of
  block that can be created by a user.
* Move handling of the 'by' and 'byName' constructor option from AbstractBlock to
  DatabaseBlock.
* getBy(), getByName(),  are now abstracts methods and each block type have to provide
  their own implementation
* getBlocker(), setBlocker() are being deprecated in AbstractBlock and moved as internal
   methods into DatabaseBlock

Bug: T227892
Depends-On: Ie2aa00cfec5e166460bcaeddba3c601fe0627c13
Change-Id: I1b17c652b12d98de3d996d309d4d3f22074be411
2019-10-31 07:45:07 -04: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
Thalia
5310373336 Stop accessing User::mBlock and User::mBlockedby from tests
Update PermissionManagerTest and FormSpecialPageTestCase to use a
mock User object that returns a specified block.

Before this commit, these tests manipulate the public properties
User::mBlock and User::mBlockedby in order to change the user's
block. There is no advantage to doing this over mocking: it is not
more realistic, and is sensitive to changes in the code. These tests
need updating in order to deprecate public access to these properties
(see T229035).

Also, PermissionManager::testUserBlock is a large, complicated method
that tests three different things, so split it into three smaller
methods, each testing one thing:
* testCheckUserBlockActions: A blocked user is blocked/unblocked
  correctly from certain actions, depending on their block.
* testCheckUserBlockMessage: The correct block message key and
  parameters are returned, depending on the block.
* testCheckUserBlockEmailConfirmToEdit: A user is or isn't asked to
  provide email confirmation in order to edit, as specified by the
  config.

Change-Id: I0bb9252b476131c2b255d4c503c0dab5dfff94be
2019-10-15 15:05:53 +00:00
jenkins-bot
8db7eb1139 Merge "Introduce a formatter service for block errors" 2019-10-08 19:42:53 +00:00
James D. Forrester
9cba9f8567 Services: Convert PermissionManager's static to a const now HHVM is gone
Change-Id: Ib75b6f5d6b3e793ddbce42951693d8c99e6b7e57
2019-10-08 11:23:08 -07:00
Thalia
df20197250 Introduce a formatter service for block errors
The main reasons for adding this service layer are:
* It allows error messages to be more consistent, by defining
  a set of reportable information that can describe any block
  type and is consistently formatted.
* It decouples formatting from the block classes, removing
  their dependency on language, for the most part.

The service provides one public method, getMessage, which
returns a Message object whose key and parameters are
determined by the type of block. This should be used instead
of the deprecated AbstractBlock::getPermissionsError and
AbstractBlock::getBlockErrorParams.

Calls to AbstractBlock::getPermissionsError are replaced in
this patch.

Bug: T227174
Change-Id: I8caae7e30a46ef7120a86a4e5e6f30ae00855063
2019-10-08 12:29:23 +01:00
Thiemo Kreuz
e4272518f7 tests: Replace PHPUnit's loose assertEquals(false) with assertFalse()
assertEquals( false, … ) still succeeds when the actual value is 0, null,
an empty string, even an empty array. All these should be reported as a
failure, I would argue.

Note this patch previously also touched assertSame( false ). I reverted
these. The only benefit would have been consistency within this codebase,
but there is no strict reason to prefer one over the other. assertFalse()
and assertSame( false ) are functionally identical.

Change-Id: Ic5f1c7d504e7249002d3184520012e03313137b4
2019-10-04 00:30:36 +00:00
jenkins-bot
296e3d4f98 Merge "Move User::getAllRights to PermissionManager." 2019-08-29 21:00:23 +00:00
Petr Pchelko
f1914810a7 Remove usages of Title::quickUserCan
Change-Id: Ifa53e0ec800e23dc4184d133a100fb9378dfee9e
2019-08-29 11:48:30 -07:00
Petr Pchelko
49e2aec53a Move User::getAllRights to PermissionManager.
Bug: T220191
Change-Id: I7f4bf7f6a85b01ffd7f9ea3991597f1bd40ab1f6
2019-08-29 15:38:26 +02:00
Aryeh Gregor
7fb4a95563 Remove unneeded overrideMwServices/resetServices
Change-Id: If6cbdec05b8f310ef3a0b4649aaa16d9fb80a047
2019-08-29 14:26:18 +03:00
Petr Pchelko
e3ac564e2d PermissionManager should not cache anonymous rights under ID 0
Bug: T228253
Change-Id: I8a54830842f220ff1ac4402a3380c2229a99b619
2019-08-28 09:47:31 -07:00
Petr Pchelko
333b6e7110 Move Title::isNamespaceProtected() to PermissionManager.
Bug: T11977
Change-Id: I589b2558fc410c9f744ec80f7310e85754506b37
2019-08-23 10:14:55 -07:00
Petr Pchelko
3cc3d00bcc Move getRestrictionLevels from NamespaceInfo to PermissionManager.
Bug: T11977
Change-Id: I051be9148c98086fdf53a66a74bf7c28699016db
2019-08-22 14:32:38 -07:00
Petr Pchelko
6dd64b7b9b Convert PermissionManager constructor to use ServiceOptions.
Change-Id: I36a3a2f338506ef14cc5d65b8bee2961a92d60da
2019-08-21 10:12:34 -07:00
Petr Pchelko
5bebae7f96 Remove usages of deprecated User::getRights.
Bug: T220191
Change-Id: Ia7472cf61765fe5fee9ae72cfa9b7060565dbe87
2019-08-20 19:43:54 -07:00
Thalia
f45359a0a9 Deprecate several public properties on the block classes
Public methods for checking and setting these properties already
exist where needed. Also update the remaining direct uses of these
properties in core.

Change-Id: Icdef025c9700e625aeb2a07975e69f1b1cc2466c
2019-07-29 21:29:54 +01:00
jenkins-bot
7f646a219e Merge "Separate right for foreign user js redirects" 2019-07-18 19:39:10 +00:00
Gergő Tisza
d8eaae539c
Separate right for foreign user js redirects
Require a new editmyuserjsredirect permission for users to edit
Javascript redirects in their userspace when the redirect target
is not in their userspace (unless they have edituserjs and can
edit any user JS anyway). This is to prevent attacks where a
popular userscript has been moved into the system namespace or
another safe location but many users still load it through the
original userspace redirect, and the attacker manages to take
over the userspace by compromising the account or getting it
renamed.

Since this is only a concern on large community wikis, by
default all users have the editmyuserjsredirect permission.

Bug: T207750
Change-Id: I36a879d5da04cb6f49ed1bc40dbe144f6862c6a1
Depends-On: I072cf857c1fff4578402904aa9cb5a0c8833f16f
2019-07-18 01:09:12 +02:00
Gergő Tisza
773f915d76 Remove pointless PermissionManager::revokeTemporaryUserRights method
Also add missing @since and make phpdoc formatting match (most) other
methods.

Change-Id: I087205ad23836f283e5ba291488a9bc1f4c3ce99
2019-07-17 22:39:27 +00:00
Gergő Tisza
659db7bddd Add mechanism for temporary user rights
Add a mechanism for adding temporary user rights that only exist
for the current request. This is occasionally needed to let normal
users act with a bot flag; traditionally the fact that User::$mRights
was public has been abused to do it, but I88992403 broke that.

Bug: T227772
Change-Id: Ife8f9d8affa750701e4e5d646ed8cd153c1d867b
2019-07-17 11:53:14 +10:00
Thalia
8cfa62d837 Bidi isolate user names in block error paramters
This fixes parameters returned by AbstractBlock::getBlockErrorParams,
but not those from ApiBlockInfoTrait.

Change-Id: I122017808766de1e9a9035f2f39a7b08607e56c1
2019-07-05 15:01:26 +01: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
Kosta Harlan
7f90d1e3a3 Revert "Factors out permissions check from User into PermissionManager service"
This reverts commit 7faa7a7420.

Reason for revert: T224607

Change-Id: I549810a4cd2e424cc4a438887d2f24614a24cc00
2019-05-30 13:51:37 +00:00
Vedmaka
7faa7a7420 Factors out permissions check from User into PermissionManager service
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: I258f02e286b6ba0387e1bff540a744fafb03dc55
Depends-On: Ie4cedf457eaaa93ec3055c37539322855e02ce26
Depends-On: Id274f240d687efa61cb9f7a15033ae2a7a532083

Bug: T218558
Bug: T223294
Change-Id: Ia0d840b772ea5f20c9594ce151cc57adc270e48b
2019-05-29 17:41:07 +02:00
Thalia
e65a5b5882 Rename Block to MediaWiki\Block\DatabaseBlock
Keep Block as a deprecated class alias for DatabaseBlock.
Update calls to the Block constructor and Block static
methods from external classes.

Also update documentation in several places that refer to
blocks as Blocks.

Bug: T222737
Change-Id: I6d96b63ca0a84bee19486471e0a16a53a79d768a
2019-05-28 12:20:48 +01:00
Thalia
824655f3b7 Separate Block into AbstractBlock, Block and SystemBlock
This commit splits the existing Block class into AbstractBlock, Block
and SystemBlock.

Before this patch, the Block class represents several types of
blocks, which can be separated into blocks stored in the database,
and temporary blocks created by the system. These are now
represented by Block and SystemBlock, which inherit from
AbstractBlock.

This lays the foundations for:
* enforcing block parameters from multiple blocks that apply to a
user/IP address
* improvements to the Block API, including the addition of services

Breaking changes: functions expecting a Block object should still
expect a Block object if it came from the database, but other
functions may now need to expect an AbstractBlock or SystemBlock
object. (Note that an alternative naming scheme, in which the
abstract class is called Block and the subclasses are DatabaseBlock
and SystemBlock, avoids this breakage. However, it introduces more
breakages to calls to static Block methods and new Block
instantiations.)

Changes to tests: system blocks don't set the $blockCreateAccount or
$mExipry block properties, so remove/change any tests that assume
they do.

Bug: T222737
Change-Id: I83bceb5e5049e254c90ace060f8f8fad44696c67
2019-05-07 17:36:31 -05:00
Thalia
2f426f06f1 Set global config for test to avoid failure
Change-Id: I4f883b0ecec5378e29625a8940a0c247967f3e71
2019-04-14 14:31:23 +01:00
Vedmaka
8e1342ed47 Introduce PermissionManager service
First iteration of adding a PermissionManager service as a replacement
for Title::userCan and User::isBlockedFrom methods.

- Created PermissionManager service
- Migrated Title::userCan to PermissionManager::userCan and deprecated the first
- Migrated Title::quickUserCan to PermissionManager::quickUserCan and deprecated the first
- Migrated User::isBlockedFrom to PermissionManager::isBlockedFrom and deprecated the first

Same for User::isBlockedFrom and PermissionManager::isBlockedFrom - the
$user parameter is now required so the declaration is changed from
isBlockedFrom( $title, ... ) to isBlockedFrom( $user, $title, .. ) which
means before User::isBlockedFrom removal all calls to it need to be updated.

Added PermissionManagerTest, it copies TitlePermissionTest but uses
PermissionManager instance instead of Title methods, this way keeping both tests
in place, we can ensure that nothing was broken and both are in working state
during the deprecation phase.

Bug: T208768
Change-Id: I94479b44afb3068695f8e327b46bda38e44e691f
2019-04-05 14:54:51 +00:00