stwalkerster /
waca
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /************************************************************************** |
||
| 3 | ********** English Wikipedia Account Request Interface ********** |
||
| 4 | *************************************************************************** |
||
| 5 | ** Wikipedia Account Request Graphic Design by Charles Melbye, ** |
||
| 6 | ** which is licensed under a Creative Commons ** |
||
| 7 | ** Attribution-Noncommercial-Share Alike 3.0 United States License. ** |
||
| 8 | ** ** |
||
| 9 | ** All other code are released under the Public Domain ** |
||
| 10 | ** by the ACC Development Team. ** |
||
| 11 | ** ** |
||
| 12 | ** See CREDITS for the list of developers. ** |
||
| 13 | ***************************************************************************/ |
||
| 14 | |||
| 15 | // Get all the classes. |
||
| 16 | require_once 'config.inc.php'; |
||
| 17 | require_once 'functions.php'; |
||
| 18 | |||
| 19 | require_once 'includes/PdoDatabase.php'; |
||
| 20 | require_once 'includes/SmartyInit.php'; |
||
| 21 | |||
| 22 | // Check to see if the database is unavailable. |
||
| 23 | // Uses the true variable as the public uses this page. |
||
| 24 | if (Offline::isOffline()) { |
||
| 25 | echo Offline::getOfflineMessage(true); |
||
| 26 | die(); |
||
| 27 | } |
||
| 28 | |||
| 29 | // TODO: move me to a maintenance job |
||
|
0 ignored issues
–
show
Coding Style
Best Practice
introduced
by
Loading history...
|
|||
| 30 | if ($enableEmailConfirm == 1) { |
||
| 31 | Request::cleanExpiredUnconfirmedRequests(); |
||
| 32 | } |
||
| 33 | |||
| 34 | $antispoofProvider = new $antispoofProviderClass(); |
||
| 35 | $xffTrustProvider = new $xffTrustProviderClass($squidIpList); |
||
| 36 | $database = gGetDb(); |
||
| 37 | |||
| 38 | // Display the header of the interface. |
||
| 39 | BootstrapSkin::displayPublicHeader(); |
||
| 40 | |||
| 41 | if (isset($_GET['action']) && $_GET['action'] == "confirm") { |
||
| 42 | try { |
||
| 43 | if (!isset($_GET['id']) || !isset($_GET['si'])) { |
||
| 44 | BootstrapSkin::displayAlertBox( |
||
| 45 | "Please check the link you received", |
||
| 46 | "alert-error", |
||
| 47 | "Missing parameters", |
||
| 48 | true, |
||
| 49 | false); |
||
| 50 | |||
| 51 | BootstrapSkin::displayPublicFooter(); |
||
| 52 | die(); |
||
| 53 | } |
||
| 54 | |||
| 55 | $request = Request::getById($_GET['id'], $database); |
||
| 56 | |||
| 57 | if ($request === false) { |
||
| 58 | BootstrapSkin::displayAlertBox( |
||
| 59 | $smarty->fetch('request/request-not-found.tpl'), |
||
| 60 | "alert-error", |
||
| 61 | "Request not found", |
||
| 62 | true, |
||
| 63 | false); |
||
| 64 | BootstrapSkin::displayPublicFooter(); |
||
| 65 | die(); |
||
| 66 | } |
||
| 67 | |||
| 68 | if ($request->getEmailConfirm() == "Confirmed") { |
||
| 69 | $smarty->display("request/email-confirmed.tpl"); |
||
| 70 | BootstrapSkin::displayPublicFooter(); |
||
| 71 | return; |
||
| 72 | } |
||
| 73 | |||
| 74 | $database->transactionally(function() use($database, $request, $smarty) |
||
| 75 | { |
||
| 76 | if ($request === false) { |
||
| 77 | throw new TransactionException($smarty->fetch('request/request-not-found.tpl'), "Ooops!"); |
||
| 78 | } |
||
| 79 | |||
| 80 | $request->confirmEmail($_GET['si']); |
||
| 81 | $request->save(); |
||
| 82 | |||
| 83 | Logger::emailConfirmed($database, $request); |
||
| 84 | }); |
||
| 85 | |||
| 86 | $smarty->display("request/email-confirmed.tpl"); |
||
| 87 | |||
| 88 | $request = Request::getById($_GET['id'], $database); |
||
| 89 | Notification::requestReceived($request); |
||
| 90 | |||
| 91 | BootstrapSkin::displayPublicFooter(); |
||
| 92 | } |
||
| 93 | catch (Exception $ex) { |
||
| 94 | BootstrapSkin::displayAlertBox($ex->getMessage(), "alert-error", "Unknown error", true, false); |
||
| 95 | BootstrapSkin::displayPublicFooter(); |
||
| 96 | } |
||
| 97 | } |
||
| 98 | else { |
||
| 99 | if ($_SERVER['REQUEST_METHOD'] == "POST") { |
||
| 100 | $errorEncountered = false; |
||
| 101 | |||
| 102 | $request = new Request(); |
||
| 103 | $request->setDatabase($database); |
||
| 104 | |||
| 105 | $request->setName($_POST['name']); |
||
| 106 | $request->setEmail($_POST['email']); |
||
| 107 | $request->setComment($_POST['comments']); |
||
| 108 | $request->setIp($_SERVER['REMOTE_ADDR']); |
||
| 109 | |||
| 110 | if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
||
| 111 | $request->setForwardedIp($_SERVER['HTTP_X_FORWARDED_FOR']); |
||
| 112 | } |
||
| 113 | |||
| 114 | if (isset($_SERVER['HTTP_USER_AGENT'])) { |
||
| 115 | $request->setUserAgent($_SERVER['HTTP_USER_AGENT']); |
||
| 116 | } |
||
| 117 | |||
| 118 | $validationHelper = new RequestValidationHelper(new BanHelper(), $request, $_POST['emailconfirm']); |
||
| 119 | |||
| 120 | // These are arrays of ValidationError. |
||
| 121 | $nameValidation = $validationHelper->validateName(); |
||
| 122 | $emailValidation = $validationHelper->validateEmail(); |
||
| 123 | $otherValidation = $validationHelper->validateOther(); |
||
| 124 | |||
| 125 | $validationErrors = array_merge($nameValidation, $emailValidation, $otherValidation); |
||
| 126 | |||
| 127 | if (count($validationErrors) > 0) { |
||
| 128 | foreach ($validationErrors as $validationError) { |
||
| 129 | BootstrapSkin::displayAlertBox( |
||
| 130 | $smarty->fetch("validation/" . $validationError->getErrorCode() . ".tpl"), |
||
| 131 | "alert-error"); |
||
| 132 | } |
||
| 133 | |||
| 134 | $smarty->display("request/request-form.tpl"); |
||
| 135 | } |
||
| 136 | else if ($enableEmailConfirm == 1) { |
||
| 137 | $request->generateEmailConfirmationHash(); |
||
| 138 | |||
| 139 | $database->transactionally(function() use($request) |
||
| 140 | { |
||
| 141 | $request->save(); |
||
| 142 | |||
| 143 | // checksum depends on the ID, so we have to save again! |
||
| 144 | $request->updateChecksum(); |
||
| 145 | $request->save(); |
||
| 146 | }); |
||
| 147 | |||
| 148 | $request->sendConfirmationEmail(); |
||
| 149 | |||
| 150 | $smarty->display("request/email-confirmation.tpl"); |
||
| 151 | } |
||
| 152 | else { |
||
| 153 | $request->setEmailConfirm(0); // Since it can't be null |
||
| 154 | $database->transactionally(function() use($request) |
||
| 155 | { |
||
| 156 | $request->save(); |
||
| 157 | $request->updateChecksum(); |
||
| 158 | $request->save(); |
||
| 159 | }); |
||
| 160 | $smarty->display("request/email-confirmed.tpl"); |
||
| 161 | Notification::requestReceived($request); |
||
| 162 | BootstrapSkin::displayPublicFooter(); |
||
| 163 | } |
||
| 164 | |||
| 165 | BootstrapSkin::displayPublicFooter(); |
||
| 166 | } |
||
| 167 | else { |
||
| 168 | $smarty->display("request/request-form.tpl"); |
||
| 169 | BootstrapSkin::displayPublicFooter(); |
||
| 170 | } |
||
| 171 | } |
||
| 172 |