MediaWiki  1.31.0
AuthManager.php
Go to the documentation of this file.
1 <?php
24 namespace MediaWiki\Auth;
25 
26 use Config;
28 use Psr\Log\LoggerAwareInterface;
29 use Psr\Log\LoggerInterface;
30 use Status;
32 use User;
34 use Wikimedia\ObjectFactory;
35 
83 class AuthManager implements LoggerAwareInterface {
85  const ACTION_LOGIN = 'login';
88  const ACTION_LOGIN_CONTINUE = 'login-continue';
90  const ACTION_CREATE = 'create';
93  const ACTION_CREATE_CONTINUE = 'create-continue';
95  const ACTION_LINK = 'link';
98  const ACTION_LINK_CONTINUE = 'link-continue';
100  const ACTION_CHANGE = 'change';
102  const ACTION_REMOVE = 'remove';
104  const ACTION_UNLINK = 'unlink';
105 
107  const SEC_OK = 'ok';
109  const SEC_REAUTH = 'reauth';
111  const SEC_FAIL = 'fail';
112 
115 
117  private static $instance = null;
118 
120  private $request;
121 
123  private $config;
124 
126  private $logger;
127 
130 
133 
136 
139 
142 
147  public static function singleton() {
148  if ( self::$instance === null ) {
149  self::$instance = new self(
150  \RequestContext::getMain()->getRequest(),
151  MediaWikiServices::getInstance()->getMainConfig()
152  );
153  }
154  return self::$instance;
155  }
156 
162  $this->request = $request;
163  $this->config = $config;
164  $this->setLogger( \MediaWiki\Logger\LoggerFactory::getInstance( 'authentication' ) );
165  }
166 
170  public function setLogger( LoggerInterface $logger ) {
171  $this->logger = $logger;
172  }
173 
177  public function getRequest() {
178  return $this->request;
179  }
180 
187  public function forcePrimaryAuthenticationProviders( array $providers, $why ) {
188  $this->logger->warning( "Overriding AuthManager primary authn because $why" );
189 
190  if ( $this->primaryAuthenticationProviders !== null ) {
191  $this->logger->warning(
192  'PrimaryAuthenticationProviders have already been accessed! I hope nothing breaks.'
193  );
194 
195  $this->allAuthenticationProviders = array_diff_key(
196  $this->allAuthenticationProviders,
197  $this->primaryAuthenticationProviders
198  );
199  $session = $this->request->getSession();
200  $session->remove( 'AuthManager::authnState' );
201  $session->remove( 'AuthManager::accountCreationState' );
202  $session->remove( 'AuthManager::accountLinkState' );
203  $this->createdAccountAuthenticationRequests = [];
204  }
205 
206  $this->primaryAuthenticationProviders = [];
207  foreach ( $providers as $provider ) {
208  if ( !$provider instanceof PrimaryAuthenticationProvider ) {
209  throw new \RuntimeException(
210  'Expected instance of MediaWiki\\Auth\\PrimaryAuthenticationProvider, got ' .
211  get_class( $provider )
212  );
213  }
214  $provider->setLogger( $this->logger );
215  $provider->setManager( $this );
216  $provider->setConfig( $this->config );
217  $id = $provider->getUniqueId();
218  if ( isset( $this->allAuthenticationProviders[$id] ) ) {
219  throw new \RuntimeException(
220  "Duplicate specifications for id $id (classes " .
221  get_class( $provider ) . ' and ' .
222  get_class( $this->allAuthenticationProviders[$id] ) . ')'
223  );
224  }
225  $this->allAuthenticationProviders[$id] = $provider;
226  $this->primaryAuthenticationProviders[$id] = $provider;
227  }
228  }
229 
239  public static function callLegacyAuthPlugin( $method, array $params, $return = null ) {
240  global $wgAuth;
241 
242  if ( $wgAuth && !$wgAuth instanceof AuthManagerAuthPlugin ) {
243  return call_user_func_array( [ $wgAuth, $method ], $params );
244  } else {
245  return $return;
246  }
247  }
248 
262  public function canAuthenticateNow() {
263  return $this->request->getSession()->canSetUser();
264  }
265 
284  public function beginAuthentication( array $reqs, $returnToUrl ) {
285  $session = $this->request->getSession();
286  if ( !$session->canSetUser() ) {
287  // Caller should have called canAuthenticateNow()
288  $session->remove( 'AuthManager::authnState' );
289  throw new \LogicException( 'Authentication is not possible now' );
290  }
291 
292  $guessUserName = null;
293  foreach ( $reqs as $req ) {
294  $req->returnToUrl = $returnToUrl;
295  // @codeCoverageIgnoreStart
296  if ( $req->username !== null && $req->username !== '' ) {
297  if ( $guessUserName === null ) {
298  $guessUserName = $req->username;
299  } elseif ( $guessUserName !== $req->username ) {
300  $guessUserName = null;
301  break;
302  }
303  }
304  // @codeCoverageIgnoreEnd
305  }
306 
307  // Check for special-case login of a just-created account
310  );
311  if ( $req ) {
312  if ( !in_array( $req, $this->createdAccountAuthenticationRequests, true ) ) {
313  throw new \LogicException(
314  'CreatedAccountAuthenticationRequests are only valid on ' .
315  'the same AuthManager that created the account'
316  );
317  }
318 
319  $user = User::newFromName( $req->username );
320  // @codeCoverageIgnoreStart
321  if ( !$user ) {
322  throw new \UnexpectedValueException(
323  "CreatedAccountAuthenticationRequest had invalid username \"{$req->username}\""
324  );
325  } elseif ( $user->getId() != $req->id ) {
326  throw new \UnexpectedValueException(
327  "ID for \"{$req->username}\" was {$user->getId()}, expected {$req->id}"
328  );
329  }
330  // @codeCoverageIgnoreEnd
331 
332  $this->logger->info( 'Logging in {user} after account creation', [
333  'user' => $user->getName(),
334  ] );
336  $this->setSessionDataForUser( $user );
337  $this->callMethodOnProviders( 7, 'postAuthentication', [ $user, $ret ] );
338  $session->remove( 'AuthManager::authnState' );
339  \Hooks::run( 'AuthManagerLoginAuthenticateAudit', [ $ret, $user, $user->getName() ] );
340  return $ret;
341  }
342 
343  $this->removeAuthenticationSessionData( null );
344 
345  foreach ( $this->getPreAuthenticationProviders() as $provider ) {
346  $status = $provider->testForAuthentication( $reqs );
347  if ( !$status->isGood() ) {
348  $this->logger->debug( 'Login failed in pre-authentication by ' . $provider->getUniqueId() );
350  Status::wrap( $status )->getMessage()
351  );
352  $this->callMethodOnProviders( 7, 'postAuthentication',
353  [ User::newFromName( $guessUserName ) ?: null, $ret ]
354  );
355  \Hooks::run( 'AuthManagerLoginAuthenticateAudit', [ $ret, null, $guessUserName ] );
356  return $ret;
357  }
358  }
359 
360  $state = [
361  'reqs' => $reqs,
362  'returnToUrl' => $returnToUrl,
363  'guessUserName' => $guessUserName,
364  'primary' => null,
365  'primaryResponse' => null,
366  'secondary' => [],
367  'maybeLink' => [],
368  'continueRequests' => [],
369  ];
370 
371  // Preserve state from a previous failed login
374  );
375  if ( $req ) {
376  $state['maybeLink'] = $req->maybeLink;
377  }
378 
379  $session = $this->request->getSession();
380  $session->setSecret( 'AuthManager::authnState', $state );
381  $session->persist();
382 
383  return $this->continueAuthentication( $reqs );
384  }
385 
408  public function continueAuthentication( array $reqs ) {
409  $session = $this->request->getSession();
410  try {
411  if ( !$session->canSetUser() ) {
412  // Caller should have called canAuthenticateNow()
413  // @codeCoverageIgnoreStart
414  throw new \LogicException( 'Authentication is not possible now' );
415  // @codeCoverageIgnoreEnd
416  }
417 
418  $state = $session->getSecret( 'AuthManager::authnState' );
419  if ( !is_array( $state ) ) {
421  wfMessage( 'authmanager-authn-not-in-progress' )
422  );
423  }
424  $state['continueRequests'] = [];
425 
426  $guessUserName = $state['guessUserName'];
427 
428  foreach ( $reqs as $req ) {
429  $req->returnToUrl = $state['returnToUrl'];
430  }
431 
432  // Step 1: Choose an primary authentication provider, and call it until it succeeds.
433 
434  if ( $state['primary'] === null ) {
435  // We haven't picked a PrimaryAuthenticationProvider yet
436  // @codeCoverageIgnoreStart
437  $guessUserName = null;
438  foreach ( $reqs as $req ) {
439  if ( $req->username !== null && $req->username !== '' ) {
440  if ( $guessUserName === null ) {
441  $guessUserName = $req->username;
442  } elseif ( $guessUserName !== $req->username ) {
443  $guessUserName = null;
444  break;
445  }
446  }
447  }
448  $state['guessUserName'] = $guessUserName;
449  // @codeCoverageIgnoreEnd
450  $state['reqs'] = $reqs;
451 
452  foreach ( $this->getPrimaryAuthenticationProviders() as $id => $provider ) {
453  $res = $provider->beginPrimaryAuthentication( $reqs );
454  switch ( $res->status ) {
456  $state['primary'] = $id;
457  $state['primaryResponse'] = $res;
458  $this->logger->debug( "Primary login with $id succeeded" );
459  break 2;
461  $this->logger->debug( "Login failed in primary authentication by $id" );
462  if ( $res->createRequest || $state['maybeLink'] ) {
463  $res->createRequest = new CreateFromLoginAuthenticationRequest(
464  $res->createRequest, $state['maybeLink']
465  );
466  }
467  $this->callMethodOnProviders( 7, 'postAuthentication',
468  [ User::newFromName( $guessUserName ) ?: null, $res ]
469  );
470  $session->remove( 'AuthManager::authnState' );
471  \Hooks::run( 'AuthManagerLoginAuthenticateAudit', [ $res, null, $guessUserName ] );
472  return $res;
474  // Continue loop
475  break;
478  $this->logger->debug( "Primary login with $id returned $res->status" );
479  $this->fillRequests( $res->neededRequests, self::ACTION_LOGIN, $guessUserName );
480  $state['primary'] = $id;
481  $state['continueRequests'] = $res->neededRequests;
482  $session->setSecret( 'AuthManager::authnState', $state );
483  return $res;
484 
485  // @codeCoverageIgnoreStart
486  default:
487  throw new \DomainException(
488  get_class( $provider ) . "::beginPrimaryAuthentication() returned $res->status"
489  );
490  // @codeCoverageIgnoreEnd
491  }
492  }
493  if ( $state['primary'] === null ) {
494  $this->logger->debug( 'Login failed in primary authentication because no provider accepted' );
496  wfMessage( 'authmanager-authn-no-primary' )
497  );
498  $this->callMethodOnProviders( 7, 'postAuthentication',
499  [ User::newFromName( $guessUserName ) ?: null, $ret ]
500  );
501  $session->remove( 'AuthManager::authnState' );
502  return $ret;
503  }
504  } elseif ( $state['primaryResponse'] === null ) {
505  $provider = $this->getAuthenticationProvider( $state['primary'] );
506  if ( !$provider instanceof PrimaryAuthenticationProvider ) {
507  // Configuration changed? Force them to start over.
508  // @codeCoverageIgnoreStart
510  wfMessage( 'authmanager-authn-not-in-progress' )
511  );
512  $this->callMethodOnProviders( 7, 'postAuthentication',
513  [ User::newFromName( $guessUserName ) ?: null, $ret ]
514  );
515  $session->remove( 'AuthManager::authnState' );
516  return $ret;
517  // @codeCoverageIgnoreEnd
518  }
519  $id = $provider->getUniqueId();
520  $res = $provider->continuePrimaryAuthentication( $reqs );
521  switch ( $res->status ) {
523  $state['primaryResponse'] = $res;
524  $this->logger->debug( "Primary login with $id succeeded" );
525  break;
527  $this->logger->debug( "Login failed in primary authentication by $id" );
528  if ( $res->createRequest || $state['maybeLink'] ) {
529  $res->createRequest = new CreateFromLoginAuthenticationRequest(
530  $res->createRequest, $state['maybeLink']
531  );
532  }
533  $this->callMethodOnProviders( 7, 'postAuthentication',
534  [ User::newFromName( $guessUserName ) ?: null, $res ]
535  );
536  $session->remove( 'AuthManager::authnState' );
537  \Hooks::run( 'AuthManagerLoginAuthenticateAudit', [ $res, null, $guessUserName ] );
538  return $res;
541  $this->logger->debug( "Primary login with $id returned $res->status" );
542  $this->fillRequests( $res->neededRequests, self::ACTION_LOGIN, $guessUserName );
543  $state['continueRequests'] = $res->neededRequests;
544  $session->setSecret( 'AuthManager::authnState', $state );
545  return $res;
546  default:
547  throw new \DomainException(
548  get_class( $provider ) . "::continuePrimaryAuthentication() returned $res->status"
549  );
550  }
551  }
552 
553  $res = $state['primaryResponse'];
554  if ( $res->username === null ) {
555  $provider = $this->getAuthenticationProvider( $state['primary'] );
556  if ( !$provider instanceof PrimaryAuthenticationProvider ) {
557  // Configuration changed? Force them to start over.
558  // @codeCoverageIgnoreStart
560  wfMessage( 'authmanager-authn-not-in-progress' )
561  );
562  $this->callMethodOnProviders( 7, 'postAuthentication',
563  [ User::newFromName( $guessUserName ) ?: null, $ret ]
564  );
565  $session->remove( 'AuthManager::authnState' );
566  return $ret;
567  // @codeCoverageIgnoreEnd
568  }
569 
570  if ( $provider->accountCreationType() === PrimaryAuthenticationProvider::TYPE_LINK &&
571  $res->linkRequest &&
572  // don't confuse the user with an incorrect message if linking is disabled
574  ) {
575  $state['maybeLink'][$res->linkRequest->getUniqueId()] = $res->linkRequest;
576  $msg = 'authmanager-authn-no-local-user-link';
577  } else {
578  $msg = 'authmanager-authn-no-local-user';
579  }
580  $this->logger->debug(
581  "Primary login with {$provider->getUniqueId()} succeeded, but returned no user"
582  );
584  $ret->neededRequests = $this->getAuthenticationRequestsInternal(
585  self::ACTION_LOGIN,
586  [],
588  );
589  if ( $res->createRequest || $state['maybeLink'] ) {
590  $ret->createRequest = new CreateFromLoginAuthenticationRequest(
591  $res->createRequest, $state['maybeLink']
592  );
593  $ret->neededRequests[] = $ret->createRequest;
594  }
595  $this->fillRequests( $ret->neededRequests, self::ACTION_LOGIN, null, true );
596  $session->setSecret( 'AuthManager::authnState', [
597  'reqs' => [], // Will be filled in later
598  'primary' => null,
599  'primaryResponse' => null,
600  'secondary' => [],
601  'continueRequests' => $ret->neededRequests,
602  ] + $state );
603  return $ret;
604  }
605 
606  // Step 2: Primary authentication succeeded, create the User object
607  // (and add the user locally if necessary)
608 
609  $user = User::newFromName( $res->username, 'usable' );
610  if ( !$user ) {
611  $provider = $this->getAuthenticationProvider( $state['primary'] );
612  throw new \DomainException(
613  get_class( $provider ) . " returned an invalid username: {$res->username}"
614  );
615  }
616  if ( $user->getId() === 0 ) {
617  // User doesn't exist locally. Create it.
618  $this->logger->info( 'Auto-creating {user} on login', [
619  'user' => $user->getName(),
620  ] );
621  $status = $this->autoCreateUser( $user, $state['primary'], false );
622  if ( !$status->isGood() ) {
624  Status::wrap( $status )->getMessage( 'authmanager-authn-autocreate-failed' )
625  );
626  $this->callMethodOnProviders( 7, 'postAuthentication', [ $user, $ret ] );
627  $session->remove( 'AuthManager::authnState' );
628  \Hooks::run( 'AuthManagerLoginAuthenticateAudit', [ $ret, $user, $user->getName() ] );
629  return $ret;
630  }
631  }
632 
633  // Step 3: Iterate over all the secondary authentication providers.
634 
635  $beginReqs = $state['reqs'];
636 
637  foreach ( $this->getSecondaryAuthenticationProviders() as $id => $provider ) {
638  if ( !isset( $state['secondary'][$id] ) ) {
639  // This provider isn't started yet, so we pass it the set
640  // of reqs from beginAuthentication instead of whatever
641  // might have been used by a previous provider in line.
642  $func = 'beginSecondaryAuthentication';
643  $res = $provider->beginSecondaryAuthentication( $user, $beginReqs );
644  } elseif ( !$state['secondary'][$id] ) {
645  $func = 'continueSecondaryAuthentication';
646  $res = $provider->continueSecondaryAuthentication( $user, $reqs );
647  } else {
648  continue;
649  }
650  switch ( $res->status ) {
652  $this->logger->debug( "Secondary login with $id succeeded" );
653  // fall through
655  $state['secondary'][$id] = true;
656  break;
658  $this->logger->debug( "Login failed in secondary authentication by $id" );
659  $this->callMethodOnProviders( 7, 'postAuthentication', [ $user, $res ] );
660  $session->remove( 'AuthManager::authnState' );
661  \Hooks::run( 'AuthManagerLoginAuthenticateAudit', [ $res, $user, $user->getName() ] );
662  return $res;
665  $this->logger->debug( "Secondary login with $id returned " . $res->status );
666  $this->fillRequests( $res->neededRequests, self::ACTION_LOGIN, $user->getName() );
667  $state['secondary'][$id] = false;
668  $state['continueRequests'] = $res->neededRequests;
669  $session->setSecret( 'AuthManager::authnState', $state );
670  return $res;
671 
672  // @codeCoverageIgnoreStart
673  default:
674  throw new \DomainException(
675  get_class( $provider ) . "::{$func}() returned $res->status"
676  );
677  // @codeCoverageIgnoreEnd
678  }
679  }
680 
681  // Step 4: Authentication complete! Set the user in the session and
682  // clean up.
683 
684  $this->logger->info( 'Login for {user} succeeded', [
685  'user' => $user->getName(),
686  ] );
690  );
691  $this->setSessionDataForUser( $user, $req && $req->rememberMe );
693  $this->callMethodOnProviders( 7, 'postAuthentication', [ $user, $ret ] );
694  $session->remove( 'AuthManager::authnState' );
695  $this->removeAuthenticationSessionData( null );
696  \Hooks::run( 'AuthManagerLoginAuthenticateAudit', [ $ret, $user, $user->getName() ] );
697  return $ret;
698  } catch ( \Exception $ex ) {
699  $session->remove( 'AuthManager::authnState' );
700  throw $ex;
701  }
702  }
703 
715  public function securitySensitiveOperationStatus( $operation ) {
717 
718  $this->logger->debug( __METHOD__ . ": Checking $operation" );
719 
720  $session = $this->request->getSession();
721  $aId = $session->getUser()->getId();
722  if ( $aId === 0 ) {
723  // User isn't authenticated. DWIM?
725  $this->logger->info( __METHOD__ . ": Not logged in! $operation is $status" );
726  return $status;
727  }
728 
729  if ( $session->canSetUser() ) {
730  $id = $session->get( 'AuthManager:lastAuthId' );
731  $last = $session->get( 'AuthManager:lastAuthTimestamp' );
732  if ( $id !== $aId || $last === null ) {
733  $timeSinceLogin = PHP_INT_MAX; // Forever ago
734  } else {
735  $timeSinceLogin = max( 0, time() - $last );
736  }
737 
738  $thresholds = $this->config->get( 'ReauthenticateTime' );
739  if ( isset( $thresholds[$operation] ) ) {
740  $threshold = $thresholds[$operation];
741  } elseif ( isset( $thresholds['default'] ) ) {
742  $threshold = $thresholds['default'];
743  } else {
744  throw new \UnexpectedValueException( '$wgReauthenticateTime lacks a default' );
745  }
746 
747  if ( $threshold >= 0 && $timeSinceLogin > $threshold ) {
749  }
750  } else {
751  $timeSinceLogin = -1;
752 
753  $pass = $this->config->get( 'AllowSecuritySensitiveOperationIfCannotReauthenticate' );
754  if ( isset( $pass[$operation] ) ) {
755  $status = $pass[$operation] ? self::SEC_OK : self::SEC_FAIL;
756  } elseif ( isset( $pass['default'] ) ) {
757  $status = $pass['default'] ? self::SEC_OK : self::SEC_FAIL;
758  } else {
759  throw new \UnexpectedValueException(
760  '$wgAllowSecuritySensitiveOperationIfCannotReauthenticate lacks a default'
761  );
762  }
763  }
764 
765  \Hooks::run( 'SecuritySensitiveOperationStatus', [
766  &$status, $operation, $session, $timeSinceLogin
767  ] );
768 
769  // If authentication is not possible, downgrade from "REAUTH" to "FAIL".
770  if ( !$this->canAuthenticateNow() && $status === self::SEC_REAUTH ) {
772  }
773 
774  $this->logger->info( __METHOD__ . ": $operation is $status" );
775 
776  return $status;
777  }
778 
788  public function userCanAuthenticate( $username ) {
789  foreach ( $this->getPrimaryAuthenticationProviders() as $provider ) {
790  if ( $provider->testUserCanAuthenticate( $username ) ) {
791  return true;
792  }
793  }
794  return false;
795  }
796 
811  public function normalizeUsername( $username ) {
812  $ret = [];
813  foreach ( $this->getPrimaryAuthenticationProviders() as $provider ) {
814  $normalized = $provider->providerNormalizeUsername( $username );
815  if ( $normalized !== null ) {
816  $ret[$normalized] = true;
817  }
818  }
819  return array_keys( $ret );
820  }
821 
836  public function revokeAccessForUser( $username ) {
837  $this->logger->info( 'Revoking access for {user}', [
838  'user' => $username,
839  ] );
840  $this->callMethodOnProviders( 6, 'providerRevokeAccessForUser', [ $username ] );
841  }
842 
852  public function allowsAuthenticationDataChange( AuthenticationRequest $req, $checkData = true ) {
853  $any = false;
854  $providers = $this->getPrimaryAuthenticationProviders() +
856  foreach ( $providers as $provider ) {
857  $status = $provider->providerAllowsAuthenticationDataChange( $req, $checkData );
858  if ( !$status->isGood() ) {
859  return Status::wrap( $status );
860  }
861  $any = $any || $status->value !== 'ignored';
862  }
863  if ( !$any ) {
864  $status = Status::newGood( 'ignored' );
865  $status->warning( 'authmanager-change-not-supported' );
866  return $status;
867  }
868  return Status::newGood();
869  }
870 
886  $this->logger->info( 'Changing authentication data for {user} class {what}', [
887  'user' => is_string( $req->username ) ? $req->username : '<no name>',
888  'what' => get_class( $req ),
889  ] );
890 
891  $this->callMethodOnProviders( 6, 'providerChangeAuthenticationData', [ $req ] );
892 
893  // When the main account's authentication data is changed, invalidate
894  // all BotPasswords too.
896  }
897 
909  public function canCreateAccounts() {
910  foreach ( $this->getPrimaryAuthenticationProviders() as $provider ) {
911  switch ( $provider->accountCreationType() ) {
914  return true;
915  }
916  }
917  return false;
918  }
919 
928  public function canCreateAccount( $username, $options = [] ) {
929  // Back compat
930  if ( is_int( $options ) ) {
931  $options = [ 'flags' => $options ];
932  }
933  $options += [
934  'flags' => User::READ_NORMAL,
935  'creating' => false,
936  ];
937  $flags = $options['flags'];
938 
939  if ( !$this->canCreateAccounts() ) {
940  return Status::newFatal( 'authmanager-create-disabled' );
941  }
942 
943  if ( $this->userExists( $username, $flags ) ) {
944  return Status::newFatal( 'userexists' );
945  }
946 
947  $user = User::newFromName( $username, 'creatable' );
948  if ( !is_object( $user ) ) {
949  return Status::newFatal( 'noname' );
950  } else {
951  $user->load( $flags ); // Explicitly load with $flags, auto-loading always uses READ_NORMAL
952  if ( $user->getId() !== 0 ) {
953  return Status::newFatal( 'userexists' );
954  }
955  }
956 
957  // Denied by providers?
958  $providers = $this->getPreAuthenticationProviders() +
961  foreach ( $providers as $provider ) {
962  $status = $provider->testUserForCreation( $user, false, $options );
963  if ( !$status->isGood() ) {
964  return Status::wrap( $status );
965  }
966  }
967 
968  return Status::newGood();
969  }
970 
976  public function checkAccountCreatePermissions( User $creator ) {
977  // Wiki is read-only?
978  if ( wfReadOnly() ) {
979  return Status::newFatal( wfMessage( 'readonlytext', wfReadOnlyReason() ) );
980  }
981 
982  // This is awful, this permission check really shouldn't go through Title.
983  $permErrors = \SpecialPage::getTitleFor( 'CreateAccount' )
984  ->getUserPermissionsErrors( 'createaccount', $creator, 'secure' );
985  if ( $permErrors ) {
987  foreach ( $permErrors as $args ) {
988  call_user_func_array( [ $status, 'fatal' ], $args );
989  }
990  return $status;
991  }
992 
993  $block = $creator->isBlockedFromCreateAccount();
994  if ( $block ) {
995  $errorParams = [
996  $block->getTarget(),
997  $block->mReason ?: wfMessage( 'blockednoreason' )->text(),
998  $block->getByName()
999  ];
1000 
1001  if ( $block->getType() === \Block::TYPE_RANGE ) {
1002  $errorMessage = 'cantcreateaccount-range-text';
1003  $errorParams[] = $this->getRequest()->getIP();
1004  } else {
1005  $errorMessage = 'cantcreateaccount-text';
1006  }
1007 
1008  return Status::newFatal( wfMessage( $errorMessage, $errorParams ) );
1009  }
1010 
1011  $ip = $this->getRequest()->getIP();
1012  if ( $creator->isDnsBlacklisted( $ip, true /* check $wgProxyWhitelist */ ) ) {
1013  return Status::newFatal( 'sorbs_create_account_reason' );
1014  }
1015 
1016  return Status::newGood();
1017  }
1018 
1038  public function beginAccountCreation( User $creator, array $reqs, $returnToUrl ) {
1039  $session = $this->request->getSession();
1040  if ( !$this->canCreateAccounts() ) {
1041  // Caller should have called canCreateAccounts()
1042  $session->remove( 'AuthManager::accountCreationState' );
1043  throw new \LogicException( 'Account creation is not possible' );
1044  }
1045 
1046  try {
1048  } catch ( \UnexpectedValueException $ex ) {
1049  $username = null;
1050  }
1051  if ( $username === null ) {
1052  $this->logger->debug( __METHOD__ . ': No username provided' );
1053  return AuthenticationResponse::newFail( wfMessage( 'noname' ) );
1054  }
1055 
1056  // Permissions check
1057  $status = $this->checkAccountCreatePermissions( $creator );
1058  if ( !$status->isGood() ) {
1059  $this->logger->debug( __METHOD__ . ': {creator} cannot create users: {reason}', [
1060  'user' => $username,
1061  'creator' => $creator->getName(),
1062  'reason' => $status->getWikiText( null, null, 'en' )
1063  ] );
1064  return AuthenticationResponse::newFail( $status->getMessage() );
1065  }
1066 
1067  $status = $this->canCreateAccount(
1068  $username, [ 'flags' => User::READ_LOCKING, 'creating' => true ]
1069  );
1070  if ( !$status->isGood() ) {
1071  $this->logger->debug( __METHOD__ . ': {user} cannot be created: {reason}', [
1072  'user' => $username,
1073  'creator' => $creator->getName(),
1074  'reason' => $status->getWikiText( null, null, 'en' )
1075  ] );
1076  return AuthenticationResponse::newFail( $status->getMessage() );
1077  }
1078 
1079  $user = User::newFromName( $username, 'creatable' );
1080  foreach ( $reqs as $req ) {
1081  $req->username = $username;
1082  $req->returnToUrl = $returnToUrl;
1083  if ( $req instanceof UserDataAuthenticationRequest ) {
1084  $status = $req->populateUser( $user );
1085  if ( !$status->isGood() ) {
1087  $session->remove( 'AuthManager::accountCreationState' );
1088  $this->logger->debug( __METHOD__ . ': UserData is invalid: {reason}', [
1089  'user' => $user->getName(),
1090  'creator' => $creator->getName(),
1091  'reason' => $status->getWikiText( null, null, 'en' ),
1092  ] );
1093  return AuthenticationResponse::newFail( $status->getMessage() );
1094  }
1095  }
1096  }
1097 
1098  $this->removeAuthenticationSessionData( null );
1099 
1100  $state = [
1101  'username' => $username,
1102  'userid' => 0,
1103  'creatorid' => $creator->getId(),
1104  'creatorname' => $creator->getName(),
1105  'reqs' => $reqs,
1106  'returnToUrl' => $returnToUrl,
1107  'primary' => null,
1108  'primaryResponse' => null,
1109  'secondary' => [],
1110  'continueRequests' => [],
1111  'maybeLink' => [],
1112  'ranPreTests' => false,
1113  ];
1114 
1115  // Special case: converting a login to an account creation
1118  );
1119  if ( $req ) {
1120  $state['maybeLink'] = $req->maybeLink;
1121 
1122  if ( $req->createRequest ) {
1123  $reqs[] = $req->createRequest;
1124  $state['reqs'][] = $req->createRequest;
1125  }
1126  }
1127 
1128  $session->setSecret( 'AuthManager::accountCreationState', $state );
1129  $session->persist();
1130 
1131  return $this->continueAccountCreation( $reqs );
1132  }
1133 
1139  public function continueAccountCreation( array $reqs ) {
1140  $session = $this->request->getSession();
1141  try {
1142  if ( !$this->canCreateAccounts() ) {
1143  // Caller should have called canCreateAccounts()
1144  $session->remove( 'AuthManager::accountCreationState' );
1145  throw new \LogicException( 'Account creation is not possible' );
1146  }
1147 
1148  $state = $session->getSecret( 'AuthManager::accountCreationState' );
1149  if ( !is_array( $state ) ) {
1151  wfMessage( 'authmanager-create-not-in-progress' )
1152  );
1153  }
1154  $state['continueRequests'] = [];
1155 
1156  // Step 0: Prepare and validate the input
1157 
1158  $user = User::newFromName( $state['username'], 'creatable' );
1159  if ( !is_object( $user ) ) {
1160  $session->remove( 'AuthManager::accountCreationState' );
1161  $this->logger->debug( __METHOD__ . ': Invalid username', [
1162  'user' => $state['username'],
1163  ] );
1164  return AuthenticationResponse::newFail( wfMessage( 'noname' ) );
1165  }
1166 
1167  if ( $state['creatorid'] ) {
1168  $creator = User::newFromId( $state['creatorid'] );
1169  } else {
1170  $creator = new User;
1171  $creator->setName( $state['creatorname'] );
1172  }
1173 
1174  // Avoid account creation races on double submissions
1176  $lock = $cache->getScopedLock( $cache->makeGlobalKey( 'account', md5( $user->getName() ) ) );
1177  if ( !$lock ) {
1178  // Don't clear AuthManager::accountCreationState for this code
1179  // path because the process that won the race owns it.
1180  $this->logger->debug( __METHOD__ . ': Could not acquire account creation lock', [
1181  'user' => $user->getName(),
1182  'creator' => $creator->getName(),
1183  ] );
1184  return AuthenticationResponse::newFail( wfMessage( 'usernameinprogress' ) );
1185  }
1186 
1187  // Permissions check
1188  $status = $this->checkAccountCreatePermissions( $creator );
1189  if ( !$status->isGood() ) {
1190  $this->logger->debug( __METHOD__ . ': {creator} cannot create users: {reason}', [
1191  'user' => $user->getName(),
1192  'creator' => $creator->getName(),
1193  'reason' => $status->getWikiText( null, null, 'en' )
1194  ] );
1195  $ret = AuthenticationResponse::newFail( $status->getMessage() );
1196  $this->callMethodOnProviders( 7, 'postAccountCreation', [ $user, $creator, $ret ] );
1197  $session->remove( 'AuthManager::accountCreationState' );
1198  return $ret;
1199  }
1200 
1201  // Load from master for existence check
1202  $user->load( User::READ_LOCKING );
1203 
1204  if ( $state['userid'] === 0 ) {
1205  if ( $user->getId() != 0 ) {
1206  $this->logger->debug( __METHOD__ . ': User exists locally', [
1207  'user' => $user->getName(),
1208  'creator' => $creator->getName(),
1209  ] );
1210  $ret = AuthenticationResponse::newFail( wfMessage( 'userexists' ) );
1211  $this->callMethodOnProviders( 7, 'postAccountCreation', [ $user, $creator, $ret ] );
1212  $session->remove( 'AuthManager::accountCreationState' );
1213  return $ret;
1214  }
1215  } else {
1216  if ( $user->getId() == 0 ) {
1217  $this->logger->debug( __METHOD__ . ': User does not exist locally when it should', [
1218  'user' => $user->getName(),
1219  'creator' => $creator->getName(),
1220  'expected_id' => $state['userid'],
1221  ] );
1222  throw new \UnexpectedValueException(
1223  "User \"{$state['username']}\" should exist now, but doesn't!"
1224  );
1225  }
1226  if ( $user->getId() != $state['userid'] ) {
1227  $this->logger->debug( __METHOD__ . ': User ID/name mismatch', [
1228  'user' => $user->getName(),
1229  'creator' => $creator->getName(),
1230  'expected_id' => $state['userid'],
1231  'actual_id' => $user->getId(),
1232  ] );
1233  throw new \UnexpectedValueException(
1234  "User \"{$state['username']}\" exists, but " .
1235  "ID {$user->getId()} != {$state['userid']}!"
1236  );
1237  }
1238  }
1239  foreach ( $state['reqs'] as $req ) {
1240  if ( $req instanceof UserDataAuthenticationRequest ) {
1241  $status = $req->populateUser( $user );
1242  if ( !$status->isGood() ) {
1243  // This should never happen...
1245  $this->logger->debug( __METHOD__ . ': UserData is invalid: {reason}', [
1246  'user' => $user->getName(),
1247  'creator' => $creator->getName(),
1248  'reason' => $status->getWikiText( null, null, 'en' ),
1249  ] );
1250  $ret = AuthenticationResponse::newFail( $status->getMessage() );
1251  $this->callMethodOnProviders( 7, 'postAccountCreation', [ $user, $creator, $ret ] );
1252  $session->remove( 'AuthManager::accountCreationState' );
1253  return $ret;
1254  }
1255  }
1256  }
1257 
1258  foreach ( $reqs as $req ) {
1259  $req->returnToUrl = $state['returnToUrl'];
1260  $req->username = $state['username'];
1261  }
1262 
1263  // Run pre-creation tests, if we haven't already
1264  if ( !$state['ranPreTests'] ) {
1265  $providers = $this->getPreAuthenticationProviders() +
1268  foreach ( $providers as $id => $provider ) {
1269  $status = $provider->testForAccountCreation( $user, $creator, $reqs );
1270  if ( !$status->isGood() ) {
1271  $this->logger->debug( __METHOD__ . ": Fail in pre-authentication by $id", [
1272  'user' => $user->getName(),
1273  'creator' => $creator->getName(),
1274  ] );
1276  Status::wrap( $status )->getMessage()
1277  );
1278  $this->callMethodOnProviders( 7, 'postAccountCreation', [ $user, $creator, $ret ] );
1279  $session->remove( 'AuthManager::accountCreationState' );
1280  return $ret;
1281  }
1282  }
1283 
1284  $state['ranPreTests'] = true;
1285  }
1286 
1287  // Step 1: Choose a primary authentication provider and call it until it succeeds.
1288 
1289  if ( $state['primary'] === null ) {
1290  // We haven't picked a PrimaryAuthenticationProvider yet
1291  foreach ( $this->getPrimaryAuthenticationProviders() as $id => $provider ) {
1292  if ( $provider->accountCreationType() === PrimaryAuthenticationProvider::TYPE_NONE ) {
1293  continue;
1294  }
1295  $res = $provider->beginPrimaryAccountCreation( $user, $creator, $reqs );
1296  switch ( $res->status ) {
1298  $this->logger->debug( __METHOD__ . ": Primary creation passed by $id", [
1299  'user' => $user->getName(),
1300  'creator' => $creator->getName(),
1301  ] );
1302  $state['primary'] = $id;
1303  $state['primaryResponse'] = $res;
1304  break 2;
1306  $this->logger->debug( __METHOD__ . ": Primary creation failed by $id", [
1307  'user' => $user->getName(),
1308  'creator' => $creator->getName(),
1309  ] );
1310  $this->callMethodOnProviders( 7, 'postAccountCreation', [ $user, $creator, $res ] );
1311  $session->remove( 'AuthManager::accountCreationState' );
1312  return $res;
1314  // Continue loop
1315  break;
1318  $this->logger->debug( __METHOD__ . ": Primary creation $res->status by $id", [
1319  'user' => $user->getName(),
1320  'creator' => $creator->getName(),
1321  ] );
1322  $this->fillRequests( $res->neededRequests, self::ACTION_CREATE, null );
1323  $state['primary'] = $id;
1324  $state['continueRequests'] = $res->neededRequests;
1325  $session->setSecret( 'AuthManager::accountCreationState', $state );
1326  return $res;
1327 
1328  // @codeCoverageIgnoreStart
1329  default:
1330  throw new \DomainException(
1331  get_class( $provider ) . "::beginPrimaryAccountCreation() returned $res->status"
1332  );
1333  // @codeCoverageIgnoreEnd
1334  }
1335  }
1336  if ( $state['primary'] === null ) {
1337  $this->logger->debug( __METHOD__ . ': Primary creation failed because no provider accepted', [
1338  'user' => $user->getName(),
1339  'creator' => $creator->getName(),
1340  ] );
1342  wfMessage( 'authmanager-create-no-primary' )
1343  );
1344  $this->callMethodOnProviders( 7, 'postAccountCreation', [ $user, $creator, $ret ] );
1345  $session->remove( 'AuthManager::accountCreationState' );
1346  return $ret;
1347  }
1348  } elseif ( $state['primaryResponse'] === null ) {
1349  $provider = $this->getAuthenticationProvider( $state['primary'] );
1350  if ( !$provider instanceof PrimaryAuthenticationProvider ) {
1351  // Configuration changed? Force them to start over.
1352  // @codeCoverageIgnoreStart
1354  wfMessage( 'authmanager-create-not-in-progress' )
1355  );
1356  $this->callMethodOnProviders( 7, 'postAccountCreation', [ $user, $creator, $ret ] );
1357  $session->remove( 'AuthManager::accountCreationState' );
1358  return $ret;
1359  // @codeCoverageIgnoreEnd
1360  }
1361  $id = $provider->getUniqueId();
1362  $res = $provider->continuePrimaryAccountCreation( $user, $creator, $reqs );
1363  switch ( $res->status ) {
1365  $this->logger->debug( __METHOD__ . ": Primary creation passed by $id", [
1366  'user' => $user->getName(),
1367  'creator' => $creator->getName(),
1368  ] );
1369  $state['primaryResponse'] = $res;
1370  break;
1372  $this->logger->debug( __METHOD__ . ": Primary creation failed by $id", [
1373  'user' => $user->getName(),
1374  'creator' => $creator->getName(),
1375  ] );
1376  $this->callMethodOnProviders( 7, 'postAccountCreation', [ $user, $creator, $res ] );
1377  $session->remove( 'AuthManager::accountCreationState' );
1378  return $res;
1381  $this->logger->debug( __METHOD__ . ": Primary creation $res->status by $id", [
1382  'user' => $user->getName(),
1383  'creator' => $creator->getName(),
1384  ] );
1385  $this->fillRequests( $res->neededRequests, self::ACTION_CREATE, null );
1386  $state['continueRequests'] = $res->neededRequests;
1387  $session->setSecret( 'AuthManager::accountCreationState', $state );
1388  return $res;
1389  default:
1390  throw new \DomainException(
1391  get_class( $provider ) . "::continuePrimaryAccountCreation() returned $res->status"
1392  );
1393  }
1394  }
1395 
1396  // Step 2: Primary authentication succeeded, create the User object
1397  // and add the user locally.
1398 
1399  if ( $state['userid'] === 0 ) {
1400  $this->logger->info( 'Creating user {user} during account creation', [
1401  'user' => $user->getName(),
1402  'creator' => $creator->getName(),
1403  ] );
1404  $status = $user->addToDatabase();
1405  if ( !$status->isOK() ) {
1406  // @codeCoverageIgnoreStart
1407  $ret = AuthenticationResponse::newFail( $status->getMessage() );
1408  $this->callMethodOnProviders( 7, 'postAccountCreation', [ $user, $creator, $ret ] );
1409  $session->remove( 'AuthManager::accountCreationState' );
1410  return $ret;
1411  // @codeCoverageIgnoreEnd
1412  }
1413  $this->setDefaultUserOptions( $user, $creator->isAnon() );
1414  \Hooks::run( 'LocalUserCreated', [ $user, false ] );
1415  $user->saveSettings();
1416  $state['userid'] = $user->getId();
1417 
1418  // Update user count
1419  \DeferredUpdates::addUpdate( \SiteStatsUpdate::factory( [ 'users' => 1 ] ) );
1420 
1421  // Watch user's userpage and talk page
1422  $user->addWatch( $user->getUserPage(), User::IGNORE_USER_RIGHTS );
1423 
1424  // Inform the provider
1425  $logSubtype = $provider->finishAccountCreation( $user, $creator, $state['primaryResponse'] );
1426 
1427  // Log the creation
1428  if ( $this->config->get( 'NewUserLog' ) ) {
1429  $isAnon = $creator->isAnon();
1430  $logEntry = new \ManualLogEntry(
1431  'newusers',
1432  $logSubtype ?: ( $isAnon ? 'create' : 'create2' )
1433  );
1434  $logEntry->setPerformer( $isAnon ? $user : $creator );
1435  $logEntry->setTarget( $user->getUserPage() );
1439  );
1440  $logEntry->setComment( $req ? $req->reason : '' );
1441  $logEntry->setParameters( [
1442  '4::userid' => $user->getId(),
1443  ] );
1444  $logid = $logEntry->insert();
1445  $logEntry->publish( $logid );
1446  }
1447  }
1448 
1449  // Step 3: Iterate over all the secondary authentication providers.
1450 
1451  $beginReqs = $state['reqs'];
1452 
1453  foreach ( $this->getSecondaryAuthenticationProviders() as $id => $provider ) {
1454  if ( !isset( $state['secondary'][$id] ) ) {
1455  // This provider isn't started yet, so we pass it the set
1456  // of reqs from beginAuthentication instead of whatever
1457  // might have been used by a previous provider in line.
1458  $func = 'beginSecondaryAccountCreation';
1459  $res = $provider->beginSecondaryAccountCreation( $user, $creator, $beginReqs );
1460  } elseif ( !$state['secondary'][$id] ) {
1461  $func = 'continueSecondaryAccountCreation';
1462  $res = $provider->continueSecondaryAccountCreation( $user, $creator, $reqs );
1463  } else {
1464  continue;
1465  }
1466  switch ( $res->status ) {
1468  $this->logger->debug( __METHOD__ . ": Secondary creation passed by $id", [
1469  'user' => $user->getName(),
1470  'creator' => $creator->getName(),
1471  ] );
1472  // fall through
1474  $state['secondary'][$id] = true;
1475  break;
1478  $this->logger->debug( __METHOD__ . ": Secondary creation $res->status by $id", [
1479  'user' => $user->getName(),
1480  'creator' => $creator->getName(),
1481  ] );
1482  $this->fillRequests( $res->neededRequests, self::ACTION_CREATE, null );
1483  $state['secondary'][$id] = false;
1484  $state['continueRequests'] = $res->neededRequests;
1485  $session->setSecret( 'AuthManager::accountCreationState', $state );
1486  return $res;
1488  throw new \DomainException(
1489  get_class( $provider ) . "::{$func}() returned $res->status." .
1490  ' Secondary providers are not allowed to fail account creation, that' .
1491  ' should have been done via testForAccountCreation().'
1492  );
1493  // @codeCoverageIgnoreStart
1494  default:
1495  throw new \DomainException(
1496  get_class( $provider ) . "::{$func}() returned $res->status"
1497  );
1498  // @codeCoverageIgnoreEnd
1499  }
1500  }
1501 
1502  $id = $user->getId();
1503  $name = $user->getName();
1506  $ret->loginRequest = $req;
1507  $this->createdAccountAuthenticationRequests[] = $req;
1508 
1509  $this->logger->info( __METHOD__ . ': Account creation succeeded for {user}', [
1510  'user' => $user->getName(),
1511  'creator' => $creator->getName(),
1512  ] );
1513 
1514  $this->callMethodOnProviders( 7, 'postAccountCreation', [ $user, $creator, $ret ] );
1515  $session->remove( 'AuthManager::accountCreationState' );
1516  $this->removeAuthenticationSessionData( null );
1517  return $ret;
1518  } catch ( \Exception $ex ) {
1519  $session->remove( 'AuthManager::accountCreationState' );
1520  throw $ex;
1521  }
1522  }
1523 
1539  public function autoCreateUser( User $user, $source, $login = true ) {
1540  if ( $source !== self::AUTOCREATE_SOURCE_SESSION &&
1542  ) {
1543  throw new \InvalidArgumentException( "Unknown auto-creation source: $source" );
1544  }
1545 
1546  $username = $user->getName();
1547 
1548  // Try the local user from the replica DB
1549  $localId = User::idFromName( $username );
1550  $flags = User::READ_NORMAL;
1551 
1552  // Fetch the user ID from the master, so that we don't try to create the user
1553  // when they already exist, due to replication lag
1554  // @codeCoverageIgnoreStart
1555  if (
1556  !$localId &&
1557  MediaWikiServices::getInstance()->getDBLoadBalancer()->getReaderIndex() != 0
1558  ) {
1559  $localId = User::idFromName( $username, User::READ_LATEST );
1560  $flags = User::READ_LATEST;
1561  }
1562  // @codeCoverageIgnoreEnd
1563 
1564  if ( $localId ) {
1565  $this->logger->debug( __METHOD__ . ': {username} already exists locally', [
1566  'username' => $username,
1567  ] );
1568  $user->setId( $localId );
1569  $user->loadFromId( $flags );
1570  if ( $login ) {
1571  $this->setSessionDataForUser( $user );
1572  }
1574  $status->warning( 'userexists' );
1575  return $status;
1576  }
1577 
1578  // Wiki is read-only?
1579  if ( wfReadOnly() ) {
1580  $this->logger->debug( __METHOD__ . ': denied by wfReadOnly(): {reason}', [
1581  'username' => $username,
1582  'reason' => wfReadOnlyReason(),
1583  ] );
1584  $user->setId( 0 );
1585  $user->loadFromId();
1586  return Status::newFatal( wfMessage( 'readonlytext', wfReadOnlyReason() ) );
1587  }
1588 
1589  // Check the session, if we tried to create this user already there's
1590  // no point in retrying.
1591  $session = $this->request->getSession();
1592  if ( $session->get( 'AuthManager::AutoCreateBlacklist' ) ) {
1593  $this->logger->debug( __METHOD__ . ': blacklisted in session {sessionid}', [
1594  'username' => $username,
1595  'sessionid' => $session->getId(),
1596  ] );
1597  $user->setId( 0 );
1598  $user->loadFromId();
1599  $reason = $session->get( 'AuthManager::AutoCreateBlacklist' );
1600  if ( $reason instanceof StatusValue ) {
1601  return Status::wrap( $reason );
1602  } else {
1603  return Status::newFatal( $reason );
1604  }
1605  }
1606 
1607  // Is the username creatable?
1608  if ( !User::isCreatableName( $username ) ) {
1609  $this->logger->debug( __METHOD__ . ': name "{username}" is not creatable', [
1610  'username' => $username,
1611  ] );
1612  $session->set( 'AuthManager::AutoCreateBlacklist', 'noname' );
1613  $user->setId( 0 );
1614  $user->loadFromId();
1615  return Status::newFatal( 'noname' );
1616  }
1617 
1618  // Is the IP user able to create accounts?
1619  $anon = new User;
1620  if ( !$anon->isAllowedAny( 'createaccount', 'autocreateaccount' ) ) {
1621  $this->logger->debug( __METHOD__ . ': IP lacks the ability to create or autocreate accounts', [
1622  'username' => $username,
1623  'ip' => $anon->getName(),
1624  ] );
1625  $session->set( 'AuthManager::AutoCreateBlacklist', 'authmanager-autocreate-noperm' );
1626  $session->persist();
1627  $user->setId( 0 );
1628  $user->loadFromId();
1629  return Status::newFatal( 'authmanager-autocreate-noperm' );
1630  }
1631 
1632  // Avoid account creation races on double submissions
1634  $lock = $cache->getScopedLock( $cache->makeGlobalKey( 'account', md5( $username ) ) );
1635  if ( !$lock ) {
1636  $this->logger->debug( __METHOD__ . ': Could not acquire account creation lock', [
1637  'user' => $username,
1638  ] );
1639  $user->setId( 0 );
1640  $user->loadFromId();
1641  return Status::newFatal( 'usernameinprogress' );
1642  }
1643 
1644  // Denied by providers?
1645  $options = [
1646  'flags' => User::READ_LATEST,
1647  'creating' => true,
1648  ];
1649  $providers = $this->getPreAuthenticationProviders() +
1652  foreach ( $providers as $provider ) {
1653  $status = $provider->testUserForCreation( $user, $source, $options );
1654  if ( !$status->isGood() ) {
1655  $ret = Status::wrap( $status );
1656  $this->logger->debug( __METHOD__ . ': Provider denied creation of {username}: {reason}', [
1657  'username' => $username,
1658  'reason' => $ret->getWikiText( null, null, 'en' ),
1659  ] );
1660  $session->set( 'AuthManager::AutoCreateBlacklist', $status );
1661  $user->setId( 0 );
1662  $user->loadFromId();
1663  return $ret;
1664  }
1665  }
1666 
1667  $backoffKey = $cache->makeKey( 'AuthManager', 'autocreate-failed', md5( $username ) );
1668  if ( $cache->get( $backoffKey ) ) {
1669  $this->logger->debug( __METHOD__ . ': {username} denied by prior creation attempt failures', [
1670  'username' => $username,
1671  ] );
1672  $user->setId( 0 );
1673  $user->loadFromId();
1674  return Status::newFatal( 'authmanager-autocreate-exception' );
1675  }
1676 
1677  // Checks passed, create the user...
1678  $from = isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : 'CLI';
1679  $this->logger->info( __METHOD__ . ': creating new user ({username}) - from: {from}', [
1680  'username' => $username,
1681  'from' => $from,
1682  ] );
1683 
1684  // Ignore warnings about master connections/writes...hard to avoid here
1685  $trxProfiler = \Profiler::instance()->getTransactionProfiler();
1686  $old = $trxProfiler->setSilenced( true );
1687  try {
1688  $status = $user->addToDatabase();
1689  if ( !$status->isOK() ) {
1690  // Double-check for a race condition (T70012). We make use of the fact that when
1691  // addToDatabase fails due to the user already existing, the user object gets loaded.
1692  if ( $user->getId() ) {
1693  $this->logger->info( __METHOD__ . ': {username} already exists locally (race)', [
1694  'username' => $username,
1695  ] );
1696  if ( $login ) {
1697  $this->setSessionDataForUser( $user );
1698  }
1700  $status->warning( 'userexists' );
1701  } else {
1702  $this->logger->error( __METHOD__ . ': {username} failed with message {msg}', [
1703  'username' => $username,
1704  'msg' => $status->getWikiText( null, null, 'en' )
1705  ] );
1706  $user->setId( 0 );
1707  $user->loadFromId();
1708  }
1709  return $status;
1710  }
1711  } catch ( \Exception $ex ) {
1712  $trxProfiler->setSilenced( $old );
1713  $this->logger->error( __METHOD__ . ': {username} failed with exception {exception}', [
1714  'username' => $username,
1715  'exception' => $ex,
1716  ] );
1717  // Do not keep throwing errors for a while
1718  $cache->set( $backoffKey, 1, 600 );
1719  // Bubble up error; which should normally trigger DB rollbacks
1720  throw $ex;
1721  }
1722 
1723  $this->setDefaultUserOptions( $user, false );
1724 
1725  // Inform the providers
1726  $this->callMethodOnProviders( 6, 'autoCreatedAccount', [ $user, $source ] );
1727 
1728  \Hooks::run( 'AuthPluginAutoCreate', [ $user ], '1.27' );
1729  \Hooks::run( 'LocalUserCreated', [ $user, true ] );
1730  $user->saveSettings();
1731 
1732  // Update user count
1733  \DeferredUpdates::addUpdate( \SiteStatsUpdate::factory( [ 'users' => 1 ] ) );
1734  // Watch user's userpage and talk page
1735  \DeferredUpdates::addCallableUpdate( function () use ( $user ) {
1736  $user->addWatch( $user->getUserPage(), User::IGNORE_USER_RIGHTS );
1737  } );
1738 
1739  // Log the creation
1740  if ( $this->config->get( 'NewUserLog' ) ) {
1741  $logEntry = new \ManualLogEntry( 'newusers', 'autocreate' );
1742  $logEntry->setPerformer( $user );
1743  $logEntry->setTarget( $user->getUserPage() );
1744  $logEntry->setComment( '' );
1745  $logEntry->setParameters( [
1746  '4::userid' => $user->getId(),
1747  ] );
1748  $logEntry->insert();
1749  }
1750 
1751  $trxProfiler->setSilenced( $old );
1752 
1753  if ( $login ) {
1754  $this->setSessionDataForUser( $user );
1755  }
1756 
1757  return Status::newGood();
1758  }
1759 
1771  public function canLinkAccounts() {
1772  foreach ( $this->getPrimaryAuthenticationProviders() as $provider ) {
1773  if ( $provider->accountCreationType() === PrimaryAuthenticationProvider::TYPE_LINK ) {
1774  return true;
1775  }
1776  }
1777  return false;
1778  }
1779 
1789  public function beginAccountLink( User $user, array $reqs, $returnToUrl ) {
1790  $session = $this->request->getSession();
1791  $session->remove( 'AuthManager::accountLinkState' );
1792 
1793  if ( !$this->canLinkAccounts() ) {
1794  // Caller should have called canLinkAccounts()
1795  throw new \LogicException( 'Account linking is not possible' );
1796  }
1797 
1798  if ( $user->getId() === 0 ) {
1799  if ( !User::isUsableName( $user->getName() ) ) {
1800  $msg = wfMessage( 'noname' );
1801  } else {
1802  $msg = wfMessage( 'authmanager-userdoesnotexist', $user->getName() );
1803  }
1804  return AuthenticationResponse::newFail( $msg );
1805  }
1806  foreach ( $reqs as $req ) {
1807  $req->username = $user->getName();
1808  $req->returnToUrl = $returnToUrl;
1809  }
1810 
1811  $this->removeAuthenticationSessionData( null );
1812 
1813  $providers = $this->getPreAuthenticationProviders();
1814  foreach ( $providers as $id => $provider ) {
1815  $status = $provider->testForAccountLink( $user );
1816  if ( !$status->isGood() ) {
1817  $this->logger->debug( __METHOD__ . ": Account linking pre-check failed by $id", [
1818  'user' => $user->getName(),
1819  ] );
1821  Status::wrap( $status )->getMessage()
1822  );
1823  $this->callMethodOnProviders( 3, 'postAccountLink', [ $user, $ret ] );
1824  return $ret;
1825  }
1826  }
1827 
1828  $state = [
1829  'username' => $user->getName(),
1830  'userid' => $user->getId(),
1831  'returnToUrl' => $returnToUrl,
1832  'primary' => null,
1833  'continueRequests' => [],
1834  ];
1835 
1836  $providers = $this->getPrimaryAuthenticationProviders();
1837  foreach ( $providers as $id => $provider ) {
1838  if ( $provider->accountCreationType() !== PrimaryAuthenticationProvider::TYPE_LINK ) {
1839  continue;
1840  }
1841 
1842  $res = $provider->beginPrimaryAccountLink( $user, $reqs );
1843  switch ( $res->status ) {
1845  $this->logger->info( "Account linked to {user} by $id", [
1846  'user' => $user->getName(),
1847  ] );
1848  $this->callMethodOnProviders( 3, 'postAccountLink', [ $user, $res ] );
1849  return $res;
1850 
1852  $this->logger->debug( __METHOD__ . ": Account linking failed by $id", [
1853  'user' => $user->getName(),
1854  ] );
1855  $this->callMethodOnProviders( 3, 'postAccountLink', [ $user, $res ] );
1856  return $res;
1857 
1859  // Continue loop
1860  break;
1861 
1864  $this->logger->debug( __METHOD__ . ": Account linking $res->status by $id", [
1865  'user' => $user->getName(),
1866  ] );
1867  $this->fillRequests( $res->neededRequests, self::ACTION_LINK, $user->getName() );
1868  $state['primary'] = $id;
1869  $state['continueRequests'] = $res->neededRequests;
1870  $session->setSecret( 'AuthManager::accountLinkState', $state );
1871  $session->persist();
1872  return $res;
1873 
1874  // @codeCoverageIgnoreStart
1875  default:
1876  throw new \DomainException(
1877  get_class( $provider ) . "::beginPrimaryAccountLink() returned $res->status"
1878  );
1879  // @codeCoverageIgnoreEnd
1880  }
1881  }
1882 
1883  $this->logger->debug( __METHOD__ . ': Account linking failed because no provider accepted', [
1884  'user' => $user->getName(),
1885  ] );
1887  wfMessage( 'authmanager-link-no-primary' )
1888  );
1889  $this->callMethodOnProviders( 3, 'postAccountLink', [ $user, $ret ] );
1890  return $ret;
1891  }
1892 
1898  public function continueAccountLink( array $reqs ) {
1899  $session = $this->request->getSession();
1900  try {
1901  if ( !$this->canLinkAccounts() ) {
1902  // Caller should have called canLinkAccounts()
1903  $session->remove( 'AuthManager::accountLinkState' );
1904  throw new \LogicException( 'Account linking is not possible' );
1905  }
1906 
1907  $state = $session->getSecret( 'AuthManager::accountLinkState' );
1908  if ( !is_array( $state ) ) {
1910  wfMessage( 'authmanager-link-not-in-progress' )
1911  );
1912  }
1913  $state['continueRequests'] = [];
1914 
1915  // Step 0: Prepare and validate the input
1916 
1917  $user = User::newFromName( $state['username'], 'usable' );
1918  if ( !is_object( $user ) ) {
1919  $session->remove( 'AuthManager::accountLinkState' );
1920  return AuthenticationResponse::newFail( wfMessage( 'noname' ) );
1921  }
1922  if ( $user->getId() != $state['userid'] ) {
1923  throw new \UnexpectedValueException(
1924  "User \"{$state['username']}\" is valid, but " .
1925  "ID {$user->getId()} != {$state['userid']}!"
1926  );
1927  }
1928 
1929  foreach ( $reqs as $req ) {
1930  $req->username = $state['username'];
1931  $req->returnToUrl = $state['returnToUrl'];
1932  }
1933 
1934  // Step 1: Call the primary again until it succeeds
1935 
1936  $provider = $this->getAuthenticationProvider( $state['primary'] );
1937  if ( !$provider instanceof PrimaryAuthenticationProvider ) {
1938  // Configuration changed? Force them to start over.
1939  // @codeCoverageIgnoreStart
1941  wfMessage( 'authmanager-link-not-in-progress' )
1942  );
1943  $this->callMethodOnProviders( 3, 'postAccountLink', [ $user, $ret ] );
1944  $session->remove( 'AuthManager::accountLinkState' );
1945  return $ret;
1946  // @codeCoverageIgnoreEnd
1947  }
1948  $id = $provider->getUniqueId();
1949  $res = $provider->continuePrimaryAccountLink( $user, $reqs );
1950  switch ( $res->status ) {
1952  $this->logger->info( "Account linked to {user} by $id", [
1953  'user' => $user->getName(),
1954  ] );
1955  $this->callMethodOnProviders( 3, 'postAccountLink', [ $user, $res ] );
1956  $session->remove( 'AuthManager::accountLinkState' );
1957  return $res;
1959  $this->logger->debug( __METHOD__ . ": Account linking failed by $id", [
1960  'user' => $user->getName(),
1961  ] );
1962  $this->callMethodOnProviders( 3, 'postAccountLink', [ $user, $res ] );
1963  $session->remove( 'AuthManager::accountLinkState' );
1964  return $res;
1967  $this->logger->debug( __METHOD__ . ": Account linking $res->status by $id", [
1968  'user' => $user->getName(),
1969  ] );
1970  $this->fillRequests( $res->neededRequests, self::ACTION_LINK, $user->getName() );
1971  $state['continueRequests'] = $res->neededRequests;
1972  $session->setSecret( 'AuthManager::accountLinkState', $state );
1973  return $res;
1974  default:
1975  throw new \DomainException(
1976  get_class( $provider ) . "::continuePrimaryAccountLink() returned $res->status"
1977  );
1978  }
1979  } catch ( \Exception $ex ) {
1980  $session->remove( 'AuthManager::accountLinkState' );
1981  throw $ex;
1982  }
1983  }
1984 
2010  public function getAuthenticationRequests( $action, User $user = null ) {
2011  $options = [];
2012  $providerAction = $action;
2013 
2014  // Figure out which providers to query
2015  switch ( $action ) {
2016  case self::ACTION_LOGIN:
2017  case self::ACTION_CREATE:
2018  $providers = $this->getPreAuthenticationProviders() +
2021  break;
2022 
2024  $state = $this->request->getSession()->getSecret( 'AuthManager::authnState' );
2025  return is_array( $state ) ? $state['continueRequests'] : [];
2026 
2028  $state = $this->request->getSession()->getSecret( 'AuthManager::accountCreationState' );
2029  return is_array( $state ) ? $state['continueRequests'] : [];
2030 
2031  case self::ACTION_LINK:
2032  $providers = array_filter( $this->getPrimaryAuthenticationProviders(), function ( $p ) {
2033  return $p->accountCreationType() === PrimaryAuthenticationProvider::TYPE_LINK;
2034  } );
2035  break;
2036 
2037  case self::ACTION_UNLINK:
2038  $providers = array_filter( $this->getPrimaryAuthenticationProviders(), function ( $p ) {
2039  return $p->accountCreationType() === PrimaryAuthenticationProvider::TYPE_LINK;
2040  } );
2041 
2042  // To providers, unlink and remove are identical.
2043  $providerAction = self::ACTION_REMOVE;
2044  break;
2045 
2047  $state = $this->request->getSession()->getSecret( 'AuthManager::accountLinkState' );
2048  return is_array( $state ) ? $state['continueRequests'] : [];
2049 
2050  case self::ACTION_CHANGE:
2051  case self::ACTION_REMOVE:
2052  $providers = $this->getPrimaryAuthenticationProviders() +
2054  break;
2055 
2056  // @codeCoverageIgnoreStart
2057  default:
2058  throw new \DomainException( __METHOD__ . ": Invalid action \"$action\"" );
2059  }
2060  // @codeCoverageIgnoreEnd
2061 
2062  return $this->getAuthenticationRequestsInternal( $providerAction, $options, $providers, $user );
2063  }
2064 
2075  $providerAction, array $options, array $providers, User $user = null
2076  ) {
2077  $user = $user ?: \RequestContext::getMain()->getUser();
2078  $options['username'] = $user->isAnon() ? null : $user->getName();
2079 
2080  // Query them and merge results
2081  $reqs = [];
2082  foreach ( $providers as $provider ) {
2083  $isPrimary = $provider instanceof PrimaryAuthenticationProvider;
2084  foreach ( $provider->getAuthenticationRequests( $providerAction, $options ) as $req ) {
2085  $id = $req->getUniqueId();
2086 
2087  // If a required request if from a Primary, mark it as "primary-required" instead
2088  if ( $isPrimary ) {
2089  if ( $req->required ) {
2091  }
2092  }
2093 
2094  if (
2095  !isset( $reqs[$id] )
2096  || $req->required === AuthenticationRequest::REQUIRED
2097  || $reqs[$id] === AuthenticationRequest::OPTIONAL
2098  ) {
2099  $reqs[$id] = $req;
2100  }
2101  }
2102  }
2103 
2104  // AuthManager has its own req for some actions
2105  switch ( $providerAction ) {
2106  case self::ACTION_LOGIN:
2107  $reqs[] = new RememberMeAuthenticationRequest;
2108  break;
2109 
2110  case self::ACTION_CREATE:
2111  $reqs[] = new UsernameAuthenticationRequest;
2112  $reqs[] = new UserDataAuthenticationRequest;
2113  if ( $options['username'] !== null ) {
2115  $options['username'] = null; // Don't fill in the username below
2116  }
2117  break;
2118  }
2119 
2120  // Fill in reqs data
2121  $this->fillRequests( $reqs, $providerAction, $options['username'], true );
2122 
2123  // For self::ACTION_CHANGE, filter out any that something else *doesn't* allow changing
2124  if ( $providerAction === self::ACTION_CHANGE || $providerAction === self::ACTION_REMOVE ) {
2125  $reqs = array_filter( $reqs, function ( $req ) {
2126  return $this->allowsAuthenticationDataChange( $req, false )->isGood();
2127  } );
2128  }
2129 
2130  return array_values( $reqs );
2131  }
2132 
2140  private function fillRequests( array &$reqs, $action, $username, $forceAction = false ) {
2141  foreach ( $reqs as $req ) {
2142  if ( !$req->action || $forceAction ) {
2143  $req->action = $action;
2144  }
2145  if ( $req->username === null ) {
2146  $req->username = $username;
2147  }
2148  }
2149  }
2150 
2157  public function userExists( $username, $flags = User::READ_NORMAL ) {
2158  foreach ( $this->getPrimaryAuthenticationProviders() as $provider ) {
2159  if ( $provider->testUserExists( $username, $flags ) ) {
2160  return true;
2161  }
2162  }
2163 
2164  return false;
2165  }
2166 
2178  public function allowsPropertyChange( $property ) {
2179  $providers = $this->getPrimaryAuthenticationProviders() +
2181  foreach ( $providers as $provider ) {
2182  if ( !$provider->providerAllowsPropertyChange( $property ) ) {
2183  return false;
2184  }
2185  }
2186  return true;
2187  }
2188 
2197  public function getAuthenticationProvider( $id ) {
2198  // Fast version
2199  if ( isset( $this->allAuthenticationProviders[$id] ) ) {
2200  return $this->allAuthenticationProviders[$id];
2201  }
2202 
2203  // Slow version: instantiate each kind and check
2204  $providers = $this->getPrimaryAuthenticationProviders();
2205  if ( isset( $providers[$id] ) ) {
2206  return $providers[$id];
2207  }
2208  $providers = $this->getSecondaryAuthenticationProviders();
2209  if ( isset( $providers[$id] ) ) {
2210  return $providers[$id];
2211  }
2212  $providers = $this->getPreAuthenticationProviders();
2213  if ( isset( $providers[$id] ) ) {
2214  return $providers[$id];
2215  }
2216 
2217  return null;
2218  }
2219 
2233  public function setAuthenticationSessionData( $key, $data ) {
2234  $session = $this->request->getSession();
2235  $arr = $session->getSecret( 'authData' );
2236  if ( !is_array( $arr ) ) {
2237  $arr = [];
2238  }
2239  $arr[$key] = $data;
2240  $session->setSecret( 'authData', $arr );
2241  }
2242 
2250  public function getAuthenticationSessionData( $key, $default = null ) {
2251  $arr = $this->request->getSession()->getSecret( 'authData' );
2252  if ( is_array( $arr ) && array_key_exists( $key, $arr ) ) {
2253  return $arr[$key];
2254  } else {
2255  return $default;
2256  }
2257  }
2258 
2264  public function removeAuthenticationSessionData( $key ) {
2265  $session = $this->request->getSession();
2266  if ( $key === null ) {
2267  $session->remove( 'authData' );
2268  } else {
2269  $arr = $session->getSecret( 'authData' );
2270  if ( is_array( $arr ) && array_key_exists( $key, $arr ) ) {
2271  unset( $arr[$key] );
2272  $session->setSecret( 'authData', $arr );
2273  }
2274  }
2275  }
2276 
2283  protected function providerArrayFromSpecs( $class, array $specs ) {
2284  $i = 0;
2285  foreach ( $specs as &$spec ) {
2286  $spec = [ 'sort2' => $i++ ] + $spec + [ 'sort' => 0 ];
2287  }
2288  unset( $spec );
2289  usort( $specs, function ( $a, $b ) {
2290  return ( (int)$a['sort'] ) - ( (int)$b['sort'] )
2291  ?: $a['sort2'] - $b['sort2'];
2292  } );
2293 
2294  $ret = [];
2295  foreach ( $specs as $spec ) {
2296  $provider = ObjectFactory::getObjectFromSpec( $spec );
2297  if ( !$provider instanceof $class ) {
2298  throw new \RuntimeException(
2299  "Expected instance of $class, got " . get_class( $provider )
2300  );
2301  }
2302  $provider->setLogger( $this->logger );
2303  $provider->setManager( $this );
2304  $provider->setConfig( $this->config );
2305  $id = $provider->getUniqueId();
2306  if ( isset( $this->allAuthenticationProviders[$id] ) ) {
2307  throw new \RuntimeException(
2308  "Duplicate specifications for id $id (classes " .
2309  get_class( $provider ) . ' and ' .
2310  get_class( $this->allAuthenticationProviders[$id] ) . ')'
2311  );
2312  }
2313  $this->allAuthenticationProviders[$id] = $provider;
2314  $ret[$id] = $provider;
2315  }
2316  return $ret;
2317  }
2318 
2323  private function getConfiguration() {
2324  return $this->config->get( 'AuthManagerConfig' ) ?: $this->config->get( 'AuthManagerAutoConfig' );
2325  }
2326 
2331  protected function getPreAuthenticationProviders() {
2332  if ( $this->preAuthenticationProviders === null ) {
2333  $conf = $this->getConfiguration();
2334  $this->preAuthenticationProviders = $this->providerArrayFromSpecs(
2335  PreAuthenticationProvider::class, $conf['preauth']
2336  );
2337  }
2339  }
2340 
2345  protected function getPrimaryAuthenticationProviders() {
2346  if ( $this->primaryAuthenticationProviders === null ) {
2347  $conf = $this->getConfiguration();
2348  $this->primaryAuthenticationProviders = $this->providerArrayFromSpecs(
2349  PrimaryAuthenticationProvider::class, $conf['primaryauth']
2350  );
2351  }
2353  }
2354 
2360  if ( $this->secondaryAuthenticationProviders === null ) {
2361  $conf = $this->getConfiguration();
2362  $this->secondaryAuthenticationProviders = $this->providerArrayFromSpecs(
2363  SecondaryAuthenticationProvider::class, $conf['secondaryauth']
2364  );
2365  }
2367  }
2368 
2374  private function setSessionDataForUser( $user, $remember = null ) {
2375  $session = $this->request->getSession();
2376  $delay = $session->delaySave();
2377 
2378  $session->resetId();
2379  $session->resetAllTokens();
2380  if ( $session->canSetUser() ) {
2381  $session->setUser( $user );
2382  }
2383  if ( $remember !== null ) {
2384  $session->setRememberUser( $remember );
2385  }
2386  $session->set( 'AuthManager:lastAuthId', $user->getId() );
2387  $session->set( 'AuthManager:lastAuthTimestamp', time() );
2388  $session->persist();
2389 
2390  \Wikimedia\ScopedCallback::consume( $delay );
2391 
2392  \Hooks::run( 'UserLoggedIn', [ $user ] );
2393  }
2394 
2399  private function setDefaultUserOptions( User $user, $useContextLang ) {
2401 
2402  $user->setToken();
2403 
2404  $lang = $useContextLang ? \RequestContext::getMain()->getLanguage() : $wgContLang;
2405  $user->setOption( 'language', $lang->getPreferredVariant() );
2406 
2407  if ( $wgContLang->hasVariants() ) {
2408  $user->setOption( 'variant', $wgContLang->getPreferredVariant() );
2409  }
2410  }
2411 
2417  private function callMethodOnProviders( $which, $method, array $args ) {
2418  $providers = [];
2419  if ( $which & 1 ) {
2420  $providers += $this->getPreAuthenticationProviders();
2421  }
2422  if ( $which & 2 ) {
2423  $providers += $this->getPrimaryAuthenticationProviders();
2424  }
2425  if ( $which & 4 ) {
2426  $providers += $this->getSecondaryAuthenticationProviders();
2427  }
2428  foreach ( $providers as $provider ) {
2429  call_user_func_array( [ $provider, $method ], $args );
2430  }
2431  }
2432 
2437  public static function resetCache() {
2438  if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
2439  // @codeCoverageIgnoreStart
2440  throw new \MWException( __METHOD__ . ' may only be called from unit tests!' );
2441  // @codeCoverageIgnoreEnd
2442  }
2443 
2444  self::$instance = null;
2445  }
2446 
2449 }
2450 
MediaWiki\Auth\AuthManager\continueAccountLink
continueAccountLink(array $reqs)
Continue an account linking flow.
Definition: AuthManager.php:1898
MediaWiki\Auth\AuthManager\continueAuthentication
continueAuthentication(array $reqs)
Continue an authentication flow.
Definition: AuthManager.php:408
MediaWiki\Auth\AuthenticationRequest\OPTIONAL
const OPTIONAL
Indicates that the request is not required for authentication to proceed.
Definition: AuthenticationRequest.php:40
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:244
MediaWiki\Auth\AuthManager\getRequest
getRequest()
Definition: AuthManager.php:177
MediaWiki\Auth\PrimaryAuthenticationProvider\TYPE_CREATE
const TYPE_CREATE
Provider can create accounts.
Definition: PrimaryAuthenticationProvider.php:77
MediaWiki\Auth\AuthManager\$preAuthenticationProviders
PreAuthenticationProvider[] $preAuthenticationProviders
Definition: AuthManager.php:132
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:614
StatusValue
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:42
MediaWiki\$action
String $action
Cache what action this request is.
Definition: MediaWiki.php:48
MediaWiki\Auth\AuthManager\SEC_REAUTH
const SEC_REAUTH
Security-sensitive operations should re-authenticate.
Definition: AuthManager.php:109
MediaWiki\Auth\PrimaryAuthenticationProvider\TYPE_NONE
const TYPE_NONE
Provider cannot create or link to accounts.
Definition: PrimaryAuthenticationProvider.php:81
ObjectCache\getLocalClusterInstance
static getLocalClusterInstance()
Get the main cluster-local cache object.
Definition: ObjectCache.php:367
User\getId
getId()
Get the user's ID.
Definition: User.php:2369
MediaWiki\Auth\AuthManager\fillRequests
fillRequests(array &$reqs, $action, $username, $forceAction=false)
Set values in an array of requests.
Definition: AuthManager.php:2140
MediaWiki\Auth\AuthManager\getPrimaryAuthenticationProviders
getPrimaryAuthenticationProviders()
Get the list of PrimaryAuthenticationProviders.
Definition: AuthManager.php:2345
Profiler\instance
static instance()
Singleton.
Definition: Profiler.php:62
MediaWiki\Auth\AuthManager\ACTION_UNLINK
const ACTION_UNLINK
Like ACTION_REMOVE but for linking providers only.
Definition: AuthManager.php:104
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
MediaWiki\Auth\AuthManager\AUTOCREATE_SOURCE_SESSION
const AUTOCREATE_SOURCE_SESSION
Auto-creation is due to SessionManager.
Definition: AuthManager.php:114
Block\TYPE_RANGE
const TYPE_RANGE
Definition: Block.php:85
MediaWiki\Auth\AuthManager\revokeAccessForUser
revokeAccessForUser( $username)
Revoke any authentication credentials for a user.
Definition: AuthManager.php:836
$last
$last
Definition: profileinfo.php:408
MediaWiki\Logger\LoggerFactory\getInstance
static getInstance( $channel)
Get a named logger instance from the currently configured logger factory.
Definition: LoggerFactory.php:92
MediaWiki\Auth\AuthManagerAuthPlugin
Backwards-compatibility wrapper for AuthManager via $wgAuth.
Definition: AuthManagerAuthPlugin.php:31
MediaWiki\Auth\AuthManager\autoCreateUser
autoCreateUser(User $user, $source, $login=true)
Auto-create an account, and log into that account.
Definition: AuthManager.php:1539
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
MediaWiki\Auth\AuthManager\$instance
static AuthManager null $instance
Definition: AuthManager.php:117
$req
this hook is for auditing only $req
Definition: hooks.txt:990
DeferredUpdates\addUpdate
static addUpdate(DeferrableUpdate $update, $stage=self::POSTSEND)
Add an update to the deferred list to be run later by execute()
Definition: DeferredUpdates.php:76
MediaWiki\Auth\PrimaryAuthenticationProvider\TYPE_LINK
const TYPE_LINK
Provider can link to existing accounts elsewhere.
Definition: PrimaryAuthenticationProvider.php:79
MediaWiki\Auth\CreatedAccountAuthenticationRequest
Returned from account creation to allow for logging into the created account.
Definition: CreatedAccountAuthenticationRequest.php:29
StatusValue\newFatal
static newFatal( $message)
Factory function for fatal errors.
Definition: StatusValue.php:68
$params
$params
Definition: styleTest.css.php:40
MediaWiki\Auth\AuthManager\beginAuthentication
beginAuthentication(array $reqs, $returnToUrl)
Start an authentication flow.
Definition: AuthManager.php:284
wfReadOnly
wfReadOnly()
Check whether the wiki is in read-only mode.
Definition: GlobalFunctions.php:1250
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:591
MediaWiki\Auth\AuthManager\userExists
userExists( $username, $flags=User::READ_NORMAL)
Determine whether a username exists.
Definition: AuthManager.php:2157
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:82
$res
$res
Definition: database.txt:21
MediaWiki\Auth\AuthManager\$allAuthenticationProviders
AuthenticationProvider[] $allAuthenticationProviders
Definition: AuthManager.php:129
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
User
User
Definition: All_system_messages.txt:425
MediaWiki\Auth\AuthManager\getPreAuthenticationProviders
getPreAuthenticationProviders()
Get the list of PreAuthenticationProviders.
Definition: AuthManager.php:2331
MediaWiki\Auth\AuthManager\getAuthenticationSessionData
getAuthenticationSessionData( $key, $default=null)
Fetch authentication data from the current session.
Definition: AuthManager.php:2250
MediaWiki\Auth\AuthManager\ACTION_LOGIN_CONTINUE
const ACTION_LOGIN_CONTINUE
Continue a login process that was interrupted by the need for user input or communication with an ext...
Definition: AuthManager.php:88
MediaWiki\Auth\AuthManager\__construct
__construct(WebRequest $request, Config $config)
Definition: AuthManager.php:161
MediaWiki\Auth\AuthManager\SEC_FAIL
const SEC_FAIL
Security-sensitive should not be performed.
Definition: AuthManager.php:111
MediaWiki\Auth\AuthenticationRequest\getRequestByClass
static getRequestByClass(array $reqs, $class, $allowSubclasses=false)
Select a request by class name.
Definition: AuthenticationRequest.php:253
php
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
IDBAccessObject\READ_LOCKING
const READ_LOCKING
Constants for object loading bitfield flags (higher => higher QoS)
Definition: IDBAccessObject.php:62
Status
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:40
MediaWiki\Auth\AuthManager\removeAuthenticationSessionData
removeAuthenticationSessionData( $key)
Remove authentication data.
Definition: AuthManager.php:2264
Config
Interface for configuration instances.
Definition: Config.php:28
MediaWiki\Auth\AuthenticationRequest\getUsernameFromRequests
static getUsernameFromRequests(array $reqs)
Get the username from the set of requests.
Definition: AuthenticationRequest.php:273
MediaWiki\Auth\AuthenticationRequest\PRIMARY_REQUIRED
const PRIMARY_REQUIRED
Indicates that the request is required by a primary authentication provider.
Definition: AuthenticationRequest.php:51
MediaWiki\Auth\AuthenticationResponse\UI
const UI
Indicates that the authentication needs further user input of some sort.
Definition: AuthenticationResponse.php:55
MediaWiki\Auth\AuthManager\beginAccountCreation
beginAccountCreation(User $creator, array $reqs, $returnToUrl)
Start an account creation flow.
Definition: AuthManager.php:1038
MediaWiki\Auth\AuthManager\getAuthenticationProvider
getAuthenticationProvider( $id)
Get a provider by ID.
Definition: AuthManager.php:2197
MediaWiki\Auth\AuthManager\ACTION_LINK_CONTINUE
const ACTION_LINK_CONTINUE
Continue a user linking process that was interrupted by the need for user input or communication with...
Definition: AuthManager.php:98
MediaWiki\Auth\CreationReasonAuthenticationRequest
Authentication request for the reason given for account creation.
Definition: CreationReasonAuthenticationRequest.php:9
$property
$property
Definition: styleTest.css.php:44
MediaWiki\Auth\AuthManager\canCreateAccounts
canCreateAccounts()
Determine whether accounts can be created.
Definition: AuthManager.php:909
MediaWiki\Auth\AuthenticationResponse\REDIRECT
const REDIRECT
Indicates that the authentication needs to be redirected to a third party to proceed.
Definition: AuthenticationResponse.php:58
MediaWiki\Auth\PreAuthenticationProvider
A pre-authentication provider can prevent authentication early on.
Definition: PreAuthenticationProvider.php:44
Status\wrap
static wrap( $sv)
Succinct helper method to wrap a StatusValue.
Definition: Status.php:55
MediaWiki\Auth\AuthManager\changeAuthenticationData
changeAuthenticationData(AuthenticationRequest $req)
Change authentication data (e.g.
Definition: AuthManager.php:885
MediaWiki\Auth\CreateFromLoginAuthenticationRequest
This transfers state between the login and account creation flows.
Definition: CreateFromLoginAuthenticationRequest.php:34
MediaWiki
A helper class for throttling authentication attempts.
MediaWiki\Auth\AuthManager\getConfiguration
getConfiguration()
Get the configuration.
Definition: AuthManager.php:2323
MediaWiki\Auth\AuthenticationResponse\ABSTAIN
const ABSTAIN
Indicates that the authentication provider does not handle this request.
Definition: AuthenticationResponse.php:52
request
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging a wrapping ErrorException instead of letting the login form give the generic error message that the account does not exist For when the account has been renamed or deleted or an array to pass a message key and parameters create2 Corresponds to logging log_action database field and which is displayed in the UI similar to $comment this hook should only be used to add variables that depend on the current page request
Definition: hooks.txt:2163
MediaWiki\Auth\AuthManager\canAuthenticateNow
canAuthenticateNow()
Indicate whether user authentication is possible.
Definition: AuthManager.php:262
MediaWiki\Auth\AuthManager\setAuthenticationSessionData
setAuthenticationSessionData( $key, $data)
Store authentication in the current session.
Definition: AuthManager.php:2233
SiteStatsUpdate\factory
static factory(array $deltas)
Definition: SiteStatsUpdate.php:66
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
MediaWiki\Auth\SecondaryAuthenticationProvider
A secondary provider mostly acts when the submitted authentication data has already been associated t...
Definition: SecondaryAuthenticationProvider.php:52
MediaWiki\Auth\UsernameAuthenticationRequest
AuthenticationRequest to ensure something with a username is present.
Definition: UsernameAuthenticationRequest.php:29
MediaWiki\Auth\AuthManager\setDefaultUserOptions
setDefaultUserOptions(User $user, $useContextLang)
Definition: AuthManager.php:2399
MediaWiki\Auth\UserDataAuthenticationRequest
This represents additional user data requested on the account creation form.
Definition: UserDataAuthenticationRequest.php:34
MediaWiki\Auth\AuthManager\callLegacyAuthPlugin
static callLegacyAuthPlugin( $method, array $params, $return=null)
Call a legacy AuthPlugin method, if necessary.
Definition: AuthManager.php:239
MediaWiki\Auth\AuthenticationResponse\FAIL
const FAIL
Indicates that the authentication failed.
Definition: AuthenticationResponse.php:42
MediaWiki\Auth\AuthManager\resetCache
static resetCache()
Reset the internal caching for unit testing.
Definition: AuthManager.php:2437
MediaWiki\Auth\AuthManager\$request
WebRequest $request
Definition: AuthManager.php:120
MediaWiki\Auth\AuthManager\beginAccountLink
beginAccountLink(User $user, array $reqs, $returnToUrl)
Start an account linking flow.
Definition: AuthManager.php:1789
MediaWiki\Auth\AuthManager\normalizeUsername
normalizeUsername( $username)
Provide normalized versions of the username for security checks.
Definition: AuthManager.php:811
MediaWiki\Auth\AuthManager\canLinkAccounts
canLinkAccounts()
Determine whether accounts can be linked.
Definition: AuthManager.php:1771
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:109
MediaWiki\Auth\AuthManager\ACTION_CREATE_CONTINUE
const ACTION_CREATE_CONTINUE
Continue a user creation process that was interrupted by the need for user input or communication wit...
Definition: AuthManager.php:93
MediaWiki\Auth\AuthManager\ACTION_CREATE
const ACTION_CREATE
Create a new user.
Definition: AuthManager.php:90
MediaWiki\Auth\AuthManager\$logger
LoggerInterface $logger
Definition: AuthManager.php:126
MediaWiki\Auth\AuthManager\$primaryAuthenticationProviders
PrimaryAuthenticationProvider[] $primaryAuthenticationProviders
Definition: AuthManager.php:135
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:81
User\isDnsBlacklisted
isDnsBlacklisted( $ip, $checkWhitelist=false)
Whether the given IP is in a DNS blacklist.
Definition: User.php:1933
MediaWiki\Auth\AuthManager\continueAccountCreation
continueAccountCreation(array $reqs)
Continue an account creation flow.
Definition: AuthManager.php:1139
BotPassword\invalidateAllPasswordsForUser
static invalidateAllPasswordsForUser( $username)
Invalidate all passwords for a user, by name.
Definition: BotPassword.php:332
MediaWiki\Auth\AuthManager\$secondaryAuthenticationProviders
SecondaryAuthenticationProvider[] $secondaryAuthenticationProviders
Definition: AuthManager.php:138
MediaWiki\Auth\AuthManager\forcePrimaryAuthenticationProviders
forcePrimaryAuthenticationProviders(array $providers, $why)
Force certain PrimaryAuthenticationProviders.
Definition: AuthManager.php:187
MediaWiki\Auth\AuthManager\ACTION_CHANGE
const ACTION_CHANGE
Change a user's credentials.
Definition: AuthManager.php:100
MediaWiki\Auth\AuthManager\callMethodOnProviders
callMethodOnProviders( $which, $method, array $args)
Definition: AuthManager.php:2417
$ret
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition: hooks.txt:1987
MediaWiki\Auth\AuthManager\ACTION_LINK
const ACTION_LINK
Link an existing user to a third-party account.
Definition: AuthManager.php:95
MediaWiki\Auth\AuthManager\allowsPropertyChange
allowsPropertyChange( $property)
Determine whether a user property should be allowed to be changed.
Definition: AuthManager.php:2178
MediaWiki\Auth\RememberMeAuthenticationRequest
This is an authentication request added by AuthManager to show a "remember me" checkbox.
Definition: RememberMeAuthenticationRequest.php:33
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:434
MediaWiki\Auth\AuthManager\securitySensitiveOperationStatus
securitySensitiveOperationStatus( $operation)
Whether security-sensitive operations should proceed.
Definition: AuthManager.php:715
MediaWiki\Auth\AuthManager
This serves as the entry point to the authentication system.
Definition: AuthManager.php:83
WebRequest
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
Definition: WebRequest.php:38
MediaWiki\Auth\AuthManager\ACTION_REMOVE
const ACTION_REMOVE
Remove a user's credentials.
Definition: AuthManager.php:102
MediaWiki\Auth\AuthManager\SEC_OK
const SEC_OK
Security-sensitive operations are ok.
Definition: AuthManager.php:107
$args
if( $line===false) $args
Definition: cdb.php:64
MediaWiki\Auth\AuthManager\getAuthenticationRequests
getAuthenticationRequests( $action, User $user=null)
Return the applicable list of AuthenticationRequests.
Definition: AuthManager.php:2010
wfReadOnlyReason
wfReadOnlyReason()
Check if the site is in read-only mode and return the message if so.
Definition: GlobalFunctions.php:1263
$cache
$cache
Definition: mcc.php:33
$options
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1987
MediaWiki\Auth\AuthManager\singleton
static singleton()
Get the global AuthManager.
Definition: AuthManager.php:147
User\idFromName
static idFromName( $name, $flags=self::READ_NORMAL)
Get database id given a user name.
Definition: User.php:883
MediaWiki\Auth\AuthenticationResponse\newFail
static newFail(Message $msg)
Definition: AuthenticationResponse.php:146
as
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
MediaWiki\Auth\AuthManager\setSessionDataForUser
setSessionDataForUser( $user, $remember=null)
Log the user in.
Definition: AuthManager.php:2374
MediaWiki\Auth\AuthManager\$createdAccountAuthenticationRequests
CreatedAccountAuthenticationRequest[] $createdAccountAuthenticationRequests
Definition: AuthManager.php:141
MediaWiki\Auth\AuthManager\$config
Config $config
Definition: AuthManager.php:123
MediaWiki\Auth\AuthManager\canCreateAccount
canCreateAccount( $username, $options=[])
Determine whether a particular account can be created.
Definition: AuthManager.php:928
$source
$source
Definition: mwdoc-filter.php:46
MediaWiki\Auth\AuthManager\ACTION_LOGIN
const ACTION_LOGIN
Log in with an existing (not necessarily local) user.
Definition: AuthManager.php:85
$status
Status::newGood()` to allow deletion, and then `return false` from the hook function. Ensure you consume the 'ChangeTagAfterDelete' hook to carry out custom deletion actions. $tag:name of the tag $user:user initiating the action & $status:Status object. See above. 'ChangeTagsListActive':Allows you to nominate which of the tags your extension uses are in active use. & $tags:list of all active tags. Append to this array. 'ChangeTagsAfterUpdateTags':Called after tags have been updated with the ChangeTags::updateTags function. Params:$addedTags:tags effectively added in the update $removedTags:tags effectively removed in the update $prevTags:tags that were present prior to the update $rc_id:recentchanges table id $rev_id:revision table id $log_id:logging table id $params:tag params $rc:RecentChange being tagged when the tagging accompanies the action or null $user:User who performed the tagging when the tagging is subsequent to the action or null 'ChangeTagsAllowedAdd':Called when checking if a user can add tags to a change. & $allowedTags:List of all the tags the user is allowed to add. Any tags the user wants to add( $addTags) that are not in this array will cause it to fail. You may add or remove tags to this array as required. $addTags:List of tags user intends to add. $user:User who is adding the tags. 'ChangeUserGroups':Called before user groups are changed. $performer:The User who will perform the change $user:The User whose groups will be changed & $add:The groups that will be added & $remove:The groups that will be removed 'Collation::factory':Called if $wgCategoryCollation is an unknown collation. $collationName:Name of the collation in question & $collationObject:Null. Replace with a subclass of the Collation class that implements the collation given in $collationName. 'ConfirmEmailComplete':Called after a user 's email has been confirmed successfully. $user:user(object) whose email is being confirmed 'ContentAlterParserOutput':Modify parser output for a given content object. Called by Content::getParserOutput after parsing has finished. Can be used for changes that depend on the result of the parsing but have to be done before LinksUpdate is called(such as adding tracking categories based on the rendered HTML). $content:The Content to render $title:Title of the page, as context $parserOutput:ParserOutput to manipulate 'ContentGetParserOutput':Customize parser output for a given content object, called by AbstractContent::getParserOutput. May be used to override the normal model-specific rendering of page content. $content:The Content to render $title:Title of the page, as context $revId:The revision ID, as context $options:ParserOptions for rendering. To avoid confusing the parser cache, the output can only depend on parameters provided to this hook function, not on global state. $generateHtml:boolean, indicating whether full HTML should be generated. If false, generation of HTML may be skipped, but other information should still be present in the ParserOutput object. & $output:ParserOutput, to manipulate or replace 'ContentHandlerDefaultModelFor':Called when the default content model is determined for a given title. May be used to assign a different model for that title. $title:the Title in question & $model:the model name. Use with CONTENT_MODEL_XXX constants. 'ContentHandlerForModelID':Called when a ContentHandler is requested for a given content model name, but no entry for that model exists in $wgContentHandlers. Note:if your extension implements additional models via this hook, please use GetContentModels hook to make them known to core. $modeName:the requested content model name & $handler:set this to a ContentHandler object, if desired. 'ContentModelCanBeUsedOn':Called to determine whether that content model can be used on a given page. This is especially useful to prevent some content models to be used in some special location. $contentModel:ID of the content model in question $title:the Title in question. & $ok:Output parameter, whether it is OK to use $contentModel on $title. Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok. 'ContribsPager::getQueryInfo':Before the contributions query is about to run & $pager:Pager object for contributions & $queryInfo:The query for the contribs Pager 'ContribsPager::reallyDoQuery':Called before really executing the query for My Contributions & $data:an array of results of all contribs queries $pager:The ContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'ContributionsLineEnding':Called before a contributions HTML line is finished $page:SpecialPage object for contributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'ContributionsToolLinks':Change tool links above Special:Contributions $id:User identifier $title:User page title & $tools:Array of tool links $specialPage:SpecialPage instance for context and services. Can be either SpecialContributions or DeletedContributionsPage. Extensions should type hint against a generic SpecialPage though. 'ConvertContent':Called by AbstractContent::convert when a conversion to another content model is requested. Handler functions that modify $result should generally return false to disable further attempts at conversion. $content:The Content object to be converted. $toModel:The ID of the content model to convert to. $lossy:boolean indicating whether lossy conversion is allowed. & $result:Output parameter, in case the handler function wants to provide a converted Content object. Note that $result->getContentModel() must return $toModel. 'CustomEditor':When invoking the page editor Return true to allow the normal editor to be used, or false if implementing a custom editor, e.g. for a special namespace, etc. $article:Article being edited $user:User performing the edit 'DatabaseOraclePostInit':Called after initialising an Oracle database $db:the DatabaseOracle object 'DeletedContribsPager::reallyDoQuery':Called before really executing the query for Special:DeletedContributions Similar to ContribsPager::reallyDoQuery & $data:an array of results of all contribs queries $pager:The DeletedContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'DeletedContributionsLineEnding':Called before a DeletedContributions HTML line is finished. Similar to ContributionsLineEnding $page:SpecialPage object for DeletedContributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'DeleteUnknownPreferences':Called by the cleanupPreferences.php maintenance script to build a WHERE clause with which to delete preferences that are not known about. This hook is used by extensions that have dynamically-named preferences that should not be deleted in the usual cleanup process. For example, the Gadgets extension creates preferences prefixed with 'gadget-', and so anything with that prefix is excluded from the deletion. &where:An array that will be passed as the $cond parameter to IDatabase::select() to determine what will be deleted from the user_properties table. $db:The IDatabase object, useful for accessing $db->buildLike() etc. 'DifferenceEngineAfterLoadNewText':called in DifferenceEngine::loadNewText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before returning true from this function. $differenceEngine:DifferenceEngine object 'DifferenceEngineLoadTextAfterNewContentIsLoaded':called in DifferenceEngine::loadText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before checking if the variable 's value is null. This hook can be used to inject content into said class member variable. $differenceEngine:DifferenceEngine object 'DifferenceEngineMarkPatrolledLink':Allows extensions to change the "mark as patrolled" link which is shown both on the diff header as well as on the bottom of a page, usually wrapped in a span element which has class="patrollink". $differenceEngine:DifferenceEngine object & $markAsPatrolledLink:The "mark as patrolled" link HTML(string) $rcid:Recent change ID(rc_id) for this change(int) 'DifferenceEngineMarkPatrolledRCID':Allows extensions to possibly change the rcid parameter. For example the rcid might be set to zero due to the user being the same as the performer of the change but an extension might still want to show it under certain conditions. & $rcid:rc_id(int) of the change or 0 $differenceEngine:DifferenceEngine object $change:RecentChange object $user:User object representing the current user 'DifferenceEngineNewHeader':Allows extensions to change the $newHeader variable, which contains information about the new revision, such as the revision 's author, whether the revision was marked as a minor edit or not, etc. $differenceEngine:DifferenceEngine object & $newHeader:The string containing the various #mw-diff-otitle[1-5] divs, which include things like revision author info, revision comment, RevisionDelete link and more $formattedRevisionTools:Array containing revision tools, some of which may have been injected with the DiffRevisionTools hook $nextlink:String containing the link to the next revision(if any) $status
Definition: hooks.txt:1255
wfMessage
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 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
MediaWiki\Auth\AuthManager\getSecondaryAuthenticationProviders
getSecondaryAuthenticationProviders()
Get the list of SecondaryAuthenticationProviders.
Definition: AuthManager.php:2359
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
$wgAuth
$wgAuth $wgAuth
Authentication plugin.
Definition: DefaultSettings.php:7362
MediaWiki\Auth\AuthManager\userCanAuthenticate
userCanAuthenticate( $username)
Determine whether a username can authenticate.
Definition: AuthManager.php:788
User\IGNORE_USER_RIGHTS
const IGNORE_USER_RIGHTS
Definition: User.php:90
MediaWikiServices
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 MediaWikiServices
Definition: injection.txt:23
MediaWiki\Auth\AuthenticationResponse\PASS
const PASS
Indicates that the authentication succeeded.
Definition: AuthenticationResponse.php:39
User\isUsableName
static isUsableName( $name)
Usernames which fail to pass this function will be blocked from user login and new account registrati...
Definition: User.php:1018
MediaWiki\Auth\AuthManager\allowsAuthenticationDataChange
allowsAuthenticationDataChange(AuthenticationRequest $req, $checkData=true)
Validate a change of authentication data (e.g.
Definition: AuthManager.php:852
MediaWiki\Auth\AuthenticationResponse\newRestart
static newRestart(Message $msg)
Definition: AuthenticationResponse.php:159
User\isBlockedFromCreateAccount
isBlockedFromCreateAccount()
Get whether the user is explicitly blocked from account creation.
Definition: User.php:4416
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:53
MediaWiki\Auth\PrimaryAuthenticationProvider
A primary authentication provider is responsible for associating the submitted authentication data wi...
Definition: PrimaryAuthenticationProvider.php:75
DeferredUpdates\addCallableUpdate
static addCallableUpdate( $callable, $stage=self::POSTSEND, $dbw=null)
Add a callable update.
Definition: DeferredUpdates.php:111
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:203
$username
this hook is for auditing only or null if authentication failed before getting that far $username
Definition: hooks.txt:783
MediaWiki\Auth
Definition: AbstractAuthenticationProvider.php:22
MediaWiki\Auth\AuthManager\setLogger
setLogger(LoggerInterface $logger)
Definition: AuthManager.php:170
MediaWiki\Auth\AuthManager\providerArrayFromSpecs
providerArrayFromSpecs( $class, array $specs)
Create an array of AuthenticationProviders from an array of ObjectFactory specs.
Definition: AuthManager.php:2283
MediaWiki\Auth\AuthenticationResponse\newPass
static newPass( $username=null)
Definition: AuthenticationResponse.php:134
User\getName
getName()
Get the user name, or the IP of an anonymous user.
Definition: User.php:2394
User\isCreatableName
static isCreatableName( $name)
Usernames which fail to pass this function will be blocked from new account registrations,...
Definition: User.php:1093
MediaWiki\Auth\AuthManager\checkAccountCreatePermissions
checkAccountCreatePermissions(User $creator)
Basic permissions checks on whether a user can create accounts.
Definition: AuthManager.php:976
MediaWiki\Auth\AuthenticationRequest
This is a value object for authentication requests.
Definition: AuthenticationRequest.php:37
MediaWiki\Auth\AuthenticationRequest\REQUIRED
const REQUIRED
Indicates that the request is required for authentication to proceed.
Definition: AuthenticationRequest.php:46
array
the array() calling protocol came about after MediaWiki 1.4rc1.
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56
MediaWiki\Auth\AuthManager\getAuthenticationRequestsInternal
getAuthenticationRequestsInternal( $providerAction, array $options, array $providers, User $user=null)
Internal request lookup for self::getAuthenticationRequests.
Definition: AuthManager.php:2074
MediaWiki\Auth\AuthenticationProvider
An AuthenticationProvider is used by AuthManager when authenticating users.
Definition: AuthenticationProvider.php:39