1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
|
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
namespace MediaWiki\User;
use InvalidArgumentException;
use LogicException;
use MediaWiki\Config\ServiceOptions;
use MediaWiki\Deferred\DeferredUpdates;
use MediaWiki\HookContainer\HookContainer;
use MediaWiki\HookContainer\HookRunner;
use MediaWiki\JobQueue\JobQueueGroup;
use MediaWiki\Logging\ManualLogEntry;
use MediaWiki\MainConfigNames;
use MediaWiki\Parser\Sanitizer;
use MediaWiki\Permissions\Authority;
use MediaWiki\Permissions\GroupPermissionsLookup;
use MediaWiki\User\TempUser\TempUserConfig;
use MediaWiki\WikiMap\WikiMap;
use Psr\Log\LoggerInterface;
use UserGroupExpiryJob;
use Wikimedia\Assert\Assert;
use Wikimedia\IPUtils;
use Wikimedia\Rdbms\IConnectionProvider;
use Wikimedia\Rdbms\IDBAccessObject;
use Wikimedia\Rdbms\ILBFactory;
use Wikimedia\Rdbms\IReadableDatabase;
use Wikimedia\Rdbms\ReadOnlyMode;
use Wikimedia\Rdbms\SelectQueryBuilder;
/**
* Manage user group memberships.
*
* @since 1.35
* @ingroup User
*/
class UserGroupManager {
/**
* @internal For use by ServiceWiring
*/
public const CONSTRUCTOR_OPTIONS = [
MainConfigNames::AddGroups,
MainConfigNames::AutoConfirmAge,
MainConfigNames::AutoConfirmCount,
MainConfigNames::Autopromote,
MainConfigNames::AutopromoteOnce,
MainConfigNames::AutopromoteOnceLogInRC,
MainConfigNames::AutopromoteOnceRCExcludedGroups,
MainConfigNames::EmailAuthentication,
MainConfigNames::ImplicitGroups,
MainConfigNames::GroupInheritsPermissions,
MainConfigNames::GroupPermissions,
MainConfigNames::GroupsAddToSelf,
MainConfigNames::GroupsRemoveFromSelf,
MainConfigNames::RevokePermissions,
MainConfigNames::RemoveGroups,
MainConfigNames::PrivilegedGroups,
];
/**
* Logical operators recognized in $wgAutopromote.
*
* @since 1.42
*/
public const VALID_OPS = [ '&', '|', '^', '!' ];
private ServiceOptions $options;
private IConnectionProvider $dbProvider;
private HookContainer $hookContainer;
private HookRunner $hookRunner;
private ReadOnlyMode $readOnlyMode;
private UserEditTracker $userEditTracker;
private GroupPermissionsLookup $groupPermissionsLookup;
private JobQueueGroup $jobQueueGroup;
private LoggerInterface $logger;
private TempUserConfig $tempUserConfig;
/** @var callable[] */
private $clearCacheCallbacks;
/** @var string|false */
private $wikiId;
/** string key for implicit groups cache */
private const CACHE_IMPLICIT = 'implicit';
/** string key for effective groups cache */
private const CACHE_EFFECTIVE = 'effective';
/** string key for group memberships cache */
private const CACHE_MEMBERSHIP = 'membership';
/** string key for former groups cache */
private const CACHE_FORMER = 'former';
/** string key for former groups cache */
private const CACHE_PRIVILEGED = 'privileged';
/**
* @var array Service caches, an assoc. array keyed after the user-keys generated
* by the getCacheKey method and storing values in the following format:
*
* userKey => [
* self::CACHE_IMPLICIT => implicit groups cache
* self::CACHE_EFFECTIVE => effective groups cache
* self::CACHE_MEMBERSHIP => [ ] // Array of UserGroupMembership objects
* self::CACHE_FORMER => former groups cache
* self::CACHE_PRIVILEGED => privileged groups cache
* ]
*/
private $userGroupCache = [];
/**
* @var array An assoc. array that stores query flags used to retrieve user groups
* from the database and is stored in the following format:
*
* userKey => [
* self::CACHE_IMPLICIT => implicit groups query flag
* self::CACHE_EFFECTIVE => effective groups query flag
* self::CACHE_MEMBERSHIP => membership groups query flag
* self::CACHE_FORMER => former groups query flag
* self::CACHE_PRIVILEGED => privileged groups query flag
* ]
*/
private $queryFlagsUsedForCaching = [];
/**
* @internal For use preventing an infinite loop when checking APCOND_BLOCKED
* @var array An assoc. array mapping the getCacheKey userKey to a bool indicating
* an ongoing condition check.
*/
private $recursionMap = [];
/**
* @param ServiceOptions $options
* @param ReadOnlyMode $readOnlyMode
* @param ILBFactory $lbFactory
* @param HookContainer $hookContainer
* @param UserEditTracker $userEditTracker
* @param GroupPermissionsLookup $groupPermissionsLookup
* @param JobQueueGroup $jobQueueGroup
* @param LoggerInterface $logger
* @param TempUserConfig $tempUserConfig
* @param callable[] $clearCacheCallbacks
* @param string|false $wikiId
*/
public function __construct(
ServiceOptions $options,
ReadOnlyMode $readOnlyMode,
ILBFactory $lbFactory,
HookContainer $hookContainer,
UserEditTracker $userEditTracker,
GroupPermissionsLookup $groupPermissionsLookup,
JobQueueGroup $jobQueueGroup,
LoggerInterface $logger,
TempUserConfig $tempUserConfig,
array $clearCacheCallbacks = [],
$wikiId = UserIdentity::LOCAL
) {
$options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
$this->options = $options;
$this->dbProvider = $lbFactory;
$this->hookContainer = $hookContainer;
$this->hookRunner = new HookRunner( $hookContainer );
$this->userEditTracker = $userEditTracker;
$this->groupPermissionsLookup = $groupPermissionsLookup;
$this->jobQueueGroup = $jobQueueGroup;
$this->logger = $logger;
$this->tempUserConfig = $tempUserConfig;
$this->readOnlyMode = $readOnlyMode;
$this->clearCacheCallbacks = $clearCacheCallbacks;
$this->wikiId = $wikiId;
}
/**
* Return the set of defined explicit groups.
* The implicit groups (by default *, 'user' and 'autoconfirmed')
* are not included, as they are defined automatically, not in the database.
* @return string[] internal group names
*/
public function listAllGroups(): array {
return array_values( array_unique(
array_diff(
array_merge(
array_keys( $this->options->get( MainConfigNames::GroupPermissions ) ),
array_keys( $this->options->get( MainConfigNames::RevokePermissions ) ),
array_keys( $this->options->get( MainConfigNames::GroupInheritsPermissions ) )
),
$this->listAllImplicitGroups()
)
) );
}
/**
* Get a list of all configured implicit groups
* @return string[]
*/
public function listAllImplicitGroups(): array {
return $this->options->get( MainConfigNames::ImplicitGroups );
}
/**
* Creates a new UserGroupMembership instance from $row.
* The fields required to build an instance could be
* found using getQueryInfo() method.
*
* @param \stdClass $row A database result object
*
* @return UserGroupMembership
*/
public function newGroupMembershipFromRow( \stdClass $row ): UserGroupMembership {
return new UserGroupMembership(
(int)$row->ug_user,
$row->ug_group,
$row->ug_expiry === null ? null : wfTimestamp(
TS_MW,
$row->ug_expiry
)
);
}
/**
* Load the user groups cache from the provided user groups data
* @internal for use by the User object only
* @param UserIdentity $user
* @param array $userGroups an array of database query results
* @param int $queryFlags
*/
public function loadGroupMembershipsFromArray(
UserIdentity $user,
array $userGroups,
int $queryFlags = IDBAccessObject::READ_NORMAL
) {
$user->assertWiki( $this->wikiId );
$membershipGroups = [];
reset( $userGroups );
foreach ( $userGroups as $row ) {
$ugm = $this->newGroupMembershipFromRow( $row );
$membershipGroups[ $ugm->getGroup() ] = $ugm;
}
$this->setCache(
$this->getCacheKey( $user ),
self::CACHE_MEMBERSHIP,
$membershipGroups,
$queryFlags
);
}
/**
* Get the list of implicit group memberships this user has.
*
* This includes 'user' if logged in, '*' for all accounts,
* and autopromoted groups
*
* @param UserIdentity $user
* @param int $queryFlags
* @param bool $recache Whether to avoid the cache
* @return string[] internal group names
*/
public function getUserImplicitGroups(
UserIdentity $user,
int $queryFlags = IDBAccessObject::READ_NORMAL,
bool $recache = false
): array {
$user->assertWiki( $this->wikiId );
$userKey = $this->getCacheKey( $user );
if ( $recache ||
!isset( $this->userGroupCache[$userKey][self::CACHE_IMPLICIT] ) ||
!$this->canUseCachedValues( $user, self::CACHE_IMPLICIT, $queryFlags )
) {
$groups = [ '*' ];
if ( $this->tempUserConfig->isTempName( $user->getName() ) ) {
$groups[] = 'temp';
} elseif ( $user->isRegistered() ) {
$groups[] = 'user';
$groups = array_unique( array_merge(
$groups,
$this->getUserAutopromoteGroups( $user )
) );
}
$this->setCache( $userKey, self::CACHE_IMPLICIT, $groups, $queryFlags );
if ( $recache ) {
// Assure data consistency with rights/groups,
// as getUserEffectiveGroups() depends on this function
$this->clearUserCacheForKind( $user, self::CACHE_EFFECTIVE );
}
}
return $this->userGroupCache[$userKey][self::CACHE_IMPLICIT];
}
/**
* Get the list of implicit group memberships the user has.
*
* This includes all explicit groups, plus 'user' if logged in,
* '*' for all accounts, and autopromoted groups
*
* @param UserIdentity $user
* @param int $queryFlags
* @param bool $recache Whether to avoid the cache
* @return string[] internal group names
*/
public function getUserEffectiveGroups(
UserIdentity $user,
int $queryFlags = IDBAccessObject::READ_NORMAL,
bool $recache = false
): array {
$user->assertWiki( $this->wikiId );
$userKey = $this->getCacheKey( $user );
// Ignore cache if the $recache flag is set, cached values can not be used
// or the cache value is missing
if ( $recache ||
!$this->canUseCachedValues( $user, self::CACHE_EFFECTIVE, $queryFlags ) ||
!isset( $this->userGroupCache[$userKey][self::CACHE_EFFECTIVE] )
) {
$groups = array_unique( array_merge(
$this->getUserGroups( $user, $queryFlags ), // explicit groups
$this->getUserImplicitGroups( $user, $queryFlags, $recache ) // implicit groups
) );
// TODO: Deprecate passing out user object in the hook by introducing
// an alternative hook
if ( $this->hookContainer->isRegistered( 'UserEffectiveGroups' ) ) {
$userObj = User::newFromIdentity( $user );
$userObj->load();
// Hook for additional groups
$this->hookRunner->onUserEffectiveGroups( $userObj, $groups );
}
// Force reindexation of groups when a hook has unset one of them
$effectiveGroups = array_values( array_unique( $groups ) );
$this->setCache( $userKey, self::CACHE_EFFECTIVE, $effectiveGroups, $queryFlags );
}
return $this->userGroupCache[$userKey][self::CACHE_EFFECTIVE];
}
/**
* Returns the groups the user has belonged to.
*
* The user may still belong to the returned groups. Compare with
* getUserGroups().
*
* The function will not return groups the user had belonged to before MW 1.17
*
* @param UserIdentity $user
* @param int $queryFlags
* @return string[] Names of the groups the user has belonged to.
*/
public function getUserFormerGroups(
UserIdentity $user,
int $queryFlags = IDBAccessObject::READ_NORMAL
): array {
$user->assertWiki( $this->wikiId );
$userKey = $this->getCacheKey( $user );
if ( $this->canUseCachedValues( $user, self::CACHE_FORMER, $queryFlags ) &&
isset( $this->userGroupCache[$userKey][self::CACHE_FORMER] )
) {
return $this->userGroupCache[$userKey][self::CACHE_FORMER];
}
if ( !$user->isRegistered() ) {
// Anon users don't have groups stored in the database
return [];
}
$res = $this->getDBConnectionRefForQueryFlags( $queryFlags )->newSelectQueryBuilder()
->select( 'ufg_group' )
->from( 'user_former_groups' )
->where( [ 'ufg_user' => $user->getId( $this->wikiId ) ] )
->caller( __METHOD__ )
->fetchResultSet();
$formerGroups = [];
foreach ( $res as $row ) {
$formerGroups[] = $row->ufg_group;
}
$this->setCache( $userKey, self::CACHE_FORMER, $formerGroups, $queryFlags );
return $this->userGroupCache[$userKey][self::CACHE_FORMER];
}
/**
* Get the groups for the given user based on $wgAutopromote.
*
* @param UserIdentity $user The user to get the groups for
* @return string[] Array of groups to promote to.
*
* @see $wgAutopromote
*/
public function getUserAutopromoteGroups( UserIdentity $user ): array {
$user->assertWiki( $this->wikiId );
$promote = [];
// TODO: remove the need for the full user object
$userObj = User::newFromIdentity( $user );
if ( $userObj->isTemp() ) {
return [];
}
foreach ( $this->options->get( MainConfigNames::Autopromote ) as $group => $cond ) {
if ( $this->recCheckCondition( $cond, $userObj ) ) {
$promote[] = $group;
}
}
$this->hookRunner->onGetAutoPromoteGroups( $userObj, $promote );
return $promote;
}
/**
* Get the groups for the given user based on the given criteria.
*
* Does not return groups the user already belongs to or has once belonged.
*
* @param UserIdentity $user The user to get the groups for
* @param string $event Key in $wgAutopromoteOnce (each event has groups/criteria)
*
* @return string[] Groups the user should be promoted to.
*
* @see $wgAutopromoteOnce
*/
public function getUserAutopromoteOnceGroups(
UserIdentity $user,
string $event
): array {
$user->assertWiki( $this->wikiId );
$autopromoteOnce = $this->options->get( MainConfigNames::AutopromoteOnce );
$promote = [];
if ( isset( $autopromoteOnce[$event] ) && count( $autopromoteOnce[$event] ) ) {
// TODO: remove the need for the full user object
$userObj = User::newFromIdentity( $user );
if ( $userObj->isTemp() ) {
return [];
}
$currentGroups = $this->getUserGroups( $user );
$formerGroups = $this->getUserFormerGroups( $user );
foreach ( $autopromoteOnce[$event] as $group => $cond ) {
// Do not check if the user's already a member
if ( in_array( $group, $currentGroups ) ) {
continue;
}
// Do not autopromote if the user has belonged to the group
if ( in_array( $group, $formerGroups ) ) {
continue;
}
// Finally - check the conditions
if ( $this->recCheckCondition( $cond, $userObj ) ) {
$promote[] = $group;
}
}
}
return $promote;
}
/**
* Returns the list of privileged groups that $user belongs to.
* Privileged groups are ones that can be abused in a dangerous way.
*
* Depending on how extensions extend this method, it might return values
* that are not strictly user groups (ACL list names, etc.).
* It is meant for logging/auditing, not for passing to methods that expect group names.
*
* @param UserIdentity $user
* @param int $queryFlags
* @param bool $recache Whether to avoid the cache
* @return string[]
* @since 1.41 (also backported to 1.39.5 and 1.40.1)
* @see $wgPrivilegedGroups
* @see https://www.mediawiki.org/wiki/Manual:Hooks/UserGetPrivilegedGroups
*/
public function getUserPrivilegedGroups(
UserIdentity $user,
int $queryFlags = IDBAccessObject::READ_NORMAL,
bool $recache = false
): array {
$userKey = $this->getCacheKey( $user );
if ( !$recache &&
$this->canUseCachedValues( $user, self::CACHE_PRIVILEGED, $queryFlags ) &&
isset( $this->userGroupCache[$userKey][self::CACHE_PRIVILEGED] )
) {
return $this->userGroupCache[$userKey][self::CACHE_PRIVILEGED];
}
if ( !$user->isRegistered() ) {
return [];
}
$groups = array_intersect(
$this->getUserEffectiveGroups( $user, $queryFlags, $recache ),
$this->options->get( 'PrivilegedGroups' )
);
$this->hookRunner->onUserPrivilegedGroups( $user, $groups );
$this->setCache(
$this->getCacheKey( $user ),
self::CACHE_PRIVILEGED,
array_values( array_unique( $groups ) ),
$queryFlags
);
return $this->userGroupCache[$userKey][self::CACHE_PRIVILEGED];
}
/**
* Recursively check a condition. Conditions are in the form
* [ '&' or '|' or '^' or '!', cond1, cond2, ... ]
* where cond1, cond2, ... are themselves conditions; *OR*
* APCOND_EMAILCONFIRMED, *OR*
* [ APCOND_EMAILCONFIRMED ], *OR*
* [ APCOND_EDITCOUNT, number of edits ], *OR*
* [ APCOND_AGE, seconds since registration ], *OR*
* similar constructs defined by extensions.
* This function evaluates the former type recursively, and passes off to
* checkCondition for evaluation of the latter type.
*
* If you change the logic of this method, please update
* ApiQuerySiteinfo::appendAutoPromote(), as it depends on this method.
*
* @param mixed $cond A condition, possibly containing other conditions
* @param User $user The user to check the conditions against
*
* @return bool Whether the condition is true
*/
private function recCheckCondition( $cond, User $user ): bool {
if ( is_array( $cond ) && count( $cond ) >= 2 && in_array( $cond[0], self::VALID_OPS ) ) {
// Recursive condition
if ( $cond[0] == '&' ) { // AND (all conds pass)
foreach ( array_slice( $cond, 1 ) as $subcond ) {
if ( !$this->recCheckCondition( $subcond, $user ) ) {
return false;
}
}
return true;
} elseif ( $cond[0] == '|' ) { // OR (at least one cond passes)
foreach ( array_slice( $cond, 1 ) as $subcond ) {
if ( $this->recCheckCondition( $subcond, $user ) ) {
return true;
}
}
return false;
} elseif ( $cond[0] == '^' ) { // XOR (exactly one cond passes)
if ( count( $cond ) > 3 ) {
$this->logger->warning(
'recCheckCondition() given XOR ("^") condition on three or more conditions.' .
' Check your $wgAutopromote and $wgAutopromoteOnce settings.'
);
}
return $this->recCheckCondition( $cond[1], $user )
xor $this->recCheckCondition( $cond[2], $user );
} elseif ( $cond[0] == '!' ) { // NOT (no conds pass)
foreach ( array_slice( $cond, 1 ) as $subcond ) {
if ( $this->recCheckCondition( $subcond, $user ) ) {
return false;
}
}
return true;
}
}
// If we got here, the array presumably does not contain other conditions;
// it's not recursive. Pass it off to checkCondition.
if ( !is_array( $cond ) ) {
$cond = [ $cond ];
}
return $this->checkCondition( $cond, $user );
}
/**
* As recCheckCondition, but *not* recursive. The only valid conditions
* are those whose first element is one of APCOND_* defined in Defines.php.
* Other types will throw an exception if no extension evaluates them.
*
* @param array $cond A condition, which must not contain other conditions
* @param User $user The user to check the condition against
* @return bool Whether the condition is true for the user
* @throws InvalidArgumentException if autopromote condition was not recognized.
* @throws LogicException if APCOND_BLOCKED is checked again before returning a result.
*/
private function checkCondition( array $cond, User $user ): bool {
if ( count( $cond ) < 1 ) {
return false;
}
switch ( $cond[0] ) {
case APCOND_EMAILCONFIRMED:
if ( Sanitizer::validateEmail( $user->getEmail() ) ) {
if ( $this->options->get( MainConfigNames::EmailAuthentication ) ) {
return (bool)$user->getEmailAuthenticationTimestamp();
} else {
return true;
}
}
return false;
case APCOND_EDITCOUNT:
$reqEditCount = $cond[1] ?? $this->options->get( MainConfigNames::AutoConfirmCount );
// T157718: Avoid edit count lookup if specified edit count is 0 or invalid
if ( $reqEditCount <= 0 ) {
return true;
}
return (int)$this->userEditTracker->getUserEditCount( $user ) >= $reqEditCount;
case APCOND_AGE:
$reqAge = $cond[1] ?? $this->options->get( MainConfigNames::AutoConfirmAge );
$age = time() - (int)wfTimestampOrNull( TS_UNIX, $user->getRegistration() );
return $age >= $reqAge;
case APCOND_AGE_FROM_EDIT:
$age = time() - (int)wfTimestampOrNull(
TS_UNIX, $this->userEditTracker->getFirstEditTimestamp( $user ) );
return $age >= $cond[1];
case APCOND_INGROUPS:
$groups = array_slice( $cond, 1 );
return count( array_intersect( $groups, $this->getUserGroups( $user ) ) ) == count( $groups );
case APCOND_ISIP:
return $cond[1] == $user->getRequest()->getIP();
case APCOND_IPINRANGE:
return IPUtils::isInRange( $user->getRequest()->getIP(), $cond[1] );
case APCOND_BLOCKED:
// Because checking for ipblock-exempt leads back to here (thus infinite recursion),
// we if we've been here before for this user without having returned a value.
// See T270145 and T349608
$userKey = $this->getCacheKey( $user );
if ( $this->recursionMap[$userKey] ?? false ) {
throw new LogicException(
"Unexpected recursion! APCOND_BLOCKED is being checked during" .
" an existing APCOND_BLOCKED check for \"{$user->getName()}\"!"
);
}
$this->recursionMap[$userKey] = true;
// Setting the second parameter here to true prevents us from getting back here
// during standard MediaWiki core behavior
$block = $user->getBlock( IDBAccessObject::READ_LATEST, true );
$this->recursionMap[$userKey] = false;
return $block && $block->isSitewide();
case APCOND_ISBOT:
return in_array( 'bot', $this->groupPermissionsLookup
->getGroupPermissions( $this->getUserGroups( $user ) ) );
default:
$result = null;
$this->hookRunner->onAutopromoteCondition( $cond[0],
// @phan-suppress-next-line PhanTypeMismatchArgument Type mismatch on pass-by-ref args
array_slice( $cond, 1 ), $user, $result );
if ( $result === null ) {
throw new InvalidArgumentException(
"Unrecognized condition {$cond[0]} for autopromotion!"
);
}
return (bool)$result;
}
}
/**
* Add the user to the group if they meet given criteria.
*
* Contrary to autopromotion by $wgAutopromote, the group will be
* possible to remove manually via Special:UserRights. In such case it
* will not be re-added automatically. The user will also not lose the
* group if they no longer meet the criteria.
*
* @param UserIdentity $user User to add to the groups
* @param string $event Key in $wgAutopromoteOnce (each event has groups/criteria)
*
* @return string[] Array of groups the user has been promoted to.
*
* @see $wgAutopromoteOnce
*/
public function addUserToAutopromoteOnceGroups(
UserIdentity $user,
string $event
): array {
$user->assertWiki( $this->wikiId );
Assert::precondition(
!$this->wikiId || WikiMap::isCurrentWikiDbDomain( $this->wikiId ),
__METHOD__ . " is not supported for foreign wikis: {$this->wikiId} used"
);
if (
$this->readOnlyMode->isReadOnly( $this->wikiId ) ||
!$user->isRegistered() ||
$this->tempUserConfig->isTempName( $user->getName() )
) {
return [];
}
$toPromote = $this->getUserAutopromoteOnceGroups( $user, $event );
if ( $toPromote === [] ) {
return [];
}
$userObj = User::newFromIdentity( $user );
if ( !$userObj->checkAndSetTouched() ) {
return []; // raced out (bug T48834)
}
$oldGroups = $this->getUserGroups( $user ); // previous groups
$oldUGMs = $this->getUserGroupMemberships( $user );
$this->addUserToMultipleGroups( $user, $toPromote );
$newGroups = array_merge( $oldGroups, $toPromote ); // all groups
$newUGMs = $this->getUserGroupMemberships( $user );
// update groups in external authentication database
// TODO: deprecate passing full User object to hook
$this->hookRunner->onUserGroupsChanged(
$userObj,
$toPromote,
[],
false,
false,
$oldUGMs,
$newUGMs
);
$logEntry = new ManualLogEntry( 'rights', 'autopromote' );
$logEntry->setPerformer( $user );
$logEntry->setTarget( $userObj->getUserPage() );
$logEntry->setParameters( [
'4::oldgroups' => $oldGroups,
'5::newgroups' => $newGroups,
] );
$logid = $logEntry->insert();
// Allow excluding autopromotions into select groups from RecentChanges (T377829).
$groupsToShowInRC = array_diff(
$toPromote,
$this->options->get( MainConfigNames::AutopromoteOnceRCExcludedGroups )
);
if ( $this->options->get( MainConfigNames::AutopromoteOnceLogInRC ) && count( $groupsToShowInRC ) ) {
$logEntry->publish( $logid );
}
return $toPromote;
}
/**
* Get the list of explicit group memberships this user has.
* The implicit * and user groups are not included.
*
* @param UserIdentity $user
* @param int $queryFlags
* @return string[]
*/
public function getUserGroups(
UserIdentity $user,
int $queryFlags = IDBAccessObject::READ_NORMAL
): array {
return array_keys( $this->getUserGroupMemberships( $user, $queryFlags ) );
}
/**
* Loads and returns UserGroupMembership objects for all the groups a user currently
* belongs to.
*
* @param UserIdentity $user the user to search for
* @param int $queryFlags
* @return UserGroupMembership[] Associative array of (group name => UserGroupMembership object)
*/
public function getUserGroupMemberships(
UserIdentity $user,
int $queryFlags = IDBAccessObject::READ_NORMAL
): array {
$user->assertWiki( $this->wikiId );
$userKey = $this->getCacheKey( $user );
if ( $this->canUseCachedValues( $user, self::CACHE_MEMBERSHIP, $queryFlags ) &&
isset( $this->userGroupCache[$userKey][self::CACHE_MEMBERSHIP] )
) {
/** @suppress PhanTypeMismatchReturn */
return $this->userGroupCache[$userKey][self::CACHE_MEMBERSHIP];
}
if ( !$user->isRegistered() ) {
// Anon users don't have groups stored in the database
return [];
}
$queryBuilder = $this->newQueryBuilder( $this->getDBConnectionRefForQueryFlags( $queryFlags ) );
$res = $queryBuilder
->where( [ 'ug_user' => $user->getId( $this->wikiId ) ] )
->caller( __METHOD__ )
->fetchResultSet();
$ugms = [];
foreach ( $res as $row ) {
$ugm = $this->newGroupMembershipFromRow( $row );
if ( !$ugm->isExpired() ) {
$ugms[$ugm->getGroup()] = $ugm;
}
}
ksort( $ugms );
$this->setCache( $userKey, self::CACHE_MEMBERSHIP, $ugms, $queryFlags );
return $ugms;
}
/**
* Add the user to the given group. This takes immediate effect.
* If the user is already in the group, the expiry time will be updated to the new
* expiry time. (If $expiry is omitted or null, the membership will be altered to
* never expire.)
*
* @param UserIdentity $user
* @param string $group Name of the group to add
* @param string|null $expiry Optional expiry timestamp in any format acceptable to
* wfTimestamp(), or null if the group assignment should not expire
* @param bool $allowUpdate Whether to perform "upsert" instead of INSERT
*
* @throws InvalidArgumentException
* @return bool
*/
public function addUserToGroup(
UserIdentity $user,
string $group,
?string $expiry = null,
bool $allowUpdate = false
): bool {
$user->assertWiki( $this->wikiId );
if ( $this->readOnlyMode->isReadOnly( $this->wikiId ) ) {
return false;
}
$isTemp = $this->tempUserConfig->isTempName( $user->getName() );
if ( !$user->isRegistered() ) {
throw new InvalidArgumentException(
'UserGroupManager::addUserToGroup() needs a positive user ID. ' .
'Perhaps addUserToGroup() was called before the user was added to the database.'
);
}
if ( $isTemp ) {
throw new InvalidArgumentException(
'UserGroupManager::addUserToGroup() cannot be called on a temporary user.'
);
}
if ( $expiry ) {
$expiry = wfTimestamp( TS_MW, $expiry );
}
// TODO: Deprecate passing out user object in the hook by introducing
// an alternative hook
if ( $this->hookContainer->isRegistered( 'UserAddGroup' ) ) {
$userObj = User::newFromIdentity( $user );
$userObj->load();
if ( !$this->hookRunner->onUserAddGroup( $userObj, $group, $expiry ) ) {
return false;
}
}
$oldUgms = $this->getUserGroupMemberships( $user, IDBAccessObject::READ_LATEST );
$dbw = $this->dbProvider->getPrimaryDatabase( $this->wikiId );
$dbw->startAtomic( __METHOD__ );
$dbw->newInsertQueryBuilder()
->insertInto( 'user_groups' )
->ignore()
->row( [
'ug_user' => $user->getId( $this->wikiId ),
'ug_group' => $group,
'ug_expiry' => $expiry ? $dbw->timestamp( $expiry ) : null,
] )
->caller( __METHOD__ )->execute();
$affected = $dbw->affectedRows();
if ( !$affected ) {
// Conflicting row already exists; it should be overridden if it is either expired
// or if $allowUpdate is true and the current row is different than the loaded row.
$conds = [
'ug_user' => $user->getId( $this->wikiId ),
'ug_group' => $group
];
if ( $allowUpdate ) {
// Update the current row if its expiry does not match that of the loaded row
$conds[] = $expiry
? $dbw->expr( 'ug_expiry', '=', null )
->or( 'ug_expiry', '!=', $dbw->timestamp( $expiry ) )
: $dbw->expr( 'ug_expiry', '!=', null );
} else {
// Update the current row if it is expired
$conds[] = $dbw->expr( 'ug_expiry', '<', $dbw->timestamp() );
}
$dbw->newUpdateQueryBuilder()
->update( 'user_groups' )
->set( [ 'ug_expiry' => $expiry ? $dbw->timestamp( $expiry ) : null ] )
->where( $conds )
->caller( __METHOD__ )->execute();
$affected = $dbw->affectedRows();
}
$dbw->endAtomic( __METHOD__ );
// Purge old, expired memberships from the DB
DeferredUpdates::addCallableUpdate( function ( $fname ) {
$dbr = $this->dbProvider->getReplicaDatabase( $this->wikiId );
$hasExpiredRow = (bool)$dbr->newSelectQueryBuilder()
->select( '1' )
->from( 'user_groups' )
->where( [ $dbr->expr( 'ug_expiry', '<', $dbr->timestamp() ) ] )
->caller( $fname )
->fetchField();
if ( $hasExpiredRow ) {
$this->jobQueueGroup->push( new UserGroupExpiryJob( [] ) );
}
} );
if ( $affected > 0 ) {
$oldUgms[$group] = new UserGroupMembership( $user->getId( $this->wikiId ), $group, $expiry );
if ( !$oldUgms[$group]->isExpired() ) {
$this->setCache(
$this->getCacheKey( $user ),
self::CACHE_MEMBERSHIP,
$oldUgms,
IDBAccessObject::READ_LATEST
);
$this->clearUserCacheForKind( $user, self::CACHE_EFFECTIVE );
}
foreach ( $this->clearCacheCallbacks as $callback ) {
$callback( $user );
}
return true;
}
return false;
}
/**
* Add the user to the given list of groups.
*
* @since 1.37
*
* @param UserIdentity $user
* @param string[] $groups Names of the groups to add
* @param string|null $expiry Optional expiry timestamp in any format acceptable to
* wfTimestamp(), or null if the group assignment should not expire
* @param bool $allowUpdate Whether to perform "upsert" instead of INSERT
*
* @throws InvalidArgumentException
*/
public function addUserToMultipleGroups(
UserIdentity $user,
array $groups,
?string $expiry = null,
bool $allowUpdate = false
) {
foreach ( $groups as $group ) {
$this->addUserToGroup( $user, $group, $expiry, $allowUpdate );
}
}
/**
* Remove the user from the given group. This takes immediate effect.
*
* @param UserIdentity $user
* @param string $group Name of the group to remove
* @throws InvalidArgumentException
* @return bool
*/
public function removeUserFromGroup( UserIdentity $user, string $group ): bool {
$user->assertWiki( $this->wikiId );
// TODO: Deprecate passing out user object in the hook by introducing
// an alternative hook
if ( $this->hookContainer->isRegistered( 'UserRemoveGroup' ) ) {
$userObj = User::newFromIdentity( $user );
$userObj->load();
if ( !$this->hookRunner->onUserRemoveGroup( $userObj, $group ) ) {
return false;
}
}
if ( $this->readOnlyMode->isReadOnly( $this->wikiId ) ) {
return false;
}
if ( !$user->isRegistered() ) {
throw new InvalidArgumentException(
'UserGroupManager::removeUserFromGroup() needs a positive user ID. ' .
'Perhaps removeUserFromGroup() was called before the user was added to the database.'
);
}
$oldUgms = $this->getUserGroupMemberships( $user, IDBAccessObject::READ_LATEST );
$oldFormerGroups = $this->getUserFormerGroups( $user, IDBAccessObject::READ_LATEST );
$dbw = $this->dbProvider->getPrimaryDatabase( $this->wikiId );
$dbw->newDeleteQueryBuilder()
->deleteFrom( 'user_groups' )
->where( [ 'ug_user' => $user->getId( $this->wikiId ), 'ug_group' => $group ] )
->caller( __METHOD__ )->execute();
if ( !$dbw->affectedRows() ) {
return false;
}
// Remember that the user was in this group
$dbw->newInsertQueryBuilder()
->insertInto( 'user_former_groups' )
->ignore()
->row( [ 'ufg_user' => $user->getId( $this->wikiId ), 'ufg_group' => $group ] )
->caller( __METHOD__ )->execute();
unset( $oldUgms[$group] );
$userKey = $this->getCacheKey( $user );
$this->setCache( $userKey, self::CACHE_MEMBERSHIP, $oldUgms, IDBAccessObject::READ_LATEST );
$oldFormerGroups[] = $group;
$this->setCache( $userKey, self::CACHE_FORMER, $oldFormerGroups, IDBAccessObject::READ_LATEST );
$this->clearUserCacheForKind( $user, self::CACHE_EFFECTIVE );
foreach ( $this->clearCacheCallbacks as $callback ) {
$callback( $user );
}
return true;
}
/**
* Return the query builder to build upon and query
*
* @param IReadableDatabase $db
* @return SelectQueryBuilder
* @internal
*/
public function newQueryBuilder( IReadableDatabase $db ): SelectQueryBuilder {
return $db->newSelectQueryBuilder()
->select( [
'ug_user',
'ug_group',
'ug_expiry',
] )
->from( 'user_groups' );
}
/**
* Purge expired memberships from the user_groups table
* @internal
* @note this could be slow and is intended for use in a background job
* @return int|false false if purging wasn't attempted (e.g. because of
* readonly), the number of rows purged (might be 0) otherwise
*/
public function purgeExpired() {
if ( $this->readOnlyMode->isReadOnly( $this->wikiId ) ) {
return false;
}
$ticket = $this->dbProvider->getEmptyTransactionTicket( __METHOD__ );
$dbw = $this->dbProvider->getPrimaryDatabase( $this->wikiId );
$lockKey = "{$dbw->getDomainID()}:UserGroupManager:purge"; // per-wiki
$scopedLock = $dbw->getScopedLockAndFlush( $lockKey, __METHOD__, 0 );
if ( !$scopedLock ) {
return false; // already running
}
$now = time();
$purgedRows = 0;
do {
$dbw->startAtomic( __METHOD__ );
$res = $this->newQueryBuilder( $dbw )
->where( [ $dbw->expr( 'ug_expiry', '<', $dbw->timestamp( $now ) ) ] )
->forUpdate()
->limit( 100 )
->caller( __METHOD__ )
->fetchResultSet();
if ( $res->numRows() > 0 ) {
$insertData = []; // array of users/groups to insert to user_former_groups
$deleteCond = []; // array for deleting the rows that are to be moved around
foreach ( $res as $row ) {
$insertData[] = [ 'ufg_user' => $row->ug_user, 'ufg_group' => $row->ug_group ];
$deleteCond[] = $dbw
->expr( 'ug_user', '=', $row->ug_user )
->and( 'ug_group', '=', $row->ug_group );
}
// Delete the rows we're about to move
$dbw->newDeleteQueryBuilder()
->deleteFrom( 'user_groups' )
->where( $dbw->orExpr( $deleteCond ) )
->caller( __METHOD__ )->execute();
// Push the groups to user_former_groups
$dbw->newInsertQueryBuilder()
->insertInto( 'user_former_groups' )
->ignore()
->rows( $insertData )
->caller( __METHOD__ )->execute();
// Count how many rows were purged
$purgedRows += $res->numRows();
}
$dbw->endAtomic( __METHOD__ );
$this->dbProvider->commitAndWaitForReplication( __METHOD__, $ticket );
} while ( $res->numRows() > 0 );
return $purgedRows;
}
/**
* @param array $config
* @param string $group
* @return string[]
*/
private function expandChangeableGroupConfig( array $config, string $group ): array {
if ( empty( $config[$group] ) ) {
return [];
} elseif ( $config[$group] === true ) {
// You get everything
return $this->listAllGroups();
} elseif ( is_array( $config[$group] ) ) {
return $config[$group];
}
return [];
}
/**
* Returns an array of the groups that a particular group can add/remove.
*
* @since 1.37
* @param string $group The group to check for whether it can add/remove
* @return array [
* 'add' => [ addablegroups ],
* 'remove' => [ removablegroups ],
* 'add-self' => [ addablegroups to self ],
* 'remove-self' => [ removable groups from self ] ]
*/
public function getGroupsChangeableByGroup( string $group ): array {
return [
'add' => $this->expandChangeableGroupConfig(
$this->options->get( MainConfigNames::AddGroups ), $group
),
'remove' => $this->expandChangeableGroupConfig(
$this->options->get( MainConfigNames::RemoveGroups ), $group
),
'add-self' => $this->expandChangeableGroupConfig(
$this->options->get( MainConfigNames::GroupsAddToSelf ), $group
),
'remove-self' => $this->expandChangeableGroupConfig(
$this->options->get( MainConfigNames::GroupsRemoveFromSelf ), $group
),
];
}
/**
* Returns an array of groups that this $actor can add and remove.
*
* @since 1.37
* @param Authority $authority
* @return array [
* 'add' => [ addablegroups ],
* 'remove' => [ removablegroups ],
* 'add-self' => [ addablegroups to self ],
* 'remove-self' => [ removable groups from self ]
* ]
* @phan-return array{add:list<string>,remove:list<string>,add-self:list<string>,remove-self:list<string>}
*/
public function getGroupsChangeableBy( Authority $authority ): array {
if ( $authority->isAllowed( 'userrights' ) ) {
// This group gives the right to modify everything (reverse-
// compatibility with old "userrights lets you change
// everything")
// Using array_merge to make the groups reindexed
$all = array_merge( $this->listAllGroups() );
return [
'add' => $all,
'remove' => $all,
'add-self' => [],
'remove-self' => []
];
}
// Okay, it's not so simple, we will have to go through the arrays
$groups = [
'add' => [],
'remove' => [],
'add-self' => [],
'remove-self' => []
];
$actorGroups = $this->getUserEffectiveGroups( $authority->getUser() );
foreach ( $actorGroups as $actorGroup ) {
$groups = array_merge_recursive(
$groups, $this->getGroupsChangeableByGroup( $actorGroup )
);
$groups['add'] = array_unique( $groups['add'] );
$groups['remove'] = array_unique( $groups['remove'] );
$groups['add-self'] = array_unique( $groups['add-self'] );
$groups['remove-self'] = array_unique( $groups['remove-self'] );
}
return $groups;
}
/**
* Cleans cached group memberships for a given user
*/
public function clearCache( UserIdentity $user ) {
$user->assertWiki( $this->wikiId );
$userKey = $this->getCacheKey( $user );
unset( $this->userGroupCache[$userKey] );
unset( $this->queryFlagsUsedForCaching[$userKey] );
}
/**
* Sets cached group memberships and query flags for a given user
*
* @param string $userKey
* @param string $cacheKind one of self::CACHE_KIND_* constants
* @param array $groupValue
* @param int $queryFlags
*/
private function setCache(
string $userKey,
string $cacheKind,
array $groupValue,
int $queryFlags
) {
$this->userGroupCache[$userKey][$cacheKind] = $groupValue;
$this->queryFlagsUsedForCaching[$userKey][$cacheKind] = $queryFlags;
}
/**
* Clears a cached group membership and query key for a given user
*
* @param UserIdentity $user
* @param string $cacheKind one of self::CACHE_* constants
*/
private function clearUserCacheForKind( UserIdentity $user, string $cacheKind ) {
$userKey = $this->getCacheKey( $user );
unset( $this->userGroupCache[$userKey][$cacheKind] );
unset( $this->queryFlagsUsedForCaching[$userKey][$cacheKind] );
}
/**
* @param int $recency a bit field composed of IDBAccessObject::READ_XXX flags
* @return IReadableDatabase
*/
private function getDBConnectionRefForQueryFlags( int $recency ): IReadableDatabase {
if ( ( IDBAccessObject::READ_LATEST & $recency ) == IDBAccessObject::READ_LATEST ) {
return $this->dbProvider->getPrimaryDatabase( $this->wikiId );
}
return $this->dbProvider->getReplicaDatabase( $this->wikiId );
}
/**
* Gets a unique key for various caches.
* @param UserIdentity $user
* @return string
*/
private function getCacheKey( UserIdentity $user ): string {
return $user->isRegistered() ? "u:{$user->getId( $this->wikiId )}" : "anon:{$user->getName()}";
}
/**
* Determines if it's ok to use cached options values for a given user and query flags
* @param UserIdentity $user
* @param string $cacheKind one of self::CACHE_* constants
* @param int $queryFlags
* @return bool
*/
private function canUseCachedValues(
UserIdentity $user,
string $cacheKind,
int $queryFlags
): bool {
if ( !$user->isRegistered() ) {
// Anon users don't have groups stored in the database,
// so $queryFlags are ignored.
return true;
}
if ( $queryFlags >= IDBAccessObject::READ_LOCKING ) {
return false;
}
$userKey = $this->getCacheKey( $user );
$queryFlagsUsed = $this->queryFlagsUsedForCaching[$userKey][$cacheKind] ?? IDBAccessObject::READ_NONE;
return $queryFlagsUsed >= $queryFlags;
}
}
|