Commit graph

37 commits

Author SHA1 Message Date
Umherirrender
cbe949410d Improve docs of various ::getQueryInfo functions
Explict types helps phan to detect errors with keys like ef82d95

Change-Id: Iee4d964ecc58273eb9c73356ed34e13f29fbd275
2022-08-13 21:18:44 +02:00
jenkins-bot
40abc7d834 Merge "Use User::isRegistered for readability instead of ::getId falsy check" 2022-05-23 04:06:10 +00:00
Timo Tijhof
8b8834739f UserGroupManager: Fix dbDomain in addUserToGroup() deferred update
This fixes a fatal error in the deferred update from addUserToGroup(),
due to it not specifying a dbDomain parameter. This bug was
introduced in 2020 with commit 40b88d635b.

== Scenario

Use meta.wikimedia.org/wiki/Special:UserRights to act on
`Example@otherwiki`.

> DBConnectionError:
> Cannot access the database: Unknown database 'metawiki'

== Problem

The domain param to getConnection() is optional for the common case of
connecting to the core database of the wiki's main load balancer.

This is the one kind of shared state we tolerate since it is
deterministically derived from site configuration, and is safely
dependency-injected from service wiring.

But, when obtaining a LoadBalancer for a foreign wiki, one must
basically always pass this to getConnection() as otherwise it will
try to connect to the local wiki database (e.g. metawiki) while
calling the LoadBalancer for otherwiki.

== Consideration

* The LoadBalancer objects should and are shared for dbs on the
  same section, thus preserving the dbDomain from the LBFactory
  method call is impractical, and probably also too magical/fragile
  in practice due to increasing the distance between these
  responsiblities and creating more easy-to-forget state.

* There is no obvious default for any given loadbalancer other than
  the local wiki's db. There are typically many wikis on the same
  LB.

* For external LBs, we actually do sometimes make use the current wiki,
  e.g. ExternalStore is structured as tables inside a DB for each
  wiki.

Bug: T193565
Change-Id: Ic82c264f7d3bbb1403600d21cfed3516f854332a
2022-05-19 16:38:46 +00:00
Tim Starling
83dbe59d57 Suppress "named" group when TempUser system is disabled
Bug: T307675
Change-Id: If3b2b7470caa35c28583cb09ef34373d7c955806
2022-05-05 22:32:57 +10:00
Umherirrender
49ad716948 Use User::isRegistered for readability instead of ::getId falsy check
Change-Id: I42aab149559e3e899cde6c77af76c66936ed0ef0
2022-04-29 21:15:57 +02:00
Aryeh Gregor
7b791474a5 Use MainConfigNames instead of string literals, #4
Now largely automated:

VARS=$(grep -o "'[A-Za-z0-9_]*'" includes/MainConfigNames.php | \
  tr "\n" '|' | sed "s/|$/\n/;s/'//g")
sed -i -E "s/'($VARS)'/MainConfigNames::\1/g" \
  $(grep -ERIl "'($VARS)'" includes/)

Then git add -p with lots of error-prone manual checking. Then
semi-manually add all the necessary "use" lines:

vim $(grep -L 'use MediaWiki\\MainConfigNames;' \
  $(git diff --cached --name-only --diff-filter=M HEAD^))

I didn't bother fixing lines that were over 100 characters unless they
were over 120 and triggered phpcs.

Bug: T305805
Change-Id: I74e0ab511abecb276717ad4276a124760a268147
2022-04-26 19:03:37 +03:00
Tim Starling
d6a3b6cfa8 TempUser EditPage and permissions
* Allow EditPage to create a user on page save. This has to be enabled
  in config and then activated by the UI/API caller.
* Add an autocreate source for temporary users.
* Allow editing by anonymous users via automatic account creation when
  $wgGroupPermisions['*']['edit'] = false. On an edit GET request, use
  an unsaved placeholder user to stand in for post-create permissions.
* On preview or aborted save, the username to be created is stashed in a
  session and restored on subsequent requests.
* On a (likely) successful page save, create the account.
* Put regular non-temporary users in a "named" group so that they can be
  given additional permissions.
* Use a different "~~~" signature for temporary users
* Show account creation warnings on edit and preview.

Change-Id: I67b23abf73cc371280bfb2b6c43b3ce0e077bfe5
2022-04-26 14:10:53 +10:00
Umherirrender
1f71eccf63 phan: Disable null_casts_as_any_type setting
Make phan stricter about null types by setting null_casts_as_any_type to
false (the default in mediawiki-phan-config)
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together

Bug: T242536
Bug: T301991
Change-Id: I0f295382b96fb3be8037a01c10487d9d591e7e01
2022-03-21 18:25:07 +00:00
daniel
b0cbb9b8ba Remove &$references from $wgAutopromote in DefaultSettings
If we want to convert DefaultSettings to a schema, we can't use variable
references.

