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;
36 use NamespaceInfo;
37 use RequestContext;
38 use SpecialPage;
39 use Title;
40 use User;
41 use Wikimedia\ScopedCallback;
42 
50 
52  public const RIGOR_QUICK = 'quick';
53 
55  public const RIGOR_FULL = 'full';
56 
58  public const RIGOR_SECURE = 'secure';
59 
64  public const CONSTRUCTOR_OPTIONS = [
65  'WhitelistRead',
66  'WhitelistReadRegexp',
67  'EmailConfirmToEdit',
68  'BlockDisablesLogin',
69  'GroupPermissions',
70  'RevokePermissions',
71  'AvailableRights',
72  'NamespaceProtection',
73  'RestrictionLevels'
74  ];
75 
77  private $options;
78 
81 
83  private $revisionLookup;
84 
86  private $nsInfo;
87 
89  private $allRights;
90 
93 
95  private $hookRunner;
96 
98  private $usersRights = null;
99 
104  private $temporaryUserRights = [];
105 
107  private $cachedRights = [];
108 
115  private $coreRights = [
116  'apihighlimits',
117  'applychangetags',
118  'autoconfirmed',
119  'autocreateaccount',
120  'autopatrol',
121  'bigdelete',
122  'block',
123  'blockemail',
124  'bot',
125  'browsearchive',
126  'changetags',
127  'createaccount',
128  'createpage',
129  'createtalk',
130  'delete',
131  'deletechangetags',
132  'deletedhistory',
133  'deletedtext',
134  'deletelogentry',
135  'deleterevision',
136  'edit',
137  'editcontentmodel',
138  'editinterface',
139  'editprotected',
140  'editmyoptions',
141  'editmyprivateinfo',
142  'editmyusercss',
143  'editmyuserjson',
144  'editmyuserjs',
145  'editmyuserjsredirect',
146  'editmywatchlist',
147  'editsemiprotected',
148  'editsitecss',
149  'editsitejson',
150  'editsitejs',
151  'editusercss',
152  'edituserjson',
153  'edituserjs',
154  'hideuser',
155  'import',
156  'importupload',
157  'ipblock-exempt',
158  'managechangetags',
159  'markbotedits',
160  'mergehistory',
161  'minoredit',
162  'move',
163  'movefile',
164  'move-categorypages',
165  'move-rootuserpages',
166  'move-subpages',
167  'nominornewtalk',
168  'noratelimit',
169  'override-export-depth',
170  'pagelang',
171  'patrol',
172  'patrolmarks',
173  'protect',
174  'purge',
175  'read',
176  'reupload',
177  'reupload-own',
178  'reupload-shared',
179  'rollback',
180  'sendemail',
181  'siteadmin',
182  'suppressionlog',
183  'suppressredirect',
184  'suppressrevision',
185  'unblockself',
186  'undelete',
187  'unwatchedpages',
188  'upload',
189  'upload_by_url',
190  'userrights',
191  'userrights-interwiki',
192  'viewmyprivateinfo',
193  'viewmywatchlist',
194  'viewsuppressed',
195  'writeapi',
196  ];
197 
206  public function __construct(
212  HookContainer $hookContainer
213  ) {
214  $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
215  $this->options = $options;
216  $this->specialPageFactory = $specialPageFactory;
217  $this->revisionLookup = $revisionLookup;
218  $this->nsInfo = $nsInfo;
219  $this->blockErrorFormatter = $blockErrorFormatter;
220  $this->hookRunner = new HookRunner( $hookContainer );
221  }
222 
242  public function userCan( $action, User $user, LinkTarget $page, $rigor = self::RIGOR_SECURE ) {
243  return !count( $this->getPermissionErrorsInternal( $action, $user, $page, $rigor, true ) );
244  }
245 
261  public function quickUserCan( $action, User $user, LinkTarget $page ) {
262  return $this->userCan( $action, $user, $page, self::RIGOR_QUICK );
263  }
264 
282  public function getPermissionErrors(
283  $action,
284  User $user,
285  LinkTarget $page,
286  $rigor = self::RIGOR_SECURE,
287  $ignoreErrors = []
288  ) {
289  $errors = $this->getPermissionErrorsInternal( $action, $user, $page, $rigor );
290 
291  // Remove the errors being ignored.
292  foreach ( $errors as $index => $error ) {
293  $errKey = is_array( $error ) ? $error[0] : $error;
294 
295  if ( in_array( $errKey, $ignoreErrors ) ) {
296  unset( $errors[$index] );
297  }
298  if ( $errKey instanceof MessageSpecifier && in_array( $errKey->getKey(), $ignoreErrors ) ) {
299  unset( $errors[$index] );
300  }
301  }
302 
303  return $errors;
304  }
305 
316  public function isBlockedFrom( User $user, LinkTarget $page, $fromReplica = false ) {
317  $block = $user->getBlock( $fromReplica );
318  if ( !$block ) {
319  return false;
320  }
321 
322  // TODO: remove upon further migration to LinkTarget
323  $title = Title::newFromLinkTarget( $page );
324 
325  $blocked = $user->isHidden();
326  if ( !$blocked ) {
327  // Special handling for a user's own talk page. The block is not aware
328  // of the user, so this must be done here.
329  if ( $title->equals( $user->getTalkPage() ) ) {
330  $blocked = $block->appliesToUsertalk( $title );
331  } else {
332  $blocked = $block->appliesToTitle( $title );
333  }
334  }
335 
336  // only for the purpose of the hook. We really don't need this here.
337  $allowUsertalk = $user->isAllowUsertalk();
338 
339  // Allow extensions to let a blocked user access a particular page
340  $this->hookRunner->onUserIsBlockedFrom( $user, $title, $blocked, $allowUsertalk );
341 
342  return $blocked;
343  }
344 
362  private function getPermissionErrorsInternal(
363  $action,
364  User $user,
365  LinkTarget $page,
366  $rigor = self::RIGOR_SECURE,
367  $short = false
368  ) {
369  if ( !in_array( $rigor, [ self::RIGOR_QUICK, self::RIGOR_FULL, self::RIGOR_SECURE ] ) ) {
370  throw new Exception( "Invalid rigor parameter '$rigor'." );
371  }
372 
373  # Read has special handling
374  if ( $action == 'read' ) {
375  $checks = [
376  'checkPermissionHooks',
377  'checkReadPermissions',
378  'checkUserBlock', // for wgBlockDisablesLogin
379  ];
380  # Don't call checkSpecialsAndNSPermissions, checkSiteConfigPermissions
381  # or checkUserConfigPermissions here as it will lead to duplicate
382  # error messages. This is okay to do since anywhere that checks for
383  # create will also check for edit, and those checks are called for edit.
384  } elseif ( $action == 'create' ) {
385  $checks = [
386  'checkQuickPermissions',
387  'checkPermissionHooks',
388  'checkPageRestrictions',
389  'checkCascadingSourcesRestrictions',
390  'checkActionPermissions',
391  'checkUserBlock'
392  ];
393  } else {
394  $checks = [
395  'checkQuickPermissions',
396  'checkPermissionHooks',
397  'checkSpecialsAndNSPermissions',
398  'checkSiteConfigPermissions',
399  'checkUserConfigPermissions',
400  'checkPageRestrictions',
401  'checkCascadingSourcesRestrictions',
402  'checkActionPermissions',
403  'checkUserBlock'
404  ];
405  }
406 
407  $errors = [];
408  foreach ( $checks as $method ) {
409  $errors = $this->$method( $action, $user, $errors, $rigor, $short, $page );
410 
411  if ( $short && $errors !== [] ) {
412  break;
413  }
414  }
415 
416  return $errors;
417  }
418 
435  private function checkPermissionHooks(
436  $action,
437  User $user,
438  $errors,
439  $rigor,
440  $short,
441  LinkTarget $page
442  ) {
443  // TODO: remove when LinkTarget usage will expand further
444  $title = Title::newFromLinkTarget( $page );
445  // Use getUserPermissionsErrors instead
446  $result = '';
447  if ( !$this->hookRunner->onUserCan( $title, $user, $action, $result ) ) {
448  return $result ? [] : [ [ 'badaccess-group0' ] ];
449  }
450  // Check getUserPermissionsErrors hook
451  if ( !$this->hookRunner->onGetUserPermissionsErrors( $title, $user, $action, $result ) ) {
452  $errors = $this->resultToError( $errors, $result );
453  }
454  // Check getUserPermissionsErrorsExpensive hook
455  if (
456  $rigor !== self::RIGOR_QUICK
457  && !( $short && count( $errors ) > 0 )
458  && !$this->hookRunner->onGetUserPermissionsErrorsExpensive(
459  $title, $user, $action, $result )
460  ) {
461  $errors = $this->resultToError( $errors, $result );
462  }
463 
464  return $errors;
465  }
466 
475  private function resultToError( $errors, $result ) {
476  if ( is_array( $result ) && count( $result ) && !is_array( $result[0] ) ) {
477  // A single array representing an error
478  $errors[] = $result;
479  } elseif ( is_array( $result ) && is_array( $result[0] ) ) {
480  // A nested array representing multiple errors
481  $errors = array_merge( $errors, $result );
482  } elseif ( $result !== '' && is_string( $result ) ) {
483  // A string representing a message-id
484  $errors[] = [ $result ];
485  } elseif ( $result instanceof MessageSpecifier ) {
486  // A message specifier representing an error
487  $errors[] = [ $result ];
488  } elseif ( $result === false ) {
489  // a generic "We don't want them to do that"
490  $errors[] = [ 'badaccess-group0' ];
491  }
492  return $errors;
493  }
494 
511  private function checkReadPermissions(
512  $action,
513  User $user,
514  $errors,
515  $rigor,
516  $short,
517  LinkTarget $page
518  ) {
519  // TODO: remove when LinkTarget usage will expand further
520  $title = Title::newFromLinkTarget( $page );
521 
522  $whiteListRead = $this->options->get( 'WhitelistRead' );
523  $whitelisted = false;
524  if ( $this->isEveryoneAllowed( 'read' ) ) {
525  # Shortcut for public wikis, allows skipping quite a bit of code
526  $whitelisted = true;
527  } elseif ( $this->userHasRight( $user, 'read' ) ) {
528  # If the user is allowed to read pages, he is allowed to read all pages
529  $whitelisted = true;
530  } elseif ( $this->isSameSpecialPage( 'Userlogin', $title )
531  || $this->isSameSpecialPage( 'PasswordReset', $title )
532  || $this->isSameSpecialPage( 'Userlogout', $title )
533  ) {
534  # Always grant access to the login page.
535  # Even anons need to be able to log in.
536  $whitelisted = true;
537  } elseif ( is_array( $whiteListRead ) && count( $whiteListRead ) ) {
538  # Time to check the whitelist
539  # Only do these checks is there's something to check against
540  $name = $title->getPrefixedText();
541  $dbName = $title->getPrefixedDBkey();
542 
543  // Check for explicit whitelisting with and without underscores
544  if ( in_array( $name, $whiteListRead, true )
545  || in_array( $dbName, $whiteListRead, true ) ) {
546  $whitelisted = true;
547  } elseif ( $title->getNamespace() == NS_MAIN ) {
548  # Old settings might have the title prefixed with
549  # a colon for main-namespace pages
550  if ( in_array( ':' . $name, $whiteListRead ) ) {
551  $whitelisted = true;
552  }
553  } elseif ( $title->isSpecialPage() ) {
554  # If it's a special page, ditch the subpage bit and check again
555  $name = $title->getDBkey();
556  list( $name, /* $subpage */ ) =
557  $this->specialPageFactory->resolveAlias( $name );
558  if ( $name ) {
559  $pure = SpecialPage::getTitleFor( $name )->getPrefixedText();
560  if ( in_array( $pure, $whiteListRead, true ) ) {
561  $whitelisted = true;
562  }
563  }
564  }
565  }
566 
567  $whitelistReadRegexp = $this->options->get( 'WhitelistReadRegexp' );
568  if ( !$whitelisted && is_array( $whitelistReadRegexp )
569  && !empty( $whitelistReadRegexp ) ) {
570  $name = $title->getPrefixedText();
571  // Check for regex whitelisting
572  foreach ( $whitelistReadRegexp as $listItem ) {
573  if ( preg_match( $listItem, $name ) ) {
574  $whitelisted = true;
575  break;
576  }
577  }
578  }
579 
580  if ( !$whitelisted ) {
581  # If the title is not whitelisted, give extensions a chance to do so...
582  $this->hookRunner->onTitleReadWhitelist( $title, $user, $whitelisted );
583  if ( !$whitelisted ) {
584  $errors[] = $this->missingPermissionError( $action, $short );
585  }
586  }
587 
588  return $errors;
589  }
590 
599  private function missingPermissionError( $action, $short ) {
600  // We avoid expensive display logic for quickUserCan's and such
601  if ( $short ) {
602  return [ 'badaccess-group0' ];
603  }
604 
605  // TODO: it would be a good idea to replace the method below with something else like
606  // maybe callback injection
607  return User::newFatalPermissionDeniedStatus( $action )->getErrorsArray()[0];
608  }
609 
618  private function isSameSpecialPage( $name, LinkTarget $page ) {
619  if ( $page->getNamespace() == NS_SPECIAL ) {
620  list( $thisName, /* $subpage */ ) =
621  $this->specialPageFactory->resolveAlias( $page->getDBkey() );
622  if ( $name == $thisName ) {
623  return true;
624  }
625  }
626  return false;
627  }
628 
645  private function checkUserBlock(
646  $action,
647  User $user,
648  $errors,
649  $rigor,
650  $short,
651  LinkTarget $page
652  ) {
653  // Account creation blocks handled at userlogin.
654  // Unblocking handled in SpecialUnblock
655  if ( $rigor === self::RIGOR_QUICK || in_array( $action, [ 'createaccount', 'unblock' ] ) ) {
656  return $errors;
657  }
658 
659  // Optimize for a very common case
660  if ( $action === 'read' && !$this->options->get( 'BlockDisablesLogin' ) ) {
661  return $errors;
662  }
663 
664  if ( $this->options->get( 'EmailConfirmToEdit' )
665  && !$user->isEmailConfirmed()
666  && $action === 'edit'
667  ) {
668  $errors[] = [ 'confirmedittext' ];
669  }
670 
671  $useReplica = ( $rigor !== self::RIGOR_SECURE );
672  $block = $user->getBlock( $useReplica );
673 
674  // If the user does not have a block, or the block they do have explicitly
675  // allows the action (like "read" or "upload").
676  if ( !$block || $block->appliesToRight( $action ) === false ) {
677  return $errors;
678  }
679 
680  // Determine if the user is blocked from this action on this page.
681  // What gets passed into this method is a user right, not an action name.
682  // There is no way to instantiate an action by restriction. However, this
683  // will get the action where the restriction is the same. This may result
684  // in actions being blocked that shouldn't be.
685  $actionObj = null;
686  if ( Action::exists( $action ) ) {
687  // TODO: this drags a ton of dependencies in, would be good to avoid Article
688  // instantiation and decouple it creating an ActionPermissionChecker interface
689  // Creating an action will perform several database queries to ensure that
690  // the action has not been overridden by the content type.
691  // FIXME: avoid use of RequestContext since it drags in User and Title dependencies
692  // probably we may use fake context object since it's unlikely that Action uses it
693  // anyway. It would be nice if we could avoid instantiating the Action at all.
694  $title = Title::newFromLinkTarget( $page, 'clone' );
696  $actionObj = Action::factory(
697  $action,
699  $context
700  );
701  // Ensure that the retrieved action matches the restriction.
702  if ( $actionObj && $actionObj->getRestriction() !== $action ) {
703  $actionObj = null;
704  }
705  }
706 
707  // If no action object is returned, assume that the action requires unblock
708  // which is the default.
709  if ( !$actionObj || $actionObj->requiresUnblock() ) {
710  if ( $this->isBlockedFrom( $user, $page, $useReplica ) ) {
711  // @todo FIXME: Pass the relevant context into this function.
713  $message = $this->blockErrorFormatter->getMessage(
714  $block,
715  $context->getUser(),
717  $context->getRequest()->getIP()
718  );
719  $errors[] = array_merge( [ $message->getKey() ], $message->getParams() );
720  }
721  }
722 
723  return $errors;
724  }
725 
742  private function checkQuickPermissions(
743  $action,
744  User $user,
745  $errors,
746  $rigor,
747  $short,
748  LinkTarget $page
749  ) {
750  // TODO: remove when LinkTarget usage will expand further
751  $title = Title::newFromLinkTarget( $page );
752 
753  if ( !$this->hookRunner->onTitleQuickPermissions( $title, $user, $action,
754  $errors, $rigor !== self::RIGOR_QUICK, $short )
755  ) {
756  return $errors;
757  }
758 
759  $isSubPage = $this->nsInfo->hasSubpages( $title->getNamespace() ) ?
760  strpos( $title->getText(), '/' ) !== false : false;
761 
762  if ( $action == 'create' ) {
763  if (
764  ( $this->nsInfo->isTalk( $title->getNamespace() ) &&
765  !$this->userHasRight( $user, 'createtalk' ) ) ||
766  ( !$this->nsInfo->isTalk( $title->getNamespace() ) &&
767  !$this->userHasRight( $user, 'createpage' ) )
768  ) {
769  $errors[] = $user->isAnon() ? [ 'nocreatetext' ] : [ 'nocreate-loggedin' ];
770  }
771  } elseif ( $action == 'move' ) {
772  if ( !$this->userHasRight( $user, 'move-rootuserpages' )
773  && $title->getNamespace() == NS_USER && !$isSubPage ) {
774  // Show user page-specific message only if the user can move other pages
775  $errors[] = [ 'cant-move-user-page' ];
776  }
777 
778  // Check if user is allowed to move files if it's a file
779  if ( $title->getNamespace() == NS_FILE &&
780  !$this->userHasRight( $user, 'movefile' ) ) {
781  $errors[] = [ 'movenotallowedfile' ];
782  }
783 
784  // Check if user is allowed to move category pages if it's a category page
785  if ( $title->getNamespace() == NS_CATEGORY &&
786  !$this->userHasRight( $user, 'move-categorypages' ) ) {
787  $errors[] = [ 'cant-move-category-page' ];
788  }
789 
790  if ( !$this->userHasRight( $user, 'move' ) ) {
791  // User can't move anything
792  $userCanMove = $this->groupHasPermission( 'user', 'move' );
793  $autoconfirmedCanMove = $this->groupHasPermission( 'autoconfirmed', 'move' );
794  if ( $user->isAnon() && ( $userCanMove || $autoconfirmedCanMove ) ) {
795  // custom message if logged-in users without any special rights can move
796  $errors[] = [ 'movenologintext' ];
797  } else {
798  $errors[] = [ 'movenotallowed' ];
799  }
800  }
801  } elseif ( $action == 'move-target' ) {
802  if ( !$this->userHasRight( $user, 'move' ) ) {
803  // User can't move anything
804  $errors[] = [ 'movenotallowed' ];
805  } elseif ( !$this->userHasRight( $user, 'move-rootuserpages' )
806  && $title->getNamespace() == NS_USER && !$isSubPage ) {
807  // Show user page-specific message only if the user can move other pages
808  $errors[] = [ 'cant-move-to-user-page' ];
809  } elseif ( !$this->userHasRight( $user, 'move-categorypages' )
810  && $title->getNamespace() == NS_CATEGORY ) {
811  // Show category page-specific message only if the user can move other pages
812  $errors[] = [ 'cant-move-to-category-page' ];
813  }
814  } elseif ( !$this->userHasRight( $user, $action ) ) {
815  $errors[] = $this->missingPermissionError( $action, $short );
816  }
817 
818  return $errors;
819  }
820 
839  private function checkPageRestrictions(
840  $action,
841  User $user,
842  $errors,
843  $rigor,
844  $short,
845  LinkTarget $page
846  ) {
847  // TODO: remove & rework upon further use of LinkTarget
848  $title = Title::newFromLinkTarget( $page );
849  foreach ( $title->getRestrictions( $action ) as $right ) {
850  // Backwards compatibility, rewrite sysop -> editprotected
851  if ( $right == 'sysop' ) {
852  $right = 'editprotected';
853  }
854  // Backwards compatibility, rewrite autoconfirmed -> editsemiprotected
855  if ( $right == 'autoconfirmed' ) {
856  $right = 'editsemiprotected';
857  }
858  if ( $right == '' ) {
859  continue;
860  }
861  if ( !$this->userHasRight( $user, $right ) ) {
862  $errors[] = [ 'protectedpagetext', $right, $action ];
863  } elseif ( $title->areRestrictionsCascading() &&
864  !$this->userHasRight( $user, 'protect' ) ) {
865  $errors[] = [ 'protectedpagetext', 'protect', $action ];
866  }
867  }
868 
869  return $errors;
870  }
871 
889  $action,
890  UserIdentity $user,
891  $errors,
892  $rigor,
893  $short,
894  LinkTarget $page
895  ) {
896  // TODO: remove & rework upon further use of LinkTarget
897  $title = Title::newFromLinkTarget( $page );
898  if ( $rigor !== self::RIGOR_QUICK && !$title->isUserConfigPage() ) {
899  list( $cascadingSources, $restrictions ) = $title->getCascadeProtectionSources();
900  # Cascading protection depends on more than this page...
901  # Several cascading protected pages may include this page...
902  # Check each cascading level
903  # This is only for protection restrictions, not for all actions
904  if ( isset( $restrictions[$action] ) ) {
905  foreach ( $restrictions[$action] as $right ) {
906  // Backwards compatibility, rewrite sysop -> editprotected
907  if ( $right == 'sysop' ) {
908  $right = 'editprotected';
909  }
910  // Backwards compatibility, rewrite autoconfirmed -> editsemiprotected
911  if ( $right == 'autoconfirmed' ) {
912  $right = 'editsemiprotected';
913  }
914  if ( $right != '' && !$this->userHasAllRights( $user, 'protect', $right ) ) {
915  $wikiPages = '';
917  foreach ( $cascadingSources as $wikiPage ) {
918  $wikiPages .= '* [[:' . $wikiPage->getPrefixedText() . "]]\n";
919  }
920  $errors[] = [ 'cascadeprotected', count( $cascadingSources ), $wikiPages, $action ];
921  }
922  }
923  }
924  }
925 
926  return $errors;
927  }
928 
945  private function checkActionPermissions(
946  $action,
947  User $user,
948  $errors,
949  $rigor,
950  $short,
951  LinkTarget $page
952  ) {
954 
955  // TODO: remove & rework upon further use of LinkTarget
956  $title = Title::newFromLinkTarget( $page );
957 
958  if ( $action == 'protect' ) {
959  if ( count( $this->getPermissionErrorsInternal( 'edit', $user, $title, $rigor, true ) ) ) {
960  // If they can't edit, they shouldn't protect.
961  $errors[] = [ 'protect-cantedit' ];
962  }
963  } elseif ( $action == 'create' ) {
964  $title_protection = $title->getTitleProtection();
965  if ( $title_protection ) {
966  if ( $title_protection['permission'] == ''
967  || !$this->userHasRight( $user, $title_protection['permission'] )
968  ) {
969  $errors[] = [
970  'titleprotected',
971  // TODO: get rid of the User dependency
972  User::whoIs( $title_protection['user'] ),
973  $title_protection['reason']
974  ];
975  }
976  }
977  } elseif ( $action == 'move' ) {
978  // Check for immobile pages
979  if ( !$this->nsInfo->isMovable( $title->getNamespace() ) ) {
980  // Specific message for this case
981  $nsText = $title->getNsText();
982  if ( $nsText === '' ) {
983  $nsText = wfMessage( 'blanknamespace' )->text();
984  }
985  $errors[] = [ 'immobile-source-namespace', $nsText ];
986  } elseif ( !$title->isMovable() ) {
987  // Less specific message for rarer cases
988  $errors[] = [ 'immobile-source-page' ];
989  }
990  } elseif ( $action == 'move-target' ) {
991  if ( !$this->nsInfo->isMovable( $title->getNamespace() ) ) {
992  $nsText = $title->getNsText();
993  if ( $nsText === '' ) {
994  $nsText = wfMessage( 'blanknamespace' )->text();
995  }
996  $errors[] = [ 'immobile-target-namespace', $nsText ];
997  } elseif ( !$title->isMovable() ) {
998  $errors[] = [ 'immobile-target-page' ];
999  }
1000  } elseif ( $action == 'delete' ) {
1001  $tempErrors = $this->checkPageRestrictions( 'edit', $user, [], $rigor, true, $title );
1002  if ( !$tempErrors ) {
1003  $tempErrors = $this->checkCascadingSourcesRestrictions( 'edit',
1004  $user, $tempErrors, $rigor, true, $title );
1005  }
1006  if ( $tempErrors ) {
1007  // If protection keeps them from editing, they shouldn't be able to delete.
1008  $errors[] = [ 'deleteprotected' ];
1009  }
1010  if ( $rigor !== self::RIGOR_QUICK && $wgDeleteRevisionsLimit
1011  && !$this->userCan( 'bigdelete', $user, $title ) && $title->isBigDeletion()
1012  ) {
1013  $errors[] = [ 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ];
1014  }
1015  } elseif ( $action === 'undelete' ) {
1016  if ( count( $this->getPermissionErrorsInternal( 'edit', $user, $title, $rigor, true ) ) ) {
1017  // Undeleting implies editing
1018  $errors[] = [ 'undelete-cantedit' ];
1019  }
1020  if ( !$title->exists()
1021  && count( $this->getPermissionErrorsInternal( 'create', $user, $title, $rigor, true ) )
1022  ) {
1023  // Undeleting where nothing currently exists implies creating
1024  $errors[] = [ 'undelete-cantcreate' ];
1025  }
1026  }
1027  return $errors;
1028  }
1029 
1047  $action,
1048  UserIdentity $user,
1049  $errors,
1050  $rigor,
1051  $short,
1052  LinkTarget $page
1053  ) {
1054  // TODO: remove & rework upon further use of LinkTarget
1055  $title = Title::newFromLinkTarget( $page );
1056 
1057  # Only 'createaccount' can be performed on special pages,
1058  # which don't actually exist in the DB.
1059  if ( $title->getNamespace() == NS_SPECIAL && $action !== 'createaccount' ) {
1060  $errors[] = [ 'ns-specialprotected' ];
1061  }
1062 
1063  # Check $wgNamespaceProtection for restricted namespaces
1064  if ( $this->isNamespaceProtected( $title->getNamespace(), $user ) ) {
1065  $ns = $title->getNamespace() == NS_MAIN ?
1066  wfMessage( 'nstab-main' )->text() : $title->getNsText();
1067  $errors[] = $title->getNamespace() == NS_MEDIAWIKI ?
1068  [ 'protectedinterface', $action ] : [ 'namespaceprotected', $ns, $action ];
1069  }
1070 
1071  return $errors;
1072  }
1073 
1090  private function checkSiteConfigPermissions(
1091  $action,
1092  User $user,
1093  $errors,
1094  $rigor,
1095  $short,
1096  LinkTarget $page
1097  ) {
1098  // TODO: remove & rework upon further use of LinkTarget
1099  $title = Title::newFromLinkTarget( $page );
1100 
1101  if ( $action != 'patrol' ) {
1102  $error = null;
1103  // Sitewide CSS/JSON/JS/RawHTML changes, like all NS_MEDIAWIKI changes, also require the
1104  // editinterface right. That's implemented as a restriction so no check needed here.
1105  if ( $title->isSiteCssConfigPage() && !$this->userHasRight( $user, 'editsitecss' ) ) {
1106  $error = [ 'sitecssprotected', $action ];
1107  } elseif ( $title->isSiteJsonConfigPage() && !$this->userHasRight( $user, 'editsitejson' ) ) {
1108  $error = [ 'sitejsonprotected', $action ];
1109  } elseif ( $title->isSiteJsConfigPage() && !$this->userHasRight( $user, 'editsitejs' ) ) {
1110  $error = [ 'sitejsprotected', $action ];
1111  }
1112  if ( $title->isRawHtmlMessage() && !$this->userCanEditRawHtmlPage( $user ) ) {
1113  $error = [ 'siterawhtmlprotected', $action ];
1114  }
1115 
1116  if ( $error ) {
1117  if ( $this->userHasRight( $user, 'editinterface' ) ) {
1118  // Most users / site admins will probably find out about the new, more restrictive
1119  // permissions by failing to edit something. Give them more info.
1120  // TODO remove this a few release cycles after 1.32
1121  $error = [ 'interfaceadmin-info', wfMessage( $error[0], $error[1] ) ];
1122  }
1123  $errors[] = $error;
1124  }
1125  }
1126 
1127  return $errors;
1128  }
1129 
1146  private function checkUserConfigPermissions(
1147  $action,
1148  UserIdentity $user,
1149  $errors,
1150  $rigor,
1151  $short,
1152  LinkTarget $page
1153  ) {
1154  // TODO: remove & rework upon further use of LinkTarget
1155  $title = Title::newFromLinkTarget( $page );
1156 
1157  # Protect css/json/js subpages of user pages
1158  # XXX: this might be better using restrictions
1159 
1160  if ( $action === 'patrol' ) {
1161  return $errors;
1162  }
1163 
1164  if ( preg_match( '/^' . preg_quote( $user->getName(), '/' ) . '\//', $title->getText() ) ) {
1165  // Users need editmyuser* to edit their own CSS/JSON/JS subpages.
1166  if (
1167  $title->isUserCssConfigPage()
1168  && !$this->userHasAnyRight( $user, 'editmyusercss', 'editusercss' )
1169  ) {
1170  $errors[] = [ 'mycustomcssprotected', $action ];
1171  } elseif (
1172  $title->isUserJsonConfigPage()
1173  && !$this->userHasAnyRight( $user, 'editmyuserjson', 'edituserjson' )
1174  ) {
1175  $errors[] = [ 'mycustomjsonprotected', $action ];
1176  } elseif (
1177  $title->isUserJsConfigPage()
1178  && !$this->userHasAnyRight( $user, 'editmyuserjs', 'edituserjs' )
1179  ) {
1180  $errors[] = [ 'mycustomjsprotected', $action ];
1181  } elseif (
1182  $title->isUserJsConfigPage()
1183  && !$this->userHasAnyRight( $user, 'edituserjs', 'editmyuserjsredirect' )
1184  ) {
1185  // T207750 - do not allow users to edit a redirect if they couldn't edit the target
1186  $rev = $this->revisionLookup->getRevisionByTitle( $title );
1187  $content = $rev ? $rev->getContent( 'main', RevisionRecord::RAW ) : null;
1188  $target = $content ? $content->getUltimateRedirectTarget() : null;
1189  if ( $target && (
1190  !$target->inNamespace( NS_USER )
1191  || !preg_match( '/^' . preg_quote( $user->getName(), '/' ) . '\//', $target->getText() )
1192  ) ) {
1193  $errors[] = [ 'mycustomjsredirectprotected', $action ];
1194  }
1195  }
1196  } else {
1197  // Users need edituser* to edit others' CSS/JSON/JS subpages, except for
1198  // deletion/suppression which cannot be used for attacks and we want to avoid the
1199  // situation where an unprivileged user can post abusive content on their subpages
1200  // and only very highly privileged users could remove it.
1201  if ( !in_array( $action, [ 'delete', 'deleterevision', 'suppressrevision' ], true ) ) {
1202  if (
1203  $title->isUserCssConfigPage()
1204  && !$this->userHasRight( $user, 'editusercss' )
1205  ) {
1206  $errors[] = [ 'customcssprotected', $action ];
1207  } elseif (
1208  $title->isUserJsonConfigPage()
1209  && !$this->userHasRight( $user, 'edituserjson' )
1210  ) {
1211  $errors[] = [ 'customjsonprotected', $action ];
1212  } elseif (
1213  $title->isUserJsConfigPage()
1214  && !$this->userHasRight( $user, 'edituserjs' )
1215  ) {
1216  $errors[] = [ 'customjsprotected', $action ];
1217  }
1218  }
1219  }
1220 
1221  return $errors;
1222  }
1223 
1234  public function userHasRight( UserIdentity $user, $action = '' ) {
1235  if ( $action === '' ) {
1236  return true; // In the spirit of DWIM
1237  }
1238  // Use strict parameter to avoid matching numeric 0 accidentally inserted
1239  // by misconfiguration: 0 == 'foo'
1240  return in_array( $action, $this->getUserPermissions( $user ), true );
1241  }
1242 
1251  public function userHasAnyRight( UserIdentity $user, ...$actions ) {
1252  foreach ( $actions as $action ) {
1253  if ( $this->userHasRight( $user, $action ) ) {
1254  return true;
1255  }
1256  }
1257  return false;
1258  }
1259 
1268  public function userHasAllRights( UserIdentity $user, ...$actions ) {
1269  foreach ( $actions as $action ) {
1270  if ( !$this->userHasRight( $user, $action ) ) {
1271  return false;
1272  }
1273  }
1274  return true;
1275  }
1276 
1286  public function getUserPermissions( UserIdentity $user ) {
1287  $user = User::newFromIdentity( $user );
1288  $rightsCacheKey = $this->getRightsCacheKey( $user );
1289  if ( !isset( $this->usersRights[ $rightsCacheKey ] ) ) {
1290  $this->usersRights[ $rightsCacheKey ] = $this->getGroupPermissions(
1291  $user->getEffectiveGroups()
1292  );
1293  $this->hookRunner->onUserGetRights( $user, $this->usersRights[ $rightsCacheKey ] );
1294 
1295  // Deny any rights denied by the user's session, unless this
1296  // endpoint has no sessions.
1297  if ( !defined( 'MW_NO_SESSION' ) ) {
1298  // FIXME: $user->getRequest().. need to be replaced with something else
1299  $allowedRights = $user->getRequest()->getSession()->getAllowedUserRights();
1300  if ( $allowedRights !== null ) {
1301  $this->usersRights[ $rightsCacheKey ] = array_intersect(
1302  $this->usersRights[ $rightsCacheKey ],
1303  $allowedRights
1304  );
1305  }
1306  }
1307 
1308  $this->hookRunner->onUserGetRightsRemove(
1309  $user, $this->usersRights[ $rightsCacheKey ] );
1310  // Force reindexation of rights when a hook has unset one of them
1311  $this->usersRights[ $rightsCacheKey ] = array_values(
1312  array_unique( $this->usersRights[ $rightsCacheKey ] )
1313  );
1314 
1315  if (
1316  $user->isLoggedIn() &&
1317  $this->options->get( 'BlockDisablesLogin' ) &&
1318  $user->getBlock()
1319  ) {
1320  $anon = new User;
1321  $this->usersRights[ $rightsCacheKey ] = array_intersect(
1322  $this->usersRights[ $rightsCacheKey ],
1323  $this->getUserPermissions( $anon )
1324  );
1325  }
1326  }
1327  $rights = $this->usersRights[ $rightsCacheKey ];
1328  foreach ( $this->temporaryUserRights[ $user->getId() ] ?? [] as $overrides ) {
1329  $rights = array_values( array_unique( array_merge( $rights, $overrides ) ) );
1330  }
1331  return $rights;
1332  }
1333 
1342  public function invalidateUsersRightsCache( $user = null ) {
1343  if ( $user !== null ) {
1344  $rightsCacheKey = $this->getRightsCacheKey( $user );
1345  if ( isset( $this->usersRights[ $rightsCacheKey ] ) ) {
1346  unset( $this->usersRights[ $rightsCacheKey ] );
1347  }
1348  } else {
1349  $this->usersRights = null;
1350  }
1351  }
1352 
1358  private function getRightsCacheKey( UserIdentity $user ) {
1359  return $user->isRegistered() ? "u:{$user->getId()}" : "anon:{$user->getName()}";
1360  }
1361 
1376  public function groupHasPermission( $group, $role ) {
1377  $groupPermissions = $this->options->get( 'GroupPermissions' );
1378  $revokePermissions = $this->options->get( 'RevokePermissions' );
1379  return isset( $groupPermissions[$group][$role] ) && $groupPermissions[$group][$role] &&
1380  !( isset( $revokePermissions[$group][$role] ) && $revokePermissions[$group][$role] );
1381  }
1382 
1391  public function getGroupPermissions( $groups ) {
1392  $rights = [];
1393  // grant every granted permission first
1394  foreach ( $groups as $group ) {
1395  if ( isset( $this->options->get( 'GroupPermissions' )[$group] ) ) {
1396  $rights = array_merge( $rights,
1397  // array_filter removes empty items
1398  array_keys( array_filter( $this->options->get( 'GroupPermissions' )[$group] ) ) );
1399  }
1400  }
1401  // now revoke the revoked permissions
1402  foreach ( $groups as $group ) {
1403  if ( isset( $this->options->get( 'RevokePermissions' )[$group] ) ) {
1404  $rights = array_diff( $rights,
1405  array_keys( array_filter( $this->options->get( 'RevokePermissions' )[$group] ) ) );
1406  }
1407  }
1408  return array_unique( $rights );
1409  }
1410 
1419  public function getGroupsWithPermission( $role ) {
1420  $allowedGroups = [];
1421  foreach ( array_keys( $this->options->get( 'GroupPermissions' ) ) as $group ) {
1422  if ( $this->groupHasPermission( $group, $role ) ) {
1423  $allowedGroups[] = $group;
1424  }
1425  }
1426  return $allowedGroups;
1427  }
1428 
1444  public function isEveryoneAllowed( $right ) {
1445  // Use the cached results, except in unit tests which rely on
1446  // being able change the permission mid-request
1447  if ( isset( $this->cachedRights[$right] ) ) {
1448  return $this->cachedRights[$right];
1449  }
1450 
1451  if ( !isset( $this->options->get( 'GroupPermissions' )['*'][$right] )
1452  || !$this->options->get( 'GroupPermissions' )['*'][$right] ) {
1453  $this->cachedRights[$right] = false;
1454  return false;
1455  }
1456 
1457  // If it's revoked anywhere, then everyone doesn't have it
1458  foreach ( $this->options->get( 'RevokePermissions' ) as $rights ) {
1459  if ( isset( $rights[$right] ) && $rights[$right] ) {
1460  $this->cachedRights[$right] = false;
1461  return false;
1462  }
1463  }
1464 
1465  // Remove any rights that aren't allowed to the global-session user,
1466  // unless there are no sessions for this endpoint.
1467  if ( !defined( 'MW_NO_SESSION' ) ) {
1468 
1469  // XXX: think what could be done with the below
1470  $allowedRights = SessionManager::getGlobalSession()->getAllowedUserRights();
1471  if ( $allowedRights !== null && !in_array( $right, $allowedRights, true ) ) {
1472  $this->cachedRights[$right] = false;
1473  return false;
1474  }
1475  }
1476 
1477  // Allow extensions to say false
1478  if ( !$this->hookRunner->onUserIsEveryoneAllowed( $right ) ) {
1479  $this->cachedRights[$right] = false;
1480  return false;
1481  }
1482 
1483  $this->cachedRights[$right] = true;
1484  return true;
1485  }
1486 
1494  public function getAllPermissions() {
1495  if ( $this->allRights === null ) {
1496  if ( count( $this->options->get( 'AvailableRights' ) ) ) {
1497  $this->allRights = array_unique( array_merge(
1498  $this->coreRights,
1499  $this->options->get( 'AvailableRights' )
1500  ) );
1501  } else {
1502  $this->allRights = $this->coreRights;
1503  }
1504  $this->hookRunner->onUserGetAllRights( $this->allRights );
1505  }
1506  return $this->allRights;
1507  }
1508 
1515  private function isNamespaceProtected( $index, UserIdentity $user ) {
1516  $namespaceProtection = $this->options->get( 'NamespaceProtection' );
1517  if ( isset( $namespaceProtection[$index] ) ) {
1518  return !$this->userHasAllRights( $user, ...(array)$namespaceProtection[$index] );
1519  }
1520  return false;
1521  }
1522 
1531  public function getNamespaceRestrictionLevels( $index, UserIdentity $user = null ) {
1532  if ( !isset( $this->options->get( 'NamespaceProtection' )[$index] ) ) {
1533  // All levels are valid if there's no namespace restriction.
1534  // But still filter by user, if necessary
1535  $levels = $this->options->get( 'RestrictionLevels' );
1536  if ( $user ) {
1537  $levels = array_values( array_filter( $levels, function ( $level ) use ( $user ) {
1538  $right = $level;
1539  if ( $right == 'sysop' ) {
1540  $right = 'editprotected'; // BC
1541  }
1542  if ( $right == 'autoconfirmed' ) {
1543  $right = 'editsemiprotected'; // BC
1544  }
1545  return $this->userHasRight( $user, $right );
1546  } ) );
1547  }
1548  return $levels;
1549  }
1550 
1551  // $wgNamespaceProtection can require one or more rights to edit the namespace, which
1552  // may be satisfied by membership in multiple groups each giving a subset of those rights.
1553  // A restriction level is redundant if, for any one of the namespace rights, all groups
1554  // giving that right also give the restriction level's right. Or, conversely, a
1555  // restriction level is not redundant if, for every namespace right, there's at least one
1556  // group giving that right without the restriction level's right.
1557  //
1558  // First, for each right, get a list of groups with that right.
1559  $namespaceRightGroups = [];
1560  foreach ( (array)$this->options->get( 'NamespaceProtection' )[$index] as $right ) {
1561  if ( $right == 'sysop' ) {
1562  $right = 'editprotected'; // BC
1563  }
1564  if ( $right == 'autoconfirmed' ) {
1565  $right = 'editsemiprotected'; // BC
1566  }
1567  if ( $right != '' ) {
1568  $namespaceRightGroups[$right] = $this->getGroupsWithPermission( $right );
1569  }
1570  }
1571 
1572  // Now, go through the protection levels one by one.
1573  $usableLevels = [ '' ];
1574  foreach ( $this->options->get( 'RestrictionLevels' ) as $level ) {
1575  $right = $level;
1576  if ( $right == 'sysop' ) {
1577  $right = 'editprotected'; // BC
1578  }
1579  if ( $right == 'autoconfirmed' ) {
1580  $right = 'editsemiprotected'; // BC
1581  }
1582 
1583  if ( $right != '' &&
1584  !isset( $namespaceRightGroups[$right] ) &&
1585  ( !$user || $this->userHasRight( $user, $right ) )
1586  ) {
1587  // Do any of the namespace rights imply the restriction right? (see explanation above)
1588  foreach ( $namespaceRightGroups as $groups ) {
1589  if ( !array_diff( $groups, $this->getGroupsWithPermission( $right ) ) ) {
1590  // Yes, this one does.
1591  continue 2;
1592  }
1593  }
1594  // No, keep the restriction level
1595  $usableLevels[] = $level;
1596  }
1597  }
1598 
1599  return $usableLevels;
1600  }
1601 
1610  private function userCanEditRawHtmlPage( UserIdentity $user ) {
1611  return $this->userHasAllRights( $user, 'editsitecss', 'editsitejs' );
1612  }
1613 
1628  public function addTemporaryUserRights( UserIdentity $user, $rights ) {
1629  $userId = $user->getId();
1630  $nextKey = count( $this->temporaryUserRights[$userId] ?? [] );
1631  $this->temporaryUserRights[$userId][$nextKey] = (array)$rights;
1632  return new ScopedCallback( function () use ( $userId, $nextKey ) {
1633  unset( $this->temporaryUserRights[$userId][$nextKey] );
1634  } );
1635  }
1636 
1647  public function overrideUserRightsForTesting( $user, $rights = [] ) {
1648  if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
1649  throw new Exception( __METHOD__ . ' can not be called outside of tests' );
1650  }
1651  $this->usersRights[ $this->getRightsCacheKey( $user ) ] =
1652  is_array( $rights ) ? $rights : [ $rights ];
1653  }
1654 
1655 }
MediaWiki\Permissions\PermissionManager\$cachedRights
bool[] $cachedRights
Cached rights for isEveryoneAllowed, [ right => allowed ].
Definition: PermissionManager.php:107
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:46
MediaWiki\Permissions\PermissionManager\checkCascadingSourcesRestrictions
checkCascadingSourcesRestrictions( $action, UserIdentity $user, $errors, $rigor, $short, LinkTarget $page)
Check restrictions on cascading pages.
Definition: PermissionManager.php:888
User\isAnon
isAnon()
Get whether the user is anonymous.
Definition: User.php:3225
MediaWiki\Permissions\PermissionManager\checkSpecialsAndNSPermissions
checkSpecialsAndNSPermissions( $action, UserIdentity $user, $errors, $rigor, $short, LinkTarget $page)
Check permissions on special pages & namespaces.
Definition: PermissionManager.php:1046
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:362
User\newFatalPermissionDeniedStatus
static newFatalPermissionDeniedStatus( $permission)
Factory function for fatal permission-denied errors.
Definition: User.php:4807
MediaWiki\Permissions\PermissionManager\userCan
userCan( $action, User $user, LinkTarget $page, $rigor=self::RIGOR_SECURE)
Can $user perform $action on a page?
Definition: PermissionManager.php:242
MediaWiki\Block\BlockErrorFormatter
A service class for getting formatted information about a block.
Definition: BlockErrorFormatter.php:34
MediaWiki\SpecialPage\SpecialPageFactory
Factory for handling the special page list and generating SpecialPage objects.
Definition: SpecialPageFactory.php:65
MessageSpecifier
Definition: MessageSpecifier.php:21
Action\exists
static exists(string $name)
Check if a given action is recognised, even if it's disabled.
Definition: Action.php:204
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:599
MediaWiki\Permissions\PermissionManager\checkPermissionHooks
checkPermissionHooks( $action, User $user, $errors, $rigor, $short, LinkTarget $page)
Check various permission hooks.
Definition: PermissionManager.php:435
NS_FILE
const NS_FILE
Definition: Defines.php:75
MediaWiki\Permissions\PermissionManager\userHasRight
userHasRight(UserIdentity $user, $action='')
Testing a permission.
Definition: PermissionManager.php:1234
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1198
MediaWiki\Permissions\PermissionManager\$coreRights
$coreRights
Array of Strings Core rights.
Definition: PermissionManager.php:115
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:90
User\newFromIdentity
static newFromIdentity(UserIdentity $identity)
Returns a User object corresponding to the given UserIdentity.
Definition: User.php:591
Action\factory
static factory(?string $action, Page $article, IContextSource $context=null)
Get an appropriate Action subclass for the given action.
Definition: Action.php:113
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:32
Revision\RevisionLookup
Service for looking up page revisions.
Definition: RevisionLookup.php:38
Action
Actions are things which can be done to pages (edit, delete, rollback, etc).
Definition: Action.php:41
NS_MAIN
const NS_MAIN
Definition: Defines.php:69
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:58
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:1342
MediaWiki\Linker\LinkTarget\getNamespace
getNamespace()
Get the namespace index.
User\getTalkPage
getTalkPage()
Get this user's talk page title.
Definition: User.php:4024
MediaWiki\Permissions\PermissionManager\resultToError
resultToError( $errors, $result)
Add the resulting error code to the errors array.
Definition: PermissionManager.php:475
MediaWiki\Permissions\PermissionManager\$revisionLookup
RevisionLookup $revisionLookup
Definition: PermissionManager.php:83
MediaWiki\Config\ServiceOptions
A class for passing options to services.
Definition: ServiceOptions.php:25
MediaWiki\Permissions\PermissionManager\$hookRunner
HookRunner $hookRunner
Definition: PermissionManager.php:95
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:1146
MediaWiki\Permissions\PermissionManager\$usersRights
string[][] $usersRights
Cached user rights.
Definition: PermissionManager.php:98
MediaWiki\Permissions\PermissionManager\$allRights
string[] null $allRights
Cached results of getAllRights()
Definition: PermissionManager.php:89
$wgLang
$wgLang
Definition: Setup.php:781
MediaWiki\Permissions\PermissionManager\isSameSpecialPage
isSameSpecialPage( $name, LinkTarget $page)
Returns true if this title resolves to the named special page.
Definition: PermissionManager.php:618
User\isHidden
isHidden()
Check if user account is hidden.
Definition: User.php:2096
MediaWiki\Permissions\PermissionManager\getRightsCacheKey
getRightsCacheKey(UserIdentity $user)
Gets a unique key for user rights cache.
Definition: PermissionManager.php:1358
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:1531
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:1515
Revision\RevisionRecord\RAW
const RAW
Definition: RevisionRecord.php:60
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:839
MediaWiki\Permissions\PermissionManager\$specialPageFactory
SpecialPageFactory $specialPageFactory
Definition: PermissionManager.php:80
MediaWiki\Permissions\PermissionManager\$nsInfo
NamespaceInfo $nsInfo
Definition: PermissionManager.php:86
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:742
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:83
RequestContext
Group all the pieces relevant to the context of a request into one instance.
Definition: RequestContext.php:34
$wgDeleteRevisionsLimit
$wgDeleteRevisionsLimit
Optional to restrict deletion of pages with higher revision counts to users with the 'bigdelete' perm...
Definition: DefaultSettings.php:5894
User\getBlock
getBlock( $fromReplica=true)
Get the block affecting the user, or null if the user is not blocked.
Definition: User.php:1978
MediaWiki\Permissions\PermissionManager\$blockErrorFormatter
BlockErrorFormatter $blockErrorFormatter
Definition: PermissionManager.php:92
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:645
MediaWiki\Permissions\PermissionManager\checkActionPermissions
checkActionPermissions( $action, User $user, $errors, $rigor, $short, LinkTarget $page)
Check action permissions not already checked in checkQuickPermissions.
Definition: PermissionManager.php:945
MediaWiki\Permissions\PermissionManager\isEveryoneAllowed
isEveryoneAllowed( $right)
Check if all users may be assumed to have the given permission.
Definition: PermissionManager.php:1444
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:511
MediaWiki\Permissions\PermissionManager\getUserPermissions
getUserPermissions(UserIdentity $user)
Get the permissions this user has.
Definition: PermissionManager.php:1286
MediaWiki\Session\SessionManager\getGlobalSession
static getGlobalSession()
Get the "global" session.
Definition: SessionManager.php:114
MediaWiki\Permissions\PermissionManager
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()-...
Definition: PermissionManager.php:49
$content
$content
Definition: router.php:76
User\whoIs
static whoIs( $id)
Get the username corresponding to a given user ID.
Definition: User.php:864
MediaWiki\Permissions\PermissionManager\getAllPermissions
getAllPermissions()
Get a list of all available permissions.
Definition: PermissionManager.php:1494
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:39
MediaWiki\Permissions\PermissionManager\getGroupsWithPermission
getGroupsWithPermission( $role)
Get all the groups who have a given permission.
Definition: PermissionManager.php:1419
MediaWiki\Session\SessionManager
This serves as the entry point to the MediaWiki session handling system.
Definition: SessionManager.php:52
MediaWiki\Permissions\PermissionManager\quickUserCan
quickUserCan( $action, User $user, LinkTarget $page)
A convenience method for calling PermissionManager::userCan with PermissionManager::RIGOR_QUICK.
Definition: PermissionManager.php:261
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:1628
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:282
MediaWiki\Permissions\PermissionManager\userCanEditRawHtmlPage
userCanEditRawHtmlPage(UserIdentity $user)
Check if user is allowed to edit sitewide pages that contain raw HTML.
Definition: PermissionManager.php:1610
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:451
Title\newFromLinkTarget
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Definition: Title.php:284
MediaWiki\Permissions\PermissionManager\checkSiteConfigPermissions
checkSiteConfigPermissions( $action, User $user, $errors, $rigor, $short, LinkTarget $page)
Check sitewide CSS/JSON/JS permissions.
Definition: PermissionManager.php:1090
MediaWiki\Permissions\PermissionManager\groupHasPermission
groupHasPermission( $group, $role)
Check, if the given group has the given permission.
Definition: PermissionManager.php:1376
MediaWiki\$action
string $action
Cache what action this request is.
Definition: MediaWiki.php:45
Title
Represents a title within MediaWiki.
Definition: Title.php:42
MediaWiki\User\UserIdentity\getId
getId()
MediaWiki\Permissions\PermissionManager\__construct
__construct(ServiceOptions $options, SpecialPageFactory $specialPageFactory, RevisionLookup $revisionLookup, NamespaceInfo $nsInfo, BlockErrorFormatter $blockErrorFormatter, HookContainer $hookContainer)
Definition: PermissionManager.php:206
MediaWiki\Permissions\PermissionManager\userHasAllRights
userHasAllRights(UserIdentity $user,... $actions)
Check if user is allowed to make all actions.
Definition: PermissionManager.php:1268
User\isEmailConfirmed
isEmailConfirmed()
Is this user's e-mail address valid-looking and confirmed within limits of the current site configura...
Definition: User.php:4359
User\isAllowUsertalk
isAllowUsertalk()
Checks if usertalk is allowed.
Definition: User.php:4863
NS_USER
const NS_USER
Definition: Defines.php:71
IContextSource\getRequest
getRequest()
MediaWiki\HookContainer\HookContainer
HookContainer class.
Definition: HookContainer.php:44
NamespaceInfo
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
Definition: NamespaceInfo.php:35
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:77
MediaWiki\HookContainer\HookRunner
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
Definition: HookRunner.php:23
Article
Class for viewing MediaWiki article and history.
Definition: Article.php:46
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:55
MediaWiki\Permissions\PermissionManager\$temporaryUserRights
string[][][] $temporaryUserRights
Temporary user rights, valid for the current request only.
Definition: PermissionManager.php:104
MediaWiki\Permissions\PermissionManager\userHasAnyRight
userHasAnyRight(UserIdentity $user,... $actions)
Check if user is allowed to make any action.
Definition: PermissionManager.php:1251
MediaWiki\Permissions\PermissionManager\getGroupPermissions
getGroupPermissions( $groups)
Get the permissions associated with a given list of groups.
Definition: PermissionManager.php:1391
MediaWiki\Permissions\PermissionManager\$options
ServiceOptions $options
Definition: PermissionManager.php:60
IContextSource\getLanguage
getLanguage()
MediaWiki\Permissions\PermissionManager\overrideUserRightsForTesting
overrideUserRightsForTesting( $user, $rights=[])
Overrides user permissions cache.
Definition: PermissionManager.php:1647
MediaWiki\Config\ServiceOptions\assertRequiredOptions
assertRequiredOptions(array $expectedKeys)
Assert that the list of options provided in this instance exactly match $expectedKeys,...
Definition: ServiceOptions.php:62
MediaWiki\Permissions
Article\newFromTitle
static newFromTitle( $title, IContextSource $context)
Create an Article object of the appropriate class for the given page.
Definition: Article.php:195
MediaWiki\Permissions\PermissionManager\isBlockedFrom
isBlockedFrom(User $user, LinkTarget $page, $fromReplica=false)
Check if user is blocked from editing a particular article.
Definition: PermissionManager.php:316