MediaWiki  master
PermissionManager.php
Go to the documentation of this file.
1 <?php
20 namespace MediaWiki\Permissions;
21 
22 use Action;
23 use Article;
24 use Exception;
39 use NamespaceInfo;
40 use RequestContext;
41 use SpecialPage;
42 use Title;
43 use User;
44 use UserCache;
45 use Wikimedia\ScopedCallback;
46 
54 
56  public const RIGOR_QUICK = 'quick';
57 
59  public const RIGOR_FULL = 'full';
60 
62  public const RIGOR_SECURE = 'secure';
63 
67  public const CONSTRUCTOR_OPTIONS = [
68  'WhitelistRead',
69  'WhitelistReadRegexp',
70  'EmailConfirmToEdit',
71  'BlockDisablesLogin',
72  'EnablePartialActionBlocks',
73  'GroupPermissions',
74  'RevokePermissions',
75  'AvailableRights',
76  'NamespaceProtection',
77  'RestrictionLevels',
78  'DeleteRevisionsLimit',
79  ];
80 
82  private $options;
83 
86 
88  private $revisionLookup;
89 
91  private $nsInfo;
92 
95 
98 
100  private $allRights;
101 
104 
106  private $hookRunner;
107 
109  private $userCache;
110 
112  private $usersRights = null;
113 
118  private $temporaryUserRights = [];
119 
121  private $cachedRights = [];
122 
129  private $coreRights = [
130  'apihighlimits',
131  'applychangetags',
132  'autoconfirmed',
133  'autocreateaccount',
134  'autopatrol',
135  'bigdelete',
136  'block',
137  'blockemail',
138  'bot',
139  'browsearchive',
140  'changetags',
141  'createaccount',
142  'createpage',
143  'createtalk',
144  'delete',
145  'delete-redirect',
146  'deletechangetags',
147  'deletedhistory',
148  'deletedtext',
149  'deletelogentry',
150  'deleterevision',
151  'edit',
152  'editcontentmodel',
153  'editinterface',
154  'editprotected',
155  'editmyoptions',
156  'editmyprivateinfo',
157  'editmyusercss',
158  'editmyuserjson',
159  'editmyuserjs',
160  'editmyuserjsredirect',
161  'editmywatchlist',
162  'editsemiprotected',
163  'editsitecss',
164  'editsitejson',
165  'editsitejs',
166  'editusercss',
167  'edituserjson',
168  'edituserjs',
169  'hideuser',
170  'import',
171  'importupload',
172  'ipblock-exempt',
173  'managechangetags',
174  'markbotedits',
175  'mergehistory',
176  'minoredit',
177  'move',
178  'movefile',
179  'move-categorypages',
180  'move-rootuserpages',
181  'move-subpages',
182  'nominornewtalk',
183  'noratelimit',
184  'override-export-depth',
185  'pagelang',
186  'patrol',
187  'patrolmarks',
188  'protect',
189  'purge',
190  'read',
191  'reupload',
192  'reupload-own',
193  'reupload-shared',
194  'rollback',
195  'sendemail',
196  'siteadmin',
197  'suppressionlog',
198  'suppressredirect',
199  'suppressrevision',
200  'unblockself',
201  'undelete',
202  'unwatchedpages',
203  'upload',
204  'upload_by_url',
205  'userrights',
206  'userrights-interwiki',
207  'viewmyprivateinfo',
208  'viewmywatchlist',
209  'viewsuppressed',
210  'writeapi',
211  ];
212 
224  public function __construct(
232  HookContainer $hookContainer,
234  ) {
235  $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
236  $this->options = $options;
237  $this->specialPageFactory = $specialPageFactory;
238  $this->revisionLookup = $revisionLookup;
239  $this->nsInfo = $nsInfo;
240  $this->groupPermissionsLookup = $groupPermissionsLookup;
241  $this->userGroupManager = $userGroupManager;
242  $this->blockErrorFormatter = $blockErrorFormatter;
243  $this->hookRunner = new HookRunner( $hookContainer );
244  $this->userCache = $userCache;
245  }
246 
264  public function userCan( $action, User $user, LinkTarget $page, $rigor = self::RIGOR_SECURE ) {
265  return !count( $this->getPermissionErrorsInternal( $action, $user, $page, $rigor, true ) );
266  }
267 
283  public function quickUserCan( $action, User $user, LinkTarget $page ) {
284  return $this->userCan( $action, $user, $page, self::RIGOR_QUICK );
285  }
286 
304  public function getPermissionErrors(
305  $action,
306  User $user,
307  LinkTarget $page,
308  $rigor = self::RIGOR_SECURE,
309  $ignoreErrors = []
310  ) {
311  $errors = $this->getPermissionErrorsInternal( $action, $user, $page, $rigor );
312 
313  // Remove the errors being ignored.
314  foreach ( $errors as $index => $error ) {
315  $errKey = is_array( $error ) ? $error[0] : $error;
316 
317  if ( in_array( $errKey, $ignoreErrors ) ) {
318  unset( $errors[$index] );
319  }
320  if ( $errKey instanceof MessageSpecifier && in_array( $errKey->getKey(), $ignoreErrors ) ) {
321  unset( $errors[$index] );
322  }
323  }
324 
325  return $errors;
326  }
327 
338  public function isBlockedFrom( User $user, $page, $fromReplica = false ) {
339  $block = $user->getBlock( $fromReplica );
340  if ( !$block ) {
341  return false;
342  }
343 
344  if ( $page instanceof PageIdentity ) {
346  } else {
348  }
349 
350  $blocked = $user->isHidden();
351  if ( !$blocked ) {
352  // Special handling for a user's own talk page. The block is not aware
353  // of the user, so this must be done here.
354  if ( $title->equals( $user->getTalkPage() ) ) {
355  $blocked = $block->appliesToUsertalk( $title );
356  } else {
357  $blocked = $block->appliesToTitle( $title );
358  }
359  }
360 
361  // only for the purpose of the hook. We really don't need this here.
362  $allowUsertalk = $user->isAllowUsertalk();
363 
364  // Allow extensions to let a blocked user access a particular page
365  $this->hookRunner->onUserIsBlockedFrom( $user, $title, $blocked, $allowUsertalk );
366 
367  return $blocked;
368  }
369 
387  private function getPermissionErrorsInternal(
388  $action,
389  User $user,
390  LinkTarget $page,
391  $rigor = self::RIGOR_SECURE,
392  $short = false
393  ) {
394  if ( !in_array( $rigor, [ self::RIGOR_QUICK, self::RIGOR_FULL, self::RIGOR_SECURE ] ) ) {
395  throw new Exception( "Invalid rigor parameter '$rigor'." );
396  }
397 
398  # Read has special handling
399  if ( $action == 'read' ) {
400  $checks = [
401  'checkPermissionHooks',
402  'checkReadPermissions',
403  'checkUserBlock', // for wgBlockDisablesLogin
404  ];
405  # Don't call checkSpecialsAndNSPermissions, checkSiteConfigPermissions
406  # or checkUserConfigPermissions here as it will lead to duplicate
407  # error messages. This is okay to do since anywhere that checks for
408  # create will also check for edit, and those checks are called for edit.
409  } elseif ( $action == 'create' ) {
410  $checks = [
411  'checkQuickPermissions',
412  'checkPermissionHooks',
413  'checkPageRestrictions',
414  'checkCascadingSourcesRestrictions',
415  'checkActionPermissions',
416  'checkUserBlock'
417  ];
418  } else {
419  $checks = [
420  'checkQuickPermissions',
421  'checkPermissionHooks',
422  'checkSpecialsAndNSPermissions',
423  'checkSiteConfigPermissions',
424  'checkUserConfigPermissions',
425  'checkPageRestrictions',
426  'checkCascadingSourcesRestrictions',
427  'checkActionPermissions',
428  'checkUserBlock'
429  ];
430 
431  // Exclude checkUserConfigPermissions on actions that cannot change the
432  // content of the configuration pages.
433  $skipUserConfigActions = [
434  // Allow patrolling per T21818
435  'patrol',
436 
437  // Allow admins and oversighters to delete. For user pages we want to avoid the
438  // situation where an unprivileged user can post abusive content on
439  // their subpages and only very highly privileged users could remove it.
440  // See T200176.
441  'delete',
442  'deleterevision',
443  'suppressrevision',
444 
445  // Allow admins and oversighters to view deleted content, even if they
446  // cannot restore it. See T202989
447  'deletedhistory',
448  'deletedtext',
449  'viewsuppressed',
450  ];
451 
452  if ( in_array( $action, $skipUserConfigActions, true ) ) {
453  $checks = array_diff(
454  $checks,
455  [ 'checkUserConfigPermissions' ]
456  );
457  // Reset numbering
458  $checks = array_values( $checks );
459  }
460  }
461 
462  $errors = [];
463  foreach ( $checks as $method ) {
464  $errors = $this->$method( $action, $user, $errors, $rigor, $short, $page );
465 
466  if ( $short && $errors !== [] ) {
467  break;
468  }
469  }
470  // remove duplicate errors
471  $errors = array_unique( $errors, SORT_REGULAR );
472 
473  return $errors;
474  }
475 
492  private function checkPermissionHooks(
493  $action,
494  User $user,
495  $errors,
496  $rigor,
497  $short,
498  LinkTarget $page
499  ) {
500  // TODO: remove when LinkTarget usage will expand further
501  $title = Title::newFromLinkTarget( $page );
502  // Use getUserPermissionsErrors instead
503  $result = '';
504  if ( !$this->hookRunner->onUserCan( $title, $user, $action, $result ) ) {
505  return $result ? [] : [ [ 'badaccess-group0' ] ];
506  }
507  // Check getUserPermissionsErrors hook
508  if ( !$this->hookRunner->onGetUserPermissionsErrors( $title, $user, $action, $result ) ) {
509  $errors = $this->resultToError( $errors, $result );
510  }
511  // Check getUserPermissionsErrorsExpensive hook
512  if (
513  $rigor !== self::RIGOR_QUICK
514  && !( $short && count( $errors ) > 0 )
515  && !$this->hookRunner->onGetUserPermissionsErrorsExpensive(
516  $title, $user, $action, $result )
517  ) {
518  $errors = $this->resultToError( $errors, $result );
519  }
520 
521  return $errors;
522  }
523 
532  private function resultToError( $errors, $result ) {
533  if ( is_array( $result ) && count( $result ) && !is_array( $result[0] ) ) {
534  // A single array representing an error
535  $errors[] = $result;
536  } elseif ( is_array( $result ) && is_array( $result[0] ) ) {
537  // A nested array representing multiple errors
538  $errors = array_merge( $errors, $result );
539  } elseif ( $result !== '' && is_string( $result ) ) {
540  // A string representing a message-id
541  $errors[] = [ $result ];
542  } elseif ( $result instanceof MessageSpecifier ) {
543  // A message specifier representing an error
544  $errors[] = [ $result ];
545  } elseif ( $result === false ) {
546  // a generic "We don't want them to do that"
547  $errors[] = [ 'badaccess-group0' ];
548  }
549  return $errors;
550  }
551 
568  private function checkReadPermissions(
569  $action,
570  User $user,
571  $errors,
572  $rigor,
573  $short,
574  LinkTarget $page
575  ) {
576  // TODO: remove when LinkTarget usage will expand further
577  $title = Title::newFromLinkTarget( $page );
578 
579  $whiteListRead = $this->options->get( 'WhitelistRead' );
580  $allowed = false;
581  if ( $this->isEveryoneAllowed( 'read' ) ) {
582  # Shortcut for public wikis, allows skipping quite a bit of code
583  $allowed = true;
584  } elseif ( $this->userHasRight( $user, 'read' ) ) {
585  # If the user is allowed to read pages, he is allowed to read all pages
586  $allowed = true;
587  } elseif ( $this->isSameSpecialPage( 'Userlogin', $title )
588  || $this->isSameSpecialPage( 'PasswordReset', $title )
589  || $this->isSameSpecialPage( 'Userlogout', $title )
590  ) {
591  # Always grant access to the login page.
592  # Even anons need to be able to log in.
593  $allowed = true;
594  } elseif ( $this->isSameSpecialPage( 'RunJobs', $title ) ) {
595  # relies on HMAC key signature alone
596  $allowed = true;
597  } elseif ( is_array( $whiteListRead ) && count( $whiteListRead ) ) {
598  # Time to check the whitelist
599  # Only do these checks is there's something to check against
600  $name = $title->getPrefixedText();
601  $dbName = $title->getPrefixedDBkey();
602 
603  // Check for explicit whitelisting with and without underscores
604  if ( in_array( $name, $whiteListRead, true )
605  || in_array( $dbName, $whiteListRead, true ) ) {
606  $allowed = true;
607  } elseif ( $title->getNamespace() === NS_MAIN ) {
608  # Old settings might have the title prefixed with
609  # a colon for main-namespace pages
610  if ( in_array( ':' . $name, $whiteListRead ) ) {
611  $allowed = true;
612  }
613  } elseif ( $title->isSpecialPage() ) {
614  # If it's a special page, ditch the subpage bit and check again
615  $name = $title->getDBkey();
616  list( $name, /* $subpage */ ) =
617  $this->specialPageFactory->resolveAlias( $name );
618  if ( $name ) {
619  $pure = SpecialPage::getTitleFor( $name )->getPrefixedText();
620  if ( in_array( $pure, $whiteListRead, true ) ) {
621  $allowed = true;
622  }
623  }
624  }
625  }
626 
627  $whitelistReadRegexp = $this->options->get( 'WhitelistReadRegexp' );
628  if ( !$allowed && is_array( $whitelistReadRegexp )
629  && !empty( $whitelistReadRegexp ) ) {
630  $name = $title->getPrefixedText();
631  // Check for regex whitelisting
632  foreach ( $whitelistReadRegexp as $listItem ) {
633  if ( preg_match( $listItem, $name ) ) {
634  $allowed = true;
635  break;
636  }
637  }
638  }
639 
640  if ( !$allowed ) {
641  # If the title is not whitelisted, give extensions a chance to do so...
642  $this->hookRunner->onTitleReadWhitelist( $title, $user, $allowed );
643  if ( !$allowed ) {
644  $errors[] = $this->missingPermissionError( $action, $short );
645  }
646  }
647 
648  return $errors;
649  }
650 
659  private function missingPermissionError( $action, $short ) {
660  // We avoid expensive display logic for quickUserCan's and such
661  if ( $short ) {
662  return [ 'badaccess-group0' ];
663  }
664 
665  // TODO: it would be a good idea to replace the method below with something else like
666  // maybe callback injection
667  return User::newFatalPermissionDeniedStatus( $action )->getErrorsArray()[0];
668  }
669 
678  private function isSameSpecialPage( $name, LinkTarget $page ) {
679  if ( $page->getNamespace() === NS_SPECIAL ) {
680  list( $thisName, /* $subpage */ ) =
681  $this->specialPageFactory->resolveAlias( $page->getDBkey() );
682  if ( $name == $thisName ) {
683  return true;
684  }
685  }
686  return false;
687  }
688 
705  private function checkUserBlock(
706  $action,
707  User $user,
708  $errors,
709  $rigor,
710  $short,
711  LinkTarget $page
712  ) {
713  // Unblocking handled in SpecialUnblock
714  if ( $rigor === self::RIGOR_QUICK || in_array( $action, [ 'unblock' ] ) ) {
715  return $errors;
716  }
717 
718  // Optimize for a very common case
719  if ( $action === 'read' && !$this->options->get( 'BlockDisablesLogin' ) ) {
720  return $errors;
721  }
722 
723  if ( $this->options->get( 'EmailConfirmToEdit' )
724  && !$user->isEmailConfirmed()
725  && $action === 'edit'
726  ) {
727  $errors[] = [ 'confirmedittext' ];
728  }
729 
730  switch ( $rigor ) {
731  case self::RIGOR_SECURE:
732  $blockInfoFreshness = Authority::READ_LATEST;
733  $useReplica = false;
734  break;
735  case self::RIGOR_FULL:
736  $blockInfoFreshness = Authority::READ_NORMAL;
737  $useReplica = true;
738  break;
739  default:
740  $useReplica = true;
741  $blockInfoFreshness = Authority::READ_NORMAL;
742  }
743 
744  $block = $user->getBlock( $blockInfoFreshness );
745 
746  if ( $action === 'createaccount' ) {
747  $applicableBlock = null;
748  if ( $block && $block->appliesToRight( 'createaccount' ) ) {
749  $applicableBlock = $block;
750  }
751 
752  # T15611: if the IP address the user is trying to create an account from is
753  # blocked with createaccount disabled, prevent new account creation there even
754  # when the user is logged in
755  if ( !$this->userHasRight( $user, 'ipblock-exempt' ) ) {
756  $ipBlock = DatabaseBlock::newFromTarget(
757  null, $user->getRequest()->getIP()
758  );
759  if ( $ipBlock && $ipBlock->appliesToRight( 'createaccount' ) ) {
760  $applicableBlock = $ipBlock;
761  }
762  }
763  // @todo FIXME: Pass the relevant context into this function.
764  if ( $applicableBlock ) {
766  $message = $this->blockErrorFormatter->getMessage(
767  $applicableBlock,
768  $context->getUser(),
770  $context->getRequest()->getIP()
771  );
772  $errors[] = array_merge( [ $message->getKey() ], $message->getParams() );
773  return $errors;
774  }
775  }
776 
777  // If the user does not have a block, or the block they do have explicitly
778  // allows the action (like "read" or "upload").
779  if ( !$block || $block->appliesToRight( $action ) === false ) {
780  return $errors;
781  }
782 
783  // Determine if the user is blocked from this action on this page.
784  // What gets passed into this method is a user right, not an action name.
785  // There is no way to instantiate an action by restriction. However, this
786  // will get the action where the restriction is the same. This may result
787  // in actions being blocked that shouldn't be.
788  $actionObj = null;
789  if ( Action::exists( $action ) ) {
790  // TODO: this drags a ton of dependencies in, would be good to avoid Article
791  // instantiation and decouple it creating an ActionPermissionChecker interface
792  // Creating an action will perform several database queries to ensure that
793  // the action has not been overridden by the content type.
794  // FIXME: avoid use of RequestContext since it drags in User and Title dependencies
795  // probably we may use fake context object since it's unlikely that Action uses it
796  // anyway. It would be nice if we could avoid instantiating the Action at all.
797  $title = Title::newFromLinkTarget( $page, 'clone' );
799  $actionObj = Action::factory(
800  $action,
802  $context
803  );
804  // Ensure that the retrieved action matches the restriction.
805  if ( $actionObj && $actionObj->getRestriction() !== $action ) {
806  $actionObj = null;
807  }
808  }
809 
810  // If no action object is returned, assume that the action requires unblock
811  // which is the default.
812  if ( !$actionObj || $actionObj->requiresUnblock() ) {
813  if (
814  $this->isBlockedFrom( $user, $page, $useReplica ) ||
815  (
816  $this->options->get( 'EnablePartialActionBlocks' ) &&
817  $block->appliesToRight( $action )
818  )
819  ) {
820  // @todo FIXME: Pass the relevant context into this function.
822  $message = $this->blockErrorFormatter->getMessage(
823  $block,
824  $context->getUser(),
826  $context->getRequest()->getIP()
827  );
828  $errors[] = array_merge( [ $message->getKey() ], $message->getParams() );
829  }
830  }
831 
832  return $errors;
833  }
834 
851  private function checkQuickPermissions(
852  $action,
853  User $user,
854  $errors,
855  $rigor,
856  $short,
857  LinkTarget $page
858  ) {
859  // TODO: remove when LinkTarget usage will expand further
860  $title = Title::newFromLinkTarget( $page );
861 
862  if ( !$this->hookRunner->onTitleQuickPermissions( $title, $user, $action,
863  $errors, $rigor !== self::RIGOR_QUICK, $short )
864  ) {
865  return $errors;
866  }
867 
868  $isSubPage = $this->nsInfo->hasSubpages( $title->getNamespace() ) ?
869  strpos( $title->getText(), '/' ) !== false : false;
870 
871  if ( $action == 'create' ) {
872  if (
873  ( $this->nsInfo->isTalk( $title->getNamespace() ) &&
874  !$this->userHasRight( $user, 'createtalk' ) ) ||
875  ( !$this->nsInfo->isTalk( $title->getNamespace() ) &&
876  !$this->userHasRight( $user, 'createpage' ) )
877  ) {
878  $errors[] = $user->isAnon() ? [ 'nocreatetext' ] : [ 'nocreate-loggedin' ];
879  }
880  } elseif ( $action == 'move' ) {
881  if ( !$this->userHasRight( $user, 'move-rootuserpages' )
882  && $title->getNamespace() === NS_USER && !$isSubPage ) {
883  // Show user page-specific message only if the user can move other pages
884  $errors[] = [ 'cant-move-user-page' ];
885  }
886 
887  // Check if user is allowed to move files if it's a file
888  if ( $title->getNamespace() === NS_FILE &&
889  !$this->userHasRight( $user, 'movefile' ) ) {
890  $errors[] = [ 'movenotallowedfile' ];
891  }
892 
893  // Check if user is allowed to move category pages if it's a category page
894  if ( $title->getNamespace() === NS_CATEGORY &&
895  !$this->userHasRight( $user, 'move-categorypages' ) ) {
896  $errors[] = [ 'cant-move-category-page' ];
897  }
898 
899  if ( !$this->userHasRight( $user, 'move' ) ) {
900  // User can't move anything
901  $userCanMove = $this->groupHasPermission( 'user', 'move' );
902  $autoconfirmedCanMove = $this->groupHasPermission( 'autoconfirmed', 'move' );
903  if ( $user->isAnon() && ( $userCanMove || $autoconfirmedCanMove ) ) {
904  // custom message if logged-in users without any special rights can move
905  $errors[] = [ 'movenologintext' ];
906  } else {
907  $errors[] = [ 'movenotallowed' ];
908  }
909  }
910  } elseif ( $action == 'move-target' ) {
911  if ( !$this->userHasRight( $user, 'move' ) ) {
912  // User can't move anything
913  $errors[] = [ 'movenotallowed' ];
914  } elseif ( !$this->userHasRight( $user, 'move-rootuserpages' )
915  && $title->getNamespace() === NS_USER
916  && !$isSubPage
917  ) {
918  // Show user page-specific message only if the user can move other pages
919  $errors[] = [ 'cant-move-to-user-page' ];
920  } elseif ( !$this->userHasRight( $user, 'move-categorypages' )
921  && $title->getNamespace() === NS_CATEGORY
922  ) {
923  // Show category page-specific message only if the user can move other pages
924  $errors[] = [ 'cant-move-to-category-page' ];
925  }
926  } elseif ( !$this->userHasRight( $user, $action ) ) {
927  $errors[] = $this->missingPermissionError( $action, $short );
928  }
929 
930  return $errors;
931  }
932 
951  private function checkPageRestrictions(
952  $action,
953  User $user,
954  $errors,
955  $rigor,
956  $short,
957  LinkTarget $page
958  ) {
959  // TODO: remove & rework upon further use of LinkTarget
960  $title = Title::newFromLinkTarget( $page );
961  foreach ( $title->getRestrictions( $action ) as $right ) {
962  // Backwards compatibility, rewrite sysop -> editprotected
963  if ( $right == 'sysop' ) {
964  $right = 'editprotected';
965  }
966  // Backwards compatibility, rewrite autoconfirmed -> editsemiprotected
967  if ( $right == 'autoconfirmed' ) {
968  $right = 'editsemiprotected';
969  }
970  if ( $right == '' ) {
971  continue;
972  }
973  if ( !$this->userHasRight( $user, $right ) ) {
974  $errors[] = [ 'protectedpagetext', $right, $action ];
975  } elseif ( $title->areRestrictionsCascading() &&
976  !$this->userHasRight( $user, 'protect' )
977  ) {
978  $errors[] = [ 'protectedpagetext', 'protect', $action ];
979  }
980  }
981 
982  return $errors;
983  }
984 
1002  $action,
1003  UserIdentity $user,
1004  $errors,
1005  $rigor,
1006  $short,
1007  LinkTarget $page
1008  ) {
1009  // TODO: remove & rework upon further use of LinkTarget
1010  $title = Title::newFromLinkTarget( $page );
1011  if ( $rigor !== self::RIGOR_QUICK && !$title->isUserConfigPage() ) {
1012  list( $cascadingSources, $restrictions ) = $title->getCascadeProtectionSources();
1013  # Cascading protection depends on more than this page...
1014  # Several cascading protected pages may include this page...
1015  # Check each cascading level
1016  # This is only for protection restrictions, not for all actions
1017  if ( isset( $restrictions[$action] ) ) {
1018  foreach ( $restrictions[$action] as $right ) {
1019  // Backwards compatibility, rewrite sysop -> editprotected
1020  if ( $right == 'sysop' ) {
1021  $right = 'editprotected';
1022  }
1023  // Backwards compatibility, rewrite autoconfirmed -> editsemiprotected
1024  if ( $right == 'autoconfirmed' ) {
1025  $right = 'editsemiprotected';
1026  }
1027  if ( $right != '' && !$this->userHasAllRights( $user, 'protect', $right ) ) {
1028  $wikiPages = '';
1030  foreach ( $cascadingSources as $wikiPage ) {
1031  $wikiPages .= '* [[:' . $wikiPage->getPrefixedText() . "]]\n";
1032  }
1033  $errors[] = [ 'cascadeprotected', count( $cascadingSources ), $wikiPages, $action ];
1034  }
1035  }
1036  }
1037  }
1038 
1039  return $errors;
1040  }
1041 
1058  private function checkActionPermissions(
1059  $action,
1060  User $user,
1061  $errors,
1062  $rigor,
1063  $short,
1064  LinkTarget $page
1065  ) {
1066  global $wgLang;
1067 
1068  // TODO: remove & rework upon further use of LinkTarget
1069  $title = Title::newFromLinkTarget( $page );
1070 
1071  if ( $action == 'protect' ) {
1072  if ( count( $this->getPermissionErrorsInternal( 'edit', $user, $title, $rigor, true ) ) ) {
1073  // If they can't edit, they shouldn't protect.
1074  $errors[] = [ 'protect-cantedit' ];
1075  }
1076  } elseif ( $action == 'create' ) {
1077  $title_protection = $title->getTitleProtection();
1078  if ( $title_protection ) {
1079  if ( $title_protection['permission'] == ''
1080  || !$this->userHasRight( $user, $title_protection['permission'] )
1081  ) {
1082  $errors[] = [
1083  'titleprotected',
1084  $this->userCache->getProp( $title_protection['user'], 'name' ),
1085  $title_protection['reason']
1086  ];
1087  }
1088  }
1089  } elseif ( $action == 'move' ) {
1090  // Check for immobile pages
1091  if ( !$this->nsInfo->isMovable( $title->getNamespace() ) ) {
1092  // Specific message for this case
1093  $nsText = $title->getNsText();
1094  if ( $nsText === '' ) {
1095  $nsText = wfMessage( 'blanknamespace' )->text();
1096  }
1097  $errors[] = [ 'immobile-source-namespace', $nsText ];
1098  } elseif ( !$title->isMovable() ) {
1099  // Less specific message for rarer cases
1100  $errors[] = [ 'immobile-source-page' ];
1101  }
1102  } elseif ( $action == 'move-target' ) {
1103  if ( !$this->nsInfo->isMovable( $title->getNamespace() ) ) {
1104  $nsText = $title->getNsText();
1105  if ( $nsText === '' ) {
1106  $nsText = wfMessage( 'blanknamespace' )->text();
1107  }
1108  $errors[] = [ 'immobile-target-namespace', $nsText ];
1109  } elseif ( !$title->isMovable() ) {
1110  $errors[] = [ 'immobile-target-page' ];
1111  }
1112  } elseif ( $action == 'delete' || $action == 'delete-redirect' ) {
1113  $tempErrors = $this->checkPageRestrictions( 'edit', $user, [], $rigor, true, $title );
1114  if ( !$tempErrors ) {
1115  $tempErrors = $this->checkCascadingSourcesRestrictions( 'edit',
1116  $user, $tempErrors, $rigor, true, $title );
1117  }
1118  if ( $tempErrors ) {
1119  // If protection keeps them from editing, they shouldn't be able to delete.
1120  $errors[] = [ 'deleteprotected' ];
1121  }
1122  if ( $rigor !== self::RIGOR_QUICK
1123  && $action == 'delete'
1124  && $this->options->get( 'DeleteRevisionsLimit' )
1125  && !$this->userCan( 'bigdelete', $user, $title )
1126  && $title->isBigDeletion()
1127  ) {
1128  $errors[] = [
1129  'delete-toobig',
1130  $wgLang->formatNum( $this->options->get( 'DeleteRevisionsLimit' ) )
1131  ];
1132  }
1133  } elseif ( $action === 'undelete' ) {
1134  if ( count( $this->getPermissionErrorsInternal( 'edit', $user, $title, $rigor, true ) ) ) {
1135  // Undeleting implies editing
1136  $errors[] = [ 'undelete-cantedit' ];
1137  }
1138  if ( !$title->exists()
1139  && count( $this->getPermissionErrorsInternal( 'create', $user, $title, $rigor, true ) )
1140  ) {
1141  // Undeleting where nothing currently exists implies creating
1142  $errors[] = [ 'undelete-cantcreate' ];
1143  }
1144  } elseif ( $action === 'edit' ) {
1145  if ( !$title->exists() ) {
1146  $errors = array_merge(
1147  $errors,
1149  'create',
1150  $user,
1151  $title,
1152  $rigor,
1153  true
1154  )
1155  );
1156  }
1157  }
1158  return $errors;
1159  }
1160 
1178  $action,
1179  UserIdentity $user,
1180  $errors,
1181  $rigor,
1182  $short,
1183  LinkTarget $page
1184  ) {
1185  // TODO: remove & rework upon further use of LinkTarget
1186  $title = Title::newFromLinkTarget( $page );
1187 
1188  # Only 'createaccount' can be performed on special pages,
1189  # which don't actually exist in the DB.
1190  if ( $title->getNamespace() === NS_SPECIAL && $action !== 'createaccount' ) {
1191  $errors[] = [ 'ns-specialprotected' ];
1192  }
1193 
1194  # Check $wgNamespaceProtection for restricted namespaces
1195  if ( $this->isNamespaceProtected( $title->getNamespace(), $user ) ) {
1196  $ns = $title->getNamespace() === NS_MAIN ?
1197  wfMessage( 'nstab-main' )->text() : $title->getNsText();
1198  $errors[] = $title->getNamespace() === NS_MEDIAWIKI ?
1199  [ 'protectedinterface', $action ] : [ 'namespaceprotected', $ns, $action ];
1200  }
1201 
1202  return $errors;
1203  }
1204 
1221  private function checkSiteConfigPermissions(
1222  $action,
1223  User $user,
1224  $errors,
1225  $rigor,
1226  $short,
1227  LinkTarget $page
1228  ) {
1229  // TODO: remove & rework upon further use of LinkTarget
1230  $title = Title::newFromLinkTarget( $page );
1231 
1232  if ( $action === 'patrol' ) {
1233  return $errors;
1234  }
1235 
1236  if ( in_array( $action, [ 'deletedhistory', 'deletedtext', 'viewsuppressed' ], true ) ) {
1237  // Allow admins and oversighters to view deleted content, even if they
1238  // cannot restore it. See T202989
1239  // Not using the same handling in `getPermissionErrorsInternal` as the checks
1240  // for skipping `checkUserConfigPermissions` since normal admins can delete
1241  // user scripts, but not sitedwide scripts
1242  return $errors;
1243  }
1244 
1245  // Sitewide CSS/JSON/JS/RawHTML changes, like all NS_MEDIAWIKI changes, also require the
1246  // editinterface right. That's implemented as a restriction so no check needed here.
1247  if ( $title->isSiteCssConfigPage() && !$this->userHasRight( $user, 'editsitecss' ) ) {
1248  $errors[] = [ 'sitecssprotected', $action ];
1249  } elseif ( $title->isSiteJsonConfigPage() && !$this->userHasRight( $user, 'editsitejson' ) ) {
1250  $errors[] = [ 'sitejsonprotected', $action ];
1251  } elseif ( $title->isSiteJsConfigPage() && !$this->userHasRight( $user, 'editsitejs' ) ) {
1252  $errors[] = [ 'sitejsprotected', $action ];
1253  }
1254  if ( $title->isRawHtmlMessage() && !$this->userCanEditRawHtmlPage( $user ) ) {
1255  $errors[] = [ 'siterawhtmlprotected', $action ];
1256  }
1257 
1258  return $errors;
1259  }
1260 
1277  private function checkUserConfigPermissions(
1278  $action,
1279  UserIdentity $user,
1280  $errors,
1281  $rigor,
1282  $short,
1283  LinkTarget $page
1284  ) {
1285  // TODO: remove & rework upon further use of LinkTarget
1286  $title = Title::newFromLinkTarget( $page );
1287 
1288  # Protect css/json/js subpages of user pages
1289  # XXX: this might be better using restrictions
1290  if ( preg_match( '/^' . preg_quote( $user->getName(), '/' ) . '\//', $title->getText() ) ) {
1291  // Users need editmyuser* to edit their own CSS/JSON/JS subpages.
1292  if (
1293  $title->isUserCssConfigPage()
1294  && !$this->userHasAnyRight( $user, 'editmyusercss', 'editusercss' )
1295  ) {
1296  $errors[] = [ 'mycustomcssprotected', $action ];
1297  } elseif (
1298  $title->isUserJsonConfigPage()
1299  && !$this->userHasAnyRight( $user, 'editmyuserjson', 'edituserjson' )
1300  ) {
1301  $errors[] = [ 'mycustomjsonprotected', $action ];
1302  } elseif (
1303  $title->isUserJsConfigPage()
1304  && !$this->userHasAnyRight( $user, 'editmyuserjs', 'edituserjs' )
1305  ) {
1306  $errors[] = [ 'mycustomjsprotected', $action ];
1307  } elseif (
1308  $title->isUserJsConfigPage()
1309  && !$this->userHasAnyRight( $user, 'edituserjs', 'editmyuserjsredirect' )
1310  ) {
1311  // T207750 - do not allow users to edit a redirect if they couldn't edit the target
1312  $rev = $this->revisionLookup->getRevisionByTitle( $title );
1313  $content = $rev ? $rev->getContent( 'main', RevisionRecord::RAW ) : null;
1314  $target = $content ? $content->getUltimateRedirectTarget() : null;
1315  if ( $target && (
1316  !$target->inNamespace( NS_USER )
1317  || !preg_match( '/^' . preg_quote( $user->getName(), '/' ) . '\//', $target->getText() )
1318  ) ) {
1319  $errors[] = [ 'mycustomjsredirectprotected', $action ];
1320  }
1321  }
1322  } else {
1323  // Users need edituser* to edit others' CSS/JSON/JS subpages.
1324  // The checks to exclude deletion/suppression, which cannot be used for
1325  // attacks and should be excluded to avoid the situation where an
1326  // unprivileged user can post abusive content on their subpages
1327  // and only very highly privileged users could remove it,
1328  // are now a part of `getPermissionErrorsInternal` and this method isn't called.
1329  if (
1330  $title->isUserCssConfigPage()
1331  && !$this->userHasRight( $user, 'editusercss' )
1332  ) {
1333  $errors[] = [ 'customcssprotected', $action ];
1334  } elseif (
1335  $title->isUserJsonConfigPage()
1336  && !$this->userHasRight( $user, 'edituserjson' )
1337  ) {
1338  $errors[] = [ 'customjsonprotected', $action ];
1339  } elseif (
1340  $title->isUserJsConfigPage()
1341  && !$this->userHasRight( $user, 'edituserjs' )
1342  ) {
1343  $errors[] = [ 'customjsprotected', $action ];
1344  }
1345  }
1346 
1347  return $errors;
1348  }
1349 
1360  public function userHasRight( UserIdentity $user, $action = '' ) {
1361  if ( $action === '' ) {
1362  return true; // In the spirit of DWIM
1363  }
1364  // Use strict parameter to avoid matching numeric 0 accidentally inserted
1365  // by misconfiguration: 0 == 'foo'
1366  return in_array( $action, $this->getUserPermissions( $user ), true );
1367  }
1368 
1377  public function userHasAnyRight( UserIdentity $user, ...$actions ) {
1378  foreach ( $actions as $action ) {
1379  if ( $this->userHasRight( $user, $action ) ) {
1380  return true;
1381  }
1382  }
1383  return false;
1384  }
1385 
1394  public function userHasAllRights( UserIdentity $user, ...$actions ) {
1395  foreach ( $actions as $action ) {
1396  if ( !$this->userHasRight( $user, $action ) ) {
1397  return false;
1398  }
1399  }
1400  return true;
1401  }
1402 
1412  public function getUserPermissions( UserIdentity $user ) {
1413  $rightsCacheKey = $this->getRightsCacheKey( $user );
1414  if ( !isset( $this->usersRights[ $rightsCacheKey ] ) ) {
1415  $userObj = User::newFromIdentity( $user );
1416  $this->usersRights[ $rightsCacheKey ] = $this->getGroupPermissions(
1417  $this->userGroupManager->getUserEffectiveGroups( $user )
1418  );
1419  // Hook requires a full User object
1420  $this->hookRunner->onUserGetRights( $userObj, $this->usersRights[ $rightsCacheKey ] );
1421 
1422  // Deny any rights denied by the user's session, unless this
1423  // endpoint has no sessions.
1424  if ( !defined( 'MW_NO_SESSION' ) ) {
1425  // FIXME: $userObj->getRequest().. need to be replaced with something else
1426  $allowedRights = $userObj->getRequest()->getSession()->getAllowedUserRights();
1427  if ( $allowedRights !== null ) {
1428  $this->usersRights[ $rightsCacheKey ] = array_intersect(
1429  $this->usersRights[ $rightsCacheKey ],
1430  $allowedRights
1431  );
1432  }
1433  }
1434 
1435  // Hook requires a full User object
1436  $this->hookRunner->onUserGetRightsRemove(
1437  $userObj, $this->usersRights[ $rightsCacheKey ] );
1438  // Force reindexation of rights when a hook has unset one of them
1439  $this->usersRights[ $rightsCacheKey ] = array_values(
1440  array_unique( $this->usersRights[ $rightsCacheKey ] )
1441  );
1442 
1443  if (
1444  $userObj->isRegistered() &&
1445  $this->options->get( 'BlockDisablesLogin' ) &&
1446  $userObj->getBlock()
1447  ) {
1448  $anon = new User;
1449  $this->usersRights[ $rightsCacheKey ] = array_intersect(
1450  $this->usersRights[ $rightsCacheKey ],
1451  $this->getUserPermissions( $anon )
1452  );
1453  }
1454  }
1455  $rights = $this->usersRights[ $rightsCacheKey ];
1456  foreach ( $this->temporaryUserRights[ $user->getId() ] ?? [] as $overrides ) {
1457  $rights = array_values( array_unique( array_merge( $rights, $overrides ) ) );
1458  }
1459  return $rights;
1460  }
1461 
1470  public function invalidateUsersRightsCache( $user = null ) {
1471  if ( $user !== null ) {
1472  $rightsCacheKey = $this->getRightsCacheKey( $user );
1473  unset( $this->usersRights[ $rightsCacheKey ] );
1474  } else {
1475  $this->usersRights = null;
1476  }
1477  }
1478 
1484  private function getRightsCacheKey( UserIdentity $user ) {
1485  return $user->isRegistered() ? "u:{$user->getId()}" : "anon:{$user->getName()}";
1486  }
1487 
1503  public function groupHasPermission( $group, $role ) {
1504  return $this->groupPermissionsLookup->groupHasPermission( $group, $role );
1505  }
1506 
1516  public function getGroupPermissions( $groups ) {
1517  return $this->groupPermissionsLookup->getGroupPermissions( $groups );
1518  }
1519 
1529  public function getGroupsWithPermission( $role ) {
1530  return $this->groupPermissionsLookup->getGroupsWithPermission( $role );
1531  }
1532 
1548  public function isEveryoneAllowed( $right ) {
1549  // Use the cached results, except in unit tests which rely on
1550  // being able change the permission mid-request
1551  if ( isset( $this->cachedRights[$right] ) ) {
1552  return $this->cachedRights[$right];
1553  }
1554 
1555  if ( !isset( $this->options->get( 'GroupPermissions' )['*'][$right] )
1556  || !$this->options->get( 'GroupPermissions' )['*'][$right] ) {
1557  $this->cachedRights[$right] = false;
1558  return false;
1559  }
1560 
1561  // If it's revoked anywhere, then everyone doesn't have it
1562  foreach ( $this->options->get( 'RevokePermissions' ) as $rights ) {
1563  if ( isset( $rights[$right] ) && $rights[$right] ) {
1564  $this->cachedRights[$right] = false;
1565  return false;
1566  }
1567  }
1568 
1569  // Remove any rights that aren't allowed to the global-session user,
1570  // unless there are no sessions for this endpoint.
1571  if ( !defined( 'MW_NO_SESSION' ) ) {
1572 
1573  // XXX: think what could be done with the below
1574  $allowedRights = SessionManager::getGlobalSession()->getAllowedUserRights();
1575  if ( $allowedRights !== null && !in_array( $right, $allowedRights, true ) ) {
1576  $this->cachedRights[$right] = false;
1577  return false;
1578  }
1579  }
1580 
1581  // Allow extensions to say false
1582  if ( !$this->hookRunner->onUserIsEveryoneAllowed( $right ) ) {
1583  $this->cachedRights[$right] = false;
1584  return false;
1585  }
1586 
1587  $this->cachedRights[$right] = true;
1588  return true;
1589  }
1590 
1598  public function getAllPermissions() {
1599  if ( $this->allRights === null ) {
1600  if ( count( $this->options->get( 'AvailableRights' ) ) ) {
1601  $this->allRights = array_unique( array_merge(
1602  $this->coreRights,
1603  $this->options->get( 'AvailableRights' )
1604  ) );
1605  } else {
1606  $this->allRights = $this->coreRights;
1607  }
1608  $this->hookRunner->onUserGetAllRights( $this->allRights );
1609  }
1610  return $this->allRights;
1611  }
1612 
1619  private function isNamespaceProtected( $index, UserIdentity $user ) {
1620  $namespaceProtection = $this->options->get( 'NamespaceProtection' );
1621  if ( isset( $namespaceProtection[$index] ) ) {
1622  return !$this->userHasAllRights( $user, ...(array)$namespaceProtection[$index] );
1623  }
1624  return false;
1625  }
1626 
1635  public function getNamespaceRestrictionLevels( $index, UserIdentity $user = null ) {
1636  if ( !isset( $this->options->get( 'NamespaceProtection' )[$index] ) ) {
1637  // All levels are valid if there's no namespace restriction.
1638  // But still filter by user, if necessary
1639  $levels = $this->options->get( 'RestrictionLevels' );
1640  if ( $user ) {
1641  $levels = array_values( array_filter( $levels, function ( $level ) use ( $user ) {
1642  $right = $level;
1643  if ( $right == 'sysop' ) {
1644  $right = 'editprotected'; // BC
1645  }
1646  if ( $right == 'autoconfirmed' ) {
1647  $right = 'editsemiprotected'; // BC
1648  }
1649  return $this->userHasRight( $user, $right );
1650  } ) );
1651  }
1652  return $levels;
1653  }
1654 
1655  // $wgNamespaceProtection can require one or more rights to edit the namespace, which
1656  // may be satisfied by membership in multiple groups each giving a subset of those rights.
1657  // A restriction level is redundant if, for any one of the namespace rights, all groups
1658  // giving that right also give the restriction level's right. Or, conversely, a
1659  // restriction level is not redundant if, for every namespace right, there's at least one
1660  // group giving that right without the restriction level's right.
1661  //
1662  // First, for each right, get a list of groups with that right.
1663  $namespaceRightGroups = [];
1664  foreach ( (array)$this->options->get( 'NamespaceProtection' )[$index] as $right ) {
1665  if ( $right == 'sysop' ) {
1666  $right = 'editprotected'; // BC
1667  }
1668  if ( $right == 'autoconfirmed' ) {
1669  $right = 'editsemiprotected'; // BC
1670  }
1671  if ( $right != '' ) {
1672  $namespaceRightGroups[$right] = $this->getGroupsWithPermission( $right );
1673  }
1674  }
1675 
1676  // Now, go through the protection levels one by one.
1677  $usableLevels = [ '' ];
1678  foreach ( $this->options->get( 'RestrictionLevels' ) as $level ) {
1679  $right = $level;
1680  if ( $right == 'sysop' ) {
1681  $right = 'editprotected'; // BC
1682  }
1683  if ( $right == 'autoconfirmed' ) {
1684  $right = 'editsemiprotected'; // BC
1685  }
1686 
1687  if ( $right != '' &&
1688  !isset( $namespaceRightGroups[$right] ) &&
1689  ( !$user || $this->userHasRight( $user, $right ) )
1690  ) {
1691  // Do any of the namespace rights imply the restriction right? (see explanation above)
1692  foreach ( $namespaceRightGroups as $groups ) {
1693  if ( !array_diff( $groups, $this->getGroupsWithPermission( $right ) ) ) {
1694  // Yes, this one does.
1695  continue 2;
1696  }
1697  }
1698  // No, keep the restriction level
1699  $usableLevels[] = $level;
1700  }
1701  }
1702 
1703  return $usableLevels;
1704  }
1705 
1714  private function userCanEditRawHtmlPage( UserIdentity $user ) {
1715  return $this->userHasAllRights( $user, 'editsitecss', 'editsitejs' );
1716  }
1717 
1732  public function addTemporaryUserRights( UserIdentity $user, $rights ) {
1733  $userId = $user->getId();
1734  $nextKey = count( $this->temporaryUserRights[$userId] ?? [] );
1735  $this->temporaryUserRights[$userId][$nextKey] = (array)$rights;
1736  return new ScopedCallback( function () use ( $userId, $nextKey ) {
1737  unset( $this->temporaryUserRights[$userId][$nextKey] );
1738  } );
1739  }
1740 
1751  public function overrideUserRightsForTesting( $user, $rights = [] ) {
1752  if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
1753  throw new Exception( __METHOD__ . ' can not be called outside of tests' );
1754  }
1755  $this->usersRights[ $this->getRightsCacheKey( $user ) ] =
1756  is_array( $rights ) ? $rights : [ $rights ];
1757  }
1758 
1759 }
MediaWiki\Permissions\PermissionManager\$cachedRights
bool[] $cachedRights
Cached rights for isEveryoneAllowed, [ right => allowed ].
Definition: PermissionManager.php:121
MediaWiki\Revision\RevisionRecord\RAW
const RAW
Definition: RevisionRecord.php:64
Page\PageIdentity
Interface for objects (potentially) representing an editable wiki page.
Definition: PageIdentity.php:64
MediaWiki\Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:47
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:72
MediaWiki\Permissions\PermissionManager\checkCascadingSourcesRestrictions
checkCascadingSourcesRestrictions( $action, UserIdentity $user, $errors, $rigor, $short, LinkTarget $page)
Check restrictions on cascading pages.
Definition: PermissionManager.php:1001
User\isAnon
isAnon()
Get whether the user is anonymous.
Definition: User.php:2978
Action\factory
static factory(string $action, Article $article, IContextSource $context=null)
Get an appropriate Action subclass for the given action.
Definition: Action.php:85
UserCache
Definition: UserCache.php:32
MediaWiki\Permissions\PermissionManager\checkSpecialsAndNSPermissions
checkSpecialsAndNSPermissions( $action, UserIdentity $user, $errors, $rigor, $short, LinkTarget $page)
Check permissions on special pages & namespaces.
Definition: PermissionManager.php:1177
MediaWiki\Permissions\PermissionManager\getPermissionErrorsInternal
getPermissionErrorsInternal( $action, User $user, LinkTarget $page, $rigor=self::RIGOR_SECURE, $short=false)
Can $user perform $action on a page? This is an internal function, with multiple levels of checks dep...
Definition: PermissionManager.php:387
MediaWiki\Permissions\GroupPermissionsLookup
Definition: GroupPermissionsLookup.php:30
User\newFatalPermissionDeniedStatus
static newFatalPermissionDeniedStatus( $permission)
Factory function for fatal permission-denied errors.
Definition: User.php:4206
MediaWiki\Permissions\PermissionManager\userCan
userCan( $action, User $user, LinkTarget $page, $rigor=self::RIGOR_SECURE)
Can $user perform $action on a page?
Definition: PermissionManager.php:264
MediaWiki\Block\BlockErrorFormatter
A service class for getting formatted information about a block.
Definition: BlockErrorFormatter.php:36
MediaWiki\SpecialPage\SpecialPageFactory
Factory for handling the special page list and generating SpecialPage objects.
Definition: SpecialPageFactory.php:63
MessageSpecifier
Definition: MessageSpecifier.php:24
Action\exists
static exists(string $name)
Check if a given action is recognised, even if it's disabled.
Definition: Action.php:121
MediaWiki\Permissions\PermissionManager\missingPermissionError
missingPermissionError( $action, $short)
Get a description array when the user doesn't have the right to perform $action (i....
Definition: PermissionManager.php:659
MediaWiki\Permissions\PermissionManager\checkPermissionHooks
checkPermissionHooks( $action, User $user, $errors, $rigor, $short, LinkTarget $page)
Check various permission hooks.
Definition: PermissionManager.php:492
MediaWiki\Permissions\PermissionManager\userHasRight
userHasRight(UserIdentity $user, $action='')
Testing a permission.
Definition: PermissionManager.php:1360
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1182
MediaWiki\Permissions\PermissionManager\$coreRights
$coreRights
Array of Strings Core rights.
Definition: PermissionManager.php:129
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Definition: SpecialPage.php:107
User\newFromIdentity
static newFromIdentity(UserIdentity $identity)
Returns a User object corresponding to the given UserIdentity.
Definition: User.php:679
MediaWiki\User\UserIdentity\getId
getId( $wikiId=self::LOCAL)
User\getBlock
getBlock( $freshness=self::READ_NORMAL, $disableIpBlockExemptChecking=false)
Get the block affecting the user, or null if the user is not blocked.
Definition: User.php:1936
$wgLang
$wgLang
Definition: Setup.php:807
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:39
MediaWiki\Revision\RevisionLookup
Service for looking up page revisions.
Definition: RevisionLookup.php:38
User\getRequest
getRequest()
Get the WebRequest object to use with this object.
Definition: User.php:3067
NS_MAIN
const NS_MAIN
Definition: Defines.php:64
Title\castFromPageIdentity
static castFromPageIdentity(?PageIdentity $pageIdentity)
Return a Title for a given PageIdentity.
Definition: Title.php:364
Action
Actions are things which can be done to pages (edit, delete, rollback, etc).
Definition: Action.php:43
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:53
MediaWiki\Block\DatabaseBlock
A DatabaseBlock (unlike a SystemBlock) is stored in the database, may give rise to autoblocks and may...
Definition: DatabaseBlock.php:52
MediaWiki\User\UserGroupManager
Managers user groups.
Definition: UserGroupManager.php:52
MediaWiki\Permissions\PermissionManager\invalidateUsersRightsCache
invalidateUsersRightsCache( $user=null)
Clears users permissions cache, if specific user is provided it tries to clear permissions cache only...
Definition: PermissionManager.php:1470
MediaWiki\Linker\LinkTarget\getNamespace
getNamespace()
Get the namespace index.
User\getTalkPage
getTalkPage()
Get this user's talk page title.
Definition: User.php:3656
MediaWiki\Permissions\PermissionManager\resultToError
resultToError( $errors, $result)
Add the resulting error code to the errors array.
Definition: PermissionManager.php:532
MediaWiki\Permissions\PermissionManager\$revisionLookup
RevisionLookup $revisionLookup
Definition: PermissionManager.php:88
MediaWiki\Config\ServiceOptions
A class for passing options to services.
Definition: ServiceOptions.php:27
MediaWiki\Permissions\PermissionManager\$hookRunner
HookRunner $hookRunner
Definition: PermissionManager.php:106
MediaWiki\User\UserIdentity\isRegistered
isRegistered()
MediaWiki\Permissions\PermissionManager\checkUserConfigPermissions
checkUserConfigPermissions( $action, UserIdentity $user, $errors, $rigor, $short, LinkTarget $page)
Check CSS/JSON/JS sub-page permissions.
Definition: PermissionManager.php:1277
MediaWiki\Permissions\PermissionManager\$usersRights
string[][] $usersRights
Cached user rights.
Definition: PermissionManager.php:112
MediaWiki\Permissions\PermissionManager\$allRights
string[] null $allRights
Cached results of getAllPermissions()
Definition: PermissionManager.php:100
MediaWiki\Permissions\PermissionManager\isSameSpecialPage
isSameSpecialPage( $name, LinkTarget $page)
Returns true if this title resolves to the named special page.
Definition: PermissionManager.php:678
User\isHidden
isHidden()
Check if user account is hidden.
Definition: User.php:2065
MediaWiki\Permissions\PermissionManager\$groupPermissionsLookup
GroupPermissionsLookup $groupPermissionsLookup
Definition: PermissionManager.php:94
MediaWiki\Permissions\PermissionManager\getRightsCacheKey
getRightsCacheKey(UserIdentity $user)
Gets a unique key for user rights cache.
Definition: PermissionManager.php:1484
MediaWiki\Permissions\PermissionManager\getNamespaceRestrictionLevels
getNamespaceRestrictionLevels( $index, UserIdentity $user=null)
Determine which restriction levels it makes sense to use in a namespace, optionally filtered by a use...
Definition: PermissionManager.php:1635
MediaWiki\Permissions\PermissionManager\isNamespaceProtected
isNamespaceProtected( $index, UserIdentity $user)
Determines if $user is unable to edit pages in namespace because it has been protected.
Definition: PermissionManager.php:1619
MediaWiki\User\UserIdentity\getName
getName()
$title
$title
Definition: testCompression.php:38
MediaWiki\Permissions\PermissionManager\checkPageRestrictions
checkPageRestrictions( $action, User $user, $errors, $rigor, $short, LinkTarget $page)
Check against page_restrictions table requirements on this page.
Definition: PermissionManager.php:951
MediaWiki\Permissions\PermissionManager\$specialPageFactory
SpecialPageFactory $specialPageFactory
Definition: PermissionManager.php:85
MediaWiki\Permissions\PermissionManager\$nsInfo
NamespaceInfo $nsInfo
Definition: PermissionManager.php:91
MediaWiki\Permissions\PermissionManager\checkQuickPermissions
checkQuickPermissions( $action, User $user, $errors, $rigor, $short, LinkTarget $page)
Permissions checks that fail most often, and which are easiest to test.
Definition: PermissionManager.php:851
RequestContext
Group all the pieces relevant to the context of a request into one instance @newable.
Definition: RequestContext.php:41
MediaWiki\Permissions\PermissionManager\$blockErrorFormatter
BlockErrorFormatter $blockErrorFormatter
Definition: PermissionManager.php:103
MediaWiki\Permissions\PermissionManager\checkUserBlock
checkUserBlock( $action, User $user, $errors, $rigor, $short, LinkTarget $page)
Check that the user isn't blocked from editing.
Definition: PermissionManager.php:705
MediaWiki\Permissions\PermissionManager\checkActionPermissions
checkActionPermissions( $action, User $user, $errors, $rigor, $short, LinkTarget $page)
Check action permissions not already checked in checkQuickPermissions.
Definition: PermissionManager.php:1058
MediaWiki\Permissions\PermissionManager\isEveryoneAllowed
isEveryoneAllowed( $right)
Check if all users may be assumed to have the given permission.
Definition: PermissionManager.php:1548
MediaWiki\Permissions\PermissionManager\checkReadPermissions
checkReadPermissions( $action, User $user, $errors, $rigor, $short, LinkTarget $page)
Check that the user is allowed to read this page.
Definition: PermissionManager.php:568
MediaWiki\Block\DatabaseBlock\newFromTarget
static newFromTarget( $specificTarget, $vagueTarget=null, $fromPrimary=false)
Given a target and the target's type, get an existing block object if possible.
Definition: DatabaseBlock.php:895
MediaWiki\Permissions\PermissionManager\getUserPermissions
getUserPermissions(UserIdentity $user)
Get the permissions this user has.
Definition: PermissionManager.php:1412
MediaWiki\Session\SessionManager\getGlobalSession
static getGlobalSession()
If PHP's session_id() has been set, returns that session.
Definition: SessionManager.php:146
MediaWiki\Permissions\PermissionManager
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()-...
Definition: PermissionManager.php:53
$content
$content
Definition: router.php:76
MediaWiki\Permissions\PermissionManager\getAllPermissions
getAllPermissions()
Get a list of all available permissions.
Definition: PermissionManager.php:1598
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:43
MediaWiki\Permissions\PermissionManager\getGroupsWithPermission
getGroupsWithPermission( $role)
Get all the groups who have a given permission.
Definition: PermissionManager.php:1529
MediaWiki\Session\SessionManager
This serves as the entry point to the MediaWiki session handling system.
Definition: SessionManager.php:83
MediaWiki\Permissions\PermissionManager\quickUserCan
quickUserCan( $action, User $user, LinkTarget $page)
A convenience method for calling PermissionManager::userCan with PermissionManager::RIGOR_QUICK.
Definition: PermissionManager.php:283
MediaWiki\Linker\LinkTarget\getDBkey
getDBkey()
Get the main part with underscores.
MediaWiki\Permissions\PermissionManager\addTemporaryUserRights
addTemporaryUserRights(UserIdentity $user, $rights)
Add temporary user rights, only valid for the current scope.
Definition: PermissionManager.php:1732
MediaWiki\Permissions\PermissionManager\$userGroupManager
UserGroupManager $userGroupManager
Definition: PermissionManager.php:97
IContextSource\getUser
getUser()
MediaWiki\Permissions\PermissionManager\getPermissionErrors
getPermissionErrors( $action, User $user, LinkTarget $page, $rigor=self::RIGOR_SECURE, $ignoreErrors=[])
Can $user perform $action on a page?
Definition: PermissionManager.php:304
NS_USER
const NS_USER
Definition: Defines.php:66
MediaWiki\Permissions\PermissionManager\userCanEditRawHtmlPage
userCanEditRawHtmlPage(UserIdentity $user)
Check if user is allowed to edit sitewide pages that contain raw HTML.
Definition: PermissionManager.php:1714
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:484
Title\newFromLinkTarget
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Definition: Title.php:327
MediaWiki\Permissions\PermissionManager\isBlockedFrom
isBlockedFrom(User $user, $page, $fromReplica=false)
Check if user is blocked from editing a particular article.
Definition: PermissionManager.php:338
MediaWiki\Permissions\PermissionManager\checkSiteConfigPermissions
checkSiteConfigPermissions( $action, User $user, $errors, $rigor, $short, LinkTarget $page)
Check sitewide CSS/JSON/JS permissions.
Definition: PermissionManager.php:1221
MediaWiki\Permissions\PermissionManager\groupHasPermission
groupHasPermission( $group, $role)
Check, if the given group has the given permission.
Definition: PermissionManager.php:1503
MediaWiki\$action
string $action
Cache what action this request is.
Definition: MediaWiki.php:45
Title
Represents a title within MediaWiki.
Definition: Title.php:49
MediaWiki\Permissions\PermissionManager\CONSTRUCTOR_OPTIONS
const CONSTRUCTOR_OPTIONS
Definition: PermissionManager.php:67
MediaWiki\Permissions\PermissionManager\userHasAllRights
userHasAllRights(UserIdentity $user,... $actions)
Check if user is allowed to make all actions.
Definition: PermissionManager.php:1394
User\isEmailConfirmed
isEmailConfirmed()
Is this user's e-mail address valid-looking and confirmed within limits of the current site configura...
Definition: User.php:3963
User\isAllowUsertalk
isAllowUsertalk()
Checks if usertalk is allowed.
Definition: User.php:4265
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:78
MediaWiki\Permissions\PermissionManager\$userCache
UserCache $userCache
Definition: PermissionManager.php:109
IContextSource\getRequest
getRequest()
MediaWiki\HookContainer\HookContainer
HookContainer class.
Definition: HookContainer.php:45
NamespaceInfo
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
Definition: NamespaceInfo.php:35
MediaWiki\HookContainer\HookRunner
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
Definition: HookRunner.php:554
Title\castFromLinkTarget
static castFromLinkTarget( $linkTarget)
Same as newFromLinkTarget, but if passed null, returns null.
Definition: Title.php:351
Article
Class for viewing MediaWiki article and history.
Definition: Article.php:50
NS_FILE
const NS_FILE
Definition: Defines.php:70
MediaWiki\Linker\LinkTarget
Definition: LinkTarget.php:26
MediaWiki\$context
IContextSource $context
Definition: MediaWiki.php:40
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:68
MediaWiki\Permissions\PermissionManager\$temporaryUserRights
string[][][] $temporaryUserRights
Temporary user rights, valid for the current request only.
Definition: PermissionManager.php:118
MediaWiki\Permissions\PermissionManager\userHasAnyRight
userHasAnyRight(UserIdentity $user,... $actions)
Check if user is allowed to make any action.
Definition: PermissionManager.php:1377
MediaWiki\Permissions\PermissionManager\getGroupPermissions
getGroupPermissions( $groups)
Get the permissions associated with a given list of groups.
Definition: PermissionManager.php:1516
MediaWiki\Permissions\PermissionManager\__construct
__construct(ServiceOptions $options, SpecialPageFactory $specialPageFactory, RevisionLookup $revisionLookup, NamespaceInfo $nsInfo, GroupPermissionsLookup $groupPermissionsLookup, UserGroupManager $userGroupManager, BlockErrorFormatter $blockErrorFormatter, HookContainer $hookContainer, UserCache $userCache)
Definition: PermissionManager.php:224
MediaWiki\Permissions\PermissionManager\$options
ServiceOptions $options
Definition: PermissionManager.php:82
IContextSource\getLanguage
getLanguage()
MediaWiki\Permissions\PermissionManager\overrideUserRightsForTesting
overrideUserRightsForTesting( $user, $rights=[])
Overrides user permissions cache.
Definition: PermissionManager.php:1751
MediaWiki\Config\ServiceOptions\assertRequiredOptions
assertRequiredOptions(array $expectedKeys)
Assert that the list of options provided in this instance exactly match $expectedKeys,...
Definition: ServiceOptions.php:71
MediaWiki\Permissions
Definition: Authority.php:21
Article\newFromTitle
static newFromTitle( $title, IContextSource $context)
Create an Article object of the appropriate class for the given page.
Definition: Article.php:164