Change-Id: Ia53cf45f7f029e1ba4191324005fef25055d5296
2022-03-11 21:38:27 +00:00
Taavi Väänänen
074bdbec2c
Fix UserGroupManager::listAllGroups() returning duplicates
Fixes a bug where if a group both inherited its rights from some other
group and had rights of its own (which seems like something we should
support), that group would be listed twice on Special:ListGroupRights.

Change-Id: Ie3d93287aa256a7ed50e48a78b5996a193e9b60f
2022-02-24 16:35:49 +02:00
Kunal Mehta
6f01b0d007 Support having groups inherit permissions from another group
There are common use cases to having a group inherit permissions from
another group. For example, if you have to have a "confirmed" group that
can be manually handed out to grant "autoconfirmed" status, or if you
wanted to make the "sysop" group also have "interface-admin" powers.

Previously to make this work you needed to either copy all the
$wgGroupPermission entries for the second group, or use a
$wgExtensionFunctions to copy it over at runtime. Neither are great
solutions, hence this patch.

This introduces a new configuration option, $wgGroupInheritsPermissions,
that GroupPermissionsLookup will use when determining what permissions
each group has. This option is not recursive for simplicity.

To make this work, Special:ListGroupRights now consults
GroupPermissionsLookup instead of looking at the
$wgGroupPermissions/$wgRevokePermissions globals. It also uses
UserGroupManager to get the list of all groups instead of looking at
more globals.

Anything still directly reading permissions from those globals is liable
to be broken, if they weren't already.

Bug: T275334
Change-Id: Iad72e126d2708012e1e403bee066b3017c16226d
2021-12-04 12:45:23 -08:00
TChin
1f673d8e8f Create new UserGroupManager::addUserToMultipleGroups method
Bug: T287247
Change-Id: I40f560a2143a2c0fda8cb7233d9954dc645749a3
2021-08-30 10:24:46 -04:00
Thiemo Kreuz
46f26dff03 Same code style and formatting for exists-style SQL queries
Queries that query a value "1" are expected to return either
that "1" (possibly as a string), or false. It's safe to simply
cast this to bool and use it as it is.

Queries for COUNT(*) are expected to return that number,
possibly as a string. It's not possible for such a query to
return false. And even if, casting to 0 is fine.

I found an existing code style where the table name and the
"1" are on the same line as the selectField() method name, and
applied it to all similar queries.

Change-Id: I9453196281871c03ef03f653f43762eb9284342f
2021-08-12 11:37:58 +02: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
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
daniel
b3b70624c9 Authority: expose user block info
Expose info about user blocks from Authority. This allows calling code
to provide more detailed information to the user about why they are
denied some action on the wiki.

Bug: T271494
Change-Id: Ia84e469888866d72752aad355292666c31e12bad
2021-06-30 13:42:21 +02:00
Petr Pchelko
0f37101217 UserGroupManager: Use a consistent cache key within method calls
In tests, we sometimes pass non-complete user identities into
UserGroupManager, for example with a mock authority we can
pass in UserIdentityValue of a registered user that doesn't exist.

Lazy-loading of such user in the middle of UserGroupManager execution
makes UGM trip on accessing arrays by non-existent keys. This
situation shouldn't really be happening in reality, since loading
of a user shouldn't be changing it's ID or name, but if it ever
does happen, hard-crashing on undefined array index seems worse
then placing a non-reachable-anymore cache entry.

Bug: T284804
Change-Id: Ibbc1c78c50a4ff1e2dcc9ff01e5984154dd210d5
2021-06-14 15:25:40 +00:00
Ppchelko
1d3d790edb Move User::changeable(By)Groups methods to UserGroupManager
Bug: T254838
Change-Id: I5868ed76c7af2adb027bad0aab4bbc8adb6daeb2
2021-05-25 21:09:38 -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
Ppchelko
b4c67ac0eb Revert "Move User::changeable(By)Groups methods to UserGroupManager"
This reverts commit b68e7e10af.

Reason for revert: T273296

Bug: T273296
Bug: T254838
Change-Id: I5124ca5b20bfd247d0d96b53bf31818c1b91d021
2021-01-30 09:54:02 -06:00
Paladox
8a08da486e Simplify code within APCOND_BLOCKED
Caches the getBlock.

