diff options
author | jenkins-bot <jenkins-bot@gerrit.wikimedia.org> | 2022-05-10 10:34:07 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@wikimedia.org> | 2022-05-10 10:34:07 +0000 |
commit | e9eb4f60d68f9ed4e7cd693d3e85b4e1d7945672 (patch) | |
tree | 9ba41e8950a18717522cce996bf9cd97572b6cff /includes | |
parent | 14bce5492dec3f4f55abdf496d57f80052e2f29a (diff) | |
parent | 5bac886e6ecb9c7ca1d13232f7cdba6d7737a38b (diff) | |
download | mediawikicore-e9eb4f60d68f9ed4e7cd693d3e85b4e1d7945672.tar.gz mediawikicore-e9eb4f60d68f9ed4e7cd693d3e85b4e1d7945672.zip |
Merge "TempUser CentralAuth integration"
Diffstat (limited to 'includes')
-rw-r--r-- | includes/EditPage.php | 27 | ||||
-rw-r--r-- | includes/Hook/TempUserCreatedRedirectHook.php | 38 | ||||
-rw-r--r-- | includes/HookContainer/HookRunner.php | 32 | ||||
-rw-r--r-- | includes/auth/AuthManager.php | 9 | ||||
-rw-r--r-- | includes/specials/helpers/LoginHelper.php | 7 |
5 files changed, 96 insertions, 17 deletions
diff --git a/includes/EditPage.php b/includes/EditPage.php index 00e2aa23b879..0c340725492f 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1958,7 +1958,7 @@ class EditPage implements IEditObject { $query .= $extraQueryRedirect; } $anchor = $resultDetails['sectionanchor'] ?? ''; - $out->redirect( $this->mTitle->getFullURL( $query ) . $anchor ); + $this->doPostEditRedirect( $query, $anchor ); return false; case self::AS_SUCCESS_UPDATE: @@ -1982,7 +1982,7 @@ class EditPage implements IEditObject { $extraQuery .= $extraQueryRedirect; } - $out->redirect( $this->mTitle->getFullURL( $extraQuery ) . $sectionanchor ); + $this->doPostEditRedirect( $extraQuery, $sectionanchor ); return false; case self::AS_SPAM_ERROR: @@ -2032,6 +2032,29 @@ class EditPage implements IEditObject { } /** + * Emit the post-save redirect. The URL is modifiable with a hook. + * + * @param string $query + * @param string $anchor + * @return void + */ + private function doPostEditRedirect( $query, $anchor ) { + $out = $this->context->getOutput(); + $url = $this->mTitle->getFullURL( $query ) . $anchor; + if ( $this->tempUserCreateDone ) { + $this->getHookRunner()->onTempUserCreatedRedirect( + $this->context->getRequest()->getSession(), + $this->context->getUser(), + $this->mTitle->getPrefixedDBkey(), + $query, + $anchor, + $url + ); + } + $out->redirect( $url ); + } + + /** * Return the summary to be used for a new section. * * @return string[] array with two values, the summary and the anchor text diff --git a/includes/Hook/TempUserCreatedRedirectHook.php b/includes/Hook/TempUserCreatedRedirectHook.php new file mode 100644 index 000000000000..e4c23391c92f --- /dev/null +++ b/includes/Hook/TempUserCreatedRedirectHook.php @@ -0,0 +1,38 @@ +<?php + +namespace MediaWiki\Hook; + +use MediaWiki\Session\Session; +use MediaWiki\User\UserIdentity; + +/** + * This is a hook handler interface, see docs/Hooks.md. + * Use the hook name "TempUserCreatedRedirect" to register handlers implementing this interface. + * + * @stable to implement + * @ingroup Hooks + */ +interface TempUserCreatedRedirectHook { + /** + * This hook is called after an action causes a temporary user to be + * created. The handler may modify the redirect URL. + * + * @since 1.39 + * + * @param Session $session + * @param UserIdentity $user + * @param string $returnTo The prefixed DB key of the title to redirect to + * @param string $returnToQuery An extra query part + * @param string $returnToAnchor Either an empty string or a fragment beginning with "#" + * @param string &$redirectUrl The URL to redirect to + * @return bool|null + */ + public function onTempUserCreatedRedirect( + Session $session, + UserIdentity $user, + string $returnTo, + string $returnToQuery, + string $returnToAnchor, + &$redirectUrl + ); +} diff --git a/includes/HookContainer/HookRunner.php b/includes/HookContainer/HookRunner.php index f50d21fbf7ed..a484e61ce810 100644 --- a/includes/HookContainer/HookRunner.php +++ b/includes/HookContainer/HookRunner.php @@ -12,6 +12,7 @@ use MediaWiki\Linker\LinkTarget; use MediaWiki\Page\ProperPageIdentity; use MediaWiki\Permissions\Authority; use MediaWiki\Revision\RevisionRecord; +use MediaWiki\Session\Session; use MediaWiki\User\UserIdentity; use Parser; use ParserOptions; @@ -369,6 +370,7 @@ class HookRunner implements \MediaWiki\Hook\SpecialWatchlistGetNonRevisionTypesHook, \MediaWiki\Hook\TestCanonicalRedirectHook, \MediaWiki\Hook\ThumbnailBeforeProduceHTMLHook, + \MediaWiki\Hook\TempUserCreatedRedirectHook, \MediaWiki\Hook\TitleExistsHook, \MediaWiki\Hook\TitleGetEditNoticesHook, \MediaWiki\Hook\TitleGetRestrictionTypesHook, @@ -2445,6 +2447,14 @@ class HookRunner implements ); } + public function onMaintenanceShellStart(): void { + $this->container->run( + 'MaintenanceShellStart', + [], + [ 'abortable' => false ] + ); + } + public function onMaintenanceUpdateAddParams( &$params ) { return $this->container->run( 'MaintenanceUpdateAddParams', @@ -3817,6 +3827,20 @@ class HookRunner implements ); } + public function onTempUserCreatedRedirect( + Session $session, + UserIdentity $user, + string $returnTo, + string $returnToQuery, + string $returnToAnchor, + &$redirectUrl + ) { + return $this->container->run( + 'TempUserCreatedRedirect', + [ $session, $user, $returnTo, $returnToQuery, $returnToAnchor, &$redirectUrl ] + ); + } + public function onTestCanonicalRedirect( $request, $title, $output ) { return $this->container->run( 'TestCanonicalRedirect', @@ -4486,12 +4510,4 @@ class HookRunner implements [ $obj, &$out, $row, $text, $rev ] ); } - - public function onMaintenanceShellStart(): void { - $this->container->run( - 'MaintenanceShellStart', - [], - [ 'abortable' => false ] - ); - } } diff --git a/includes/auth/AuthManager.php b/includes/auth/AuthManager.php index 2241a6abb49b..c5886f574d51 100644 --- a/includes/auth/AuthManager.php +++ b/includes/auth/AuthManager.php @@ -1722,11 +1722,10 @@ class AuthManager implements LoggerAwareInterface { } } - // Is the username creatable? - if ( $source !== self::AUTOCREATE_SOURCE_TEMP - && !$this->userNameUtils->isCreatable( $username ) - ) { - $this->logger->debug( __METHOD__ . ': name "{username}" is not creatable', [ + // Is the username valid? (Previously isCreatable() was checked here but + // that doesn't work with auto-creation of TempUser accounts by CentralAuth) + if ( !$this->userNameUtils->isValid( $username ) ) { + $this->logger->debug( __METHOD__ . ': name "{username}" is not valid', [ 'username' => $username, ] ); $session->set( 'AuthManager::AutoCreateBlacklist', 'noname' ); diff --git a/includes/specials/helpers/LoginHelper.php b/includes/specials/helpers/LoginHelper.php index 5805d0082535..a44b70ad7cd7 100644 --- a/includes/specials/helpers/LoginHelper.php +++ b/includes/specials/helpers/LoginHelper.php @@ -66,9 +66,11 @@ class LoginHelper extends ContextSource { * @param array|string $returnToQuery * @param bool $stickHTTPS Keep redirect link on HTTPS. Ignored (treated as * true) if $wgForceHTTPS is true. + * @param string $returnToAnchor A string to append to the URL, presumed to + * be either a fragment including the leading hash or an empty string. */ public function showReturnToPage( - $type, $returnTo = '', $returnToQuery = '', $stickHTTPS = false + $type, $returnTo = '', $returnToQuery = '', $stickHTTPS = false, $returnToAnchor = '' ) { $config = $this->getConfig(); if ( $type !== 'error' && $config->get( MainConfigNames::RedirectOnLogin ) !== null ) { @@ -97,7 +99,8 @@ class LoginHelper extends ContextSource { } if ( $type === 'successredirect' ) { - $redirectUrl = $returnToTitle->getFullUrlForRedirect( $returnToQuery, $proto ); + $redirectUrl = $returnToTitle->getFullUrlForRedirect( $returnToQuery, $proto ) + . $returnToAnchor; $this->getOutput()->redirect( $redirectUrl ); } else { $this->getOutput()->addReturnTo( $returnToTitle, $returnToQuery, null, $options ); |