Commit graph

51 commits

Author SHA1 Message Date
daniel
e6e0ad2472 Replace "@stable for implementation" with "@stable to implement"
For compliance with the new version of the table interface policy
(T255803).

This patch was created by an automated search & replace operation
on the includes/ directory.

Bug: T257789
Change-Id: I17e5e92e24c708ffc846945a136347670a3a20c7
2020-07-13 11:05:49 +02:00
DannyS712
94169ee873 Whitespace cleanup: Use tabs for indentation, avoid double spaces
Change-Id: I346073b59d283029bd6666356c62c81e687ea5e6
2020-06-27 07:53:07 +00:00
Petr Pchelko
40b88d635b Create UserGroupManager
Introduce a UserGroupManagerFactory and UserGroupManager.
The factory utilizes the same pattern as RevisionStore
for access to user groups of a foreign wiki.

Some user group related methods were ported from User
and UserGroupMembership and deprecated, more methods to
be moved over in future patches, not to make this one to large.

Eventually as all the group-related methods are moved and their
usages are replaced, the need for the UserRightsProxy will disappear,
thus it also will be deprecated and removed. Currently for backwards
compatibility, I've had to create artificial UserIdentityValue
objects in some of the deprecated methods to avoid making transitional
temporary methods in the UserGroupManager that would take user ID
instead of the UserIdentity. All of this will go away once migration
to UserGroupManager is completed.

Bug: T234921
Change-Id: If29c6a03dfdbb80b2e846243f7e384b334da9f07
2020-06-03 16:46:51 -07: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
8cbf108de7 Merge "immobile-source-namespace: use blanknamespace for main namespace" 2020-05-28 21:32:09 +00:00
Tim Starling
550f5930f2 Hook interface type fixes, to fix Phan errors
Phan flagged a lot of incorrect type hints when run against the call
site migration patch.

Bug: T240307
Change-Id: I698de5536446c241b200430198b21b72763b0c69
2020-05-05 11:22:04 +10:00
Tim Starling
0b7295a5cd Hook interface doc comment followup
Mostly just narrower array types. A handful of other errors fixed.

Change-Id: Ied79d9e389867911bf83696dbb47f43305f8be7b
2020-04-21 09:12:23 +10:00
apaskulin
c44488f725 docs: Hook interface doc comment review
Edited doc comments for hook interfaces to improve
consistency and add type hints.

Bug: T246855
Change-Id: I38fa802463cd6f39bf5946dbbeb1b3ebaea604b2
2020-04-21 09:10:08 +10:00
Tim Starling
f5aaf75ad1 Automatically generated hook interfaces
Add hook interfaces which were generated by a script which parses
hooks.txt and identifies caller namespaces and directories.

Hook interfaces are mostly placed in a Hook/ subdirectory
relative to the caller location. When there are callers in multiple
directories, a "primary" caller was manually selected. The exceptions to
this are:

* The source root, maintenance and tests, which use includes/Hook. Test
  hooks need to be autoloadable in a non-test request so that
  implementing test interfaces in a generic handler will not fail.
* resources uses includes/resourceloader/Hook
* The following third-level subdirectories had their hooks placed in
  the parent ../Hook:
    * includes/filerepo/file
    * includes/search/searchwidgets
    * includes/specials/forms
    * includes/specials/helpers
    * includes/specials/pagers

Parameters marked as legacy references in hooks.txt are passed
by value in the interfaces.

Bug: T240307
Change-Id: I6efe2e7dd1f0c6a3d0f4d100a4c34e41f8428720
2020-04-20 13:31:05 +10:00
ArtBaltai
8d2ebb5647 Hard deprecate Action construction with WikiPage
Tests, PermissionManager, EditAction: Construct Action with Article

Bug: T239975
Change-Id: Ia3f653f3c193312e03ccef56586e8b8222c80fa6
2020-04-14 23:13:59 +00:00
DannyS712
77bcb3a1b1 immobile-source-namespace: use blanknamespace for main namespace
Also for target-namespace

