Page MenuHomePhabricator

Refactor OATHAuth's ProxySpecialPage
Closed, DeclinedPublic

Description

Instead of using ProxySpecialPage, I think the wgSpecialPages entry can just define a callback that does what SpecialOATH::getTargetPage() currently does.

T137471: Migrate special pages to use AuthManager might remove the need for ProxySpecialPage, this is just in case it doesn't.

Event Timeline

I don't think a callback is the correct way of doing this...

Changing it for code that does something like the below feels kinda awful

	public static function onRegistration() {
		global $wgSpecialPages, $wgRequest, $wgUser;
		$wgSpecialPages['OATH'] = function() use ( $wgRequest, $wgUser ) {
			$repo = OATHAuthHooks::getOATHUserRepository();

			/** @var array $sessionUser */
			$loginInfo = $wgRequest->getSessionData( 'oath_login' );

			/** @var SpecialOATHDisable|SpecialOATHEnable|SpecialOATHLogin|SpecialPage $page */
			$page = null;
			if ( $wgUser->isAnon() && $loginInfo !== null ) {
				// User is anonymous, so they are logging in
				$loginInfo = OATHAuthUtils::decryptSessionData(
					$loginInfo,
					$wgRequest->getSessionData( 'oath_uid' )
				);
				$page = new SpecialOATHLogin(
					$repo->findByUser( User::newFromName( $loginInfo['wpName'] ) ),
					new DerivativeRequest(
						$wgRequest,
						$loginInfo,
						$wgRequest
					)
				);
			} else {
				$user = $repo->findByUser( $wgUser );

				if ( $user->getKey() === null ) {
					$page = new SpecialOATHEnable( $repo, $user );
				} else {
					$page = new SpecialOATHDisable( $repo, $user );
				}
			}

			return $page;
		};
	}

ProxySpecialPage no longer exists