jenkins-bot has submitted this change and it was merged.

Change subject: UserLogin: Allow extensions to add valid error messages
......................................................................


UserLogin: Allow extensions to add valid error messages

Add hook LoginFormValidErrorMessages to allow extensions, to add own valid
error messages to redirect to the login form.

Bug: 71769
Change-Id: I9e996a88e3972f09946726060916a21124de049c
---
M docs/hooks.txt
M includes/exception/UserNotLoggedIn.php
M includes/specials/SpecialUserlogin.php
3 files changed, 28 insertions(+), 6 deletions(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/docs/hooks.txt b/docs/hooks.txt
index 52eeab8..7afbf1c 100644
--- a/docs/hooks.txt
+++ b/docs/hooks.txt
@@ -3005,6 +3005,11 @@
 $to: Array of MailAddress objects for the recipients
 &$returnPath: The return address string
 
+'LoginFormValidErrorMessages': Called in LoginForm when a function gets valid 
error
+messages. Allows to add additional error messages (except messages already in
+LoginForm::$validErrorMessages).
+&$messages Already added messages (inclusive messages from 
LoginForm::$validErrorMessages)
+
 'WantedPages::getQueryInfo': Called in WantedPagesPage::getQueryInfo(), can be
 used to alter the SQL query which gets the list of wanted pages.
 &$wantedPages: WantedPagesPage object
diff --git a/includes/exception/UserNotLoggedIn.php 
b/includes/exception/UserNotLoggedIn.php
index 03ba0b2..02fca3d 100644
--- a/includes/exception/UserNotLoggedIn.php
+++ b/includes/exception/UserNotLoggedIn.php
@@ -25,8 +25,9 @@
  * 'exception-nologin' as a title and 'exception-nologin-text' for the message.
  *
  * @note In order for this exception to redirect, the error message passed to 
the
- * constructor has to be explicitly added to LoginForm::validErrorMessages. 
Otherwise,
- * the user will just be shown the message rather than redirected.
+ * constructor has to be explicitly added to LoginForm::validErrorMessages or 
with
+ * the LoginFormValidErrorMessages hook. Otherwise, the user will just be 
shown the message
+ * rather than redirected.
  *
  * @par Example:
  * @code
@@ -52,7 +53,8 @@
 class UserNotLoggedIn extends ErrorPageError {
 
        /**
-        * @note The value of the $reasonMsg parameter must be put into 
LoginForm::validErrorMessages
+        * @note The value of the $reasonMsg parameter must be put into 
LoginForm::validErrorMessages or
+        * set with the LoginFormValidErrorMessages Hook.
         * if you want the user to be automatically redirected to the login 
form.
         *
         * @param string $reasonMsg A message key containing the reason for the 
error.
@@ -77,7 +79,7 @@
        public function report() {
                // If an unsupported message is used, don't try redirecting to 
Special:Userlogin,
                // since the message may not be compatible.
-               if ( !in_array( $this->msg, LoginForm::$validErrorMessages ) ) {
+               if ( !in_array( $this->msg, LoginForm::getValidErrorMessages() 
) ) {
                        parent::report();
                }
 
diff --git a/includes/specials/SpecialUserlogin.php 
b/includes/specials/SpecialUserlogin.php
index bdd6751..b6a3be2 100644
--- a/includes/specials/SpecialUserlogin.php
+++ b/includes/specials/SpecialUserlogin.php
@@ -114,6 +114,21 @@
        }
 
        /**
+        * Returns an array of all valid error messages.
+        *
+        * @return array
+        */
+       public static function getValidErrorMessages() {
+               static $messages = null;
+               if ( !$messages ) {
+                       $messages = self::$validErrorMessages;
+                       wfRunHooks( 'LoginFormValidErrorMessages', array( 
&$messages ) );
+               }
+
+               return $messages;
+       }
+
+       /**
         * Loader
         */
        function load() {
@@ -175,13 +190,13 @@
 
                // Only show valid error or warning messages.
                if ( $entryError->exists()
-                       && in_array( $entryError->getKey(), 
self::$validErrorMessages )
+                       && in_array( $entryError->getKey(), 
self::getValidErrorMessages() )
                ) {
                        $this->mEntryErrorType = 'error';
                        $this->mEntryError = $entryError->rawParams( 
$loginreqlink )->escaped();
 
                } elseif ( $entryWarning->exists()
-                       && in_array( $entryWarning->getKey(), 
self::$validErrorMessages )
+                       && in_array( $entryWarning->getKey(), 
self::getValidErrorMessages() )
                ) {
                        $this->mEntryErrorType = 'warning';
                        $this->mEntryError = $entryWarning->rawParams( 
$loginreqlink )->escaped();

-- 
To view, visit https://gerrit.wikimedia.org/r/170520
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9e996a88e3972f09946726060916a21124de049c
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to