Page MenuHomePhabricator

Refactor OATHAuth's ProxySpecialPage
Open, LowPublic

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

csteipp created this task.Mar 29 2016, 12:21 AM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptMar 29 2016, 12:21 AM
csteipp triaged this task as Low priority.Mar 29 2016, 12:21 AM
Reedy added a subscriber: Reedy.Nov 12 2016, 2:44 AM

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;
		};
	}
TheDJ updated the task description. (Show Details)Nov 23 2016, 11:09 PM