Bug: T224350
Change-Id: I878b5f7ea1d2cebfc295bf08de372726a580cc28
2020-04-11 01:08:31 +00:00
Tim Starling
44d51cb04e Fix the namespace of SpecialPageFactory
Follows-up d4045035b0.

This class was added to the MediaWiki\Special namespace, contrary to the
plan in T166010 which reserves that namespace for core special pages.
Instead, use MediaWiki\SpecialPage, following the directory in which it
is located.

Also, fix two bugs which prevented the introduction of a namespaced
class alias.

Bug: T166010
Change-Id: I6e31340aaae32a89beb7e45b79d76a7fea9808d2
2020-02-21 13:46:19 +11:00
James D. Forrester
4f2d1efdda Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUse
Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
2020-01-10 09:32:25 -08: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
Brad Jorsch
4580ceda60 PermissionManager: Remove long-obsolete comment
When cascading protection was originally added in r19095, the author
considered it too hard to correctly apply overlapping protection from
multiple source pages. A comment was placed in the code describing this
fact.

When r20471 a few months later did start applying the source-page
protections, it did not remove the comment that it made obsolete.

Change-Id: Ic8e115b501bd36f3bc7b89b77d4f8fa67e707838
2019-12-05 10:53:29 -05:00
jenkins-bot
af4b49e67c Merge "Improve param docs" 2019-11-28 19:36:24 +00:00
Umherirrender
c7ad21c25f Improve param docs
Change-Id: I746a69f6ed01c3ff000da125457df62b02d13b34
2019-11-28 19:08:59 +01:00
Ammar Abdulhamid
1540aeb445 New error message for editing site pages with raw HTML
Bug: T207652
Change-Id: I9fa91dec055c87b8302a9d35e760720581115932
2019-11-23 17:04:56 +00:00
Daimona Eaytoy
cae0110e5a Fix new phan errors, part 1
First part, mostly doc-only.

Bug: T231636
Change-Id: Id59f585740fa5bfb53c257287121f51a30de38fe
2019-10-11 15:04:04 +00:00
jenkins-bot
b6aa471bea Merge "Fix confusing comment in PermissionManager::checkUserConfigPermissions" 2019-10-10 10:42:41 +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
Máté Szabó
18038e766e PermissionManager: Use explicit varargs in method parameters
With the removal of HHVM support, we can now use explicit varargs
in function arguments. This patch updates PermissionManager to
do so, and also removes PhanCommentParamWithoutRealParam check suppressions,
which are now redundant.

Bug: T231710
Change-Id: I27898e3e8c92efef699801670cb04bbf769e5596
2019-10-05 18:03:24 +02:00
DannyS712
28b8ac1c55 Fix confusing comment in PermissionManager::checkUserConfigPermissions
Bug: T233510
Change-Id: I4167896cff8fd37073cad932da3466f7566269f4
2019-09-22 04:30:07 +00:00
Daimona Eaytoy
e5444ea55a docs: Avoid some scalar juggling
Phan can treat scalar types as non-interchangeable with
`scalar_implicit_cast` set to false. This patch fixes some of those
issues (which are in total >1000), namely the ones with alphabetic order
< includes/actions.

