MediaWiki  master
PermissionManager.php
Go to the documentation of this file.
1 <?php
21 
22 use Action;
24 use Hooks;
35 use Title;
36 use User;
39 
47 
49  const RIGOR_QUICK = 'quick';
50 
52  const RIGOR_FULL = 'full';
53 
55  const RIGOR_SECURE = 'secure';
56 
58  private $specialPageFactory;
59 
61  private $revisionLookup;
62 
64  private $whitelistRead;
65 
68 
71 
74 
76  private $nsInfo;
77 
80 
83 
86 
88  private $allRights = false;
89 
91  private $usersRights = null;
92 
97  private $temporaryUserRights = [];
98 
100  private $cachedRights = [];
101 
108  private $coreRights = [
109  'apihighlimits',
110  'applychangetags',
111  'autoconfirmed',
112  'autocreateaccount',
113  'autopatrol',
114  'bigdelete',
115  'block',
116  'blockemail',
117  'bot',
118  'browsearchive',
119  'changetags',
120  'createaccount',
121  'createpage',
122  'createtalk',
123  'delete',
124  'deletechangetags',
125  'deletedhistory',
126  'deletedtext',
127  'deletelogentry',
128  'deleterevision',
129  'edit',
130  'editcontentmodel',
131  'editinterface',
132  'editprotected',
133  'editmyoptions',
134  'editmyprivateinfo',
135  'editmyusercss',
136  'editmyuserjson',
137  'editmyuserjs',
138  'editmyuserjsredirect',
139  'editmywatchlist',
140  'editsemiprotected',
141  'editsitecss',
142  'editsitejson',
143  'editsitejs',
144  'editusercss',
145  'edituserjson',
146  'edituserjs',
147  'hideuser',
148  'import',
149  'importupload',
150  'ipblock-exempt',
151  'managechangetags',
152  'markbotedits',
153  'mergehistory',
154  'minoredit',
155  'move',
156  'movefile',
157  'move-categorypages',
158  'move-rootuserpages',
159  'move-subpages',
160  'nominornewtalk',
161  'noratelimit',
162  'override-export-depth',
163  'pagelang',
164  'patrol',
165  'patrolmarks',
166  'protect',
167  'purge',
168  'read',
169  'reupload',
170  'reupload-own',
171  'reupload-shared',
172  'rollback',
173  'sendemail',
174  'siteadmin',
175  'suppressionlog',
176  'suppressredirect',
177  'suppressrevision',
178  'unblockself',
179  'undelete',
180  'unwatchedpages',
181  'upload',
182  'upload_by_url',
183  'userrights',
184  'userrights-interwiki',
185  'viewmyprivateinfo',
186  'viewmywatchlist',
187  'viewsuppressed',
188  'writeapi',
189  ];
190 
203  public function __construct(
214  ) {
215  $this->specialPageFactory = $specialPageFactory;
216  $this->revisionLookup = $revisionLookup;
217  $this->whitelistRead = $whitelistRead;
218  $this->whitelistReadRegexp = $whitelistReadRegexp;
219  $this->emailConfirmToEdit = $emailConfirmToEdit;
220  $this->blockDisablesLogin = $blockDisablesLogin;
221  $this->groupPermissions = $groupPermissions;
222  $this->revokePermissions = $revokePermissions;
223  $this->availableRights = $availableRights;
224  $this->nsInfo = $nsInfo;
225  }
226 
246  public function userCan( $action, User $user, LinkTarget $page, $rigor = self::RIGOR_SECURE ) {
247  return !count( $this->getPermissionErrorsInternal( $action, $user, $page, $rigor, true ) );
248  }
249 
267  public function getPermissionErrors(
268  $action,
269  User $user,
270  LinkTarget $page,
271  $rigor = self::RIGOR_SECURE,
272  $ignoreErrors = []
273  ) {
274  $errors = $this->getPermissionErrorsInternal( $action, $user, $page, $rigor );
275 
276  // Remove the errors being ignored.
277  foreach ( $errors as $index => $error ) {
278  $errKey = is_array( $error ) ? $error[0] : $error;
279 
280  if ( in_array( $errKey, $ignoreErrors ) ) {
281  unset( $errors[$index] );
282  }
283  if ( $errKey instanceof MessageSpecifier && in_array( $errKey->getKey(), $ignoreErrors ) ) {
284  unset( $errors[$index] );
285  }
286  }
287 
288  return $errors;
289  }
290 
300  public function isBlockedFrom( User $user, LinkTarget $page, $fromReplica = false ) {
301  $blocked = $user->isHidden();
302 
303  // TODO: remove upon further migration to LinkTarget
304  $title = Title::newFromLinkTarget( $page );
305 
306  if ( !$blocked ) {
307  $block = $user->getBlock( $fromReplica );
308  if ( $block ) {
309  // Special handling for a user's own talk page. The block is not aware
310  // of the user, so this must be done here.
311  if ( $title->equals( $user->getTalkPage() ) ) {
312  $blocked = $block->appliesToUsertalk( $title );
313  } else {
314  $blocked = $block->appliesToTitle( $title );
315  }
316  }
317  }
318 
319  // only for the purpose of the hook. We really don't need this here.
320  $allowUsertalk = $user->isAllowUsertalk();
321 
322  Hooks::run( 'UserIsBlockedFrom', [ $user, $title, &$blocked, &$allowUsertalk ] );
323 
324  return $blocked;
325  }
326 
344  private function getPermissionErrorsInternal(
345  $action,
346  User $user,
347  LinkTarget $page,
348  $rigor = self::RIGOR_SECURE,
349  $short = false
350  ) {
351  if ( !in_array( $rigor, [ self::RIGOR_QUICK, self::RIGOR_FULL, self::RIGOR_SECURE ] ) ) {
352  throw new Exception( "Invalid rigor parameter '$rigor'." );
353  }
354 
355  # Read has special handling
356  if ( $action == 'read' ) {
357  $checks = [
358  'checkPermissionHooks',
359  'checkReadPermissions',
360  'checkUserBlock', // for wgBlockDisablesLogin
361  ];
362  # Don't call checkSpecialsAndNSPermissions, checkSiteConfigPermissions
363  # or checkUserConfigPermissions here as it will lead to duplicate
364  # error messages. This is okay to do since anywhere that checks for
365  # create will also check for edit, and those checks are called for edit.
366  } elseif ( $action == 'create' ) {
367  $checks = [
368  'checkQuickPermissions',
369  'checkPermissionHooks',
370  'checkPageRestrictions',
371  'checkCascadingSourcesRestrictions',
372  'checkActionPermissions',
373  'checkUserBlock'
374  ];
375  } else {
376  $checks = [
377  'checkQuickPermissions',
378  'checkPermissionHooks',
379  'checkSpecialsAndNSPermissions',
380  'checkSiteConfigPermissions',
381  'checkUserConfigPermissions',
382  'checkPageRestrictions',
383  'checkCascadingSourcesRestrictions',
384  'checkActionPermissions',
385  'checkUserBlock'
386  ];
387  }
388 
389  $errors = [];
390  foreach ( $checks as $method ) {
391  $errors = $this->$method( $action, $user, $errors, $rigor, $short, $page );
392 
393  if ( $short && $errors !== [] ) {
394  break;
395  }
396  }
397 
398  return $errors;
399  }
400 
417  private function checkPermissionHooks(
418  $action,
419  User $user,
420  $errors,
421  $rigor,
422  $short,
423  LinkTarget $page
424  ) {
425  // TODO: remove when LinkTarget usage will expand further
426  $title = Title::newFromLinkTarget( $page );
427  // Use getUserPermissionsErrors instead
428  $result = '';
429  if ( !Hooks::run( 'userCan', [ &$title, &$user, $action, &$result ] ) ) {
430  return $result ? [] : [ [ 'badaccess-group0' ] ];
431  }
432  // Check getUserPermissionsErrors hook
433  if ( !Hooks::run( 'getUserPermissionsErrors', [ &$title, &$user, $action, &$result ] ) ) {
434  $errors = $this->resultToError( $errors, $result );
435  }
436  // Check getUserPermissionsErrorsExpensive hook
437  if (
438  $rigor !== self::RIGOR_QUICK
439  && !( $short && count( $errors ) > 0 )
440  && !Hooks::run( 'getUserPermissionsErrorsExpensive', [ &$title, &$user, $action, &$result ] )
441  ) {
442  $errors = $this->resultToError( $errors, $result );
443  }
444 
445  return $errors;
446  }
447 
456  private function resultToError( $errors, $result ) {
457  if ( is_array( $result ) && count( $result ) && !is_array( $result[0] ) ) {
458  // A single array representing an error
459  $errors[] = $result;
460  } elseif ( is_array( $result ) && is_array( $result[0] ) ) {
461  // A nested array representing multiple errors
462  $errors = array_merge( $errors, $result );
463  } elseif ( $result !== '' && is_string( $result ) ) {
464  // A string representing a message-id
465  $errors[] = [ $result ];
466  } elseif ( $result instanceof MessageSpecifier ) {
467  // A message specifier representing an error
468  $errors[] = [ $result ];
469  } elseif ( $result === false ) {
470  // a generic "We don't want them to do that"
471  $errors[] = [ 'badaccess-group0' ];
472  }
473  return $errors;
474  }
475 
492  private function checkReadPermissions(
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 
503  $whitelisted = false;
504  if ( User::isEveryoneAllowed( 'read' ) ) {
505  # Shortcut for public wikis, allows skipping quite a bit of code
506  $whitelisted = true;
507  } elseif ( $user->isAllowed( 'read' ) ) {
508  # If the user is allowed to read pages, he is allowed to read all pages
509  $whitelisted = true;
510  } elseif ( $this->isSameSpecialPage( 'Userlogin', $title )
511  || $this->isSameSpecialPage( 'PasswordReset', $title )
512  || $this->isSameSpecialPage( 'Userlogout', $title )
513  ) {
514  # Always grant access to the login page.
515  # Even anons need to be able to log in.
516  $whitelisted = true;
517  } elseif ( is_array( $this->whitelistRead ) && count( $this->whitelistRead ) ) {
518  # Time to check the whitelist
519  # Only do these checks is there's something to check against
520  $name = $title->getPrefixedText();
521  $dbName = $title->getPrefixedDBkey();
522 
523  // Check for explicit whitelisting with and without underscores
524  if ( in_array( $name, $this->whitelistRead, true )
525  || in_array( $dbName, $this->whitelistRead, true ) ) {
526  $whitelisted = true;
527  } elseif ( $title->getNamespace() == NS_MAIN ) {
528  # Old settings might have the title prefixed with
529  # a colon for main-namespace pages
530  if ( in_array( ':' . $name, $this->whitelistRead ) ) {
531  $whitelisted = true;
532  }
533  } elseif ( $title->isSpecialPage() ) {
534  # If it's a special page, ditch the subpage bit and check again
535  $name = $title->getDBkey();
536  list( $name, /* $subpage */ ) =
537  $this->specialPageFactory->resolveAlias( $name );
538  if ( $name ) {
539  $pure = SpecialPage::getTitleFor( $name )->getPrefixedText();
540  if ( in_array( $pure, $this->whitelistRead, true ) ) {
541  $whitelisted = true;
542  }
543  }
544  }
545  }
546 
547  if ( !$whitelisted && is_array( $this->whitelistReadRegexp )
548  && !empty( $this->whitelistReadRegexp ) ) {
549  $name = $title->getPrefixedText();
550  // Check for regex whitelisting
551  foreach ( $this->whitelistReadRegexp as $listItem ) {
552  if ( preg_match( $listItem, $name ) ) {
553  $whitelisted = true;
554  break;
555  }
556  }
557  }
558 
559  if ( !$whitelisted ) {
560  # If the title is not whitelisted, give extensions a chance to do so...
561  Hooks::run( 'TitleReadWhitelist', [ $title, $user, &$whitelisted ] );
562  if ( !$whitelisted ) {
563  $errors[] = $this->missingPermissionError( $action, $short );
564  }
565  }
566 
567  return $errors;
568  }
569 
578  private function missingPermissionError( $action, $short ) {
579  // We avoid expensive display logic for quickUserCan's and such
580  if ( $short ) {
581  return [ 'badaccess-group0' ];
582  }
583 
584  // TODO: it would be a good idea to replace the method below with something else like
585  // maybe callback injection
586  return User::newFatalPermissionDeniedStatus( $action )->getErrorsArray()[0];
587  }
588 
597  private function isSameSpecialPage( $name, LinkTarget $page ) {
598  if ( $page->getNamespace() == NS_SPECIAL ) {
599  list( $thisName, /* $subpage */ ) =
600  $this->specialPageFactory->resolveAlias( $page->getDBkey() );
601  if ( $name == $thisName ) {
602  return true;
603  }
604  }
605  return false;
606  }
607 
624  private function checkUserBlock(
625  $action,
626  User $user,
627  $errors,
628  $rigor,
629  $short,
630  LinkTarget $page
631  ) {
632  // Account creation blocks handled at userlogin.
633  // Unblocking handled in SpecialUnblock
634  if ( $rigor === self::RIGOR_QUICK || in_array( $action, [ 'createaccount', 'unblock' ] ) ) {
635  return $errors;
636  }
637 
638  // Optimize for a very common case
639  if ( $action === 'read' && !$this->blockDisablesLogin ) {
640  return $errors;
641  }
642 
643  if ( $this->emailConfirmToEdit
644  && !$user->isEmailConfirmed()
645  && $action === 'edit'
646  ) {
647  $errors[] = [ 'confirmedittext' ];
648  }
649 
650  $useReplica = ( $rigor !== self::RIGOR_SECURE );
651  $block = $user->getBlock( $useReplica );
652 
653  // If the user does not have a block, or the block they do have explicitly
654  // allows the action (like "read" or "upload").
655  if ( !$block || $block->appliesToRight( $action ) === false ) {
656  return $errors;
657  }
658 
659  // Determine if the user is blocked from this action on this page.
660  // What gets passed into this method is a user right, not an action name.
661  // There is no way to instantiate an action by restriction. However, this
662  // will get the action where the restriction is the same. This may result
663  // in actions being blocked that shouldn't be.
664  $actionObj = null;
665  if ( Action::exists( $action ) ) {
666  // TODO: this drags a ton of dependencies in, would be good to avoid WikiPage
667  // instantiation and decouple it creating an ActionPermissionChecker interface
668  $wikiPage = WikiPage::factory( Title::newFromLinkTarget( $page, 'clone' ) );
669  // Creating an action will perform several database queries to ensure that
670  // the action has not been overridden by the content type.
671  // FIXME: avoid use of RequestContext since it drags in User and Title dependencies
672  // probably we may use fake context object since it's unlikely that Action uses it
673  // anyway. It would be nice if we could avoid instantiating the Action at all.
674  $actionObj = Action::factory( $action, $wikiPage, RequestContext::getMain() );
675  // Ensure that the retrieved action matches the restriction.
676  if ( $actionObj && $actionObj->getRestriction() !== $action ) {
677  $actionObj = null;
678  }
679  }
680 
681  // If no action object is returned, assume that the action requires unblock
682  // which is the default.
683  if ( !$actionObj || $actionObj->requiresUnblock() ) {
684  if ( $this->isBlockedFrom( $user, $page, $useReplica ) ) {
685  // @todo FIXME: Pass the relevant context into this function.
686  $errors[] = $block->getPermissionsError( RequestContext::getMain() );
687  }
688  }
689 
690  return $errors;
691  }
692 
709  private function checkQuickPermissions(
710  $action,
711  User $user,
712  $errors,
713  $rigor,
714  $short,
715  LinkTarget $page
716  ) {
717  // TODO: remove when LinkTarget usage will expand further
718  $title = Title::newFromLinkTarget( $page );
719 
720  if ( !Hooks::run( 'TitleQuickPermissions',
721  [ $title, $user, $action, &$errors, ( $rigor !== self::RIGOR_QUICK ), $short ] )
722  ) {
723  return $errors;
724  }
725 
726  $isSubPage = $this->nsInfo->hasSubpages( $title->getNamespace() ) ?
727  strpos( $title->getText(), '/' ) !== false : false;
728 
729  if ( $action == 'create' ) {
730  if (
731  ( $this->nsInfo->isTalk( $title->getNamespace() ) &&
732  !$user->isAllowed( 'createtalk' ) ) ||
733  ( !$this->nsInfo->isTalk( $title->getNamespace() ) &&
734  !$user->isAllowed( 'createpage' ) )
735  ) {
736  $errors[] = $user->isAnon() ? [ 'nocreatetext' ] : [ 'nocreate-loggedin' ];
737  }
738  } elseif ( $action == 'move' ) {
739  if ( !$user->isAllowed( 'move-rootuserpages' )
740  && $title->getNamespace() == NS_USER && !$isSubPage ) {
741  // Show user page-specific message only if the user can move other pages
742  $errors[] = [ 'cant-move-user-page' ];
743  }
744 
745  // Check if user is allowed to move files if it's a file
746  if ( $title->getNamespace() == NS_FILE && !$user->isAllowed( 'movefile' ) ) {
747  $errors[] = [ 'movenotallowedfile' ];
748  }
749 
750  // Check if user is allowed to move category pages if it's a category page
751  if ( $title->getNamespace() == NS_CATEGORY && !$user->isAllowed( 'move-categorypages' ) ) {
752  $errors[] = [ 'cant-move-category-page' ];
753  }
754 
755  if ( !$user->isAllowed( 'move' ) ) {
756  // User can't move anything
757  $userCanMove = User::groupHasPermission( 'user', 'move' );
758  $autoconfirmedCanMove = User::groupHasPermission( 'autoconfirmed', 'move' );
759  if ( $user->isAnon() && ( $userCanMove || $autoconfirmedCanMove ) ) {
760  // custom message if logged-in users without any special rights can move
761  $errors[] = [ 'movenologintext' ];
762  } else {
763  $errors[] = [ 'movenotallowed' ];
764  }
765  }
766  } elseif ( $action == 'move-target' ) {
767  if ( !$user->isAllowed( 'move' ) ) {
768  // User can't move anything
769  $errors[] = [ 'movenotallowed' ];
770  } elseif ( !$user->isAllowed( 'move-rootuserpages' )
771  && $title->getNamespace() == NS_USER && !$isSubPage ) {
772  // Show user page-specific message only if the user can move other pages
773  $errors[] = [ 'cant-move-to-user-page' ];
774  } elseif ( !$user->isAllowed( 'move-categorypages' )
775  && $title->getNamespace() == NS_CATEGORY ) {
776  // Show category page-specific message only if the user can move other pages
777  $errors[] = [ 'cant-move-to-category-page' ];
778  }
779  } elseif ( !$user->isAllowed( $action ) ) {
780  $errors[] = $this->missingPermissionError( $action, $short );
781  }
782 
783  return $errors;
784  }
785 
804  private function checkPageRestrictions(
805  $action,
806  User $user,
807  $errors,
808  $rigor,
809  $short,
810  LinkTarget $page
811  ) {
812  // TODO: remove & rework upon further use of LinkTarget
813  $title = Title::newFromLinkTarget( $page );
814  foreach ( $title->getRestrictions( $action ) as $right ) {
815  // Backwards compatibility, rewrite sysop -> editprotected
816  if ( $right == 'sysop' ) {
817  $right = 'editprotected';
818  }
819  // Backwards compatibility, rewrite autoconfirmed -> editsemiprotected
820  if ( $right == 'autoconfirmed' ) {
821  $right = 'editsemiprotected';
822  }
823  if ( $right == '' ) {
824  continue;
825  }
826  if ( !$user->isAllowed( $right ) ) {
827  $errors[] = [ 'protectedpagetext', $right, $action ];
828  } elseif ( $title->areRestrictionsCascading() && !$user->isAllowed( 'protect' ) ) {
829  $errors[] = [ 'protectedpagetext', 'protect', $action ];
830  }
831  }
832 
833  return $errors;
834  }
835 
853  $action,
854  User $user,
855  $errors,
856  $rigor,
857  $short,
858  LinkTarget $page
859  ) {
860  // TODO: remove & rework upon further use of LinkTarget
861  $title = Title::newFromLinkTarget( $page );
862  if ( $rigor !== self::RIGOR_QUICK && !$title->isUserConfigPage() ) {
863  # We /could/ use the protection level on the source page, but it's
864  # fairly ugly as we have to establish a precedence hierarchy for pages
865  # included by multiple cascade-protected pages. So just restrict
866  # it to people with 'protect' permission, as they could remove the
867  # protection anyway.
868  list( $cascadingSources, $restrictions ) = $title->getCascadeProtectionSources();
869  # Cascading protection depends on more than this page...
870  # Several cascading protected pages may include this page...
871  # Check each cascading level
872  # This is only for protection restrictions, not for all actions
873  if ( isset( $restrictions[$action] ) ) {
874  foreach ( $restrictions[$action] as $right ) {
875  // Backwards compatibility, rewrite sysop -> editprotected
876  if ( $right == 'sysop' ) {
877  $right = 'editprotected';
878  }
879  // Backwards compatibility, rewrite autoconfirmed -> editsemiprotected
880  if ( $right == 'autoconfirmed' ) {
881  $right = 'editsemiprotected';
882  }
883  if ( $right != '' && !$user->isAllowedAll( 'protect', $right ) ) {
884  $wikiPages = '';
886  foreach ( $cascadingSources as $wikiPage ) {
887  $wikiPages .= '* [[:' . $wikiPage->getPrefixedText() . "]]\n";
888  }
889  $errors[] = [ 'cascadeprotected', count( $cascadingSources ), $wikiPages, $action ];
890  }
891  }
892  }
893  }
894 
895  return $errors;
896  }
897 
914  private function checkActionPermissions(
915  $action,
916  User $user,
917  $errors,
918  $rigor,
919  $short,
920  LinkTarget $page
921  ) {
923 
924  // TODO: remove & rework upon further use of LinkTarget
925  $title = Title::newFromLinkTarget( $page );
926 
927  if ( $action == 'protect' ) {
928  if ( count( $this->getPermissionErrorsInternal( 'edit', $user, $title, $rigor, true ) ) ) {
929  // If they can't edit, they shouldn't protect.
930  $errors[] = [ 'protect-cantedit' ];
931  }
932  } elseif ( $action == 'create' ) {
933  $title_protection = $title->getTitleProtection();
934  if ( $title_protection ) {
935  if ( $title_protection['permission'] == ''
936  || !$user->isAllowed( $title_protection['permission'] )
937  ) {
938  $errors[] = [
939  'titleprotected',
940  // TODO: get rid of the User dependency
941  User::whoIs( $title_protection['user'] ),
942  $title_protection['reason']
943  ];
944  }
945  }
946  } elseif ( $action == 'move' ) {
947  // Check for immobile pages
948  if ( !$this->nsInfo->isMovable( $title->getNamespace() ) ) {
949  // Specific message for this case
950  $errors[] = [ 'immobile-source-namespace', $title->getNsText() ];
951  } elseif ( !$title->isMovable() ) {
952  // Less specific message for rarer cases
953  $errors[] = [ 'immobile-source-page' ];
954  }
955  } elseif ( $action == 'move-target' ) {
956  if ( !$this->nsInfo->isMovable( $title->getNamespace() ) ) {
957  $errors[] = [ 'immobile-target-namespace', $title->getNsText() ];
958  } elseif ( !$title->isMovable() ) {
959  $errors[] = [ 'immobile-target-page' ];
960  }
961  } elseif ( $action == 'delete' ) {
962  $tempErrors = $this->checkPageRestrictions( 'edit', $user, [], $rigor, true, $title );
963  if ( !$tempErrors ) {
964  $tempErrors = $this->checkCascadingSourcesRestrictions( 'edit',
965  $user, $tempErrors, $rigor, true, $title );
966  }
967  if ( $tempErrors ) {
968  // If protection keeps them from editing, they shouldn't be able to delete.
969  $errors[] = [ 'deleteprotected' ];
970  }
971  if ( $rigor !== self::RIGOR_QUICK && $wgDeleteRevisionsLimit
972  && !$this->userCan( 'bigdelete', $user, $title ) && $title->isBigDeletion()
973  ) {
974  $errors[] = [ 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ];
975  }
976  } elseif ( $action === 'undelete' ) {
977  if ( count( $this->getPermissionErrorsInternal( 'edit', $user, $title, $rigor, true ) ) ) {
978  // Undeleting implies editing
979  $errors[] = [ 'undelete-cantedit' ];
980  }
981  if ( !$title->exists()
982  && count( $this->getPermissionErrorsInternal( 'create', $user, $title, $rigor, true ) )
983  ) {
984  // Undeleting where nothing currently exists implies creating
985  $errors[] = [ 'undelete-cantcreate' ];
986  }
987  }
988  return $errors;
989  }
990 
1008  $action,
1009  User $user,
1010  $errors,
1011  $rigor,
1012  $short,
1013  LinkTarget $page
1014  ) {
1015  // TODO: remove & rework upon further use of LinkTarget
1016  $title = Title::newFromLinkTarget( $page );
1017 
1018  # Only 'createaccount' can be performed on special pages,
1019  # which don't actually exist in the DB.
1020  if ( $title->getNamespace() == NS_SPECIAL && $action !== 'createaccount' ) {
1021  $errors[] = [ 'ns-specialprotected' ];
1022  }
1023 
1024  # Check $wgNamespaceProtection for restricted namespaces
1025  if ( $title->isNamespaceProtected( $user ) ) {
1026  $ns = $title->getNamespace() == NS_MAIN ?
1027  wfMessage( 'nstab-main' )->text() : $title->getNsText();
1028  $errors[] = $title->getNamespace() == NS_MEDIAWIKI ?
1029  [ 'protectedinterface', $action ] : [ 'namespaceprotected', $ns, $action ];
1030  }
1031 
1032  return $errors;
1033  }
1034 
1051  private function checkSiteConfigPermissions(
1052  $action,
1053  User $user,
1054  $errors,
1055  $rigor,
1056  $short,
1057  LinkTarget $page
1058  ) {
1059  // TODO: remove & rework upon further use of LinkTarget
1060  $title = Title::newFromLinkTarget( $page );
1061 
1062  if ( $action != 'patrol' ) {
1063  $error = null;
1064  // Sitewide CSS/JSON/JS changes, like all NS_MEDIAWIKI changes, also require the
1065  // editinterface right. That's implemented as a restriction so no check needed here.
1066  if ( $title->isSiteCssConfigPage() && !$user->isAllowed( 'editsitecss' ) ) {
1067  $error = [ 'sitecssprotected', $action ];
1068  } elseif ( $title->isSiteJsonConfigPage() && !$user->isAllowed( 'editsitejson' ) ) {
1069  $error = [ 'sitejsonprotected', $action ];
1070  } elseif ( $title->isSiteJsConfigPage() && !$user->isAllowed( 'editsitejs' ) ) {
1071  $error = [ 'sitejsprotected', $action ];
1072  } elseif ( $title->isRawHtmlMessage() ) {
1073  // Raw HTML can be used to deploy CSS or JS so require rights for both.
1074  if ( !$user->isAllowed( 'editsitejs' ) ) {
1075  $error = [ 'sitejsprotected', $action ];
1076  } elseif ( !$user->isAllowed( 'editsitecss' ) ) {
1077  $error = [ 'sitecssprotected', $action ];
1078  }
1079  }
1080 
1081  if ( $error ) {
1082  if ( $user->isAllowed( 'editinterface' ) ) {
1083  // Most users / site admins will probably find out about the new, more restrictive
1084  // permissions by failing to edit something. Give them more info.
1085  // TODO remove this a few release cycles after 1.32
1086  $error = [ 'interfaceadmin-info', wfMessage( $error[0], $error[1] ) ];
1087  }
1088  $errors[] = $error;
1089  }
1090  }
1091 
1092  return $errors;
1093  }
1094 
1111  private function checkUserConfigPermissions(
1112  $action,
1113  User $user,
1114  $errors,
1115  $rigor,
1116  $short,
1117  LinkTarget $page
1118  ) {
1119  // TODO: remove & rework upon further use of LinkTarget
1120  $title = Title::newFromLinkTarget( $page );
1121 
1122  # Protect css/json/js subpages of user pages
1123  # XXX: this might be better using restrictions
1124 
1125  if ( $action === 'patrol' ) {
1126  return $errors;
1127  }
1128 
1129  if ( preg_match( '/^' . preg_quote( $user->getName(), '/' ) . '\//', $title->getText() ) ) {
1130  // Users need editmyuser* to edit their own CSS/JSON/JS subpages.
1131  if (
1132  $title->isUserCssConfigPage()
1133  && !$user->isAllowedAny( 'editmyusercss', 'editusercss' )
1134  ) {
1135  $errors[] = [ 'mycustomcssprotected', $action ];
1136  } elseif (
1137  $title->isUserJsonConfigPage()
1138  && !$user->isAllowedAny( 'editmyuserjson', 'edituserjson' )
1139  ) {
1140  $errors[] = [ 'mycustomjsonprotected', $action ];
1141  } elseif (
1142  $title->isUserJsConfigPage()
1143  && !$user->isAllowedAny( 'editmyuserjs', 'edituserjs' )
1144  ) {
1145  $errors[] = [ 'mycustomjsprotected', $action ];
1146  } elseif (
1147  $title->isUserJsConfigPage()
1148  && !$user->isAllowedAny( 'edituserjs', 'editmyuserjsredirect' )
1149  ) {
1150  // T207750 - do not allow users to edit a redirect if they couldn't edit the target
1151  $rev = $this->revisionLookup->getRevisionByTitle( $title );
1152  $content = $rev ? $rev->getContent( 'main', RevisionRecord::RAW ) : null;
1153  $target = $content ? $content->getUltimateRedirectTarget() : null;
1154  if ( $target && (
1155  !$target->inNamespace( NS_USER )
1156  || !preg_match( '/^' . preg_quote( $user->getName(), '/' ) . '\//', $target->getText() )
1157  ) ) {
1158  $errors[] = [ 'mycustomjsredirectprotected', $action ];
1159  }
1160  }
1161  } else {
1162  // Users need editmyuser* to edit their own CSS/JSON/JS subpages, except for
1163  // deletion/suppression which cannot be used for attacks and we want to avoid the
1164  // situation where an unprivileged user can post abusive content on their subpages
1165  // and only very highly privileged users could remove it.
1166  if ( !in_array( $action, [ 'delete', 'deleterevision', 'suppressrevision' ], true ) ) {
1167  if (
1168  $title->isUserCssConfigPage()
1169  && !$user->isAllowed( 'editusercss' )
1170  ) {
1171  $errors[] = [ 'customcssprotected', $action ];
1172  } elseif (
1173  $title->isUserJsonConfigPage()
1174  && !$user->isAllowed( 'edituserjson' )
1175  ) {
1176  $errors[] = [ 'customjsonprotected', $action ];
1177  } elseif (
1178  $title->isUserJsConfigPage()
1179  && !$user->isAllowed( 'edituserjs' )
1180  ) {
1181  $errors[] = [ 'customjsprotected', $action ];
1182  }
1183  }
1184  }
1185 
1186  return $errors;
1187  }
1188 
1199  public function userHasRight( UserIdentity $user, $action = '' ) {
1200  if ( $action === '' ) {
1201  return true; // In the spirit of DWIM
1202  }
1203  // Use strict parameter to avoid matching numeric 0 accidentally inserted
1204  // by misconfiguration: 0 == 'foo'
1205  return in_array( $action, $this->getUserPermissions( $user ), true );
1206  }
1207 
1218  $user = User::newFromIdentity( $user );
1219  if ( !isset( $this->usersRights[ $user->getId() ] ) ) {
1220  $this->usersRights[ $user->getId() ] = $this->getGroupPermissions(
1221  $user->getEffectiveGroups()
1222  );
1223  Hooks::run( 'UserGetRights', [ $user, &$this->usersRights[ $user->getId() ] ] );
1224 
1225  // Deny any rights denied by the user's session, unless this
1226  // endpoint has no sessions.
1227  if ( !defined( 'MW_NO_SESSION' ) ) {
1228  // FIXME: $user->getRequest().. need to be replaced with something else
1229  $allowedRights = $user->getRequest()->getSession()->getAllowedUserRights();
1230  if ( $allowedRights !== null ) {
1231  $this->usersRights[ $user->getId() ] = array_intersect(
1232  $this->usersRights[ $user->getId() ],
1233  $allowedRights
1234  );
1235  }
1236  }
1237 
1238  Hooks::run( 'UserGetRightsRemove', [ $user, &$this->usersRights[ $user->getId() ] ] );
1239  // Force reindexation of rights when a hook has unset one of them
1240  $this->usersRights[ $user->getId() ] = array_values(
1241  array_unique( $this->usersRights[ $user->getId() ] )
1242  );
1243 
1244  if (
1245  $user->isLoggedIn() &&
1246  $this->blockDisablesLogin &&
1247  $user->getBlock()
1248  ) {
1249  $anon = new User;
1250  $this->usersRights[ $user->getId() ] = array_intersect(
1251  $this->usersRights[ $user->getId() ],
1252  $this->getUserPermissions( $anon )
1253  );
1254  }
1255  }
1256  $rights = $this->usersRights[ $user->getId() ];
1257  foreach ( $this->temporaryUserRights[ $user->getId() ] ?? [] as $overrides ) {
1258  $rights = array_values( array_unique( array_merge( $rights, $overrides ) ) );
1259  }
1260  return $rights;
1261  }
1262 
1271  public function invalidateUsersRightsCache( $user = null ) {
1272  if ( $user !== null ) {
1273  if ( isset( $this->usersRights[ $user->getId() ] ) ) {
1274  unset( $this->usersRights[$user->getId()] );
1275  }
1276  } else {
1277  $this->usersRights = null;
1278  }
1279  }
1280 
1295  public function groupHasPermission( $group, $role ) {
1296  return isset( $this->groupPermissions[$group][$role] ) &&
1297  $this->groupPermissions[$group][$role] &&
1298  !( isset( $this->revokePermissions[$group][$role] ) &&
1299  $this->revokePermissions[$group][$role] );
1300  }
1301 
1310  public function getGroupPermissions( $groups ) {
1311  $rights = [];
1312  // grant every granted permission first
1313  foreach ( $groups as $group ) {
1314  if ( isset( $this->groupPermissions[$group] ) ) {
1315  $rights = array_merge( $rights,
1316  // array_filter removes empty items
1317  array_keys( array_filter( $this->groupPermissions[$group] ) ) );
1318  }
1319  }
1320  // now revoke the revoked permissions
1321  foreach ( $groups as $group ) {
1322  if ( isset( $this->revokePermissions[$group] ) ) {
1323  $rights = array_diff( $rights,
1324  array_keys( array_filter( $this->revokePermissions[$group] ) ) );
1325  }
1326  }
1327  return array_unique( $rights );
1328  }
1329 
1338  public function getGroupsWithPermission( $role ) {
1339  $allowedGroups = [];
1340  foreach ( array_keys( $this->groupPermissions ) as $group ) {
1341  if ( $this->groupHasPermission( $group, $role ) ) {
1342  $allowedGroups[] = $group;
1343  }
1344  }
1345  return $allowedGroups;
1346  }
1347 
1363  public function isEveryoneAllowed( $right ) {
1364  // Use the cached results, except in unit tests which rely on
1365  // being able change the permission mid-request
1366  if ( isset( $this->cachedRights[$right] ) ) {
1367  return $this->cachedRights[$right];
1368  }
1369 
1370  if ( !isset( $this->groupPermissions['*'][$right] )
1371  || !$this->groupPermissions['*'][$right] ) {
1372  $this->cachedRights[$right] = false;
1373  return false;
1374  }
1375 
1376  // If it's revoked anywhere, then everyone doesn't have it
1377  foreach ( $this->revokePermissions as $rights ) {
1378  if ( isset( $rights[$right] ) && $rights[$right] ) {
1379  $this->cachedRights[$right] = false;
1380  return false;
1381  }
1382  }
1383 
1384  // Remove any rights that aren't allowed to the global-session user,
1385  // unless there are no sessions for this endpoint.
1386  if ( !defined( 'MW_NO_SESSION' ) ) {
1387 
1388  // XXX: think what could be done with the below
1389  $allowedRights = SessionManager::getGlobalSession()->getAllowedUserRights();
1390  if ( $allowedRights !== null && !in_array( $right, $allowedRights, true ) ) {
1391  $this->cachedRights[$right] = false;
1392  return false;
1393  }
1394  }
1395 
1396  // Allow extensions to say false
1397  if ( !Hooks::run( 'UserIsEveryoneAllowed', [ $right ] ) ) {
1398  $this->cachedRights[$right] = false;
1399  return false;
1400  }
1401 
1402  $this->cachedRights[$right] = true;
1403  return true;
1404  }
1405 
1413  public function getAllPermissions() {
1414  if ( $this->allRights === false ) {
1415  if ( count( $this->availableRights ) ) {
1416  $this->allRights = array_unique( array_merge(
1417  $this->coreRights,
1418  $this->availableRights
1419  ) );
1420  } else {
1421  $this->allRights = $this->coreRights;
1422  }
1423  Hooks::run( 'UserGetAllRights', [ &$this->allRights ] );
1424  }
1425  return $this->allRights;
1426  }
1427 
1442  public function addTemporaryUserRights( UserIdentity $user, $rights ) {
1443  $userId = $user->getId();
1444  $nextKey = count( $this->temporaryUserRights[$userId] ?? [] );
1445  $this->temporaryUserRights[$userId][$nextKey] = (array)$rights;
1446  return new ScopedCallback( function () use ( $userId, $nextKey ) {
1447  unset( $this->temporaryUserRights[$userId][$nextKey] );
1448  } );
1449  }
1450 
1461  public function overrideUserRightsForTesting( $user, $rights = [] ) {
1462  if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
1463  throw new Exception( __METHOD__ . ' can not be called outside of tests' );
1464  }
1465  $this->usersRights[ $user->getId() ] = is_array( $rights ) ? $rights : [ $rights ];
1466  }
1467 
1468 }
getPermissionErrors( $action, User $user, LinkTarget $page, $rigor=self::RIGOR_SECURE, $ignoreErrors=[])
Can $user perform $action on a page?
checkPageRestrictions( $action, User $user, $errors, $rigor, $short, LinkTarget $page)
Check against page_restrictions table requirements on this page.
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:138
isHidden()
Check if user account is hidden.
Definition: User.php:2207
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...
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
string [] $whitelistRead
List of pages names anonymous user may see.
isAllowedAll()
Definition: User.php:3622
static whoIs( $id)
Get the username corresponding to a given user ID.
Definition: User.php:844
checkSiteConfigPermissions( $action, User $user, $errors, $rigor, $short, LinkTarget $page)
Check sitewide CSS/JSON/JS permissions.
checkReadPermissions( $action, User $user, $errors, $rigor, $short, LinkTarget $page)
Check that the user is allowed to read this page.
const NS_MAIN
Definition: Defines.php:60
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
string [][] $usersRights
Cached user rights.
static isEveryoneAllowed( $right)
Check if all users may be assumed to have the given permission.
Definition: User.php:4854
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
isAllowedAny()
Check if user is allowed to access a feature / make an action.
Definition: User.php:3607
string [][] $groupPermissions
Access rights for groups and users in these groups.
static factory( $action, Page $page, IContextSource $context=null)
Get an appropriate Action subclass for the given action.
Definition: Action.php:97
getBlock( $fromReplica=true)
Get the block affecting the user, or null if the user is not blocked.
Definition: User.php:2089
userCan( $action, User $user, LinkTarget $page, $rigor=self::RIGOR_SECURE)
Can $user perform $action on a page?
const NS_SPECIAL
Definition: Defines.php:49
string $action
Cache what action this request is.
Definition: MediaWiki.php:48
invalidateUsersRightsCache( $user=null)
Clears users permissions cache, if specific user is provided it tries to clear permissions cache only...
static exists( $name)
Check if a given action is recognised, even if it&#39;s disabled.
Definition: Action.php:170
overrideUserRightsForTesting( $user, $rights=[])
Overrides user permissions cache.
getName()
Get the user name, or the IP of an anonymous user.
Definition: User.php:2251
getNamespace()
Get the namespace index.
$coreRights
Array of Strings Core rights.
getAllPermissions()
Get a list of all available permissions.
missingPermissionError( $action, $short)
Get a description array when the user doesn&#39;t have the right to perform $action (i.e.
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImgAuthModifyHeaders':Executed just before a file is streamed to a user via img_auth.php, allowing headers to be modified beforehand. $title:LinkTarget object & $headers:HTTP headers(name=> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\*-\*)") will be honored when streaming the file. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED since 1.28! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1970
string [] $availableRights
A list of available rights, in addition to the ones defined by the core.
Interface for objects representing user identity.
The User object encapsulates all of the user-specific settings (user_id, name, rights, email address, options, last login time).
Definition: User.php:51
isEmailConfirmed()
Is this user&#39;s e-mail address valid-looking and confirmed within limits of the current site configura...
Definition: User.php:4690
$wgLang
Definition: Setup.php:922
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt
Factory for handling the special page list and generating SpecialPage objects.
static getMain()
Get the RequestContext object associated with the main request.
isAnon()
Get whether the user is anonymous.
Definition: User.php:3582
isAllowUsertalk()
Checks if usertalk is allowed.
Definition: User.php:5404
isBlockedFrom(User $user, LinkTarget $page, $fromReplica=false)
Check if user is blocked from editing a particular article.
checkActionPermissions( $action, User $user, $errors, $rigor, $short, LinkTarget $page)
Check action permissions not already checked in checkQuickPermissions.
resultToError( $errors, $result)
Add the resulting error code to the errors array.
getDBkey()
Get the main part with underscores.
checkUserConfigPermissions( $action, User $user, $errors, $rigor, $short, LinkTarget $page)
Check CSS/JSON/JS sub-page permissions.
getGroupsWithPermission( $role)
Get all the groups who have a given permission.
const NS_CATEGORY
Definition: Defines.php:74
isAllowed( $action='')
Internal mechanics of testing a permission.
Definition: User.php:3642
bool $blockDisablesLogin
If set to true, blocked users will no longer be allowed to log in.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:767
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
Service for looking up page revisions.
const NS_FILE
Definition: Defines.php:66
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don&#39;t need a full Title object...
Definition: SpecialPage.php:83
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition: hooks.txt:1748
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
static newFromIdentity(UserIdentity $identity)
Returns a User object corresponding to the given UserIdentity.
Definition: User.php:602
const NS_MEDIAWIKI
Definition: Defines.php:68
checkUserBlock( $action, User $user, $errors, $rigor, $short, LinkTarget $page)
Check that the user isn&#39;t blocked from editing.
static groupHasPermission( $group, $role)
Check, if the given group has the given permission.
Definition: User.php:4831
getGroupPermissions( $groups)
Get the permissions associated with a given list of groups.
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Definition: Title.php:274
getUserPermissions(UserIdentity $user)
Get the permissions this user has.
static getGlobalSession()
Get the "global" session.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
isEveryoneAllowed( $right)
Check if all users may be assumed to have the given permission.
checkPermissionHooks( $action, User $user, $errors, $rigor, $short, LinkTarget $page)
Check various permission hooks.
userHasRight(UserIdentity $user, $action='')
Testing a permission.
addTemporaryUserRights(UserIdentity $user, $rights)
Add temporary user rights, only valid for the current scope.
static newFatalPermissionDeniedStatus( $permission)
Factory function for fatal permission-denied errors.
Definition: User.php:5350
$wgDeleteRevisionsLimit
Optional to restrict deletion of pages with higher revision counts to users with the &#39;bigdelete&#39; perm...
bool $emailConfirmToEdit
Require users to confirm email address before they can edit.
string [] $cachedRights
Cached rights for isEveryoneAllowed.
string [][][] $temporaryUserRights
Temporary user rights, valid for the current request only.
groupHasPermission( $group, $role)
Check, if the given group has the given permission.
checkQuickPermissions( $action, User $user, $errors, $rigor, $short, LinkTarget $page)
Permissions checks that fail most often, and which are easiest to test.
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
string [] $whitelistReadRegexp
Whitelists publicly readable titles with regular expressions.
string [] $allRights
Cached results of getAllRights()
checkCascadingSourcesRestrictions( $action, User $user, $errors, $rigor, $short, LinkTarget $page)
Check restrictions on cascading pages.
checkSpecialsAndNSPermissions( $action, User $user, $errors, $rigor, $short, LinkTarget $page)
Check permissions on special pages & namespaces.
$content
Definition: pageupdater.txt:72
getTalkPage()
Get this user&#39;s talk page title.
Definition: User.php:4340
__construct(SpecialPageFactory $specialPageFactory, RevisionLookup $revisionLookup, $whitelistRead, $whitelistReadRegexp, $emailConfirmToEdit, $blockDisablesLogin, $groupPermissions, $revokePermissions, $availableRights, NamespaceInfo $nsInfo)
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()-...
isSameSpecialPage( $name, LinkTarget $page)
Returns true if this title resolves to the named special page.
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1454
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
string [][] $revokePermissions
Permission keys revoked from users in each group.