Return error message in users API cancreate field
authorGergő Tisza <tgr.huwiki@gmail.com>
Mon, 30 May 2016 18:16:07 +0000 (20:16 +0200)
committerGergő Tisza <tgr.huwiki@gmail.com>
Mon, 30 May 2016 18:16:07 +0000 (20:16 +0200)
That API field exposes AuthManager::canCreateAccount, where the error
message is important.

Change-Id: Idef441b311b94ff0cb6c4deaed1ac93959ee7ee8

includes/api/ApiQueryUsers.php

index 68ec38d..5afb66f 100644 (file)
@@ -262,8 +262,11 @@ class ApiQueryUsers extends ApiQueryBase {
                                } else {
                                        $data[$u]['missing'] = true;
                                        if ( isset( $this->prop['cancreate'] ) && !$this->getConfig()->get( 'DisableAuthManager' ) ) {
-                                               $data[$u]['cancreate'] = MediaWiki\Auth\AuthManager::singleton()->canCreateAccount( $u )
-                                                       ->isGood();
+                                               $status = MediaWiki\Auth\AuthManager::singleton()->canCreateAccount( $u );
+                                               $data[$u]['cancreate'] = $status->isGood();
+                                               if ( !$status->isGood() ) {
+                                                       $data[$u]['cancreateerror'] = $this->getErrorFormatter()->arrayFromStatus( $status );
+                                               }
                                        }
                                }
                        } else {