Extension:CentralAuth/CentralAuthPostLoginRedirect

From MediaWiki.org
Jump to navigation Jump to search
CentralAuthPostLoginRedirect
Available from version 1.22
Allow extensions to change the page the user redirects to after login or account creation, and also change or modify the query string for that page.
Define function:
public static function onCentralAuthPostLoginRedirect( &$returnTo, &$returnToQuery, $stickHTTPS, $type ) { ... }
Attach hook:

In extension.json:

{
	"Hooks": {
		"CentralAuthPostLoginRedirect": "MyExtensionHooks::onCentralAuthPostLoginRedirect"
	}
}

For MediaWiki ≤1.25:

$wgHooks['CentralAuthPostLoginRedirect'][] = 'MyExtensionHooks::onCentralAuthPostLoginRedirect';
Called from:File(s): specials/SpecialCentralLogin.php

For more information about attaching hooks, see Manual:Hooks.
For examples of extensions using this hook, see Category:CentralAuthPostLoginRedirect extensions.

Details[edit]

The login and create account forms always supported returnto and returntoquery parameters so that after login or creation the user could be returned to their original page (or possibly some other page). The Create account / Login links on pages fill these in with the current page and its query string (if any), and custom links to the forms can specify something else.

In release 1.22, if the CentralAuth extension is installed and $wgCentralAuthSilentLogin is true, then login and create account always redirect, there is no more "Welcome user" page at the end of successful form submission. This hook allows extensions to change the returnto to a particular welcome page or provide a query string parameter t Extensions which do override the returnTo should probably add the original to the returnToQuery parameter, so that they can display a "[Thanks, now take me back to wherever]" link.

If there is no returnto parameter to the login or create account form, and no extension changes the link, CentralAuth redirects to the default page of the wiki.

  • &$returnTo: page to which user will be redirected after success. The CentralAuth extension sets this to the returnto query string parameter that was passed to the login or create account form (if any); extensions can replace it with another page.
  • &$returnToQuery: query string that will be appended to the page to which the user will be redirected after success. The extension sets this to the returntoquery query string parameter that was passed to the login or create account form (if any); extensions can replace or add to it.
  • $stickHTTPS specific to $wgSecureLogin (if the site wants SSL connection)
  • $type either "signup" or "login"

Extensions that add HTML to the "success" form page after login or account creation by hooking UserLoginComplete or BeforeWelcomeCreation will probably need to hook this to achieve similar results if CentralAuth is in use.