Change-Id: Ib1c6573ab899088bc319b9da9ceaffc850da3dbe
2019-09-19 17:21:24 +00:00
Daimona Eaytoy
e70b5b3309 Unsuppress other phan issues (part 4)
Bug: T231636
Depends-On: I58e67c2b38389df874438deada4239510d21654f
Change-Id: I6e5fba7bd273219b1206559420b5bdb78734aa84
2019-08-31 17:13:39 +00:00
Daimona Eaytoy
5eac6d131c Unsuppress more phan issues (part 3)
Bug: T231636
Depends-On: I78354bf5f0c831108c8f606e50c87cf6bc00d8bd
Change-Id: I58e67c2b38389df874438deada4239510d21654f
2019-08-31 16:38:55 +00:00
Petr Pchelko
f1914810a7 Remove usages of Title::quickUserCan
Change-Id: Ifa53e0ec800e23dc4184d133a100fb9378dfee9e
2019-08-29 11:48:30 -07: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
jenkins-bot
8390e37efc Merge "Move getRestrictionLevels from NamespaceInfo to PermissionManager." 2019-08-23 11:27:45 +00:00
Petr Pchelko
5019accfe1 PermissionManager::userHas{All,Any}Right: don't specify a variadic param.
Change-Id: Ife9d01be57a4926f4a5efa99661163a391564a6e
2019-08-22 17:46:08 -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
fd130247c2 Deprecate and replace usages of User:isAllowed{All,Any}
Bug: T220191
Change-Id: I197b8fadaa93e7b320fc19c10e3e09387fe09ad2
2019-08-21 18:36:16 -07:00
jenkins-bot
36a00f6d19 Merge "Convert PermissionManager constructor to use ServiceOptions." 2019-08-21 18:14:12 +00:00
Petr Pchelko
6dd64b7b9b Convert PermissionManager constructor to use ServiceOptions.
Change-Id: I36a3a2f338506ef14cc5d65b8bee2961a92d60da
2019-08-21 10:12:34 -07:00
Thalia
7a5508573a Ensure block hooks keep user state consistent with realistic blocks
Several block-related hooks allow the user to be put into in a state
that is inconsistent with blocks that can actually be made:
* With UserIsHidden, User::mHideName can be set to true without there
  being a block
* With UserIsBlockedFrom, a user can be blocked from editing a page
  without there being a block
* With GetBlockedStatus, public block properties can be arbitrarily
  set on a user

These problems are mostly theoretical, but mean that it is impossible to
make some basic assumptions, e.g. that a user who is blocked from a page
must have a block. The hooks are not widely used, and with a few changes
we can make them more robust so such assumptions can be made.

This patch:
* Ensures UserIsBlockedFrom is only called if there is a block. This
  would be a breaking change if any extensions were using this to block
  an unblocked user; the intended use case is clearly for extensions to
  allow user talk page access to blocked users.
* Adds a new hook, GetUserBlockComplete, which passes the block for
  modification. This should be used instead GetBlockedStatus and
  UserIsHidden, which will be deprecated in the future.
* Allows the 'hideName' option to be passed into the AbstractBlock
  constructor so that suppressing system blocks can be made.

Bug: T228948
Bug: T229035
Change-Id: I6f145335abeb16775b08e8c7c751a01f113281e3
2019-08-21 17:38:52 +01:00
Petr Pchelko
1d286560d2 Replace User::isAllowed with PermissionManager.
Covers root includes, actions, api, block, changes,
changetags, diff and PermissionManager itself.

Bug: T220191
Change-Id: Ic027d32f5dd8f4c74865df0c8a9fcf91123c889c
2019-08-20 14:43:51 -07:00
Thalia
b8ba323205 Rename variables for Title objects in PermissionManager
Change-Id: I0322ec6cebb0aa958de77ca41c4fa2beb72879cd
2019-08-08 15:13:17 +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
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
Umherirrender
141f8cfee0 Update type of PermissionManager::resultToError
Also update the copy source in Title::resultToError

Change-Id: Iaa3b8d124e599fe9db7f941d0591776adc96906b
2019-06-07 17:23:50 +02: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
Derick Alangi
fb9a84de84 Permissions: Declare the $nsInfo property and document it in constructor
Was added in commit 1f7ab9c but was never documented nor declared before its
usage.

Change-Id: Iea833f9ffb6ac210251912d35cdebf9bb064d610
2019-05-05 17:21:39 +01:00
Aryeh Gregor
1f7ab9c6d0 Update PermissionManager to use NamespaceInfo
Change-Id: I60825beb74d1d0a4e2a9bae0202372cc26752d0c
2019-04-10 15:22:09 +03:00