enwikipedia-acc /
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 | function zoomPage($id, $urlhash) |
||
| 16 | { |
||
| 17 | global $session, $availableRequestStates, $createdid; |
||
| 18 | global $smarty, $locationProvider, $rdnsProvider, $antispoofProvider; |
||
| 19 | global $xffTrustProvider, $enableEmailConfirm; |
||
| 20 | |||
| 21 | $database = gGetDb(); |
||
| 22 | $request = Request::getById($id, $database); |
||
| 23 | if ($request == false) { |
||
| 24 | // Notifies the user and stops the script. |
||
| 25 | BootstrapSkin::displayAlertBox("Could not load the requested request!", "alert-error", "Error", true, false); |
||
| 26 | BootstrapSkin::displayInternalFooter(); |
||
| 27 | die(); |
||
| 28 | } |
||
| 29 | |||
| 30 | $smarty->assign('ecenable', $enableEmailConfirm); |
||
| 31 | |||
| 32 | if (isset($_GET['ecoverride']) && User::getCurrent()->isAdmin()) { |
||
| 33 | $smarty->assign('ecoverride', true); |
||
| 34 | } |
||
| 35 | else { |
||
| 36 | $smarty->assign('ecoverride', false); |
||
| 37 | } |
||
| 38 | |||
| 39 | $smarty->assign('request', $request); |
||
| 40 | |||
| 41 | $smarty->assign("usernamerawunicode", html_entity_decode($request->getName())); |
||
| 42 | |||
| 43 | $smarty->assign("iplocation", $locationProvider->getIpLocation($request->getTrustedIp())); |
||
| 44 | |||
| 45 | $createdreason = EmailTemplate::getById($createdid, gGetDb()); |
||
| 46 | $smarty->assign("createdEmailTemplate", $createdreason); |
||
| 47 | |||
| 48 | #region setup whether data is viewable or not |
||
| 49 | |||
| 50 | $viewableDataStatement = $database->prepare(<<<SQL |
||
| 51 | SELECT COUNT(*) |
||
| 52 | FROM request |
||
| 53 | WHERE |
||
| 54 | ( |
||
| 55 | email = :email |
||
| 56 | OR ip = :trustedIp |
||
| 57 | OR forwardedip LIKE :trustedProxy |
||
| 58 | ) |
||
| 59 | AND reserved = :reserved |
||
| 60 | AND emailconfirm = 'Confirmed' |
||
| 61 | AND status != 'Closed'; |
||
| 62 | SQL |
||
| 63 | ); |
||
| 64 | |||
| 65 | $viewableDataStatement->bindValue(":email", $request->getEmail()); |
||
| 66 | $viewableDataStatement->bindValue(":reserved", User::getCurrent()->getId()); |
||
| 67 | $viewableDataStatement->bindValue(":trustedIp", $request->getTrustedIp()); |
||
| 68 | $viewableDataStatement->bindValue(":trustedProxy", '%' . $request->getTrustedIp() . '%'); |
||
| 69 | |||
| 70 | $viewableDataStatement->execute(); |
||
| 71 | |||
| 72 | $viewableData = $viewableDataStatement->fetchColumn(); |
||
| 73 | $viewableDataStatement->closeCursor(); |
||
| 74 | |||
| 75 | $hideinfo = ($viewableData == 0); |
||
| 76 | |||
| 77 | #endregion |
||
| 78 | |||
| 79 | if ($request->getStatus() == "Closed") { |
||
| 80 | $hash = md5($request->getId() . $request->getEmail() . $request->getTrustedIp() . microtime()); //If the request is closed, change the hash based on microseconds similar to the checksums. |
||
|
0 ignored issues
–
show
|
|||
| 81 | $smarty->assign("isclosed", true); |
||
| 82 | } |
||
| 83 | else { |
||
| 84 | $hash = md5($request->getId() . $request->getEmail() . $request->getTrustedIp()); |
||
| 85 | $smarty->assign("isclosed", false); |
||
| 86 | } |
||
| 87 | $smarty->assign("hash", $hash); |
||
| 88 | if ($hash == $urlhash) { |
||
| 89 | $correcthash = true; |
||
| 90 | } |
||
| 91 | else { |
||
| 92 | $correcthash = false; |
||
| 93 | } |
||
| 94 | |||
| 95 | $smarty->assign("showinfo", false); |
||
| 96 | if ($hideinfo == false || $correcthash == true || User::getCurrent()->isAdmin() || User::getCurrent()->isCheckuser()) { |
||
| 97 | $smarty->assign("showinfo", true); |
||
| 98 | } |
||
| 99 | |||
| 100 | $emailDomain = explode("@", $request->getEmail())[1]; |
||
| 101 | $smarty->assign("emailurl", $emailDomain); |
||
| 102 | |||
| 103 | // force to not show, overriden later |
||
| 104 | $smarty->assign("proxyip", ""); |
||
| 105 | |||
| 106 | if ($hideinfo == false || $correcthash == true || User::getCurrent()->isAdmin() || User::getCurrent()->isCheckuser()) { |
||
| 107 | $smarty->assign("proxyip", $request->getForwardedIp()); |
||
| 108 | if ($request->getForwardedIp()) { |
||
| 109 | $smartyproxies = array(); // Initialize array to store data to be output in Smarty template. |
||
| 110 | $smartyproxiesindex = 0; |
||
| 111 | |||
| 112 | $proxies = explode(",", $request->getForwardedIp()); |
||
| 113 | $proxies[] = $request->getIp(); |
||
| 114 | |||
| 115 | $origin = $proxies[0]; |
||
| 116 | $smarty->assign("origin", $origin); |
||
| 117 | |||
| 118 | $proxies = array_reverse($proxies); |
||
| 119 | $trust = true; |
||
| 120 | global $rfc1918ips; |
||
| 121 | |||
| 122 | foreach ($proxies as $proxynum => $p) { |
||
| 123 | $p2 = trim($p); |
||
| 124 | $smartyproxies[$smartyproxiesindex]['ip'] = $p2; |
||
| 125 | |||
| 126 | // get data on this IP. |
||
| 127 | $trusted = $xffTrustProvider->isTrusted($p2); |
||
| 128 | $ipisprivate = ipInRange($rfc1918ips, $p2); |
||
| 129 | |||
| 130 | if (!$ipisprivate) { |
||
| 131 | $iprdns = $rdnsProvider->getRdns($p2); |
||
| 132 | $iplocation = $locationProvider->getIpLocation($p2); |
||
| 133 | } |
||
| 134 | else { |
||
| 135 | // this is going to fail, so why bother trying? |
||
| 136 | $iprdns = false; |
||
| 137 | $iplocation = false; |
||
| 138 | } |
||
| 139 | |||
| 140 | // current trust chain status BEFORE this link |
||
| 141 | $pretrust = $trust; |
||
| 142 | |||
| 143 | // is *this* link trusted? |
||
| 144 | $smartyproxies[$smartyproxiesindex]['trustedlink'] = $trusted; |
||
| 145 | |||
| 146 | // current trust chain status AFTER this link |
||
| 147 | $trust = $trust & $trusted; |
||
| 148 | if ($pretrust && $p2 == $origin) { |
||
| 149 | $trust = true; |
||
| 150 | } |
||
| 151 | $smartyproxies[$smartyproxiesindex]['trust'] = $trust; |
||
| 152 | |||
| 153 | $smartyproxies[$smartyproxiesindex]['rdnsfailed'] = $iprdns === false; |
||
| 154 | $smartyproxies[$smartyproxiesindex]['rdns'] = $iprdns; |
||
| 155 | $smartyproxies[$smartyproxiesindex]['routable'] = !$ipisprivate; |
||
| 156 | |||
| 157 | $smartyproxies[$smartyproxiesindex]['location'] = $iplocation; |
||
| 158 | |||
| 159 | if ($iprdns == $p2 && $ipisprivate == false) { |
||
| 160 | $smartyproxies[$smartyproxiesindex]['rdns'] = null; |
||
| 161 | } |
||
| 162 | |||
| 163 | $smartyproxies[$smartyproxiesindex]['showlinks'] = (!$trust || $p2 == $origin) && !$ipisprivate; |
||
| 164 | |||
| 165 | $smartyproxiesindex++; |
||
| 166 | } |
||
| 167 | |||
| 168 | $smarty->assign("proxies", $smartyproxies); |
||
| 169 | } |
||
| 170 | } |
||
| 171 | |||
| 172 | global $defaultRequestStateKey; |
||
| 173 | |||
| 174 | // TODO: remove me and replace with call in the template directly |
||
| 175 | $smarty->assign("isprotected", $request->isProtected()); |
||
| 176 | |||
| 177 | $smarty->assign("defaultstate", $defaultRequestStateKey); |
||
| 178 | $smarty->assign("requeststates", $availableRequestStates); |
||
| 179 | |||
| 180 | try { |
||
| 181 | $spoofs = $antispoofProvider->getSpoofs($request->getName()); |
||
| 182 | } |
||
| 183 | catch (Exception $ex) { |
||
| 184 | $spoofs = $ex->getMessage(); |
||
| 185 | } |
||
| 186 | |||
| 187 | $smarty->assign("spoofs", $spoofs); |
||
| 188 | |||
| 189 | // START LOG DISPLAY |
||
| 190 | |||
| 191 | $logs = Logger::getRequestLogsWithComments($request->getId(), $request->getDatabase()); |
||
| 192 | $requestLogs = array(); |
||
| 193 | |||
| 194 | if (trim($request->getComment()) !== "") { |
||
| 195 | $requestLogs[] = array( |
||
| 196 | 'type' => 'comment', |
||
| 197 | 'security' => 'user', |
||
| 198 | 'userid' => null, |
||
| 199 | 'user' => $request->getName(), |
||
| 200 | 'entry' => null, |
||
| 201 | 'time' => $request->getDate(), |
||
| 202 | 'canedit' => false, |
||
| 203 | 'id' => $request->getId(), |
||
| 204 | 'comment' => $request->getComment(), |
||
| 205 | ); |
||
| 206 | } |
||
| 207 | |||
| 208 | $namecache = array(); |
||
| 209 | |||
| 210 | $editableComments = false; |
||
| 211 | if (User::getCurrent()->isAdmin() || User::getCurrent()->isCheckuser()) { |
||
| 212 | $editableComments = true; |
||
| 213 | } |
||
| 214 | |||
| 215 | foreach ($logs as $entry) { |
||
| 216 | // both log and comment have a 'user' field |
||
| 217 | if (!array_key_exists($entry->getUser(), $namecache)) { |
||
| 218 | $namecache[$entry->getUser()] = $entry->getUserObject(); |
||
| 219 | } |
||
| 220 | |||
| 221 | if ($entry instanceof Comment) { |
||
| 222 | $requestLogs[] = array( |
||
| 223 | 'type' => 'comment', |
||
| 224 | 'security' => $entry->getVisibility(), |
||
| 225 | 'user' => $namecache[$entry->getUser()]->getUsername(), |
||
| 226 | 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
||
| 227 | 'entry' => null, |
||
| 228 | 'time' => $entry->getTime(), |
||
| 229 | 'canedit' => ($editableComments || $entry->getUser() == User::getCurrent()->getId()), |
||
| 230 | 'id' => $entry->getId(), |
||
| 231 | 'comment' => $entry->getComment(), |
||
| 232 | ); |
||
| 233 | } |
||
| 234 | |||
| 235 | if ($entry instanceof Log) { |
||
| 236 | $requestLogs[] = array( |
||
| 237 | 'type' => 'log', |
||
| 238 | 'security' => 'user', |
||
| 239 | 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
||
| 240 | 'user' => $namecache[$entry->getUser()]->getUsername(), |
||
| 241 | 'entry' => Logger::getLogDescription($entry), |
||
| 242 | 'time' => $entry->getTimestamp(), |
||
| 243 | 'canedit' => false, |
||
| 244 | 'id' => $entry->getId(), |
||
| 245 | 'comment' => $entry->getComment(), |
||
| 246 | ); |
||
| 247 | } |
||
| 248 | } |
||
| 249 | |||
| 250 | $smarty->assign("requestLogs", $requestLogs); |
||
| 251 | |||
| 252 | |||
| 253 | // START OTHER REQUESTS BY IP AND EMAIL STUFF |
||
| 254 | |||
| 255 | // Displays other requests from this ip. |
||
| 256 | |||
| 257 | // assign to user |
||
| 258 | $userListQuery = "SELECT username FROM user WHERE status = 'User' or status = 'Admin';"; |
||
| 259 | $userListResult = gGetDb()->query($userListQuery); |
||
| 260 | $userListData = $userListResult->fetchAll(PDO::FETCH_COLUMN); |
||
| 261 | $userListProcessedData = array(); |
||
| 262 | foreach ($userListData as $userListItem) { |
||
| 263 | $userListProcessedData[] = "\"" . htmlentities($userListItem) . "\""; |
||
| 264 | } |
||
| 265 | |||
| 266 | $userList = '[' . implode(",", $userListProcessedData) . ']'; |
||
| 267 | $smarty->assign("jsuserlist", $userList); |
||
| 268 | // end: assign to user |
||
| 269 | |||
| 270 | // TODO: refactor this! |
||
| 271 | $createreasons = EmailTemplate::getActiveTemplates(EmailTemplate::CREATED); |
||
| 272 | $smarty->assign("createreasons", $createreasons); |
||
| 273 | |||
| 274 | $declinereasons = EmailTemplate::getActiveTemplates(EmailTemplate::NOT_CREATED); |
||
| 275 | $smarty->assign("declinereasons", $declinereasons); |
||
| 276 | |||
| 277 | $allcreatereasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::CREATED); |
||
| 278 | $smarty->assign("allcreatereasons", $allcreatereasons); |
||
| 279 | |||
| 280 | $alldeclinereasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::NOT_CREATED); |
||
| 281 | $smarty->assign("alldeclinereasons", $alldeclinereasons); |
||
| 282 | |||
| 283 | $allotherreasons = EmailTemplate::getAllActiveTemplates(false); |
||
| 284 | $smarty->assign("allotherreasons", $allotherreasons); |
||
| 285 | |||
| 286 | return $smarty->fetch("request-zoom.tpl"); |
||
| 287 | } |
||
| 288 |
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.