MediaWiki  1.32.0
LoginSignupSpecialPage.php
Go to the documentation of this file.
1 <?php
31 use Wikimedia\ScopedCallback;
32 
39  protected $mReturnTo;
40  protected $mPosted;
41  protected $mAction;
42  protected $mLanguage;
43  protected $mReturnToQuery;
44  protected $mToken;
45  protected $mStickHTTPS;
46  protected $mFromHTTP;
47  protected $mEntryError = '';
48  protected $mEntryErrorType = 'error';
49 
50  protected $mLoaded = false;
51  protected $mLoadedRequest = false;
52  protected $mSecureLoginUrl;
53 
55  protected $securityLevel;
56 
61  protected $targetUser;
62 
64  protected $authForm;
65 
67  protected $fakeTemplate;
68 
69  abstract protected function isSignup();
70 
77  abstract protected function successfulAction( $direct = false, $extraMessages = null );
78 
84  abstract protected function logAuthResult( $success, $status = null );
85 
86  public function __construct( $name ) {
88  parent::__construct( $name );
89 
90  // Override UseMediaWikiEverywhere to true, to force login and create form to use mw ui
92  }
93 
94  protected function setRequest( array $data, $wasPosted = null ) {
95  parent::setRequest( $data, $wasPosted );
96  $this->mLoadedRequest = false;
97  }
98 
103  private function loadRequestParameters( $subPage ) {
104  if ( $this->mLoadedRequest ) {
105  return;
106  }
107  $this->mLoadedRequest = true;
108  $request = $this->getRequest();
109 
110  $this->mPosted = $request->wasPosted();
111  $this->mIsReturn = $subPage === 'return';
112  $this->mAction = $request->getVal( 'action' );
113  $this->mFromHTTP = $request->getBool( 'fromhttp', false )
114  || $request->getBool( 'wpFromhttp', false );
115  $this->mStickHTTPS = ( !$this->mFromHTTP && $request->getProtocol() === 'https' )
116  || $request->getBool( 'wpForceHttps', false );
117  $this->mLanguage = $request->getText( 'uselang' );
118  $this->mReturnTo = $request->getVal( 'returnto', '' );
119  $this->mReturnToQuery = $request->getVal( 'returntoquery', '' );
120  }
121 
127  protected function load( $subPage ) {
128  global $wgSecureLogin;
129 
131  if ( $this->mLoaded ) {
132  return;
133  }
134  $this->mLoaded = true;
135  $request = $this->getRequest();
136 
137  $securityLevel = $this->getRequest()->getText( 'force' );
138  if (
139  $securityLevel && AuthManager::singleton()->securitySensitiveOperationStatus(
140  $securityLevel ) === AuthManager::SEC_REAUTH
141  ) {
142  $this->securityLevel = $securityLevel;
143  }
144 
145  $this->loadAuth( $subPage );
146 
147  $this->mToken = $request->getVal( $this->getTokenName() );
148 
149  // Show an error or warning passed on from a previous page
150  $entryError = $this->msg( $request->getVal( 'error', '' ) );
151  $entryWarning = $this->msg( $request->getVal( 'warning', '' ) );
152  // bc: provide login link as a parameter for messages where the translation
153  // was not updated
154  $loginreqlink = $this->getLinkRenderer()->makeKnownLink(
155  $this->getPageTitle(),
156  $this->msg( 'loginreqlink' )->text(),
157  [],
158  [
159  'returnto' => $this->mReturnTo,
160  'returntoquery' => $this->mReturnToQuery,
161  'uselang' => $this->mLanguage ?: null,
162  'fromhttp' => $wgSecureLogin && $this->mFromHTTP ? '1' : null,
163  ]
164  );
165 
166  // Only show valid error or warning messages.
167  if ( $entryError->exists()
168  && in_array( $entryError->getKey(), LoginHelper::getValidErrorMessages(), true )
169  ) {
170  $this->mEntryErrorType = 'error';
171  $this->mEntryError = $entryError->rawParams( $loginreqlink )->parse();
172 
173  } elseif ( $entryWarning->exists()
174  && in_array( $entryWarning->getKey(), LoginHelper::getValidErrorMessages(), true )
175  ) {
176  $this->mEntryErrorType = 'warning';
177  $this->mEntryError = $entryWarning->rawParams( $loginreqlink )->parse();
178  }
179 
180  # 1. When switching accounts, it sucks to get automatically logged out
181  # 2. Do not return to PasswordReset after a successful password change
182  # but goto Wiki start page (Main_Page) instead ( T35997 )
183  $returnToTitle = Title::newFromText( $this->mReturnTo );
184  if ( is_object( $returnToTitle )
185  && ( $returnToTitle->isSpecial( 'Userlogout' )
186  || $returnToTitle->isSpecial( 'PasswordReset' ) )
187  ) {
188  $this->mReturnTo = '';
189  $this->mReturnToQuery = '';
190  }
191  }
192 
193  protected function getPreservedParams( $withToken = false ) {
194  global $wgSecureLogin;
195 
196  $params = parent::getPreservedParams( $withToken );
197  $params += [
198  'returnto' => $this->mReturnTo ?: null,
199  'returntoquery' => $this->mReturnToQuery ?: null,
200  ];
201  if ( $wgSecureLogin && !$this->isSignup() ) {
202  $params['fromhttp'] = $this->mFromHTTP ? '1' : null;
203  }
204  return $params;
205  }
206 
207  protected function beforeExecute( $subPage ) {
208  // finish initializing the class before processing the request - T135924
210  return parent::beforeExecute( $subPage );
211  }
212 
216  public function execute( $subPage ) {
217  if ( $this->mPosted ) {
218  $time = microtime( true );
219  $profilingScope = new ScopedCallback( function () use ( $time ) {
220  $time = microtime( true ) - $time;
221  $statsd = MediaWikiServices::getInstance()->getStatsdDataFactory();
222  $statsd->timing( "timing.login.ui.{$this->authAction}", $time * 1000 );
223  } );
224  }
225 
226  $authManager = AuthManager::singleton();
227  $session = SessionManager::getGlobalSession();
228 
229  // Session data is used for various things in the authentication process, so we must make
230  // sure a session cookie or some equivalent mechanism is set.
231  $session->persist();
232 
233  $this->load( $subPage );
234  $this->setHeaders();
235  $this->checkPermissions();
236 
237  // Make sure the system configuration allows log in / sign up
238  if ( !$this->isSignup() && !$authManager->canAuthenticateNow() ) {
239  if ( !$session->canSetUser() ) {
240  throw new ErrorPageError( 'cannotloginnow-title', 'cannotloginnow-text', [
241  $session->getProvider()->describe( RequestContext::getMain()->getLanguage() )
242  ] );
243  }
244  throw new ErrorPageError( 'cannotlogin-title', 'cannotlogin-text' );
245  } elseif ( $this->isSignup() && !$authManager->canCreateAccounts() ) {
246  throw new ErrorPageError( 'cannotcreateaccount-title', 'cannotcreateaccount-text' );
247  }
248 
249  /*
250  * In the case where the user is already logged in, and was redirected to
251  * the login form from a page that requires login, do not show the login
252  * page. The use case scenario for this is when a user opens a large number
253  * of tabs, is redirected to the login page on all of them, and then logs
254  * in on one, expecting all the others to work properly.
255  *
256  * However, do show the form if it was visited intentionally (no 'returnto'
257  * is present). People who often switch between several accounts have grown
258  * accustomed to this behavior.
259  *
260  * Also make an exception when force=<level> is set in the URL, which means the user must
261  * reauthenticate for security reasons.
262  */
263  if ( !$this->isSignup() && !$this->mPosted && !$this->securityLevel &&
264  ( $this->mReturnTo !== '' || $this->mReturnToQuery !== '' ) &&
265  $this->getUser()->isLoggedIn()
266  ) {
267  $this->successfulAction();
268  return;
269  }
270 
271  // If logging in and not on HTTPS, either redirect to it or offer a link.
272  global $wgSecureLogin;
273  if ( $this->getRequest()->getProtocol() !== 'https' ) {
274  $title = $this->getFullTitle();
275  $query = $this->getPreservedParams( false ) + [
276  'title' => null,
277  ( $this->mEntryErrorType === 'error' ? 'error'
278  : 'warning' ) => $this->mEntryError,
279  ] + $this->getRequest()->getQueryValues();
280  $url = $title->getFullURL( $query, false, PROTO_HTTPS );
281  if ( $wgSecureLogin && !$this->mFromHTTP &&
282  wfCanIPUseHTTPS( $this->getRequest()->getIP() )
283  ) {
284  // Avoid infinite redirect
285  $url = wfAppendQuery( $url, 'fromhttp=1' );
286  $this->getOutput()->redirect( $url );
287  // Since we only do this redir to change proto, always vary
288  $this->getOutput()->addVaryHeader( 'X-Forwarded-Proto' );
289 
290  return;
291  } else {
292  // A wiki without HTTPS login support should set $wgServer to
293  // http://somehost, in which case the secure URL generated
294  // above won't actually start with https://
295  if ( substr( $url, 0, 8 ) === 'https://' ) {
296  $this->mSecureLoginUrl = $url;
297  }
298  }
299  }
300 
301  if ( !$this->isActionAllowed( $this->authAction ) ) {
302  // FIXME how do we explain this to the user? can we handle session loss better?
303  // messages used: authpage-cannot-login, authpage-cannot-login-continue,
304  // authpage-cannot-create, authpage-cannot-create-continue
305  $this->mainLoginForm( [], 'authpage-cannot-' . $this->authAction );
306  return;
307  }
308 
309  if ( $this->canBypassForm( $button_name ) ) {
310  $this->setRequest( [], true );
311  $this->getRequest()->setVal( $this->getTokenName(), $this->getToken() );
312  if ( $button_name ) {
313  $this->getRequest()->setVal( $button_name, true );
314  }
315  }
316 
317  $status = $this->trySubmit();
318 
319  if ( !$status || !$status->isGood() ) {
320  $this->mainLoginForm( $this->authRequests, $status ? $status->getMessage() : '', 'error' );
321  return;
322  }
323 
325  $response = $status->getValue();
326 
327  $returnToUrl = $this->getPageTitle( 'return' )
328  ->getFullURL( $this->getPreservedParams( true ), false, PROTO_HTTPS );
329  switch ( $response->status ) {
330  case AuthenticationResponse::PASS:
331  $this->logAuthResult( true );
332  $this->proxyAccountCreation = $this->isSignup() && !$this->getUser()->isAnon();
333  $this->targetUser = User::newFromName( $response->username );
334 
335  if (
336  !$this->proxyAccountCreation
337  && $response->loginRequest
338  && $authManager->canAuthenticateNow()
339  ) {
340  // successful registration; log the user in instantly
341  $response2 = $authManager->beginAuthentication( [ $response->loginRequest ],
342  $returnToUrl );
343  if ( $response2->status !== AuthenticationResponse::PASS ) {
344  LoggerFactory::getInstance( 'login' )
345  ->error( 'Could not log in after account creation' );
346  $this->successfulAction( true, Status::newFatal( 'createacct-loginerror' ) );
347  break;
348  }
349  }
350 
351  if ( !$this->proxyAccountCreation ) {
352  // Ensure that the context user is the same as the session user.
354  }
355 
356  $this->successfulAction( true );
357  break;
358  case AuthenticationResponse::FAIL:
359  // fall through
360  case AuthenticationResponse::RESTART:
361  unset( $this->authForm );
362  if ( $response->status === AuthenticationResponse::FAIL ) {
363  $action = $this->getDefaultAction( $subPage );
364  $messageType = 'error';
365  } else {
366  $action = $this->getContinueAction( $this->authAction );
367  $messageType = 'warning';
368  }
369  $this->logAuthResult( false, $response->message ? $response->message->getKey() : '-' );
370  $this->loadAuth( $subPage, $action, true );
371  $this->mainLoginForm( $this->authRequests, $response->message, $messageType );
372  break;
373  case AuthenticationResponse::REDIRECT:
374  unset( $this->authForm );
375  $this->getOutput()->redirect( $response->redirectTarget );
376  break;
377  case AuthenticationResponse::UI:
378  unset( $this->authForm );
379  $this->authAction = $this->isSignup() ? AuthManager::ACTION_CREATE_CONTINUE
380  : AuthManager::ACTION_LOGIN_CONTINUE;
381  $this->authRequests = $response->neededRequests;
382  $this->mainLoginForm( $response->neededRequests, $response->message, $response->messageType );
383  break;
384  default:
385  throw new LogicException( 'invalid AuthenticationResponse' );
386  }
387  }
388 
402  private function canBypassForm( &$button_name ) {
403  $button_name = null;
404  if ( $this->isContinued() ) {
405  return false;
406  }
407  $fields = AuthenticationRequest::mergeFieldInfo( $this->authRequests );
408  foreach ( $fields as $fieldname => $field ) {
409  if ( !isset( $field['type'] ) ) {
410  return false;
411  }
412  if ( !empty( $field['skippable'] ) ) {
413  continue;
414  }
415  if ( $field['type'] === 'button' ) {
416  if ( $button_name !== null ) {
417  $button_name = null;
418  return false;
419  } else {
420  $button_name = $fieldname;
421  }
422  } elseif ( $field['type'] !== 'null' ) {
423  return false;
424  }
425  }
426  return true;
427  }
428 
438  protected function showSuccessPage(
439  $type, $title, $msgname, $injected_html, $extraMessages
440  ) {
441  $out = $this->getOutput();
442  $out->setPageTitle( $title );
443  if ( $msgname ) {
444  $out->addWikiMsg( $msgname, wfEscapeWikiText( $this->getUser()->getName() ) );
445  }
446  if ( $extraMessages ) {
447  $extraMessages = Status::wrap( $extraMessages );
448  $out->addWikiText( $extraMessages->getWikiText() );
449  }
450 
451  $out->addHTML( $injected_html );
452 
453  $helper = new LoginHelper( $this->getContext() );
454  $helper->showReturnToPage( $type, $this->mReturnTo, $this->mReturnToQuery, $this->mStickHTTPS );
455  }
456 
472  public function showReturnToPage(
473  $type, $returnTo = '', $returnToQuery = '', $stickHTTPS = false
474  ) {
475  $helper = new LoginHelper( $this->getContext() );
476  $helper->showReturnToPage( $type, $returnTo, $returnToQuery, $stickHTTPS );
477  }
478 
483  protected function setSessionUserForCurrentRequest() {
484  global $wgUser, $wgLang;
485 
487  $localContext = $this->getContext();
488  if ( $context !== $localContext ) {
489  // remove AuthManagerSpecialPage context hack
490  $this->setContext( $context );
491  }
492 
493  $user = $context->getRequest()->getSession()->getUser();
494 
495  $wgUser = $user;
496  $context->setUser( $user );
497 
498  $code = $this->getRequest()->getVal( 'uselang', $user->getOption( 'language' ) );
499  $userLang = Language::factory( $code );
500  $wgLang = $userLang;
501  $context->setLanguage( $userLang );
502  }
503 
518  protected function mainLoginForm( array $requests, $msg = '', $msgtype = 'error' ) {
519  $user = $this->getUser();
520  $out = $this->getOutput();
521 
522  // FIXME how to handle empty $requests - restart, or no form, just an error message?
523  // no form would be better for no session type errors, restart is better when can* fails.
524  if ( !$requests ) {
525  $this->authAction = $this->getDefaultAction( $this->subPage );
526  $this->authForm = null;
527  $requests = AuthManager::singleton()->getAuthenticationRequests( $this->authAction, $user );
528  }
529 
530  // Generic styles and scripts for both login and signup form
531  $out->addModuleStyles( [
532  'mediawiki.ui',
533  'mediawiki.ui.button',
534  'mediawiki.ui.checkbox',
535  'mediawiki.ui.input',
536  'mediawiki.special.userlogin.common.styles'
537  ] );
538  if ( $this->isSignup() ) {
539  // XXX hack pending RL or JS parse() support for complex content messages T27349
540  $out->addJsConfigVars( 'wgCreateacctImgcaptchaHelp',
541  $this->msg( 'createacct-imgcaptcha-help' )->parse() );
542 
543  // Additional styles and scripts for signup form
544  $out->addModules( [
545  'mediawiki.special.userlogin.signup.js'
546  ] );
547  $out->addModuleStyles( [
548  'mediawiki.special.userlogin.signup.styles'
549  ] );
550  } else {
551  // Additional styles for login form
552  $out->addModuleStyles( [
553  'mediawiki.special.userlogin.login.styles'
554  ] );
555  }
556  $out->disallowUserJs(); // just in case...
557 
558  $form = $this->getAuthForm( $requests, $this->authAction, $msg, $msgtype );
559  $form->prepareForm();
560 
561  $submitStatus = Status::newGood();
562  if ( $msg && $msgtype === 'warning' ) {
563  $submitStatus->warning( $msg );
564  } elseif ( $msg && $msgtype === 'error' ) {
565  $submitStatus->fatal( $msg );
566  }
567 
568  // warning header for non-standard workflows (e.g. security reauthentication)
569  if (
570  !$this->isSignup() &&
571  $this->getUser()->isLoggedIn() &&
572  $this->authAction !== AuthManager::ACTION_LOGIN_CONTINUE
573  ) {
574  $reauthMessage = $this->securityLevel ? 'userlogin-reauth' : 'userlogin-loggedin';
575  $submitStatus->warning( $reauthMessage, $this->getUser()->getName() );
576  }
577 
578  $formHtml = $form->getHTML( $submitStatus );
579 
580  $out->addHTML( $this->getPageHtml( $formHtml ) );
581  }
582 
589  protected function getPageHtml( $formHtml ) {
591 
592  $loginPrompt = $this->isSignup() ? '' : Html::rawElement( 'div',
593  [ 'id' => 'userloginprompt' ], $this->msg( 'loginprompt' )->parseAsBlock() );
594  $languageLinks = $wgLoginLanguageSelector ? $this->makeLanguageSelector() : '';
595  $signupStartMsg = $this->msg( 'signupstart' );
596  $signupStart = ( $this->isSignup() && !$signupStartMsg->isDisabled() )
597  ? Html::rawElement( 'div', [ 'id' => 'signupstart' ], $signupStartMsg->parseAsBlock() ) : '';
598  if ( $languageLinks ) {
599  $languageLinks = Html::rawElement( 'div', [ 'id' => 'languagelinks' ],
600  Html::rawElement( 'p', [], $languageLinks )
601  );
602  }
603 
604  $benefitsContainer = '';
605  if ( $this->isSignup() && $this->showExtraInformation() ) {
606  // messages used:
607  // createacct-benefit-icon1 createacct-benefit-head1 createacct-benefit-body1
608  // createacct-benefit-icon2 createacct-benefit-head2 createacct-benefit-body2
609  // createacct-benefit-icon3 createacct-benefit-head3 createacct-benefit-body3
610  $benefitCount = 3;
611  $benefitList = '';
612  for ( $benefitIdx = 1; $benefitIdx <= $benefitCount; $benefitIdx++ ) {
613  $headUnescaped = $this->msg( "createacct-benefit-head$benefitIdx" )->text();
614  $iconClass = $this->msg( "createacct-benefit-icon$benefitIdx" )->text();
615  $benefitList .= Html::rawElement( 'div', [ 'class' => "mw-number-text $iconClass" ],
616  Html::rawElement( 'h3', [],
617  $this->msg( "createacct-benefit-head$benefitIdx" )->escaped()
618  )
619  . Html::rawElement( 'p', [],
620  $this->msg( "createacct-benefit-body$benefitIdx" )->params( $headUnescaped )->escaped()
621  )
622  );
623  }
624  $benefitsContainer = Html::rawElement( 'div', [ 'class' => 'mw-createacct-benefits-container' ],
625  Html::rawElement( 'h2', [], $this->msg( 'createacct-benefit-heading' )->escaped() )
626  . Html::rawElement( 'div', [ 'class' => 'mw-createacct-benefits-list' ],
627  $benefitList
628  )
629  );
630  }
631 
632  $html = Html::rawElement( 'div', [ 'class' => 'mw-ui-container' ],
633  $loginPrompt
634  . $languageLinks
635  . $signupStart
636  . Html::rawElement( 'div', [ 'id' => 'userloginForm' ],
637  $formHtml
638  )
639  . $benefitsContainer
640  );
641 
642  return $html;
643  }
644 
653  protected function getAuthForm( array $requests, $action, $msg = '', $msgType = 'error' ) {
654  global $wgSecureLogin;
655  // FIXME merge this with parent
656 
657  if ( isset( $this->authForm ) ) {
658  return $this->authForm;
659  }
660 
661  $usingHTTPS = $this->getRequest()->getProtocol() === 'https';
662 
663  // get basic form description from the auth logic
664  $fieldInfo = AuthenticationRequest::mergeFieldInfo( $requests );
665  $fakeTemplate = $this->getFakeTemplate( $msg, $msgType );
666  $this->fakeTemplate = $fakeTemplate; // FIXME there should be a saner way to pass this to the hook
667  // this will call onAuthChangeFormFields()
668  $formDescriptor = static::fieldInfoToFormDescriptor( $requests, $fieldInfo, $this->authAction );
669  $this->postProcessFormDescriptor( $formDescriptor, $requests );
670 
671  $context = $this->getContext();
672  if ( $context->getRequest() !== $this->getRequest() ) {
673  // We have overridden the request, need to make sure the form uses that too.
674  $context = new DerivativeContext( $this->getContext() );
675  $context->setRequest( $this->getRequest() );
676  }
677  $form = HTMLForm::factory( 'vform', $formDescriptor, $context );
678 
679  $form->addHiddenField( 'authAction', $this->authAction );
680  if ( $this->mLanguage ) {
681  $form->addHiddenField( 'uselang', $this->mLanguage );
682  }
683  $form->addHiddenField( 'force', $this->securityLevel );
684  $form->addHiddenField( $this->getTokenName(), $this->getToken()->toString() );
685  if ( $wgSecureLogin ) {
686  // If using HTTPS coming from HTTP, then the 'fromhttp' parameter must be preserved
687  if ( !$this->isSignup() ) {
688  $form->addHiddenField( 'wpForceHttps', (int)$this->mStickHTTPS );
689  $form->addHiddenField( 'wpFromhttp', $usingHTTPS );
690  }
691  }
692 
693  // set properties of the form itself
694  $form->setAction( $this->getPageTitle()->getLocalURL( $this->getReturnToQueryStringFragment() ) );
695  $form->setName( 'userlogin' . ( $this->isSignup() ? '2' : '' ) );
696  if ( $this->isSignup() ) {
697  $form->setId( 'userlogin2' );
698  }
699 
700  $form->suppressDefaultSubmit();
701 
702  $this->authForm = $form;
703 
704  return $form;
705  }
706 
713  protected function getFakeTemplate( $msg, $msgType ) {
716 
717  // make a best effort to get the value of fields which used to be fixed in the old login
718  // template but now might or might not exist depending on what providers are used
719  $request = $this->getRequest();
720  $data = (object)[
721  'mUsername' => $request->getText( 'wpName' ),
722  'mPassword' => $request->getText( 'wpPassword' ),
723  'mRetype' => $request->getText( 'wpRetype' ),
724  'mEmail' => $request->getText( 'wpEmail' ),
725  'mRealName' => $request->getText( 'wpRealName' ),
726  'mDomain' => $request->getText( 'wpDomain' ),
727  'mReason' => $request->getText( 'wpReason' ),
728  'mRemember' => $request->getCheck( 'wpRemember' ),
729  ];
730 
731  // Preserves a bunch of logic from the old code that was rewritten in getAuthForm().
732  // There is no code reuse to make this easier to remove .
733  // If an extension tries to change any of these values, they are out of luck - we only
734  // actually use the domain/usedomain/domainnames, extraInput and extrafields keys.
735 
736  $titleObj = $this->getPageTitle();
737  $user = $this->getUser();
738  $template = new FakeAuthTemplate();
739 
740  // Pre-fill username (if not creating an account, T46775).
741  if ( $data->mUsername == '' && $this->isSignup() ) {
742  if ( $user->isLoggedIn() ) {
743  $data->mUsername = $user->getName();
744  } else {
745  $data->mUsername = $this->getRequest()->getSession()->suggestLoginUsername();
746  }
747  }
748 
749  if ( $this->isSignup() ) {
750  // Must match number of benefits defined in messages
751  $template->set( 'benefitCount', 3 );
752 
753  $q = 'action=submitlogin&type=signup';
754  $linkq = 'type=login';
755  } else {
756  $q = 'action=submitlogin&type=login';
757  $linkq = 'type=signup';
758  }
759 
760  if ( $this->mReturnTo !== '' ) {
761  $returnto = '&returnto=' . wfUrlencode( $this->mReturnTo );
762  if ( $this->mReturnToQuery !== '' ) {
763  $returnto .= '&returntoquery=' .
764  wfUrlencode( $this->mReturnToQuery );
765  }
766  $q .= $returnto;
767  $linkq .= $returnto;
768  }
769 
770  # Don't show a "create account" link if the user can't.
771  if ( $this->showCreateAccountLink() ) {
772  # Pass any language selection on to the mode switch link
773  if ( $this->mLanguage ) {
774  $linkq .= '&uselang=' . urlencode( $this->mLanguage );
775  }
776  // Supply URL, login template creates the button.
777  $template->set( 'createOrLoginHref', $titleObj->getLocalURL( $linkq ) );
778  } else {
779  $template->set( 'link', '' );
780  }
781 
782  $resetLink = $this->isSignup()
783  ? null
784  : is_array( $wgPasswordResetRoutes )
785  && in_array( true, array_values( $wgPasswordResetRoutes ), true );
786 
787  $template->set( 'header', '' );
788  $template->set( 'formheader', '' );
789  $template->set( 'skin', $this->getSkin() );
790 
791  $template->set( 'name', $data->mUsername );
792  $template->set( 'password', $data->mPassword );
793  $template->set( 'retype', $data->mRetype );
794  $template->set( 'createemailset', false ); // no easy way to get that from AuthManager
795  $template->set( 'email', $data->mEmail );
796  $template->set( 'realname', $data->mRealName );
797  $template->set( 'domain', $data->mDomain );
798  $template->set( 'reason', $data->mReason );
799  $template->set( 'remember', $data->mRemember );
800 
801  $template->set( 'action', $titleObj->getLocalURL( $q ) );
802  $template->set( 'message', $msg );
803  $template->set( 'messagetype', $msgType );
804  $template->set( 'createemail', $wgEnableEmail && $user->isLoggedIn() );
805  $template->set( 'userealname', !in_array( 'realname', $wgHiddenPrefs, true ) );
806  $template->set( 'useemail', $wgEnableEmail );
807  $template->set( 'emailrequired', $wgEmailConfirmToEdit );
808  $template->set( 'emailothers', $wgEnableUserEmail );
809  $template->set( 'canreset', $wgAuth->allowPasswordChange() );
810  $template->set( 'resetlink', $resetLink );
811  $template->set( 'canremember', $request->getSession()->getProvider()
812  ->getRememberUserDuration() !== null );
813  $template->set( 'usereason', $user->isLoggedIn() );
814  $template->set( 'cansecurelogin', ( $wgSecureLogin ) );
815  $template->set( 'stickhttps', (int)$this->mStickHTTPS );
816  $template->set( 'loggedin', $user->isLoggedIn() );
817  $template->set( 'loggedinuser', $user->getName() );
818  $template->set( 'token', $this->getToken()->toString() );
819 
820  $action = $this->isSignup() ? 'signup' : 'login';
821  $wgAuth->modifyUITemplate( $template, $action );
822 
823  $oldTemplate = $template;
824 
825  // Both Hooks::run are explicit here to make findHooks.php happy
826  if ( $this->isSignup() ) {
827  Hooks::run( 'UserCreateForm', [ &$template ], '1.27' );
828  if ( $oldTemplate !== $template ) {
829  wfDeprecated( "reference in UserCreateForm hook", '1.27' );
830  }
831  } else {
832  Hooks::run( 'UserLoginForm', [ &$template ], '1.27' );
833  if ( $oldTemplate !== $template ) {
834  wfDeprecated( "reference in UserLoginForm hook", '1.27' );
835  }
836  }
837 
838  return $template;
839  }
840 
841  public function onAuthChangeFormFields(
842  array $requests, array $fieldInfo, array &$formDescriptor, $action
843  ) {
844  $coreFieldDescriptors = $this->getFieldDefinitions( $this->fakeTemplate );
845  $specialFields = array_merge( [ 'extraInput' ],
846  array_keys( $this->fakeTemplate->getExtraInputDefinitions() ) );
847 
848  // keep the ordering from getCoreFieldDescriptors() where there is no explicit weight
849  foreach ( $coreFieldDescriptors as $fieldName => $coreField ) {
850  $requestField = $formDescriptor[$fieldName] ?? [];
851 
852  // remove everything that is not in the fieldinfo, is not marked as a supplemental field
853  // to something in the fieldinfo, is not B/C for the pre-AuthManager templates,
854  // and is not an info field or a submit button
855  if (
856  !isset( $fieldInfo[$fieldName] )
857  && (
858  !isset( $coreField['baseField'] )
859  || !isset( $fieldInfo[$coreField['baseField']] )
860  )
861  && !in_array( $fieldName, $specialFields, true )
862  && (
863  !isset( $coreField['type'] )
864  || !in_array( $coreField['type'], [ 'submit', 'info' ], true )
865  )
866  ) {
867  $coreFieldDescriptors[$fieldName] = null;
868  continue;
869  }
870 
871  // core message labels should always take priority
872  if (
873  isset( $coreField['label'] )
874  || isset( $coreField['label-message'] )
875  || isset( $coreField['label-raw'] )
876  ) {
877  unset( $requestField['label'], $requestField['label-message'], $coreField['label-raw'] );
878  }
879 
880  $coreFieldDescriptors[$fieldName] += $requestField;
881  }
882 
883  $formDescriptor = array_filter( $coreFieldDescriptors + $formDescriptor );
884  return true;
885  }
886 
893  protected function showExtraInformation() {
894  return $this->authAction !== $this->getContinueAction( $this->authAction )
896  }
897 
903  protected function getFieldDefinitions( $template ) {
904  global $wgEmailConfirmToEdit;
905 
906  $isLoggedIn = $this->getUser()->isLoggedIn();
907  $continuePart = $this->isContinued() ? 'continue-' : '';
908  $anotherPart = $isLoggedIn ? 'another-' : '';
909  $expiration = $this->getRequest()->getSession()->getProvider()->getRememberUserDuration();
910  $expirationDays = ceil( $expiration / ( 3600 * 24 ) );
911  $secureLoginLink = '';
912  if ( $this->mSecureLoginUrl ) {
913  $secureLoginLink = Html::element( 'a', [
914  'href' => $this->mSecureLoginUrl,
915  'class' => 'mw-ui-flush-right mw-secure',
916  ], $this->msg( 'userlogin-signwithsecure' )->text() );
917  }
918  $usernameHelpLink = '';
919  if ( !$this->msg( 'createacct-helpusername' )->isDisabled() ) {
920  $usernameHelpLink = Html::rawElement( 'span', [
921  'class' => 'mw-ui-flush-right',
922  ], $this->msg( 'createacct-helpusername' )->parse() );
923  }
924 
925  if ( $this->isSignup() ) {
926  $fieldDefinitions = [
927  'statusarea' => [
928  // used by the mediawiki.special.userlogin.signup.js module for error display
929  // FIXME merge this with HTMLForm's normal status (error) area
930  'type' => 'info',
931  'raw' => true,
932  'default' => Html::element( 'div', [ 'id' => 'mw-createacct-status-area' ] ),
933  'weight' => -105,
934  ],
935  'username' => [
936  'label-raw' => $this->msg( 'userlogin-yourname' )->escaped() . $usernameHelpLink,
937  'id' => 'wpName2',
938  'placeholder-message' => $isLoggedIn ? 'createacct-another-username-ph'
939  : 'userlogin-yourname-ph',
940  ],
941  'mailpassword' => [
942  // create account without providing password, a temporary one will be mailed
943  'type' => 'check',
944  'label-message' => 'createaccountmail',
945  'name' => 'wpCreateaccountMail',
946  'id' => 'wpCreateaccountMail',
947  ],
948  'password' => [
949  'id' => 'wpPassword2',
950  'placeholder-message' => 'createacct-yourpassword-ph',
951  'hide-if' => [ '===', 'wpCreateaccountMail', '1' ],
952  ],
953  'domain' => [],
954  'retype' => [
955  'baseField' => 'password',
956  'type' => 'password',
957  'label-message' => 'createacct-yourpasswordagain',
958  'id' => 'wpRetype',
959  'cssclass' => 'loginPassword',
960  'size' => 20,
961  'validation-callback' => function ( $value, $alldata ) {
962  if ( empty( $alldata['mailpassword'] ) && !empty( $alldata['password'] ) ) {
963  if ( !$value ) {
964  return $this->msg( 'htmlform-required' );
965  } elseif ( $value !== $alldata['password'] ) {
966  return $this->msg( 'badretype' );
967  }
968  }
969  return true;
970  },
971  'hide-if' => [ '===', 'wpCreateaccountMail', '1' ],
972  'placeholder-message' => 'createacct-yourpasswordagain-ph',
973  ],
974  'email' => [
975  'type' => 'email',
976  'label-message' => $wgEmailConfirmToEdit ? 'createacct-emailrequired'
977  : 'createacct-emailoptional',
978  'id' => 'wpEmail',
979  'cssclass' => 'loginText',
980  'size' => '20',
981  // FIXME will break non-standard providers
982  'required' => $wgEmailConfirmToEdit,
983  'validation-callback' => function ( $value, $alldata ) {
984  global $wgEmailConfirmToEdit;
985 
986  // AuthManager will check most of these, but that will make the auth
987  // session fail and this won't, so nicer to do it this way
988  if ( !$value && $wgEmailConfirmToEdit ) {
989  // no point in allowing registration without email when email is
990  // required to edit
991  return $this->msg( 'noemailtitle' );
992  } elseif ( !$value && !empty( $alldata['mailpassword'] ) ) {
993  // cannot send password via email when there is no email address
994  return $this->msg( 'noemailcreate' );
995  } elseif ( $value && !Sanitizer::validateEmail( $value ) ) {
996  return $this->msg( 'invalidemailaddress' );
997  }
998  return true;
999  },
1000  'placeholder-message' => 'createacct-' . $anotherPart . 'email-ph',
1001  ],
1002  'realname' => [
1003  'type' => 'text',
1004  'help-message' => $isLoggedIn ? 'createacct-another-realname-tip'
1005  : 'prefs-help-realname',
1006  'label-message' => 'createacct-realname',
1007  'cssclass' => 'loginText',
1008  'size' => 20,
1009  'id' => 'wpRealName',
1010  ],
1011  'reason' => [
1012  // comment for the user creation log
1013  'type' => 'text',
1014  'label-message' => 'createacct-reason',
1015  'cssclass' => 'loginText',
1016  'id' => 'wpReason',
1017  'size' => '20',
1018  'placeholder-message' => 'createacct-reason-ph',
1019  ],
1020  'extrainput' => [], // placeholder for fields coming from the template
1021  'createaccount' => [
1022  // submit button
1023  'type' => 'submit',
1024  'default' => $this->msg( 'createacct-' . $anotherPart . $continuePart .
1025  'submit' )->text(),
1026  'name' => 'wpCreateaccount',
1027  'id' => 'wpCreateaccount',
1028  'weight' => 100,
1029  ],
1030  ];
1031  } else {
1032  $fieldDefinitions = [
1033  'username' => [
1034  'label-raw' => $this->msg( 'userlogin-yourname' )->escaped() . $secureLoginLink,
1035  'id' => 'wpName1',
1036  'placeholder-message' => 'userlogin-yourname-ph',
1037  ],
1038  'password' => [
1039  'id' => 'wpPassword1',
1040  'placeholder-message' => 'userlogin-yourpassword-ph',
1041  ],
1042  'domain' => [],
1043  'extrainput' => [],
1044  'rememberMe' => [
1045  // option for saving the user token to a cookie
1046  'type' => 'check',
1047  'name' => 'wpRemember',
1048  'label-message' => $this->msg( 'userlogin-remembermypassword' )
1049  ->numParams( $expirationDays ),
1050  'id' => 'wpRemember',
1051  ],
1052  'loginattempt' => [
1053  // submit button
1054  'type' => 'submit',
1055  'default' => $this->msg( 'pt-login-' . $continuePart . 'button' )->text(),
1056  'id' => 'wpLoginAttempt',
1057  'weight' => 100,
1058  ],
1059  'linkcontainer' => [
1060  // help link
1061  'type' => 'info',
1062  'cssclass' => 'mw-form-related-link-container mw-userlogin-help',
1063  // 'id' => 'mw-userlogin-help', // FIXME HTMLInfoField ignores this
1064  'raw' => true,
1065  'default' => Html::element( 'a', [
1066  'href' => Skin::makeInternalOrExternalUrl( $this->msg( 'helplogin-url' )
1067  ->inContentLanguage()
1068  ->text() ),
1069  ], $this->msg( 'userlogin-helplink2' )->text() ),
1070  'weight' => 200,
1071  ],
1072  // button for ResetPasswordSecondaryAuthenticationProvider
1073  'skipReset' => [
1074  'weight' => 110,
1075  'flags' => [],
1076  ],
1077  ];
1078  }
1079 
1080  $fieldDefinitions['username'] += [
1081  'type' => 'text',
1082  'name' => 'wpName',
1083  'cssclass' => 'loginText',
1084  'size' => 20,
1085  // 'required' => true,
1086  ];
1087  $fieldDefinitions['password'] += [
1088  'type' => 'password',
1089  // 'label-message' => 'userlogin-yourpassword', // would override the changepassword label
1090  'name' => 'wpPassword',
1091  'cssclass' => 'loginPassword',
1092  'size' => 20,
1093  // 'required' => true,
1094  ];
1095 
1096  if ( $template->get( 'header' ) || $template->get( 'formheader' ) ) {
1097  // B/C for old extensions that haven't been converted to AuthManager (or have been
1098  // but somebody is using the old version) and still use templates via the
1099  // UserCreateForm/UserLoginForm hook.
1100  // 'header' used by ConfirmEdit, ConfirmAccount, Persona, WikimediaIncubator, SemanticSignup
1101  // 'formheader' used by MobileFrontend
1102  $fieldDefinitions['header'] = [
1103  'type' => 'info',
1104  'raw' => true,
1105  'default' => $template->get( 'header' ) ?: $template->get( 'formheader' ),
1106  'weight' => -110,
1107  ];
1108  }
1109  if ( $this->mEntryError ) {
1110  $fieldDefinitions['entryError'] = [
1111  'type' => 'info',
1112  'default' => Html::rawElement( 'div', [ 'class' => $this->mEntryErrorType . 'box', ],
1113  $this->mEntryError ),
1114  'raw' => true,
1115  'rawrow' => true,
1116  'weight' => -100,
1117  ];
1118  }
1119  if ( !$this->showExtraInformation() ) {
1120  unset( $fieldDefinitions['linkcontainer'], $fieldDefinitions['signupend'] );
1121  }
1122  if ( $this->isSignup() && $this->showExtraInformation() ) {
1123  // blank signup footer for site customization
1124  // uses signupend-https for HTTPS requests if it's not blank, signupend otherwise
1125  $signupendMsg = $this->msg( 'signupend' );
1126  $signupendHttpsMsg = $this->msg( 'signupend-https' );
1127  if ( !$signupendMsg->isDisabled() ) {
1128  $usingHTTPS = $this->getRequest()->getProtocol() === 'https';
1129  $signupendText = ( $usingHTTPS && !$signupendHttpsMsg->isBlank() )
1130  ? $signupendHttpsMsg->parse() : $signupendMsg->parse();
1131  $fieldDefinitions['signupend'] = [
1132  'type' => 'info',
1133  'raw' => true,
1134  'default' => Html::rawElement( 'div', [ 'id' => 'signupend' ], $signupendText ),
1135  'weight' => 225,
1136  ];
1137  }
1138  }
1139  if ( !$this->isSignup() && $this->showExtraInformation() ) {
1140  $passwordReset = new PasswordReset( $this->getConfig(), AuthManager::singleton() );
1141  if ( $passwordReset->isAllowed( $this->getUser() )->isGood() ) {
1142  $fieldDefinitions['passwordReset'] = [
1143  'type' => 'info',
1144  'raw' => true,
1145  'cssclass' => 'mw-form-related-link-container',
1146  'default' => $this->getLinkRenderer()->makeLink(
1147  SpecialPage::getTitleFor( 'PasswordReset' ),
1148  $this->msg( 'userlogin-resetpassword-link' )->text()
1149  ),
1150  'weight' => 230,
1151  ];
1152  }
1153 
1154  // Don't show a "create account" link if the user can't.
1155  if ( $this->showCreateAccountLink() ) {
1156  // link to the other action
1157  $linkTitle = $this->getTitleFor( $this->isSignup() ? 'Userlogin' : 'CreateAccount' );
1158  $linkq = $this->getReturnToQueryStringFragment();
1159  // Pass any language selection on to the mode switch link
1160  if ( $this->mLanguage ) {
1161  $linkq .= '&uselang=' . urlencode( $this->mLanguage );
1162  }
1163  $loggedIn = $this->getUser()->isLoggedIn();
1164 
1165  $fieldDefinitions['createOrLogin'] = [
1166  'type' => 'info',
1167  'raw' => true,
1168  'linkQuery' => $linkq,
1169  'default' => function ( $params ) use ( $loggedIn, $linkTitle ) {
1170  return Html::rawElement( 'div',
1171  [ 'id' => 'mw-createaccount' . ( !$loggedIn ? '-cta' : '' ),
1172  'class' => ( $loggedIn ? 'mw-form-related-link-container' : 'mw-ui-vform-field' ) ],
1173  ( $loggedIn ? '' : $this->msg( 'userlogin-noaccount' )->escaped() )
1174  . Html::element( 'a',
1175  [
1176  'id' => 'mw-createaccount-join' . ( $loggedIn ? '-loggedin' : '' ),
1177  'href' => $linkTitle->getLocalURL( $params['linkQuery'] ),
1178  'class' => ( $loggedIn ? '' : 'mw-ui-button' ),
1179  'tabindex' => 100,
1180  ],
1181  $this->msg(
1182  $loggedIn ? 'userlogin-createanother' : 'userlogin-joinproject'
1183  )->text()
1184  )
1185  );
1186  },
1187  'weight' => 235,
1188  ];
1189  }
1190  }
1191 
1192  $fieldDefinitions = $this->getBCFieldDefinitions( $fieldDefinitions, $template );
1193  $fieldDefinitions = array_filter( $fieldDefinitions );
1194 
1195  return $fieldDefinitions;
1196  }
1197 
1204  protected function getBCFieldDefinitions( $fieldDefinitions, $template ) {
1205  if ( $template->get( 'usedomain', false ) ) {
1206  // TODO probably should be translated to the new domain notation in AuthManager
1207  $fieldDefinitions['domain'] = [
1208  'type' => 'select',
1209  'label-message' => 'yourdomainname',
1210  'options' => array_combine( $template->get( 'domainnames', [] ),
1211  $template->get( 'domainnames', [] ) ),
1212  'default' => $template->get( 'domain', '' ),
1213  'name' => 'wpDomain',
1214  // FIXME id => 'mw-user-domain-section' on the parent div
1215  ];
1216  }
1217 
1218  // poor man's associative array_splice
1219  $extraInputPos = array_search( 'extrainput', array_keys( $fieldDefinitions ), true );
1220  $fieldDefinitions = array_slice( $fieldDefinitions, 0, $extraInputPos, true )
1221  + $template->getExtraInputDefinitions()
1222  + array_slice( $fieldDefinitions, $extraInputPos + 1, null, true );
1223 
1224  return $fieldDefinitions;
1225  }
1226 
1236  protected function hasSessionCookie() {
1238 
1239  return $wgDisableCookieCheck || (
1241  $this->getRequest()->getSession()->getId() === (string)$wgInitialSessionId
1242  );
1243  }
1244 
1250  protected function getReturnToQueryStringFragment() {
1251  $returnto = '';
1252  if ( $this->mReturnTo !== '' ) {
1253  $returnto = 'returnto=' . wfUrlencode( $this->mReturnTo );
1254  if ( $this->mReturnToQuery !== '' ) {
1255  $returnto .= '&returntoquery=' . wfUrlencode( $this->mReturnToQuery );
1256  }
1257  }
1258  return $returnto;
1259  }
1260 
1266  private function showCreateAccountLink() {
1267  if ( $this->isSignup() ) {
1268  return true;
1269  } elseif ( $this->getUser()->isAllowed( 'createaccount' ) ) {
1270  return true;
1271  } else {
1272  return false;
1273  }
1274  }
1275 
1276  protected function getTokenName() {
1277  return $this->isSignup() ? 'wpCreateaccountToken' : 'wpLoginToken';
1278  }
1279 
1286  protected function makeLanguageSelector() {
1287  $msg = $this->msg( 'loginlanguagelinks' )->inContentLanguage();
1288  if ( $msg->isBlank() ) {
1289  return '';
1290  }
1291  $langs = explode( "\n", $msg->text() );
1292  $links = [];
1293  foreach ( $langs as $lang ) {
1294  $lang = trim( $lang, '* ' );
1295  $parts = explode( '|', $lang );
1296  if ( count( $parts ) >= 2 ) {
1297  $links[] = $this->makeLanguageSelectorLink( $parts[0], trim( $parts[1] ) );
1298  }
1299  }
1300 
1301  return count( $links ) > 0 ? $this->msg( 'loginlanguagelabel' )->rawParams(
1302  $this->getLanguage()->pipeList( $links ) )->escaped() : '';
1303  }
1304 
1313  protected function makeLanguageSelectorLink( $text, $lang ) {
1314  if ( $this->getLanguage()->getCode() == $lang ) {
1315  // no link for currently used language
1316  return htmlspecialchars( $text );
1317  }
1318  $query = [ 'uselang' => $lang ];
1319  if ( $this->mReturnTo !== '' ) {
1320  $query['returnto'] = $this->mReturnTo;
1321  $query['returntoquery'] = $this->mReturnToQuery;
1322  }
1323 
1324  $attr = [];
1325  $targetLanguage = Language::factory( $lang );
1326  $attr['lang'] = $attr['hreflang'] = $targetLanguage->getHtmlCode();
1327 
1328  return $this->getLinkRenderer()->makeKnownLink(
1329  $this->getPageTitle(),
1330  $text,
1331  $attr,
1332  $query
1333  );
1334  }
1335 
1336  protected function getGroupName() {
1337  return 'login';
1338  }
1339 
1345  // Pre-fill username (if not creating an account, T46775).
1346  if (
1347  isset( $formDescriptor['username'] ) &&
1348  !isset( $formDescriptor['username']['default'] ) &&
1349  !$this->isSignup()
1350  ) {
1351  $user = $this->getUser();
1352  if ( $user->isLoggedIn() ) {
1353  $formDescriptor['username']['default'] = $user->getName();
1354  } else {
1355  $formDescriptor['username']['default'] =
1356  $this->getRequest()->getSession()->suggestLoginUsername();
1357  }
1358  }
1359 
1360  // don't show a submit button if there is nothing to submit (i.e. the only form content
1361  // is other submit buttons, for redirect flows)
1362  if ( !$this->needsSubmitButton( $requests ) ) {
1363  unset( $formDescriptor['createaccount'], $formDescriptor['loginattempt'] );
1364  }
1365 
1366  if ( !$this->isSignup() ) {
1367  // FIXME HACK don't focus on non-empty field
1368  // maybe there should be an autofocus-if similar to hide-if?
1369  if (
1370  isset( $formDescriptor['username'] )
1371  && empty( $formDescriptor['username']['default'] )
1372  && !$this->getRequest()->getCheck( 'wpName' )
1373  ) {
1374  $formDescriptor['username']['autofocus'] = true;
1375  } elseif ( isset( $formDescriptor['password'] ) ) {
1376  $formDescriptor['password']['autofocus'] = true;
1377  }
1378  }
1379 
1380  $this->addTabIndex( $formDescriptor );
1381  }
1382 }
1383 
1391  public function execute() {
1392  throw new LogicException( 'not used' );
1393  }
1394 
1404  public function addInputItem( $name, $value, $type, $msg, $helptext = false ) {
1405  // use the same indexes as UserCreateForm just in case someone adds an item manually
1406  $this->data['extrainput'][] = [
1407  'name' => $name,
1408  'value' => $value,
1409  'type' => $type,
1410  'msg' => $msg,
1411  'helptext' => $helptext,
1412  ];
1413  }
1414 
1419  public function getExtraInputDefinitions() {
1420  $definitions = [];
1421 
1422  foreach ( $this->get( 'extrainput', [] ) as $field ) {
1423  $definition = [
1424  'type' => $field['type'] === 'checkbox' ? 'check' : $field['type'],
1425  'name' => $field['name'],
1426  'value' => $field['value'],
1427  'id' => $field['name'],
1428  ];
1429  if ( $field['msg'] ) {
1430  $definition['label-message'] = $this->getMsg( $field['msg'] );
1431  }
1432  if ( $field['helptext'] ) {
1433  $definition['help'] = $this->msgWiki( $field['helptext'] );
1434  }
1435 
1436  // the array key doesn't matter much when name is defined explicitly but
1437  // let's try and follow HTMLForm conventions
1438  $name = preg_replace( '/^wp(?=[A-Z])/', '', $field['name'] );
1439  $definitions[$name] = $definition;
1440  }
1441 
1442  if ( $this->haveData( 'extrafields' ) ) {
1443  $definitions['extrafields'] = [
1444  'type' => 'info',
1445  'raw' => true,
1446  'default' => $this->get( 'extrafields' ),
1447  ];
1448  }
1449 
1450  return $definitions;
1451  }
1452 }
1453 
1459 class LoginForm extends SpecialPage {
1460  const SUCCESS = 0;
1461  const NO_NAME = 1;
1462  const ILLEGAL = 2;
1464  const NOT_EXISTS = 4;
1465  const WRONG_PASS = 5;
1466  const EMPTY_PASS = 6;
1467  const RESET_PASS = 7;
1468  const ABORTED = 8;
1469  const CREATE_BLOCKED = 9;
1470  const THROTTLED = 10;
1471  const USER_BLOCKED = 11;
1472  const NEED_TOKEN = 12;
1473  const WRONG_TOKEN = 13;
1474  const USER_MIGRATED = 14;
1475 
1476  public static $statusCodes = [
1477  self::SUCCESS => 'success',
1478  self::NO_NAME => 'no_name',
1479  self::ILLEGAL => 'illegal',
1480  self::WRONG_PLUGIN_PASS => 'wrong_plugin_pass',
1481  self::NOT_EXISTS => 'not_exists',
1482  self::WRONG_PASS => 'wrong_pass',
1483  self::EMPTY_PASS => 'empty_pass',
1484  self::RESET_PASS => 'reset_pass',
1485  self::ABORTED => 'aborted',
1486  self::CREATE_BLOCKED => 'create_blocked',
1487  self::THROTTLED => 'throttled',
1488  self::USER_BLOCKED => 'user_blocked',
1489  self::NEED_TOKEN => 'need_token',
1490  self::WRONG_TOKEN => 'wrong_token',
1491  self::USER_MIGRATED => 'user_migrated',
1492  ];
1493 
1497  public function __construct( $request = null ) {
1498  wfDeprecated( 'LoginForm', '1.27' );
1499  parent::__construct();
1500  }
1501 
1506  public static function getValidErrorMessages() {
1508  }
1509 
1515  public static function incrementLoginThrottle( $username ) {
1516  wfDeprecated( __METHOD__, "1.27" );
1517  global $wgRequest;
1519  $throttler = new Throttler();
1520  return $throttler->increase( $username, $wgRequest->getIP(), __METHOD__ );
1521  }
1522 
1528  public static function incLoginThrottle( $username ) {
1529  wfDeprecated( __METHOD__, "1.27" );
1531  return is_array( $res ) ? true : 0;
1532  }
1533 
1539  public static function clearLoginThrottle( $username ) {
1540  wfDeprecated( __METHOD__, "1.27" );
1541  global $wgRequest;
1543  $throttler = new Throttler();
1544  return $throttler->clear( $username, $wgRequest->getIP() );
1545  }
1546 
1550  public static function getLoginToken() {
1551  wfDeprecated( __METHOD__, '1.27' );
1552  global $wgRequest;
1553  return $wgRequest->getSession()->getToken( '', 'login' )->toString();
1554  }
1555 
1559  public static function setLoginToken() {
1560  wfDeprecated( __METHOD__, '1.27' );
1561  }
1562 
1566  public static function clearLoginToken() {
1567  wfDeprecated( __METHOD__, '1.27' );
1568  global $wgRequest;
1569  $wgRequest->getSession()->resetToken( 'login' );
1570  }
1571 
1576  public static function getCreateaccountToken() {
1577  wfDeprecated( __METHOD__, '1.27' );
1578  global $wgRequest;
1579  return $wgRequest->getSession()->getToken( '', 'createaccount' )->toString();
1580  }
1581 
1585  public static function setCreateaccountToken() {
1586  wfDeprecated( __METHOD__, '1.27' );
1587  }
1588 
1592  public static function clearCreateaccountToken() {
1593  wfDeprecated( __METHOD__, '1.27' );
1594  global $wgRequest;
1595  $wgRequest->getSession()->resetToken( 'createaccount' );
1596  }
1597 }
$wgHiddenPrefs
$wgHiddenPrefs
An array of preferences to not show for the user.
Definition: DefaultSettings.php:4926
$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. 'ContentSecurityPolicyDefaultSource':Modify the allowed CSP load sources. This affects all directives except for the script directive. If you want to add a script source, see ContentSecurityPolicyScriptSource hook. & $defaultSrc:Array of Content-Security-Policy allowed sources $policyConfig:Current configuration for the Content-Security-Policy header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyDirectives':Modify the content security policy directives. Use this only if ContentSecurityPolicyDefaultSource and ContentSecurityPolicyScriptSource do not meet your needs. & $directives:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyScriptSource':Modify the allowed CSP script sources. Note that you also have to use ContentSecurityPolicyDefaultSource if you want non-script sources to be loaded from whatever you add. & $scriptSrc:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header '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:1305
LoginSignupSpecialPage\getTokenName
getTokenName()
Returns the name of the CSRF token (under which it should be found in the POST or GET data).
Definition: LoginSignupSpecialPage.php:1276
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:678
LoginSignupSpecialPage\$mEntryErrorType
$mEntryErrorType
Definition: LoginSignupSpecialPage.php:48
LoginSignupSpecialPage\setRequest
setRequest(array $data, $wasPosted=null)
Override the POST data, GET data from the real request is preserved.
Definition: LoginSignupSpecialPage.php:94
BaseTemplate\msgWiki
msgWiki( $str)
An ugly, ugly hack.
Definition: BaseTemplate.php:58
$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
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:280
$template
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping $template
Definition: hooks.txt:813
LoginForm\$statusCodes
static $statusCodes
Definition: LoginSignupSpecialPage.php:1476
LoginSignupSpecialPage\postProcessFormDescriptor
postProcessFormDescriptor(&$formDescriptor, $requests)
Definition: LoginSignupSpecialPage.php:1344
SpecialPage\msg
msg( $key)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:796
wfCanIPUseHTTPS
wfCanIPUseHTTPS( $ip)
Determine whether the client at a given source IP is likely to be able to access the wiki via HTTPS.
Definition: GlobalFunctions.php:3163
LoginForm\USER_BLOCKED
const USER_BLOCKED
Definition: LoginSignupSpecialPage.php:1471
LoginSignupSpecialPage\__construct
__construct( $name)
Definition: LoginSignupSpecialPage.php:86
AuthManagerSpecialPage\addTabIndex
addTabIndex(&$formDescriptor)
Adds a sequential tabindex starting from 1 to all form elements.
Definition: AuthManagerSpecialPage.php:603
FakeAuthTemplate\getExtraInputDefinitions
getExtraInputDefinitions()
Turns addInputItem-style field definitions into HTMLForm field definitions.
Definition: LoginSignupSpecialPage.php:1419
LoginForm\WRONG_PASS
const WRONG_PASS
Definition: LoginSignupSpecialPage.php:1465
$context
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2675
LoginSignupSpecialPage\getBCFieldDefinitions
getBCFieldDefinitions( $fieldDefinitions, $template)
Adds fields provided via the deprecated UserLoginForm / UserCreateForm hooks.
Definition: LoginSignupSpecialPage.php:1204
LoginForm\CREATE_BLOCKED
const CREATE_BLOCKED
Definition: LoginSignupSpecialPage.php:1469
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:725
LoginSignupSpecialPage\$mReturnTo
$mReturnTo
Definition: LoginSignupSpecialPage.php:39
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
LoginForm\ILLEGAL
const ILLEGAL
Definition: LoginSignupSpecialPage.php:1462
LoginSignupSpecialPage\showSuccessPage
showSuccessPage( $type, $title, $msgname, $injected_html, $extraMessages)
Show the success page.
Definition: LoginSignupSpecialPage.php:438
captcha-old.count
count
Definition: captcha-old.py:249
LoginForm\SUCCESS
const SUCCESS
Definition: LoginSignupSpecialPage.php:1460
LoginSignupSpecialPage\$mReturnToQuery
$mReturnToQuery
Definition: LoginSignupSpecialPage.php:43
$wgPasswordResetRoutes
$wgPasswordResetRoutes
Whether to allow password resets ("enter some identifying data, and we'll send an email with a tempor...
Definition: DefaultSettings.php:4818
LoginSignupSpecialPage\showCreateAccountLink
showCreateAccountLink()
Whether the login/create account form should display a link to the other form (in addition to whateve...
Definition: LoginSignupSpecialPage.php:1266
LoginSignupSpecialPage\load
load( $subPage)
Load data from request.
Definition: LoginSignupSpecialPage.php:127
LoginForm\incLoginThrottle
static incLoginThrottle( $username)
Definition: LoginSignupSpecialPage.php:1528
$wgUseMediaWikiUIEverywhere
$wgUseMediaWikiUIEverywhere
Temporary variable that applies MediaWiki UI wherever it can be supported.
Definition: DefaultSettings.php:3287
wfUrlencode
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
Definition: GlobalFunctions.php:331
SpecialPage\checkPermissions
checkPermissions()
Checks if userCanExecute, and if not throws a PermissionsError.
Definition: SpecialPage.php:309
LoginSignupSpecialPage\makeLanguageSelectorLink
makeLanguageSelectorLink( $text, $lang)
Create a language selector link for a particular language Links back to this page preserving type and...
Definition: LoginSignupSpecialPage.php:1313
LoginSignupSpecialPage\beforeExecute
beforeExecute( $subPage)
Gets called before.
Definition: LoginSignupSpecialPage.php:207
StatusValue\newFatal
static newFatal( $message)
Factory function for fatal errors.
Definition: StatusValue.php:68
$wgEnableUserEmail
$wgEnableUserEmail
Set to true to enable user-to-user e-mail.
Definition: DefaultSettings.php:1667
$params
$params
Definition: styleTest.css.php:44
LoginForm\RESET_PASS
const RESET_PASS
Definition: LoginSignupSpecialPage.php:1467
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:592
LoginForm\getCreateaccountToken
static getCreateaccountToken()
Definition: LoginSignupSpecialPage.php:1576
LoginSignupSpecialPage\$mStickHTTPS
$mStickHTTPS
Definition: LoginSignupSpecialPage.php:45
LoginForm\clearLoginThrottle
static clearLoginThrottle( $username)
Definition: LoginSignupSpecialPage.php:1539
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
LoginForm\THROTTLED
const THROTTLED
Definition: LoginSignupSpecialPage.php:1470
$formDescriptor
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead & $formDescriptor
Definition: hooks.txt:2115
SpecialPage\getSkin
getSkin()
Shortcut to get the skin being used for this instance.
Definition: SpecialPage.php:745
MediaWiki\Auth\Throttler
Definition: Throttler.php:37
$res
$res
Definition: database.txt:21
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:755
$success
$success
Definition: NoLocalSettings.php:42
data
and how to run hooks for an and one after Each event has a preferably in CamelCase For ArticleDelete hook A clump of code and data that should be run when an event happens This can be either a function and a chunk of data
Definition: hooks.txt:6
SpecialPage\getName
getName()
Get the name of this Special Page.
Definition: SpecialPage.php:152
AuthManagerSpecialPage
A special page subclass for authentication-related special pages.
Definition: AuthManagerSpecialPage.php:14
LoginSignupSpecialPage\setSessionUserForCurrentRequest
setSessionUserForCurrentRequest()
Replace some globals to make sure the fact that the user has just been logged in is reflected in the ...
Definition: LoginSignupSpecialPage.php:483
LoginForm\getValidErrorMessages
static getValidErrorMessages()
Definition: LoginSignupSpecialPage.php:1506
LoginHelper
Helper functions for the login form that need to be shared with other special pages (such as CentralA...
Definition: LoginHelper.php:8
LoginForm\USER_MIGRATED
const USER_MIGRATED
Definition: LoginSignupSpecialPage.php:1474
LoginSignupSpecialPage\getReturnToQueryStringFragment
getReturnToQueryStringFragment()
Returns a string that can be appended to the URL (without encoding) to preserve the return target.
Definition: LoginSignupSpecialPage.php:1250
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
LoginForm\setLoginToken
static setLoginToken()
Definition: LoginSignupSpecialPage.php:1559
LoginForm\clearCreateaccountToken
static clearCreateaccountToken()
Definition: LoginSignupSpecialPage.php:1592
LoginForm\EMPTY_PASS
const EMPTY_PASS
Definition: LoginSignupSpecialPage.php:1466
AuthManagerSpecialPage\trySubmit
trySubmit()
Attempts to do an authentication step with the submitted data.
Definition: AuthManagerSpecialPage.php:397
wfAppendQuery
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
Definition: GlobalFunctions.php:460
FakeAuthTemplate
B/C class to try handling login/signup template modifications even though login/signup does not actua...
Definition: LoginSignupSpecialPage.php:1390
$query
null for the wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1627
AuthManagerSpecialPage\$subPage
string $subPage
Subpage of the special page.
Definition: AuthManagerSpecialPage.php:34
LoginSignupSpecialPage\$mEntryError
$mEntryError
Definition: LoginSignupSpecialPage.php:47
DerivativeContext
An IContextSource implementation which will inherit context from another source but allow individual ...
Definition: DerivativeContext.php:30
LoginForm\ABORTED
const ABORTED
Definition: LoginSignupSpecialPage.php:1468
$html
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 just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition: hooks.txt:2036
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:764
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:964
$wgLoginLanguageSelector
$wgLoginLanguageSelector
Show a bar of language selection links in the user login and user registration forms; edit the "login...
Definition: DefaultSettings.php:3164
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1118
Status\wrap
static wrap( $sv)
Succinct helper method to wrap a StatusValue.
Definition: Status.php:55
LoginSignupSpecialPage\logAuthResult
logAuthResult( $success, $status=null)
Logs to the authmanager-stats channel.
LoginSignupSpecialPage
Holds shared logic for login and account creation pages.
Definition: LoginSignupSpecialPage.php:38
SpecialPage\getFullTitle
getFullTitle()
Return the full title, including $par.
Definition: SpecialPage.php:774
LoginSignupSpecialPage\$proxyAccountCreation
bool $proxyAccountCreation
True if the user if creating an account for someone else.
Definition: LoginSignupSpecialPage.php:59
HTMLForm\factory
static factory( $displayFormat)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:286
MediaWiki\Auth\AuthenticationResponse
This is a value object to hold authentication response data.
Definition: AuthenticationResponse.php:37
$wgLang
$wgLang
Definition: Setup.php:902
LoginForm\NOT_EXISTS
const NOT_EXISTS
Definition: LoginSignupSpecialPage.php:1464
AuthManagerSpecialPage\loadAuth
loadAuth( $subPage, $authAction=null, $reset=false)
Load or initialize $authAction, $authRequests and $subPage.
Definition: AuthManagerSpecialPage.php:231
LoginSignupSpecialPage\$mPosted
$mPosted
Definition: LoginSignupSpecialPage.php:40
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
$code
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
Definition: hooks.txt:813
LoginSignupSpecialPage\mainLoginForm
mainLoginForm(array $requests, $msg='', $msgtype='error')
Definition: LoginSignupSpecialPage.php:518
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:531
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:735
$wgEnableEmail
$wgEnableEmail
Set to true to enable the e-mail basic features: Password reminders, etc.
Definition: DefaultSettings.php:1661
$time
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1841
LoginSignupSpecialPage\makeLanguageSelector
makeLanguageSelector()
Produce a bar of links which allow the user to select another language during login/registration but ...
Definition: LoginSignupSpecialPage.php:1286
LoginSignupSpecialPage\hasSessionCookie
hasSessionCookie()
Check if a session cookie is present.
Definition: LoginSignupSpecialPage.php:1236
LoginForm
LoginForm as a special page has been replaced by SpecialUserLogin and SpecialCreateAccount,...
Definition: LoginSignupSpecialPage.php:1459
LoginForm\__construct
__construct( $request=null)
Definition: LoginSignupSpecialPage.php:1497
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
LoginSignupSpecialPage\$mFromHTTP
$mFromHTTP
Definition: LoginSignupSpecialPage.php:46
string
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
Definition: hooks.txt:175
PROTO_HTTPS
const PROTO_HTTPS
Definition: Defines.php:220
LoginForm\setCreateaccountToken
static setCreateaccountToken()
Definition: LoginSignupSpecialPage.php:1585
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:698
$request
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2675
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
LoginSignupSpecialPage\$mLoaded
$mLoaded
Definition: LoginSignupSpecialPage.php:50
FakeAuthTemplate\addInputItem
addInputItem( $name, $value, $type, $msg, $helptext=false)
Extensions (AntiSpoof and TitleBlacklist) call this in response to UserCreateForm hook to add checkbo...
Definition: LoginSignupSpecialPage.php:1404
LoginSignupSpecialPage\getFakeTemplate
getFakeTemplate( $msg, $msgType)
Temporary B/C method to handle extensions using the UserLoginForm/UserCreateForm hooks.
Definition: LoginSignupSpecialPage.php:713
BaseTemplate\getMsg
getMsg( $name)
Get a Message object with its context set.
Definition: BaseTemplate.php:38
$value
$value
Definition: styleTest.css.php:49
LoginForm\WRONG_TOKEN
const WRONG_TOKEN
Definition: LoginSignupSpecialPage.php:1473
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:81
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:36
LoginSignupSpecialPage\$mAction
$mAction
Definition: LoginSignupSpecialPage.php:41
MediaWiki\Session\SessionManager
This serves as the entry point to the MediaWiki session handling system.
Definition: SessionManager.php:50
LoginSignupSpecialPage\canBypassForm
canBypassForm(&$button_name)
Determine if the login form can be bypassed.
Definition: LoginSignupSpecialPage.php:402
LoginSignupSpecialPage\$mLanguage
$mLanguage
Definition: LoginSignupSpecialPage.php:42
LoginSignupSpecialPage\$mToken
$mToken
Definition: LoginSignupSpecialPage.php:44
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1617
LoginSignupSpecialPage\$authForm
HTMLForm $authForm
Definition: LoginSignupSpecialPage.php:64
LoginSignupSpecialPage\getPageHtml
getPageHtml( $formHtml)
Add page elements which are outside the form.
Definition: LoginSignupSpecialPage.php:589
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:432
LoginSignupSpecialPage\$fakeTemplate
FakeAuthTemplate $fakeTemplate
Definition: LoginSignupSpecialPage.php:67
$response
this hook is for auditing only $response
Definition: hooks.txt:813
AuthManagerSpecialPage\getDefaultAction
getDefaultAction( $subPage)
Get the default action for this special page, if none is given via URL/POST data.
MediaWiki\Auth\AuthManager
This serves as the entry point to the authentication system.
Definition: AuthManager.php:83
AuthManagerSpecialPage\getContinueAction
getContinueAction( $action)
Gets the _CONTINUE version of an action.
Definition: AuthManagerSpecialPage.php:279
$wgEmailConfirmToEdit
$wgEmailConfirmToEdit
Should editors be required to have a validated e-mail address before being allowed to edit?
Definition: DefaultSettings.php:5094
LoginSignupSpecialPage\isSignup
isSignup()
FakeAuthTemplate\execute
execute()
Main function, used by classes that subclass QuickTemplate to show the actual HTML output.
Definition: LoginSignupSpecialPage.php:1391
QuickTemplate\haveData
haveData( $str)
Definition: QuickTemplate.php:158
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:908
text
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
Definition: All_system_messages.txt:1267
$wgDisableCookieCheck
$wgDisableCookieCheck
By default, MediaWiki checks if the client supports cookies during the login process,...
Definition: DefaultSettings.php:6040
AuthManagerSpecialPage\isActionAllowed
isActionAllowed( $action)
Checks whether AuthManager is ready to perform the action.
Definition: AuthManagerSpecialPage.php:302
LoginSignupSpecialPage\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: LoginSignupSpecialPage.php:1336
LoginSignupSpecialPage\showReturnToPage
showReturnToPage( $type, $returnTo='', $returnToQuery='', $stickHTTPS=false)
Add a "return to" link or redirect to it.
Definition: LoginSignupSpecialPage.php:472
AuthManagerSpecialPage\needsSubmitButton
needsSubmitButton(array $requests)
Returns true if the form built from the given AuthenticationRequests needs a submit button.
Definition: AuthManagerSpecialPage.php:565
User\getCanonicalName
static getCanonicalName( $name, $validate='valid')
Given unvalidated user input, return a canonical username, or false if the username is invalid.
Definition: User.php:1238
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
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:210
LoginForm\NEED_TOKEN
const NEED_TOKEN
Definition: LoginSignupSpecialPage.php:1472
SpecialPage\setContext
setContext( $context)
Sets the context this SpecialPage is executed in.
Definition: SpecialPage.php:688
$requests
Allows to change the fields on the form that will be generated are created Can be used to omit specific feeds from being outputted You must not use this hook to add use OutputPage::addFeedLink() instead. & $feedLinks hooks can tweak the array to change how login etc forms should look $requests
Definition: hooks.txt:304
LoginSignupSpecialPage\getPreservedParams
getPreservedParams( $withToken=false)
Returns URL query parameters which can be used to reload the page (or leave and return) while preserv...
Definition: LoginSignupSpecialPage.php:193
LoggerFactory
MediaWiki Logger LoggerFactory implements a PSR[0] compatible message logging system Named Psr Log LoggerInterface instances can be obtained from the MediaWiki Logger LoggerFactory::getInstance() static method. MediaWiki\Logger\LoggerFactory expects a class implementing the MediaWiki\Logger\Spi interface to act as a factory for new Psr\Log\LoggerInterface instances. The "Spi" in MediaWiki\Logger\Spi stands for "service provider interface". An SPI is an API intended to be implemented or extended by a third party. This software design pattern is intended to enable framework extension and replaceable components. It is specifically used in the MediaWiki\Logger\LoggerFactory service to allow alternate PSR-3 logging implementations to be easily integrated with MediaWiki. The service provider interface allows the backend logging library to be implemented in multiple ways. The $wgMWLoggerDefaultSpi global provides the classname of the default MediaWiki\Logger\Spi implementation to be loaded at runtime. This can either be the name of a class implementing the MediaWiki\Logger\Spi with a zero argument const ructor or a callable that will return an MediaWiki\Logger\Spi instance. Alternately the MediaWiki\Logger\LoggerFactory MediaWiki Logger LoggerFactory
Definition: logger.txt:5
AuthManagerSpecialPage\isContinued
isContinued()
Returns true if this is not the first step of the authentication.
Definition: AuthManagerSpecialPage.php:266
LoginSignupSpecialPage\loadRequestParameters
loadRequestParameters( $subPage)
Load basic request parameters for this Special page.
Definition: LoginSignupSpecialPage.php:103
true
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 just before the function returns a value If you return true
Definition: hooks.txt:2036
AuthManagerSpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: AuthManagerSpecialPage.php:63
LoginForm\NO_NAME
const NO_NAME
Definition: LoginSignupSpecialPage.php:1461
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:214
LoginSignupSpecialPage\$mLoadedRequest
$mLoadedRequest
Definition: LoginSignupSpecialPage.php:51
AuthManagerSpecialPage\getToken
getToken()
Returns the CSRF token.
Definition: AuthManagerSpecialPage.php:623
LoginSignupSpecialPage\$mSecureLoginUrl
$mSecureLoginUrl
Definition: LoginSignupSpecialPage.php:52
LoginSignupSpecialPage\$targetUser
User $targetUser
FIXME another flag for passing data.
Definition: LoginSignupSpecialPage.php:61
LoginSignupSpecialPage\execute
execute( $subPage)
Definition: LoginSignupSpecialPage.php:216
$wgAuth
$wgAuth $wgAuth
Authentication plugin.
Definition: DefaultSettings.php:7472
object
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
Definition: globals.txt:25
LoginForm\getLoginToken
static getLoginToken()
Definition: LoginSignupSpecialPage.php:1550
$wgRequest
if(! $wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:747
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:232
LoginSignupSpecialPage\successfulAction
successfulAction( $direct=false, $extraMessages=null)
LoginSignupSpecialPage\$securityLevel
string $securityLevel
Definition: LoginSignupSpecialPage.php:55
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
LoginSignupSpecialPage\onAuthChangeFormFields
onAuthChangeFormFields(array $requests, array $fieldInfo, array &$formDescriptor, $action)
Change the form descriptor that determines how a field will look in the authentication form.
Definition: LoginSignupSpecialPage.php:841
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition: ErrorPageError.php:27
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:47
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
$username
this hook is for auditing only or null if authentication failed before getting that far $username
Definition: hooks.txt:813
LoginSignupSpecialPage\getFieldDefinitions
getFieldDefinitions( $template)
Create a HTMLForm descriptor for the core login fields.
Definition: LoginSignupSpecialPage.php:903
PasswordReset
Helper class for the password reset functionality shared by the web UI and the API.
Definition: PasswordReset.php:36
LoginHelper\getValidErrorMessages
static getValidErrorMessages()
Returns an array of all valid error messages.
Definition: LoginHelper.php:36
$wgSecureLogin
$wgSecureLogin
This is to let user authenticate using https when they come from http.
Definition: DefaultSettings.php:4952
LoginSignupSpecialPage\showExtraInformation
showExtraInformation()
Show extra information such as password recovery information, link from login to signup,...
Definition: LoginSignupSpecialPage.php:893
BaseTemplate
New base template for a skin's template extended from QuickTemplate this class features helper method...
Definition: BaseTemplate.php:29
$wgInitialSessionId
$wgInitialSessionId
Definition: Setup.php:834
LoginForm\clearLoginToken
static clearLoginToken()
Definition: LoginSignupSpecialPage.php:1566
MediaWiki\Auth\AuthenticationRequest
This is a value object for authentication requests.
Definition: AuthenticationRequest.php:37
LoginSignupSpecialPage\getAuthForm
getAuthForm(array $requests, $action, $msg='', $msgType='error')
Generates a form from the given request.
Definition: LoginSignupSpecialPage.php:653
Skin\makeInternalOrExternalUrl
static makeInternalOrExternalUrl( $name)
If url string starts with http, consider as external URL, else internal.
Definition: Skin.php:1195
LoginForm\WRONG_PLUGIN_PASS
const WRONG_PLUGIN_PASS
Definition: LoginSignupSpecialPage.php:1463
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition: HTMLForm.php:136
$out
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:813
$type
$type
Definition: testCompression.php:48
LoginForm\incrementLoginThrottle
static incrementLoginThrottle( $username)
Definition: LoginSignupSpecialPage.php:1515