Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| LoginErrorHelper | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
| getValidErrorMessages | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Exception; |
| 4 | |
| 5 | use MediaWiki\HookContainer\HookRunner; |
| 6 | use MediaWiki\MediaWikiServices; |
| 7 | |
| 8 | /** |
| 9 | * Helper functions for the login errors |
| 10 | * @since 1.46 |
| 11 | */ |
| 12 | class LoginErrorHelper { |
| 13 | |
| 14 | /** |
| 15 | * @var string[] |
| 16 | */ |
| 17 | private static $validErrorMessages = [ |
| 18 | 'exception-nologin-text', |
| 19 | 'exception-nologin-text-for-temp-user', |
| 20 | 'watchlistanontext', |
| 21 | 'watchlistanontext-for-temp-user', |
| 22 | 'watchlistlabels-not-logged-in', |
| 23 | 'watchlistlabels-not-logged-in-for-temp-user', |
| 24 | 'changeemail-no-info', |
| 25 | 'confirmemail_needlogin', |
| 26 | 'prefsnologintext2', |
| 27 | 'prefsnologintext2-for-temp-user', |
| 28 | 'specialmute-login-required', |
| 29 | 'specialmute-login-required-for-temp-user', |
| 30 | 'mailnologintext', |
| 31 | ]; |
| 32 | |
| 33 | /** @var array|null Cache for {@link LoginErrorHelper::getValidErrorMessages} */ |
| 34 | private static ?array $validErrorMessagesCache = null; |
| 35 | |
| 36 | /** |
| 37 | * Returns an array of all error and warning messages that can be displayed on Special:UserLogin or |
| 38 | * Special:CreateAccount through the ?error or ?warning GET parameters. |
| 39 | * |
| 40 | * Special:UserLogin and Special:CreateAccount can show an error or warning message on the form when |
| 41 | * coming from another page using the aforementioned GET parameters. |
| 42 | * |
| 43 | * Further keys can be added by the LoginFormValidErrorMessages hook. If a message key is not in this |
| 44 | * list, then no redirect will be performed to Special:UserLogin or Special:CreateAccount. |
| 45 | * |
| 46 | * @return string[] |
| 47 | * @see LoginErrorHelper::$validErrorMessages |
| 48 | */ |
| 49 | public static function getValidErrorMessages(): array { |
| 50 | if ( !static::$validErrorMessagesCache ) { |
| 51 | static::$validErrorMessagesCache = self::$validErrorMessages; |
| 52 | ( new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) ) |
| 53 | ->onLoginFormValidErrorMessages( static::$validErrorMessagesCache ); |
| 54 | } |
| 55 | |
| 56 | return static::$validErrorMessagesCache; |
| 57 | } |
| 58 | } |