Change-Id: I6121b4310fc37c2cdeee25d3283c6f5dcab69e58
2021-01-28 23:51:04 +00:00
jenkins-bot
8d6e4d4044 Merge "Fix fetching ipblock-exempt within BlockManager::getUserBlock" 2021-01-27 22:12:30 +00:00
Paladox
ffe96ff3fb Fix fetching ipblock-exempt within BlockManager::getUserBlock
Bug: T271551
Bug: T270145
Change-Id: I458b7b6b3f79c5961c01c35677b7b25021e316a0
2021-01-25 13:29:39 +00:00
Petr Pchelko
b68e7e10af Move User::changeable(By)Groups methods to UserGroupManager
Bug: T254838
Change-Id: Idb6050a38fb48e206129c12f20a0d017cbd2b5ba
2021-01-21 08:25:26 -06:00
Ppchelko
bdb5f394d3 Revert "Enhance GroupPermissionsLookup and use it."
This reverts commit 900c6663b0.

Reason for revert: breaks Parsoid CI. Instead of fixing the test in presence of the FlaggedRevs hook, I would rather convert DefaultPreferencesFactory to Authority and fix the tests once instead of doing it twice.

Change-Id: Iaa440a9804c9ed97339e737162ef64ccf29ceb51
2021-01-12 04:48:49 +00:00
Petr Pchelko
900c6663b0 Enhance GroupPermissionsLookup and use it.
Added new methods:
- ::getGroupsWithAnyPermissions
- ::getGroupsWithAllPermissions
- ::groupHasAnyPermission
- ::groupHasAllPermission

Replaced relevant calls to PermissionManager with
calls to GroupPermissionsLookup.

Bug: T254537
Change-Id: I0b9c3352c5bebc94e1649239fe0527144e7c2eb2
2021-01-11 11:05:54 -06:00
Petr Pchelko
ae0b6c6a1e Introduce GroupPermissionsLookup
In order to break up cyclic dependency between UserGroupManager
and PermissionManager, introduce a lightweight service for checking
group permissions.

Bug: T254537
Depends-On: I99ab3a69c41b3ec6721f9504ad6c77d3122df591
Change-Id: I1acd55c07d07b4a0d43fd838e11374b6d9be98d9
2021-01-06 17:12:28 -06:00
Thiemo Kreuz
b0130ca649 Update a lot of unspecific "array" types in PHPDocs
This includes fixing some mistakes, as well as removing
redundant text that doesn't add new information, either because
it literally repeats what the code already says, or is actually
duplicated.

Change-Id: I3a8dd8ce57192deda8916cc444c87d7ab1a36515
2020-10-28 11:01:33 +01:00
Aryeh Gregor
a24e8a06b5 Mark CONSTRUCTOR_OPTIONS as internal
These were never meant to be part of the public interface and should not
ever have been marked with @since. They're only useful for constructing
the respective objects, which no outside users should be doing.

Change-Id: I86e01272d46fc72af32172d8a12b9180971d4613
2020-08-21 00:18:45 -04:00
jenkins-bot
2f9ccec7d3 Merge "Followups for UserGroupManager" 2020-06-15 14:50:34 +00:00
Petr Pchelko
c8d3f524ee Followups for UserGroupManager
1. User::addGroup has to be allowed to update the old group
2. Replace use of string constants to identify cache class,
that's prone to typos and errors. Instead, use private constants
3. Update cached user group memberships in place upon modification.
Before UserGroupManager, we've used to do that - this saves some
DB queries, and is better for correctness - for example UserrightsPage
is adding new memberships and then immediately reads from replica,
expecting it's changes to be there already.
We do not know however how many other cases there are which rely
on this pattern, so implement in-place cache update.

Bug: T255330
Change-Id: Ia5ae0e22d4156fd5e4b9aa7eeb801902e79803d1
2020-06-15 07:10:13 -07:00
Petr Pchelko
d00dfbd756 Move User::addAutopromoteOnceGroups to UserGroupManager
Additionally, User::checkAndSetTouched was made public and
marked as @internal. Eventually, as User class refactoring
continues, I would expect this to be replaced by some service.

Bug: T252621
Change-Id: I53533f494950d08ee5ed1ec54d24958c21e7b3aa
2020-06-12 12:06:10 -07:00
Petr Pchelko
cd6b72ecd7 Move autopromote groups logic into UserGroupManager
Bug: T252621
Change-Id: Ic51119cd01771ab1b68294fa5dfacb8034e33b6b
2020-06-11 22:13:48 +00:00
Clara Andrew-Wani
144157dbdb UserGroupManager: Consider $queryFlags when caching
Bug: T254282
Change-Id: I41a31ba6d597c11c7d7c8e753aa0e4c29303d5d9
2020-06-10 15:01:04 -04:00
Petr Pchelko
229acec87d UserGroupManager: add tests for coverage gaps
Bug: T234921
Change-Id: I724c153f690483a9618ccb62f142d0561713f030
2020-06-05 07:42:57 -07: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