50 bool $evaluatePrivateConditionsForRestrictedGroups =
true
71 array $groupMemberships,
78 [ $unaddableNoPrivate, $irremovableNoPrivate ] = $this->getDisallowedGroupChanges(
79 $addGroups, $removeGroups, $newExpiries, $groupMemberships, $permittedChangesNoPrivate );
80 [ $unaddableWithPrivate, $irremovableWithPrivate ] = $this->getDisallowedGroupChanges(
81 $addGroups, $removeGroups, $newExpiries, $groupMemberships, $permittedChangesWithPrivate );
83 $unchangeableGroupsNoPrivate = array_merge( $unaddableNoPrivate, $irremovableNoPrivate );
84 $unchangeableGroupsWithPrivate = array_merge( $unaddableWithPrivate, $irremovableWithPrivate );
86 $unchangeableGroupsDueToPrivate = array_diff( $unchangeableGroupsWithPrivate, $unchangeableGroupsNoPrivate );
88 $restrictedGroups = $permittedChangesWithPrivate[
'restricted'];
92 foreach ( $unchangeableGroupsWithPrivate as $group ) {
94 if ( !in_array( $group, $knownGroups ) ) {
98 if ( in_array( $group, $unchangeableGroupsDueToPrivate ) ) {
99 $result[$group] =
'private-condition';
100 } elseif ( isset( $restrictedGroups[$group] ) ) {
101 $result[$group] =
'restricted';
103 $result[$group] =
'rights';
134 $potentiallyChangeable = $this->getChangeableGroups( $performer, $target, false );
135 $conditions = $this->getPrivateConditionsInvolvedInChange(
140 $potentiallyChangeable
143 if ( !$conditions ) {
147 $this->hookRunner->onReadPrivateUserRequirementsCondition( $performer->
getUser(), $target, $conditions );
161 private function getPrivateConditionsInvolvedInChange(
162 UserIdentity $target,
166 array $potentiallyChangeableGroups,
168 $restrictedGroups = $potentiallyChangeableGroups[
'restricted'];
169 $groupsWithPrivateConditionsInvolved = [];
170 foreach ( $restrictedGroups as $group => $groupData ) {
171 if ( $groupData[
'condition-met'] ===
null && !$groupData[
'ignore-condition'] ) {
172 $groupsWithPrivateConditionsInvolved[] = $group;
177 foreach ( $addGroups as $group ) {
180 if ( !in_array( $group, $groupsWithPrivateConditionsInvolved ) ) {
186 if ( !isset( $existingUGMs[$group] ) ) {
187 $groupsToCheck[] = $group;
190 $currentExpiry = $existingUGMs[$group]->getExpiry() ??
'infinity';
191 $newExpiry = $newExpiries[$group] ??
'infinity';
193 if ( $newExpiry > $currentExpiry ) {
194 $groupsToCheck[] = $group;
198 $privateConditions = [];
199 $restrictedGroupChecker = $this->getRestrictedGroupChecker( $target );
200 foreach ( $groupsToCheck as $group ) {
201 $privateConditions = array_merge(
203 $restrictedGroupChecker->getPrivateConditionsForGroup( $group )
206 return array_values( array_unique( $privateConditions ) );
227 array &$removeGroups,
230 array $permittedChanges
232 [ $unaddableGroups, $irremovableGroups ] = self::getDisallowedGroupChanges(
233 $addGroups, $removeGroups, $newExpiries, $existingUGMs, $permittedChanges
236 $addGroups = array_diff( $addGroups, $unaddableGroups );
237 $removeGroups = array_diff( $removeGroups, $irremovableGroups );
238 foreach ( $unaddableGroups as $group ) {
239 unset( $newExpiries[$group] );
252 private static function getDisallowedGroupChanges(
257 array $permittedChanges
259 $canAdd = $permittedChanges[
'add'];
260 $canRemove = $permittedChanges[
'remove'];
261 $involvedGroups = array_unique( array_merge( array_keys( $existingUGMs ), $addGroups, $removeGroups ) );
264 $unaddableGroups = [];
265 $irremovableGroups = [];
267 foreach ( $involvedGroups as $group ) {
268 $hasGroup = isset( $existingUGMs[$group] );
269 $wantsAddGroup = in_array( $group, $addGroups );
270 $wantsRemoveGroup = in_array( $group, $removeGroups );
274 ( !$hasGroup && $wantsRemoveGroup ) ||
275 ( $wantsAddGroup && $wantsRemoveGroup )
277 $unaddableGroups[] = $group;
278 $irremovableGroups[] = $group;
282 if ( !$hasGroup && !$wantsAddGroup ) {
285 if ( $hasGroup && !$wantsRemoveGroup && !$wantsAddGroup ) {
290 if ( $hasGroup && $wantsRemoveGroup ) {
291 if ( !in_array( $group, $canRemove ) ) {
292 $irremovableGroups[] = $group;
294 } elseif ( !$hasGroup && $wantsAddGroup ) {
295 if ( !in_array( $group, $canAdd ) ) {
296 $unaddableGroups[] = $group;
298 } elseif ( $hasGroup && $wantsAddGroup ) {
299 $currentExpiry = $existingUGMs[$group]->getExpiry() ??
'infinity';
300 $wantedExpiry = $newExpiries[$group] ??
'infinity';
302 if ( $wantedExpiry > $currentExpiry ) {
304 $canChange = in_array( $group, $canAdd );
307 $canChange = in_array( $group, $canRemove );
312 $unaddableGroups[] = $group;
317 return [ $unaddableGroups, $irremovableGroups ];
334 $unix = strtotime( $expiry, ConvertibleTimestamp::time() );
336 if ( !$unix || $unix === -1 ) {