Cannot accept account request if 'real name' is a hidden preference
Closed, ResolvedPublic

Description

When attempting to accept an account request at the "Confirm account requests" page by clicking the "Confirm" button, I get an "Internal error". Exception details are:

[606028908e7c360b3c96d892] /w/index.php?title=Special:CreateAccount&AccountRequestId=7&wpName=USERNAME&returnto=Special%3AConfirmAccounts%2Fauthors&reason=
MWException from line 461 of /srv/www/wiki/includes/htmlform/HTMLForm.php: Descriptor with no class for realname: Array

Backtrace:

#0 /srv/www/wiki/includes/htmlform/HTMLForm.php(481): HTMLForm::getClassFromDescriptor(string, array)
#1 /srv/www/wiki/includes/htmlform/VFormHTMLForm.php(48): HTMLForm::loadInputFromParameters(string, array, VFormHTMLForm)
#2 /srv/www/wiki/includes/htmlform/HTMLForm.php(336): VFormHTMLForm::loadInputFromParameters(string, array, VFormHTMLForm)
#3 /srv/www/wiki/includes/libs/ObjectFactory.php(147): HTMLForm->__construct(array, RequestContext)
#4 /srv/www/wiki/includes/htmlform/HTMLForm.php(281): ObjectFactory::constructClassInstance(string, array)
#5 /srv/www/wiki/includes/specialpage/LoginSignupSpecialPage.php(663): HTMLForm::factory(string, array, RequestContext)
#6 /srv/www/wiki/includes/specialpage/AuthManagerSpecialPage.php(402): LoginSignupSpecialPage->getAuthForm(array, string)
#7 /srv/www/wiki/includes/specialpage/LoginSignupSpecialPage.php(305): AuthManagerSpecialPage->trySubmit()
#8 /srv/www/wiki/includes/specialpage/SpecialPage.php(522): LoginSignupSpecialPage->execute(NULL)
#9 /srv/www/wiki/includes/specialpage/SpecialPageFactory.php(576): SpecialPage->run(NULL)
#10 /srv/www/wiki/includes/MediaWiki.php(283): SpecialPageFactory::executePath(Title, RequestContext)
#11 /srv/www/wiki/includes/MediaWiki.php(851): MediaWiki->performRequest()
#12 /srv/www/wiki/includes/MediaWiki.php(512): MediaWiki->main()
#13 /srv/www/wiki/index.php(43): MediaWiki->run()
#14 {main}

It appears to be trying to populate the realname field of the account creation form even if that field won't be rendered because realname is a hidden ('realname' is in the $wgHiddenPrefs array).

(I also have $wgConfirmAccountRequestFormItems['RealName']['enabled'] = false; in my LocalSettings.)

Event Timeline

I fixed this in my own wiki by checking $wgHiddenPrefs in two places.

In frontend/ConfirmAccountUI.hooks.php in onAuthChangeFormFields():

At line 102:

		global $wgHiddenPrefs;

At line 141, around the lines of code dealing with $formDescriptor['realname']:

		if ( !in_array( 'realname', $wgHiddenPrefs, true ) ) {
			...
		}

In business/ConfirmAccountPreAuthenticationProvider.php in testForAccountCreation():

At line 39:

		global $wgHiddenPrefs;

At line 69, replace the existing if statement with:

		$realNameMismatch = !in_array( 'realname', $wgHiddenPrefs, true ) &&
			$usrDataAuthReq->realname !== $accountReq->getRealName();

		# Make sure certain field were left unchanged from the account request
		if (
			!$tmpPassAuthReq ||
			$usrDataAuthReq->email !== $accountReq->getEmail() ||
			$realNameMismatch ||
			!$tmpPassAuthReq->mailpassword
		) {
			return StatusValue::newFatal( 'confirmaccount-mismatched-general' );
		}

Thanks for taking a look at the code!

You are very welcome to use developer access to submit the proposed code changes as a Git branch directly into Gerrit which makes it easier to review them quickly and provide feedback.
If you don't want to set up Git/Gerrit, you can also use the Gerrit Patch Uploader. Thanks again!

Change #1180974 had a related patch set uploaded (by Jack Phoenix; author: Jack Phoenix):

[mediawiki/extensions/ConfirmAccount@master] Make it possible to approve account requests when the 'realname' preference is in $wgHiddenPrefs

https://gerrit.wikimedia.org/r/1180974

Change #1180974 merged by jenkins-bot:

[mediawiki/extensions/ConfirmAccount@master] Approve account requests when the 'realname' preference is hidden.

https://gerrit.wikimedia.org/r/1180974

ashley assigned this task to MarkAHershberger.