Merge "Add Status outparam for AbortNewAccount hook to fix API error handling"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 23 Jan 2014 20:27:00 +0000 (20:27 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 23 Jan 2014 20:27:00 +0000 (20:27 +0000)
docs/hooks.txt
includes/specials/SpecialUserlogin.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messageTypes.inc

index 51cf65c..3f1152b 100644 (file)
@@ -269,6 +269,9 @@ $reason: the reason for the move (added in 1.13)
 'AbortNewAccount': Return false to cancel explicit account creation.
 $user: the User object about to be created (read-only, incomplete)
 &$msg: out parameter: HTML to display on abort
+&$status: out parameter: Status object to return, replaces the older $msg param (added in 1.23)
+          Create the object with Status::newFatal() to ensure proper API error messages
+          are returned when creating account through API clients.
 
 'AbortTalkPageEmailNotification': Return false to cancel talk page email notification
 $targetUser: the user whom to send talk page email notification
index 8e5ef58..eca1839 100644 (file)
@@ -444,12 +444,23 @@ class LoginForm extends SpecialPage {
                $u->setRealName( $this->mRealName );
 
                $abortError = '';
-               if ( !wfRunHooks( 'AbortNewAccount', array( $u, &$abortError ) ) ) {
+               $abortStatus = null;
+               if ( !wfRunHooks( 'AbortNewAccount', array( $u, &$abortError, &$abortStatus ) ) ) {
                        // Hook point to add extra creation throttles and blocks
                        wfDebug( "LoginForm::addNewAccountInternal: a hook blocked creation\n" );
-                       $abortError = new RawMessage( $abortError );
-                       $abortError->text();
-                       return Status::newFatal( $abortError );
+                       if ( $abortStatus === null ) {
+                               // Report back the old string as a raw message status.
+                               // This will report the error back as 'createaccount-hook-aborted'
+                               // with the given string as the message.
+                               // To return a different error code, return a Status object.
+                               $abortError = new Message( 'createaccount-hook-aborted', array( $abortError ) );
+                               $abortError->text();
+                               return Status::newFatal( $abortError );
+                       } else {
+                               // For MediaWiki 1.23+ and updated hooks, return the Status object
+                               // returned from the hook.
+                               return $abortStatus;
+                       }
                }
 
                // Hook point to check for exempt from account creation throttle
index 4d12683..f9ea261 100644 (file)
@@ -1629,6 +1629,7 @@ The reason given by $3 is ''$2''",
 'cantcreateaccount-text' => "Account creation from this IP address ('''$1''') has been blocked by [[User:$3|$3]].
 
 The reason given by $3 is ''$2''",
+'createaccount-hook-aborted' => '$1', # do not translate or duplicate this message to other languages
 
 # History pages
 'viewpagelogs'           => 'View logs for this page',
index 8166aeb..e45f38d 100644 (file)
@@ -2322,6 +2322,7 @@ See also:
 * $2 - reason or {{msg-mw|Blockednoreason}}
 * $3 - username
 * $4 - current user's IP address",
+'createaccount-hook-aborted' => 'Placeholder message to return with API errors on account create; passes through the message from a hook {{notranslate}}',
 
 # History pages
 'viewpagelogs' => 'Link displayed in history of pages',
index 7704668..e0dd8ee 100644 (file)
@@ -271,6 +271,7 @@ $wgIgnoredMessages = array(
        'autocomment-prefix',
        'move-redirect-text',
        'interlanguage-link-title-langonly',
+       'createaccount-hook-abort',
 );
 
 /** Optional messages, which may be translated only if changed in the target language. */