|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Waca\Validation; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
|
|
7
|
|
|
class ValidationError |
|
8
|
|
|
{ |
|
9
|
|
|
const NAME_EMPTY = "name_empty"; |
|
10
|
|
|
const NAME_EXISTS = "name_exists"; |
|
11
|
|
|
const NAME_EXISTS_SUL = "name_exists"; |
|
12
|
|
|
const NAME_NUMONLY = "name_numonly"; |
|
13
|
|
|
const NAME_INVALIDCHAR = "name_invalidchar"; |
|
14
|
|
|
const NAME_SANITISED = "name_sanitised"; |
|
15
|
|
|
const EMAIL_EMPTY = "email_empty"; |
|
16
|
|
|
const EMAIL_WIKIMEDIA = "email_wikimedia"; |
|
17
|
|
|
const EMAIL_INVALID = "email_invalid"; |
|
18
|
|
|
const EMAIL_MISMATCH = "email_mismatch"; |
|
19
|
|
|
const OPEN_REQUEST_NAME = "open_request_name"; |
|
20
|
|
|
const BANNED = "banned"; |
|
21
|
|
|
const BANNED_TOR = "banned_tor"; |
|
22
|
|
|
/** |
|
23
|
|
|
* Summary of $errorCode |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
private $errorCode; |
|
27
|
|
|
/** |
|
28
|
|
|
* Summary of $isError |
|
29
|
|
|
* @var bool |
|
30
|
|
|
*/ |
|
31
|
|
|
private $isError; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Summary of __construct |
|
35
|
|
|
* |
|
36
|
|
|
* @param string $errorCode |
|
37
|
|
|
* @param bool $isError |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct($errorCode, $isError = true) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->errorCode = $errorCode; |
|
42
|
|
|
$this->isError = $isError; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Summary of getErrorCode |
|
47
|
|
|
* @return string |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getErrorCode() |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->errorCode; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return string |
|
56
|
|
|
* @throws Exception |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getErrorMessage() |
|
59
|
|
|
{ |
|
60
|
|
|
switch ($this->errorCode) { |
|
61
|
|
|
case self::NAME_EMPTY: |
|
62
|
|
|
return 'You\'ve not chosen a username!'; |
|
63
|
|
|
case self::NAME_EXISTS: |
|
64
|
|
|
case self::NAME_EXISTS_SUL: |
|
65
|
|
|
return 'I\'m sorry, but the username you selected is already taken. Please try another. Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore [[User:example]] would become [[User:Example]].'; |
|
|
|
|
|
|
66
|
|
|
case self::NAME_NUMONLY: |
|
67
|
|
|
return 'The username you chose is invalid: it consists entirely of numbers. Please retry with a valid username.'; |
|
68
|
|
|
case self::NAME_INVALIDCHAR: |
|
69
|
|
|
return 'There appears to be an invalid character in your username. Please note that the following characters are not allowed: <code># @ / < > [ ] | { }</code>'; |
|
|
|
|
|
|
70
|
|
|
case self::NAME_SANITISED: |
|
71
|
|
|
return 'Your requested username has been automatically adjusted due to technical restrictions. Underscores have been replaced with spaces, and the first character has been capitalised.'; |
|
|
|
|
|
|
72
|
|
|
case self::EMAIL_EMPTY: |
|
73
|
|
|
return 'You need to supply an email address.'; |
|
74
|
|
|
case self::EMAIL_WIKIMEDIA: |
|
75
|
|
|
return 'Please provide your email address here.'; |
|
76
|
|
|
case self::EMAIL_INVALID: |
|
77
|
|
|
return 'Invalid E-mail address supplied. Please check you entered it correctly.'; |
|
78
|
|
|
case self::EMAIL_MISMATCH: |
|
79
|
|
|
return 'The email addresses you entered do not match. Please try again.'; |
|
80
|
|
|
case self::OPEN_REQUEST_NAME: |
|
81
|
|
|
return 'There is already an open request with this name in this system.'; |
|
82
|
|
|
case self::BANNED: |
|
83
|
|
|
return 'I\'m sorry, but you are currently banned from requesting accounts using this tool. However, you can still send an email to [email protected] to request an account.'; |
|
|
|
|
|
|
84
|
|
|
case self::BANNED_TOR: |
|
85
|
|
|
return 'Tor exit nodes are currently banned from using this tool due to excessive abuse. Please note that Tor is also currently banned from editing Wikipedia.'; |
|
|
|
|
|
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
throw new Exception('Unknown validation error'); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Summary of isError |
|
93
|
|
|
* @return bool |
|
94
|
|
|
*/ |
|
95
|
|
|
public function isError() |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->isError; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.