@@ -129,7 +129,7 @@  | 
                                                    ||
| 129 | 129 | /**  | 
                                                        
| 130 | 130 | * Assigns a Smarty variable  | 
                                                        
| 131 | 131 | *  | 
                                                        
| 132 | - * @param array|string $name the template variable name(s)  | 
                                                        |
| 132 | + * @param string $name the template variable name(s)  | 
                                                        |
| 133 | 133 | * @param mixed $value the value to assign  | 
                                                        
| 134 | 134 | */  | 
                                                        
| 135 | 135 | abstract protected function assign($name, $value);  | 
                                                        
@@ -24,335 +24,335 @@  | 
                                                    ||
| 24 | 24 | |
| 25 | 25 | trait RequestData  | 
                                                        
| 26 | 26 |  { | 
                                                        
| 27 | - /**  | 
                                                        |
| 28 | - * @var array Array of IP address classed as 'private' by RFC1918.  | 
                                                        |
| 29 | - */  | 
                                                        |
| 30 | - protected static $rfc1918ips = array(  | 
                                                        |
| 31 | - "10.0.0.0" => "10.255.255.255",  | 
                                                        |
| 32 | - "172.16.0.0" => "172.31.255.255",  | 
                                                        |
| 33 | - "192.168.0.0" => "192.168.255.255",  | 
                                                        |
| 34 | - "169.254.0.0" => "169.254.255.255",  | 
                                                        |
| 35 | - "127.0.0.0" => "127.255.255.255",  | 
                                                        |
| 36 | - );  | 
                                                        |
| 37 | -  | 
                                                        |
| 38 | - /**  | 
                                                        |
| 39 | - * Gets a request object  | 
                                                        |
| 40 | - *  | 
                                                        |
| 41 | - * @param PdoDatabase $database The database connection  | 
                                                        |
| 42 | - * @param int $requestId The ID of the request to retrieve  | 
                                                        |
| 43 | - *  | 
                                                        |
| 44 | - * @return Request  | 
                                                        |
| 45 | - * @throws ApplicationLogicException  | 
                                                        |
| 46 | - */  | 
                                                        |
| 47 | - protected function getRequest(PdoDatabase $database, $requestId)  | 
                                                        |
| 48 | -    { | 
                                                        |
| 49 | -        if ($requestId === null) { | 
                                                        |
| 50 | -            throw new ApplicationLogicException("No request specified"); | 
                                                        |
| 51 | - }  | 
                                                        |
| 52 | -  | 
                                                        |
| 53 | - $request = Request::getById($requestId, $database);  | 
                                                        |
| 54 | -        if ($request === false || !is_a($request, Request::class)) { | 
                                                        |
| 55 | -            throw new ApplicationLogicException('Could not load the requested request!'); | 
                                                        |
| 56 | - }  | 
                                                        |
| 57 | -  | 
                                                        |
| 58 | - return $request;  | 
                                                        |
| 59 | - }  | 
                                                        |
| 60 | -  | 
                                                        |
| 61 | - /**  | 
                                                        |
| 62 | - * Returns a value stating whether the user is allowed to see private data or not  | 
                                                        |
| 63 | - *  | 
                                                        |
| 64 | - * @param Request $request  | 
                                                        |
| 65 | - * @param User $currentUser  | 
                                                        |
| 66 | - *  | 
                                                        |
| 67 | - * @return bool  | 
                                                        |
| 68 | - * @category Security-Critical  | 
                                                        |
| 69 | - */  | 
                                                        |
| 70 | - protected function isAllowedPrivateData(Request $request, User $currentUser)  | 
                                                        |
| 71 | -    { | 
                                                        |
| 72 | - // Test the main security barrier for private data access using SecurityManager  | 
                                                        |
| 73 | -        if ($this->barrierTest('privateData')) { | 
                                                        |
| 74 | - // Tool admins/check-users can always see private data  | 
                                                        |
| 75 | - return true;  | 
                                                        |
| 76 | - }  | 
                                                        |
| 77 | -  | 
                                                        |
| 78 | - // reserving user is allowed to see the data  | 
                                                        |
| 79 | -        if ($currentUser->getId() === $request->getReserved() && $request->getReserved() !== null) { | 
                                                        |
| 80 | - return true;  | 
                                                        |
| 81 | - }  | 
                                                        |
| 82 | -  | 
                                                        |
| 83 | - // user has the reveal hash  | 
                                                        |
| 84 | -        if (WebRequest::getString('hash') === $request->getRevealHash()) { | 
                                                        |
| 85 | - return true;  | 
                                                        |
| 86 | - }  | 
                                                        |
| 87 | -  | 
                                                        |
| 88 | - // nope. Not allowed.  | 
                                                        |
| 89 | - return false;  | 
                                                        |
| 90 | - }  | 
                                                        |
| 91 | -  | 
                                                        |
| 92 | - /**  | 
                                                        |
| 93 | - * Tests the security barrier for a specified action.  | 
                                                        |
| 94 | - *  | 
                                                        |
| 95 | - * Intended to be used from within templates  | 
                                                        |
| 96 | - *  | 
                                                        |
| 97 | - * @param string $action  | 
                                                        |
| 98 | - *  | 
                                                        |
| 99 | - * @return boolean  | 
                                                        |
| 100 | - * @category Security-Critical  | 
                                                        |
| 101 | - */  | 
                                                        |
| 102 | - abstract protected function barrierTest($action);  | 
                                                        |
| 103 | -  | 
                                                        |
| 104 | - /**  | 
                                                        |
| 105 | - * Gets the name of the route that has been passed from the request router.  | 
                                                        |
| 106 | - * @return string  | 
                                                        |
| 107 | - */  | 
                                                        |
| 108 | - abstract protected function getRouteName();  | 
                                                        |
| 109 | -  | 
                                                        |
| 110 | - /** @return SecurityManager */  | 
                                                        |
| 111 | - abstract protected function getSecurityManager();  | 
                                                        |
| 112 | -  | 
                                                        |
| 113 | - /**  | 
                                                        |
| 114 | - * Sets the name of the template this page should display.  | 
                                                        |
| 115 | - *  | 
                                                        |
| 116 | - * @param string $name  | 
                                                        |
| 117 | - */  | 
                                                        |
| 118 | - abstract protected function setTemplate($name);  | 
                                                        |
| 119 | -  | 
                                                        |
| 120 | - /** @return IXffTrustProvider */  | 
                                                        |
| 121 | - abstract protected function getXffTrustProvider();  | 
                                                        |
| 122 | -  | 
                                                        |
| 123 | - /** @return ILocationProvider */  | 
                                                        |
| 124 | - abstract protected function getLocationProvider();  | 
                                                        |
| 125 | -  | 
                                                        |
| 126 | - /** @return IRDnsProvider */  | 
                                                        |
| 127 | - abstract protected function getRdnsProvider();  | 
                                                        |
| 128 | -  | 
                                                        |
| 129 | - /**  | 
                                                        |
| 130 | - * Assigns a Smarty variable  | 
                                                        |
| 131 | - *  | 
                                                        |
| 132 | - * @param array|string $name the template variable name(s)  | 
                                                        |
| 133 | - * @param mixed $value the value to assign  | 
                                                        |
| 134 | - */  | 
                                                        |
| 135 | - abstract protected function assign($name, $value);  | 
                                                        |
| 136 | -  | 
                                                        |
| 137 | - /**  | 
                                                        |
| 138 | - * @param int $requestReservationId  | 
                                                        |
| 139 | - * @param PdoDatabase $database  | 
                                                        |
| 140 | - * @param User $currentUser  | 
                                                        |
| 141 | - */  | 
                                                        |
| 142 | - protected function setupReservationDetails($requestReservationId, PdoDatabase $database, User $currentUser)  | 
                                                        |
| 143 | -    { | 
                                                        |
| 144 | - $requestIsReserved = $requestReservationId !== null;  | 
                                                        |
| 145 | -        $this->assign('requestIsReserved', $requestIsReserved); | 
                                                        |
| 146 | -        $this->assign('requestIsReservedByMe', false); | 
                                                        |
| 147 | -  | 
                                                        |
| 148 | -        if ($requestIsReserved) { | 
                                                        |
| 149 | -            $this->assign('requestReservedByName', User::getById($requestReservationId, $database)->getUsername()); | 
                                                        |
| 150 | -            $this->assign('requestReservedById', $requestReservationId); | 
                                                        |
| 151 | -  | 
                                                        |
| 152 | -            if ($requestReservationId === $currentUser->getId()) { | 
                                                        |
| 153 | -                $this->assign('requestIsReservedByMe', true); | 
                                                        |
| 154 | - }  | 
                                                        |
| 155 | - }  | 
                                                        |
| 156 | - }  | 
                                                        |
| 157 | -  | 
                                                        |
| 158 | - /**  | 
                                                        |
| 159 | - * Adds private request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED!  | 
                                                        |
| 160 | - *  | 
                                                        |
| 161 | - * @param Request $request  | 
                                                        |
| 162 | - * @param User $currentUser  | 
                                                        |
| 163 | - * @param SiteConfiguration $configuration  | 
                                                        |
| 164 | - *  | 
                                                        |
| 165 | - * @param PdoDatabase $database  | 
                                                        |
| 166 | - */  | 
                                                        |
| 167 | - protected function setupPrivateData(  | 
                                                        |
| 168 | - $request,  | 
                                                        |
| 169 | - User $currentUser,  | 
                                                        |
| 170 | - SiteConfiguration $configuration,  | 
                                                        |
| 171 | - PdoDatabase $database  | 
                                                        |
| 172 | -    ) { | 
                                                        |
| 173 | - $xffProvider = $this->getXffTrustProvider();  | 
                                                        |
| 174 | -  | 
                                                        |
| 175 | - $relatedEmailRequests = RequestSearchHelper::get($database)  | 
                                                        |
| 176 | - ->byEmailAddress($request->getEmail())  | 
                                                        |
| 177 | - ->withConfirmedEmail()  | 
                                                        |
| 178 | - ->excludingPurgedData($configuration)  | 
                                                        |
| 179 | - ->excludingRequest($request->getId())  | 
                                                        |
| 180 | - ->fetch();  | 
                                                        |
| 181 | -  | 
                                                        |
| 182 | -        $this->assign('requestEmail', $request->getEmail()); | 
                                                        |
| 183 | -        $emailDomain = explode("@", $request->getEmail())[1]; | 
                                                        |
| 184 | -        $this->assign("emailurl", $emailDomain); | 
                                                        |
| 185 | -        $this->assign('requestRelatedEmailRequestsCount', count($relatedEmailRequests)); | 
                                                        |
| 186 | -        $this->assign('requestRelatedEmailRequests', $relatedEmailRequests); | 
                                                        |
| 187 | -  | 
                                                        |
| 188 | - $trustedIp = $xffProvider->getTrustedClientIp($request->getIp(), $request->getForwardedIp());  | 
                                                        |
| 189 | -        $this->assign('requestTrustedIp', $trustedIp); | 
                                                        |
| 190 | -        $this->assign('requestRealIp', $request->getIp()); | 
                                                        |
| 191 | -        $this->assign('requestForwardedIp', $request->getForwardedIp()); | 
                                                        |
| 192 | -  | 
                                                        |
| 193 | - $trustedIpLocation = $this->getLocationProvider()->getIpLocation($trustedIp);  | 
                                                        |
| 194 | -        $this->assign('requestTrustedIpLocation', $trustedIpLocation); | 
                                                        |
| 195 | -  | 
                                                        |
| 196 | -        $this->assign('requestHasForwardedIp', $request->getForwardedIp() !== null); | 
                                                        |
| 197 | -  | 
                                                        |
| 198 | - $relatedIpRequests = RequestSearchHelper::get($database)  | 
                                                        |
| 199 | - ->byIp($trustedIp)  | 
                                                        |
| 200 | - ->withConfirmedEmail()  | 
                                                        |
| 201 | - ->excludingPurgedData($configuration)  | 
                                                        |
| 202 | - ->excludingRequest($request->getId())  | 
                                                        |
| 203 | - ->fetch();  | 
                                                        |
| 204 | -  | 
                                                        |
| 205 | -        $this->assign('requestRelatedIpRequestsCount', count($relatedIpRequests)); | 
                                                        |
| 206 | -        $this->assign('requestRelatedIpRequests', $relatedIpRequests); | 
                                                        |
| 207 | -  | 
                                                        |
| 208 | -        $this->assign('showRevealLink', false); | 
                                                        |
| 209 | - if ($request->getReserved() === $currentUser->getId() ||  | 
                                                        |
| 210 | - $currentUser->isAdmin() ||  | 
                                                        |
| 211 | - $currentUser->isCheckuser()  | 
                                                        |
| 212 | -        ) { | 
                                                        |
| 213 | -            $this->assign('showRevealLink', true); | 
                                                        |
| 214 | -  | 
                                                        |
| 215 | -            $this->assign('revealHash', $request->getRevealHash()); | 
                                                        |
| 216 | - }  | 
                                                        |
| 217 | -  | 
                                                        |
| 218 | - $this->setupForwardedIpData($request);  | 
                                                        |
| 219 | - }  | 
                                                        |
| 220 | -  | 
                                                        |
| 221 | - /**  | 
                                                        |
| 222 | - * Adds checkuser request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED!  | 
                                                        |
| 223 | - *  | 
                                                        |
| 224 | - * @param Request $request  | 
                                                        |
| 225 | - */  | 
                                                        |
| 226 | - protected function setupCheckUserData(Request $request)  | 
                                                        |
| 227 | -    { | 
                                                        |
| 228 | -        $this->assign('requestUserAgent', $request->getUserAgent()); | 
                                                        |
| 229 | - }  | 
                                                        |
| 230 | -  | 
                                                        |
| 231 | - /**  | 
                                                        |
| 232 | - * Sets up the basic data for this request, and adds it to Smarty  | 
                                                        |
| 233 | - *  | 
                                                        |
| 234 | - * @param Request $request  | 
                                                        |
| 235 | - * @param SiteConfiguration $config  | 
                                                        |
| 236 | - */  | 
                                                        |
| 237 | - protected function setupBasicData(Request $request, SiteConfiguration $config)  | 
                                                        |
| 238 | -    { | 
                                                        |
| 239 | -        $this->assign('requestId', $request->getId()); | 
                                                        |
| 240 | -        $this->assign('updateVersion', $request->getUpdateVersion()); | 
                                                        |
| 241 | -        $this->assign('requestName', $request->getName()); | 
                                                        |
| 242 | -        $this->assign('requestDate', $request->getDate()); | 
                                                        |
| 243 | -        $this->assign('requestStatus', $request->getStatus()); | 
                                                        |
| 244 | -  | 
                                                        |
| 245 | -        $this->assign('requestIsClosed', !array_key_exists($request->getStatus(), $config->getRequestStates())); | 
                                                        |
| 246 | - }  | 
                                                        |
| 247 | -  | 
                                                        |
| 248 | - /**  | 
                                                        |
| 249 | - * Sets up the forwarded IP data for this request and adds it to Smarty  | 
                                                        |
| 250 | - *  | 
                                                        |
| 251 | - * @param Request $request  | 
                                                        |
| 252 | - */  | 
                                                        |
| 253 | - protected function setupForwardedIpData(Request $request)  | 
                                                        |
| 254 | -    { | 
                                                        |
| 255 | -        if ($request->getForwardedIp() !== null) { | 
                                                        |
| 256 | - $requestProxyData = array(); // Initialize array to store data to be output in Smarty template.  | 
                                                        |
| 257 | - $proxyIndex = 0;  | 
                                                        |
| 258 | -  | 
                                                        |
| 259 | - // Assuming [client] <=> [proxy1] <=> [proxy2] <=> [proxy3] <=> [us], we will see an XFF header of [client],  | 
                                                        |
| 260 | - // [proxy1], [proxy2], and our actual IP will be [proxy3]  | 
                                                        |
| 261 | -            $proxies = explode(",", $request->getForwardedIp()); | 
                                                        |
| 262 | - $proxies[] = $request->getIp();  | 
                                                        |
| 263 | -  | 
                                                        |
| 264 | - // Origin is the supposed "client" IP.  | 
                                                        |
| 265 | - $origin = $proxies[0];  | 
                                                        |
| 266 | -            $this->assign("forwardedOrigin", $origin); | 
                                                        |
| 267 | -  | 
                                                        |
| 268 | - // We step through the servers in reverse order, from closest to furthest  | 
                                                        |
| 269 | - $proxies = array_reverse($proxies);  | 
                                                        |
| 270 | -  | 
                                                        |
| 271 | - // By default, we have trust, because the first in the chain is now REMOTE_ADDR, which is hardest to spoof.  | 
                                                        |
| 272 | - $trust = true;  | 
                                                        |
| 273 | -  | 
                                                        |
| 274 | - /**  | 
                                                        |
| 275 | - * @var int $index The zero-based index of the proxy.  | 
                                                        |
| 276 | - * @var string $proxyData The proxy IP address (although possibly not!)  | 
                                                        |
| 277 | - */  | 
                                                        |
| 278 | -            foreach ($proxies as $index => $proxyData) { | 
                                                        |
| 279 | - $proxyAddress = trim($proxyData);  | 
                                                        |
| 280 | - $requestProxyData[$proxyIndex]['ip'] = $proxyAddress;  | 
                                                        |
| 281 | -  | 
                                                        |
| 282 | - // get data on this IP.  | 
                                                        |
| 283 | - $thisProxyIsTrusted = $this->getXffTrustProvider()->isTrusted($proxyAddress);  | 
                                                        |
| 284 | -  | 
                                                        |
| 285 | - $proxyIsInPrivateRange = $this->getXffTrustProvider()  | 
                                                        |
| 286 | - ->ipInRange(self::$rfc1918ips, $proxyAddress);  | 
                                                        |
| 287 | -  | 
                                                        |
| 288 | -                if (!$proxyIsInPrivateRange) { | 
                                                        |
| 289 | - $proxyReverseDns = $this->getRdnsProvider()->getReverseDNS($proxyAddress);  | 
                                                        |
| 290 | - $proxyLocation = $this->getLocationProvider()->getIpLocation($proxyAddress);  | 
                                                        |
| 291 | - }  | 
                                                        |
| 292 | -                else { | 
                                                        |
| 293 | - // this is going to fail, so why bother trying?  | 
                                                        |
| 294 | - $proxyReverseDns = false;  | 
                                                        |
| 295 | - $proxyLocation = false;  | 
                                                        |
| 296 | - }  | 
                                                        |
| 297 | -  | 
                                                        |
| 298 | - // current trust chain status BEFORE this link  | 
                                                        |
| 299 | - $preLinkTrust = $trust;  | 
                                                        |
| 300 | -  | 
                                                        |
| 301 | - // is *this* link trusted? Note, this will be true even if there is an untrusted link before this!  | 
                                                        |
| 302 | - $requestProxyData[$proxyIndex]['trustedlink'] = $thisProxyIsTrusted;  | 
                                                        |
| 303 | -  | 
                                                        |
| 304 | - // set the trust status of the chain to this point  | 
                                                        |
| 305 | - $trust = $trust & $thisProxyIsTrusted;  | 
                                                        |
| 306 | -  | 
                                                        |
| 307 | - // If this is the origin address, and the chain was trusted before this point, then we can trust  | 
                                                        |
| 308 | - // the origin.  | 
                                                        |
| 309 | -                if ($preLinkTrust && $proxyAddress == $origin) { | 
                                                        |
| 310 | - // if this is the origin, then we are at the last point in the chain.  | 
                                                        |
| 311 | - // @todo: this is probably the cause of some bugs when an IP appears twice - we're missing a check  | 
                                                        |
| 312 | - // to see if this is *really* the last in the chain, rather than just the same IP as it.  | 
                                                        |
| 313 | - $trust = true;  | 
                                                        |
| 314 | - }  | 
                                                        |
| 315 | -  | 
                                                        |
| 316 | - $requestProxyData[$proxyIndex]['trust'] = $trust;  | 
                                                        |
| 317 | -  | 
                                                        |
| 318 | - $requestProxyData[$proxyIndex]['rdnsfailed'] = $proxyReverseDns === false;  | 
                                                        |
| 319 | - $requestProxyData[$proxyIndex]['rdns'] = $proxyReverseDns;  | 
                                                        |
| 320 | - $requestProxyData[$proxyIndex]['routable'] = !$proxyIsInPrivateRange;  | 
                                                        |
| 321 | -  | 
                                                        |
| 322 | - $requestProxyData[$proxyIndex]['location'] = $proxyLocation;  | 
                                                        |
| 323 | -  | 
                                                        |
| 324 | -                if ($proxyReverseDns === $proxyAddress && $proxyIsInPrivateRange === false) { | 
                                                        |
| 325 | - $requestProxyData[$proxyIndex]['rdns'] = null;  | 
                                                        |
| 326 | - }  | 
                                                        |
| 327 | -  | 
                                                        |
| 328 | - $showLinks = (!$trust || $proxyAddress == $origin) && !$proxyIsInPrivateRange;  | 
                                                        |
| 329 | - $requestProxyData[$proxyIndex]['showlinks'] = $showLinks;  | 
                                                        |
| 330 | -  | 
                                                        |
| 331 | - $proxyIndex++;  | 
                                                        |
| 332 | - }  | 
                                                        |
| 333 | -  | 
                                                        |
| 334 | -            $this->assign("requestProxyData", $requestProxyData); | 
                                                        |
| 335 | - }  | 
                                                        |
| 336 | - }  | 
                                                        |
| 337 | -  | 
                                                        |
| 338 | - /**  | 
                                                        |
| 339 | - * Sets up the security for this page. If certain actions have different permissions, this should be reflected in  | 
                                                        |
| 340 | - * the return value from this function.  | 
                                                        |
| 341 | - *  | 
                                                        |
| 342 | - * If this page even supports actions, you will need to check the route  | 
                                                        |
| 343 | - *  | 
                                                        |
| 344 | - * @return SecurityConfiguration  | 
                                                        |
| 345 | - * @category Security-Critical  | 
                                                        |
| 346 | - */  | 
                                                        |
| 347 | - protected function getSecurityConfiguration()  | 
                                                        |
| 348 | -    { | 
                                                        |
| 349 | -        switch ($this->getRouteName()) { | 
                                                        |
| 350 | - case PageViewRequest::PRIVATE_DATA_BARRIER:  | 
                                                        |
| 351 | - return $this->getSecurityManager()->configure()->asGeneralPrivateDataAccess();  | 
                                                        |
| 352 | - case PageViewRequest::SET_BAN_BARRIER:  | 
                                                        |
| 353 | - return $this->getSecurityManager()->configure()->asAdminPage();  | 
                                                        |
| 354 | - default:  | 
                                                        |
| 355 | - return $this->getSecurityManager()->configure()->asInternalPage();  | 
                                                        |
| 356 | - }  | 
                                                        |
| 357 | - }  | 
                                                        |
| 27 | + /**  | 
                                                        |
| 28 | + * @var array Array of IP address classed as 'private' by RFC1918.  | 
                                                        |
| 29 | + */  | 
                                                        |
| 30 | + protected static $rfc1918ips = array(  | 
                                                        |
| 31 | + "10.0.0.0" => "10.255.255.255",  | 
                                                        |
| 32 | + "172.16.0.0" => "172.31.255.255",  | 
                                                        |
| 33 | + "192.168.0.0" => "192.168.255.255",  | 
                                                        |
| 34 | + "169.254.0.0" => "169.254.255.255",  | 
                                                        |
| 35 | + "127.0.0.0" => "127.255.255.255",  | 
                                                        |
| 36 | + );  | 
                                                        |
| 37 | +  | 
                                                        |
| 38 | + /**  | 
                                                        |
| 39 | + * Gets a request object  | 
                                                        |
| 40 | + *  | 
                                                        |
| 41 | + * @param PdoDatabase $database The database connection  | 
                                                        |
| 42 | + * @param int $requestId The ID of the request to retrieve  | 
                                                        |
| 43 | + *  | 
                                                        |
| 44 | + * @return Request  | 
                                                        |
| 45 | + * @throws ApplicationLogicException  | 
                                                        |
| 46 | + */  | 
                                                        |
| 47 | + protected function getRequest(PdoDatabase $database, $requestId)  | 
                                                        |
| 48 | +	{ | 
                                                        |
| 49 | +		if ($requestId === null) { | 
                                                        |
| 50 | +			throw new ApplicationLogicException("No request specified"); | 
                                                        |
| 51 | + }  | 
                                                        |
| 52 | +  | 
                                                        |
| 53 | + $request = Request::getById($requestId, $database);  | 
                                                        |
| 54 | +		if ($request === false || !is_a($request, Request::class)) { | 
                                                        |
| 55 | +			throw new ApplicationLogicException('Could not load the requested request!'); | 
                                                        |
| 56 | + }  | 
                                                        |
| 57 | +  | 
                                                        |
| 58 | + return $request;  | 
                                                        |
| 59 | + }  | 
                                                        |
| 60 | +  | 
                                                        |
| 61 | + /**  | 
                                                        |
| 62 | + * Returns a value stating whether the user is allowed to see private data or not  | 
                                                        |
| 63 | + *  | 
                                                        |
| 64 | + * @param Request $request  | 
                                                        |
| 65 | + * @param User $currentUser  | 
                                                        |
| 66 | + *  | 
                                                        |
| 67 | + * @return bool  | 
                                                        |
| 68 | + * @category Security-Critical  | 
                                                        |
| 69 | + */  | 
                                                        |
| 70 | + protected function isAllowedPrivateData(Request $request, User $currentUser)  | 
                                                        |
| 71 | +	{ | 
                                                        |
| 72 | + // Test the main security barrier for private data access using SecurityManager  | 
                                                        |
| 73 | +		if ($this->barrierTest('privateData')) { | 
                                                        |
| 74 | + // Tool admins/check-users can always see private data  | 
                                                        |
| 75 | + return true;  | 
                                                        |
| 76 | + }  | 
                                                        |
| 77 | +  | 
                                                        |
| 78 | + // reserving user is allowed to see the data  | 
                                                        |
| 79 | +		if ($currentUser->getId() === $request->getReserved() && $request->getReserved() !== null) { | 
                                                        |
| 80 | + return true;  | 
                                                        |
| 81 | + }  | 
                                                        |
| 82 | +  | 
                                                        |
| 83 | + // user has the reveal hash  | 
                                                        |
| 84 | +		if (WebRequest::getString('hash') === $request->getRevealHash()) { | 
                                                        |
| 85 | + return true;  | 
                                                        |
| 86 | + }  | 
                                                        |
| 87 | +  | 
                                                        |
| 88 | + // nope. Not allowed.  | 
                                                        |
| 89 | + return false;  | 
                                                        |
| 90 | + }  | 
                                                        |
| 91 | +  | 
                                                        |
| 92 | + /**  | 
                                                        |
| 93 | + * Tests the security barrier for a specified action.  | 
                                                        |
| 94 | + *  | 
                                                        |
| 95 | + * Intended to be used from within templates  | 
                                                        |
| 96 | + *  | 
                                                        |
| 97 | + * @param string $action  | 
                                                        |
| 98 | + *  | 
                                                        |
| 99 | + * @return boolean  | 
                                                        |
| 100 | + * @category Security-Critical  | 
                                                        |
| 101 | + */  | 
                                                        |
| 102 | + abstract protected function barrierTest($action);  | 
                                                        |
| 103 | +  | 
                                                        |
| 104 | + /**  | 
                                                        |
| 105 | + * Gets the name of the route that has been passed from the request router.  | 
                                                        |
| 106 | + * @return string  | 
                                                        |
| 107 | + */  | 
                                                        |
| 108 | + abstract protected function getRouteName();  | 
                                                        |
| 109 | +  | 
                                                        |
| 110 | + /** @return SecurityManager */  | 
                                                        |
| 111 | + abstract protected function getSecurityManager();  | 
                                                        |
| 112 | +  | 
                                                        |
| 113 | + /**  | 
                                                        |
| 114 | + * Sets the name of the template this page should display.  | 
                                                        |
| 115 | + *  | 
                                                        |
| 116 | + * @param string $name  | 
                                                        |
| 117 | + */  | 
                                                        |
| 118 | + abstract protected function setTemplate($name);  | 
                                                        |
| 119 | +  | 
                                                        |
| 120 | + /** @return IXffTrustProvider */  | 
                                                        |
| 121 | + abstract protected function getXffTrustProvider();  | 
                                                        |
| 122 | +  | 
                                                        |
| 123 | + /** @return ILocationProvider */  | 
                                                        |
| 124 | + abstract protected function getLocationProvider();  | 
                                                        |
| 125 | +  | 
                                                        |
| 126 | + /** @return IRDnsProvider */  | 
                                                        |
| 127 | + abstract protected function getRdnsProvider();  | 
                                                        |
| 128 | +  | 
                                                        |
| 129 | + /**  | 
                                                        |
| 130 | + * Assigns a Smarty variable  | 
                                                        |
| 131 | + *  | 
                                                        |
| 132 | + * @param array|string $name the template variable name(s)  | 
                                                        |
| 133 | + * @param mixed $value the value to assign  | 
                                                        |
| 134 | + */  | 
                                                        |
| 135 | + abstract protected function assign($name, $value);  | 
                                                        |
| 136 | +  | 
                                                        |
| 137 | + /**  | 
                                                        |
| 138 | + * @param int $requestReservationId  | 
                                                        |
| 139 | + * @param PdoDatabase $database  | 
                                                        |
| 140 | + * @param User $currentUser  | 
                                                        |
| 141 | + */  | 
                                                        |
| 142 | + protected function setupReservationDetails($requestReservationId, PdoDatabase $database, User $currentUser)  | 
                                                        |
| 143 | +	{ | 
                                                        |
| 144 | + $requestIsReserved = $requestReservationId !== null;  | 
                                                        |
| 145 | +		$this->assign('requestIsReserved', $requestIsReserved); | 
                                                        |
| 146 | +		$this->assign('requestIsReservedByMe', false); | 
                                                        |
| 147 | +  | 
                                                        |
| 148 | +		if ($requestIsReserved) { | 
                                                        |
| 149 | +			$this->assign('requestReservedByName', User::getById($requestReservationId, $database)->getUsername()); | 
                                                        |
| 150 | +			$this->assign('requestReservedById', $requestReservationId); | 
                                                        |
| 151 | +  | 
                                                        |
| 152 | +			if ($requestReservationId === $currentUser->getId()) { | 
                                                        |
| 153 | +				$this->assign('requestIsReservedByMe', true); | 
                                                        |
| 154 | + }  | 
                                                        |
| 155 | + }  | 
                                                        |
| 156 | + }  | 
                                                        |
| 157 | +  | 
                                                        |
| 158 | + /**  | 
                                                        |
| 159 | + * Adds private request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED!  | 
                                                        |
| 160 | + *  | 
                                                        |
| 161 | + * @param Request $request  | 
                                                        |
| 162 | + * @param User $currentUser  | 
                                                        |
| 163 | + * @param SiteConfiguration $configuration  | 
                                                        |
| 164 | + *  | 
                                                        |
| 165 | + * @param PdoDatabase $database  | 
                                                        |
| 166 | + */  | 
                                                        |
| 167 | + protected function setupPrivateData(  | 
                                                        |
| 168 | + $request,  | 
                                                        |
| 169 | + User $currentUser,  | 
                                                        |
| 170 | + SiteConfiguration $configuration,  | 
                                                        |
| 171 | + PdoDatabase $database  | 
                                                        |
| 172 | +	) { | 
                                                        |
| 173 | + $xffProvider = $this->getXffTrustProvider();  | 
                                                        |
| 174 | +  | 
                                                        |
| 175 | + $relatedEmailRequests = RequestSearchHelper::get($database)  | 
                                                        |
| 176 | + ->byEmailAddress($request->getEmail())  | 
                                                        |
| 177 | + ->withConfirmedEmail()  | 
                                                        |
| 178 | + ->excludingPurgedData($configuration)  | 
                                                        |
| 179 | + ->excludingRequest($request->getId())  | 
                                                        |
| 180 | + ->fetch();  | 
                                                        |
| 181 | +  | 
                                                        |
| 182 | +		$this->assign('requestEmail', $request->getEmail()); | 
                                                        |
| 183 | +		$emailDomain = explode("@", $request->getEmail())[1]; | 
                                                        |
| 184 | +		$this->assign("emailurl", $emailDomain); | 
                                                        |
| 185 | +		$this->assign('requestRelatedEmailRequestsCount', count($relatedEmailRequests)); | 
                                                        |
| 186 | +		$this->assign('requestRelatedEmailRequests', $relatedEmailRequests); | 
                                                        |
| 187 | +  | 
                                                        |
| 188 | + $trustedIp = $xffProvider->getTrustedClientIp($request->getIp(), $request->getForwardedIp());  | 
                                                        |
| 189 | +		$this->assign('requestTrustedIp', $trustedIp); | 
                                                        |
| 190 | +		$this->assign('requestRealIp', $request->getIp()); | 
                                                        |
| 191 | +		$this->assign('requestForwardedIp', $request->getForwardedIp()); | 
                                                        |
| 192 | +  | 
                                                        |
| 193 | + $trustedIpLocation = $this->getLocationProvider()->getIpLocation($trustedIp);  | 
                                                        |
| 194 | +		$this->assign('requestTrustedIpLocation', $trustedIpLocation); | 
                                                        |
| 195 | +  | 
                                                        |
| 196 | +		$this->assign('requestHasForwardedIp', $request->getForwardedIp() !== null); | 
                                                        |
| 197 | +  | 
                                                        |
| 198 | + $relatedIpRequests = RequestSearchHelper::get($database)  | 
                                                        |
| 199 | + ->byIp($trustedIp)  | 
                                                        |
| 200 | + ->withConfirmedEmail()  | 
                                                        |
| 201 | + ->excludingPurgedData($configuration)  | 
                                                        |
| 202 | + ->excludingRequest($request->getId())  | 
                                                        |
| 203 | + ->fetch();  | 
                                                        |
| 204 | +  | 
                                                        |
| 205 | +		$this->assign('requestRelatedIpRequestsCount', count($relatedIpRequests)); | 
                                                        |
| 206 | +		$this->assign('requestRelatedIpRequests', $relatedIpRequests); | 
                                                        |
| 207 | +  | 
                                                        |
| 208 | +		$this->assign('showRevealLink', false); | 
                                                        |
| 209 | + if ($request->getReserved() === $currentUser->getId() ||  | 
                                                        |
| 210 | + $currentUser->isAdmin() ||  | 
                                                        |
| 211 | + $currentUser->isCheckuser()  | 
                                                        |
| 212 | +		) { | 
                                                        |
| 213 | +			$this->assign('showRevealLink', true); | 
                                                        |
| 214 | +  | 
                                                        |
| 215 | +			$this->assign('revealHash', $request->getRevealHash()); | 
                                                        |
| 216 | + }  | 
                                                        |
| 217 | +  | 
                                                        |
| 218 | + $this->setupForwardedIpData($request);  | 
                                                        |
| 219 | + }  | 
                                                        |
| 220 | +  | 
                                                        |
| 221 | + /**  | 
                                                        |
| 222 | + * Adds checkuser request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED!  | 
                                                        |
| 223 | + *  | 
                                                        |
| 224 | + * @param Request $request  | 
                                                        |
| 225 | + */  | 
                                                        |
| 226 | + protected function setupCheckUserData(Request $request)  | 
                                                        |
| 227 | +	{ | 
                                                        |
| 228 | +		$this->assign('requestUserAgent', $request->getUserAgent()); | 
                                                        |
| 229 | + }  | 
                                                        |
| 230 | +  | 
                                                        |
| 231 | + /**  | 
                                                        |
| 232 | + * Sets up the basic data for this request, and adds it to Smarty  | 
                                                        |
| 233 | + *  | 
                                                        |
| 234 | + * @param Request $request  | 
                                                        |
| 235 | + * @param SiteConfiguration $config  | 
                                                        |
| 236 | + */  | 
                                                        |
| 237 | + protected function setupBasicData(Request $request, SiteConfiguration $config)  | 
                                                        |
| 238 | +	{ | 
                                                        |
| 239 | +		$this->assign('requestId', $request->getId()); | 
                                                        |
| 240 | +		$this->assign('updateVersion', $request->getUpdateVersion()); | 
                                                        |
| 241 | +		$this->assign('requestName', $request->getName()); | 
                                                        |
| 242 | +		$this->assign('requestDate', $request->getDate()); | 
                                                        |
| 243 | +		$this->assign('requestStatus', $request->getStatus()); | 
                                                        |
| 244 | +  | 
                                                        |
| 245 | +		$this->assign('requestIsClosed', !array_key_exists($request->getStatus(), $config->getRequestStates())); | 
                                                        |
| 246 | + }  | 
                                                        |
| 247 | +  | 
                                                        |
| 248 | + /**  | 
                                                        |
| 249 | + * Sets up the forwarded IP data for this request and adds it to Smarty  | 
                                                        |
| 250 | + *  | 
                                                        |
| 251 | + * @param Request $request  | 
                                                        |
| 252 | + */  | 
                                                        |
| 253 | + protected function setupForwardedIpData(Request $request)  | 
                                                        |
| 254 | +	{ | 
                                                        |
| 255 | +		if ($request->getForwardedIp() !== null) { | 
                                                        |
| 256 | + $requestProxyData = array(); // Initialize array to store data to be output in Smarty template.  | 
                                                        |
| 257 | + $proxyIndex = 0;  | 
                                                        |
| 258 | +  | 
                                                        |
| 259 | + // Assuming [client] <=> [proxy1] <=> [proxy2] <=> [proxy3] <=> [us], we will see an XFF header of [client],  | 
                                                        |
| 260 | + // [proxy1], [proxy2], and our actual IP will be [proxy3]  | 
                                                        |
| 261 | +			$proxies = explode(",", $request->getForwardedIp()); | 
                                                        |
| 262 | + $proxies[] = $request->getIp();  | 
                                                        |
| 263 | +  | 
                                                        |
| 264 | + // Origin is the supposed "client" IP.  | 
                                                        |
| 265 | + $origin = $proxies[0];  | 
                                                        |
| 266 | +			$this->assign("forwardedOrigin", $origin); | 
                                                        |
| 267 | +  | 
                                                        |
| 268 | + // We step through the servers in reverse order, from closest to furthest  | 
                                                        |
| 269 | + $proxies = array_reverse($proxies);  | 
                                                        |
| 270 | +  | 
                                                        |
| 271 | + // By default, we have trust, because the first in the chain is now REMOTE_ADDR, which is hardest to spoof.  | 
                                                        |
| 272 | + $trust = true;  | 
                                                        |
| 273 | +  | 
                                                        |
| 274 | + /**  | 
                                                        |
| 275 | + * @var int $index The zero-based index of the proxy.  | 
                                                        |
| 276 | + * @var string $proxyData The proxy IP address (although possibly not!)  | 
                                                        |
| 277 | + */  | 
                                                        |
| 278 | +			foreach ($proxies as $index => $proxyData) { | 
                                                        |
| 279 | + $proxyAddress = trim($proxyData);  | 
                                                        |
| 280 | + $requestProxyData[$proxyIndex]['ip'] = $proxyAddress;  | 
                                                        |
| 281 | +  | 
                                                        |
| 282 | + // get data on this IP.  | 
                                                        |
| 283 | + $thisProxyIsTrusted = $this->getXffTrustProvider()->isTrusted($proxyAddress);  | 
                                                        |
| 284 | +  | 
                                                        |
| 285 | + $proxyIsInPrivateRange = $this->getXffTrustProvider()  | 
                                                        |
| 286 | + ->ipInRange(self::$rfc1918ips, $proxyAddress);  | 
                                                        |
| 287 | +  | 
                                                        |
| 288 | +				if (!$proxyIsInPrivateRange) { | 
                                                        |
| 289 | + $proxyReverseDns = $this->getRdnsProvider()->getReverseDNS($proxyAddress);  | 
                                                        |
| 290 | + $proxyLocation = $this->getLocationProvider()->getIpLocation($proxyAddress);  | 
                                                        |
| 291 | + }  | 
                                                        |
| 292 | +				else { | 
                                                        |
| 293 | + // this is going to fail, so why bother trying?  | 
                                                        |
| 294 | + $proxyReverseDns = false;  | 
                                                        |
| 295 | + $proxyLocation = false;  | 
                                                        |
| 296 | + }  | 
                                                        |
| 297 | +  | 
                                                        |
| 298 | + // current trust chain status BEFORE this link  | 
                                                        |
| 299 | + $preLinkTrust = $trust;  | 
                                                        |
| 300 | +  | 
                                                        |
| 301 | + // is *this* link trusted? Note, this will be true even if there is an untrusted link before this!  | 
                                                        |
| 302 | + $requestProxyData[$proxyIndex]['trustedlink'] = $thisProxyIsTrusted;  | 
                                                        |
| 303 | +  | 
                                                        |
| 304 | + // set the trust status of the chain to this point  | 
                                                        |
| 305 | + $trust = $trust & $thisProxyIsTrusted;  | 
                                                        |
| 306 | +  | 
                                                        |
| 307 | + // If this is the origin address, and the chain was trusted before this point, then we can trust  | 
                                                        |
| 308 | + // the origin.  | 
                                                        |
| 309 | +				if ($preLinkTrust && $proxyAddress == $origin) { | 
                                                        |
| 310 | + // if this is the origin, then we are at the last point in the chain.  | 
                                                        |
| 311 | + // @todo: this is probably the cause of some bugs when an IP appears twice - we're missing a check  | 
                                                        |
| 312 | + // to see if this is *really* the last in the chain, rather than just the same IP as it.  | 
                                                        |
| 313 | + $trust = true;  | 
                                                        |
| 314 | + }  | 
                                                        |
| 315 | +  | 
                                                        |
| 316 | + $requestProxyData[$proxyIndex]['trust'] = $trust;  | 
                                                        |
| 317 | +  | 
                                                        |
| 318 | + $requestProxyData[$proxyIndex]['rdnsfailed'] = $proxyReverseDns === false;  | 
                                                        |
| 319 | + $requestProxyData[$proxyIndex]['rdns'] = $proxyReverseDns;  | 
                                                        |
| 320 | + $requestProxyData[$proxyIndex]['routable'] = !$proxyIsInPrivateRange;  | 
                                                        |
| 321 | +  | 
                                                        |
| 322 | + $requestProxyData[$proxyIndex]['location'] = $proxyLocation;  | 
                                                        |
| 323 | +  | 
                                                        |
| 324 | +				if ($proxyReverseDns === $proxyAddress && $proxyIsInPrivateRange === false) { | 
                                                        |
| 325 | + $requestProxyData[$proxyIndex]['rdns'] = null;  | 
                                                        |
| 326 | + }  | 
                                                        |
| 327 | +  | 
                                                        |
| 328 | + $showLinks = (!$trust || $proxyAddress == $origin) && !$proxyIsInPrivateRange;  | 
                                                        |
| 329 | + $requestProxyData[$proxyIndex]['showlinks'] = $showLinks;  | 
                                                        |
| 330 | +  | 
                                                        |
| 331 | + $proxyIndex++;  | 
                                                        |
| 332 | + }  | 
                                                        |
| 333 | +  | 
                                                        |
| 334 | +			$this->assign("requestProxyData", $requestProxyData); | 
                                                        |
| 335 | + }  | 
                                                        |
| 336 | + }  | 
                                                        |
| 337 | +  | 
                                                        |
| 338 | + /**  | 
                                                        |
| 339 | + * Sets up the security for this page. If certain actions have different permissions, this should be reflected in  | 
                                                        |
| 340 | + * the return value from this function.  | 
                                                        |
| 341 | + *  | 
                                                        |
| 342 | + * If this page even supports actions, you will need to check the route  | 
                                                        |
| 343 | + *  | 
                                                        |
| 344 | + * @return SecurityConfiguration  | 
                                                        |
| 345 | + * @category Security-Critical  | 
                                                        |
| 346 | + */  | 
                                                        |
| 347 | + protected function getSecurityConfiguration()  | 
                                                        |
| 348 | +	{ | 
                                                        |
| 349 | +		switch ($this->getRouteName()) { | 
                                                        |
| 350 | + case PageViewRequest::PRIVATE_DATA_BARRIER:  | 
                                                        |
| 351 | + return $this->getSecurityManager()->configure()->asGeneralPrivateDataAccess();  | 
                                                        |
| 352 | + case PageViewRequest::SET_BAN_BARRIER:  | 
                                                        |
| 353 | + return $this->getSecurityManager()->configure()->asAdminPage();  | 
                                                        |
| 354 | + default:  | 
                                                        |
| 355 | + return $this->getSecurityManager()->configure()->asInternalPage();  | 
                                                        |
| 356 | + }  | 
                                                        |
| 357 | + }  | 
                                                        |
| 358 | 358 | }  | 
                                                        
| 359 | 359 | \ No newline at end of file  | 
                                                        
@@ -47,7 +47,7 @@  | 
                                                    ||
| 47 | 47 | /**  | 
                                                        
| 48 | 48 | * Gets the default route if no explicit route is requested.  | 
                                                        
| 49 | 49 | *  | 
                                                        
| 50 | - * @return callable  | 
                                                        |
| 50 | + * @return string[]  | 
                                                        |
| 51 | 51 | */  | 
                                                        
| 52 | 52 | protected function getDefaultRoute()  | 
                                                        
| 53 | 53 |      { | 
                                                        
@@ -15,42 +15,42 @@  | 
                                                    ||
| 15 | 15 | |
| 16 | 16 | class PublicRequestRouter extends RequestRouter  | 
                                                        
| 17 | 17 |  { | 
                                                        
| 18 | - /**  | 
                                                        |
| 19 | - * Gets the route map to be used by this request router.  | 
                                                        |
| 20 | - *  | 
                                                        |
| 21 | - * @return array  | 
                                                        |
| 22 | - */  | 
                                                        |
| 23 | - protected function getRouteMap()  | 
                                                        |
| 24 | -    { | 
                                                        |
| 25 | - return array(  | 
                                                        |
| 26 | - // Page showing a message stating the request has been submitted to our internal queues  | 
                                                        |
| 27 | - 'requestSubmitted' =>  | 
                                                        |
| 28 | - array(  | 
                                                        |
| 29 | - 'class' => PageRequestSubmitted::class,  | 
                                                        |
| 30 | - 'actions' => array(),  | 
                                                        |
| 31 | - ),  | 
                                                        |
| 32 | - // Page showing a message stating that email confirmation is required to continue  | 
                                                        |
| 33 | - 'emailConfirmationRequired' =>  | 
                                                        |
| 34 | - array(  | 
                                                        |
| 35 | - 'class' => PageEmailConfirmationRequired::class,  | 
                                                        |
| 36 | - 'actions' => array(),  | 
                                                        |
| 37 | - ),  | 
                                                        |
| 38 | - // Action page which handles email confirmation  | 
                                                        |
| 39 | - 'confirmEmail' =>  | 
                                                        |
| 40 | - array(  | 
                                                        |
| 41 | - 'class' => PageConfirmEmail::class,  | 
                                                        |
| 42 | - 'actions' => array(),  | 
                                                        |
| 43 | - ),  | 
                                                        |
| 44 | - );  | 
                                                        |
| 45 | - }  | 
                                                        |
| 18 | + /**  | 
                                                        |
| 19 | + * Gets the route map to be used by this request router.  | 
                                                        |
| 20 | + *  | 
                                                        |
| 21 | + * @return array  | 
                                                        |
| 22 | + */  | 
                                                        |
| 23 | + protected function getRouteMap()  | 
                                                        |
| 24 | +	{ | 
                                                        |
| 25 | + return array(  | 
                                                        |
| 26 | + // Page showing a message stating the request has been submitted to our internal queues  | 
                                                        |
| 27 | + 'requestSubmitted' =>  | 
                                                        |
| 28 | + array(  | 
                                                        |
| 29 | + 'class' => PageRequestSubmitted::class,  | 
                                                        |
| 30 | + 'actions' => array(),  | 
                                                        |
| 31 | + ),  | 
                                                        |
| 32 | + // Page showing a message stating that email confirmation is required to continue  | 
                                                        |
| 33 | + 'emailConfirmationRequired' =>  | 
                                                        |
| 34 | + array(  | 
                                                        |
| 35 | + 'class' => PageEmailConfirmationRequired::class,  | 
                                                        |
| 36 | + 'actions' => array(),  | 
                                                        |
| 37 | + ),  | 
                                                        |
| 38 | + // Action page which handles email confirmation  | 
                                                        |
| 39 | + 'confirmEmail' =>  | 
                                                        |
| 40 | + array(  | 
                                                        |
| 41 | + 'class' => PageConfirmEmail::class,  | 
                                                        |
| 42 | + 'actions' => array(),  | 
                                                        |
| 43 | + ),  | 
                                                        |
| 44 | + );  | 
                                                        |
| 45 | + }  | 
                                                        |
| 46 | 46 | |
| 47 | - /**  | 
                                                        |
| 48 | - * Gets the default route if no explicit route is requested.  | 
                                                        |
| 49 | - *  | 
                                                        |
| 50 | - * @return callable  | 
                                                        |
| 51 | - */  | 
                                                        |
| 52 | - protected function getDefaultRoute()  | 
                                                        |
| 53 | -    { | 
                                                        |
| 54 | - return array(PageRequestAccount::class, 'main');  | 
                                                        |
| 55 | - }  | 
                                                        |
| 47 | + /**  | 
                                                        |
| 48 | + * Gets the default route if no explicit route is requested.  | 
                                                        |
| 49 | + *  | 
                                                        |
| 50 | + * @return callable  | 
                                                        |
| 51 | + */  | 
                                                        |
| 52 | + protected function getDefaultRoute()  | 
                                                        |
| 53 | +	{ | 
                                                        |
| 54 | + return array(PageRequestAccount::class, 'main');  | 
                                                        |
| 55 | + }  | 
                                                        |
| 56 | 56 | }  | 
                                                        
| 57 | 57 | \ No newline at end of file  | 
                                                        
@@ -435,7 +435,7 @@  | 
                                                    ||
| 435 | 435 | }  | 
                                                        
| 436 | 436 | |
| 437 | 437 | /**  | 
                                                        
| 438 | - * @return callable  | 
                                                        |
| 438 | + * @return string[]  | 
                                                        |
| 439 | 439 | */  | 
                                                        
| 440 | 440 | protected function getDefaultRoute()  | 
                                                        
| 441 | 441 |      { | 
                                                        
@@ -54,391 +54,391 @@  | 
                                                    ||
| 54 | 54 | */  | 
                                                        
| 55 | 55 | class RequestRouter implements IRequestRouter  | 
                                                        
| 56 | 56 |  { | 
                                                        
| 57 | - /**  | 
                                                        |
| 58 | - * This is the core routing table for the application. The basic idea is:  | 
                                                        |
| 59 | - *  | 
                                                        |
| 60 | - * array(  | 
                                                        |
| 61 | - * "foo" =>  | 
                                                        |
| 62 | - * array(  | 
                                                        |
| 63 | - * "class" => PageFoo::class,  | 
                                                        |
| 64 | -     *                  "actions" => array("bar", "other") | 
                                                        |
| 65 | - * ),  | 
                                                        |
| 66 | - * );  | 
                                                        |
| 67 | - *  | 
                                                        |
| 68 | - * Things to note:  | 
                                                        |
| 69 | - * - If no page is requested, we go to PageMain. PageMain can't have actions defined.  | 
                                                        |
| 70 | - *  | 
                                                        |
| 71 | - * - If a page is defined and requested, but no action is requested, go to that page's main() method  | 
                                                        |
| 72 | - * - If a page is defined and requested, and an action is defined and requested, go to that action's method.  | 
                                                        |
| 73 | - * - If a page is defined and requested, and an action NOT defined and requested, go to Page404 and it's main()  | 
                                                        |
| 74 | - * method.  | 
                                                        |
| 75 | - * - If a page is NOT defined and requested, go to Page404 and it's main() method.  | 
                                                        |
| 76 | - *  | 
                                                        |
| 77 | - * - Query parameters are ignored.  | 
                                                        |
| 78 | - *  | 
                                                        |
| 79 | - * The key point here is request routing with validation that this is allowed, before we start hitting the  | 
                                                        |
| 80 | - * filesystem through the AutoLoader, and opening random files. Also, so that we validate the action requested  | 
                                                        |
| 81 | - * before we start calling random methods through the web UI.  | 
                                                        |
| 82 | - *  | 
                                                        |
| 83 | - * Examples:  | 
                                                        |
| 84 | - * /internal.php => returns instance of PageMain, routed to main()  | 
                                                        |
| 85 | - * /internal.php?query => returns instance of PageMain, routed to main()  | 
                                                        |
| 86 | - * /internal.php/foo => returns instance of PageFoo, routed to main()  | 
                                                        |
| 87 | - * /internal.php/foo?query => returns instance of PageFoo, routed to main()  | 
                                                        |
| 88 | - * /internal.php/foo/bar => returns instance of PageFoo, routed to bar()  | 
                                                        |
| 89 | - * /internal.php/foo/bar?query => returns instance of PageFoo, routed to bar()  | 
                                                        |
| 90 | - * /internal.php/foo/baz => returns instance of Page404, routed to main()  | 
                                                        |
| 91 | - * /internal.php/foo/baz?query => returns instance of Page404, routed to main()  | 
                                                        |
| 92 | - * /internal.php/bar => returns instance of Page404, routed to main()  | 
                                                        |
| 93 | - * /internal.php/bar?query => returns instance of Page404, routed to main()  | 
                                                        |
| 94 | - * /internal.php/bar/baz => returns instance of Page404, routed to main()  | 
                                                        |
| 95 | - * /internal.php/bar/baz?query => returns instance of Page404, routed to main()  | 
                                                        |
| 96 | - *  | 
                                                        |
| 97 | - * Take care when changing this - a lot of places rely on the array key for redirects and other links. If you need  | 
                                                        |
| 98 | - * to change the key, then you'll likely have to update a lot of files.  | 
                                                        |
| 99 | - *  | 
                                                        |
| 100 | - * @var array  | 
                                                        |
| 101 | - */  | 
                                                        |
| 102 | - private $routeMap = array(  | 
                                                        |
| 103 | -  | 
                                                        |
| 104 | - //////////////////////////////////////////////////////////////////////////////////////////////////  | 
                                                        |
| 105 | - // Login and registration  | 
                                                        |
| 106 | - 'logout' =>  | 
                                                        |
| 107 | - array(  | 
                                                        |
| 108 | - 'class' => PageLogout::class,  | 
                                                        |
| 109 | - 'actions' => array(),  | 
                                                        |
| 110 | - ),  | 
                                                        |
| 111 | - 'login' =>  | 
                                                        |
| 112 | - array(  | 
                                                        |
| 113 | - 'class' => PageLogin::class,  | 
                                                        |
| 114 | - 'actions' => array(),  | 
                                                        |
| 115 | - ),  | 
                                                        |
| 116 | - 'forgotPassword' =>  | 
                                                        |
| 117 | - array(  | 
                                                        |
| 118 | - 'class' => PageForgotPassword::class,  | 
                                                        |
| 119 | -                'actions' => array('reset'), | 
                                                        |
| 120 | - ),  | 
                                                        |
| 121 | - 'register' =>  | 
                                                        |
| 122 | - array(  | 
                                                        |
| 123 | - 'class' => PageRegister::class,  | 
                                                        |
| 124 | -                'actions' => array('done'), | 
                                                        |
| 125 | - ),  | 
                                                        |
| 126 | -  | 
                                                        |
| 127 | - //////////////////////////////////////////////////////////////////////////////////////////////////  | 
                                                        |
| 128 | - // Discovery  | 
                                                        |
| 129 | - 'search' =>  | 
                                                        |
| 130 | - array(  | 
                                                        |
| 131 | - 'class' => PageSearch::class,  | 
                                                        |
| 132 | - 'actions' => array(),  | 
                                                        |
| 133 | - ),  | 
                                                        |
| 134 | - 'logs' =>  | 
                                                        |
| 135 | - array(  | 
                                                        |
| 136 | - 'class' => PageLog::class,  | 
                                                        |
| 137 | - 'actions' => array(),  | 
                                                        |
| 138 | - ),  | 
                                                        |
| 139 | -  | 
                                                        |
| 140 | - //////////////////////////////////////////////////////////////////////////////////////////////////  | 
                                                        |
| 141 | - // Administration  | 
                                                        |
| 142 | - 'bans' =>  | 
                                                        |
| 143 | - array(  | 
                                                        |
| 144 | - 'class' => PageBan::class,  | 
                                                        |
| 145 | -                'actions' => array('set', 'remove'), | 
                                                        |
| 146 | - ),  | 
                                                        |
| 147 | - 'userManagement' =>  | 
                                                        |
| 148 | - array(  | 
                                                        |
| 149 | - 'class' => PageUserManagement::class,  | 
                                                        |
| 150 | - 'actions' => array(  | 
                                                        |
| 151 | - 'approve',  | 
                                                        |
| 152 | - 'decline',  | 
                                                        |
| 153 | - 'rename',  | 
                                                        |
| 154 | - 'editUser',  | 
                                                        |
| 155 | - 'suspend',  | 
                                                        |
| 156 | - 'promote',  | 
                                                        |
| 157 | - 'demote',  | 
                                                        |
| 158 | - ),  | 
                                                        |
| 159 | - ),  | 
                                                        |
| 160 | - 'siteNotice' =>  | 
                                                        |
| 161 | - array(  | 
                                                        |
| 162 | - 'class' => PageSiteNotice::class,  | 
                                                        |
| 163 | - 'actions' => array(),  | 
                                                        |
| 164 | - ),  | 
                                                        |
| 165 | - 'emailManagement' =>  | 
                                                        |
| 166 | - array(  | 
                                                        |
| 167 | - 'class' => PageEmailManagement::class,  | 
                                                        |
| 168 | -                'actions' => array('create', 'edit', 'view'), | 
                                                        |
| 169 | - ),  | 
                                                        |
| 170 | -  | 
                                                        |
| 171 | - //////////////////////////////////////////////////////////////////////////////////////////////////  | 
                                                        |
| 172 | - // Personal preferences  | 
                                                        |
| 173 | - 'preferences' =>  | 
                                                        |
| 174 | - array(  | 
                                                        |
| 175 | - 'class' => PagePreferences::class,  | 
                                                        |
| 176 | -                'actions' => array('changePassword'), | 
                                                        |
| 177 | - ),  | 
                                                        |
| 178 | - 'oauth' =>  | 
                                                        |
| 179 | - array(  | 
                                                        |
| 180 | - 'class' => PageOAuth::class,  | 
                                                        |
| 181 | -                'actions' => array('detach', 'attach'), | 
                                                        |
| 182 | - ),  | 
                                                        |
| 183 | -  | 
                                                        |
| 184 | - //////////////////////////////////////////////////////////////////////////////////////////////////  | 
                                                        |
| 185 | - // Welcomer configuration  | 
                                                        |
| 186 | - 'welcomeTemplates' =>  | 
                                                        |
| 187 | - array(  | 
                                                        |
| 188 | - 'class' => PageWelcomeTemplateManagement::class,  | 
                                                        |
| 189 | -                'actions' => array('select', 'edit', 'delete', 'add', 'view'), | 
                                                        |
| 190 | - ),  | 
                                                        |
| 191 | -  | 
                                                        |
| 192 | - //////////////////////////////////////////////////////////////////////////////////////////////////  | 
                                                        |
| 193 | - // Statistics  | 
                                                        |
| 194 | - 'statistics' =>  | 
                                                        |
| 195 | - array(  | 
                                                        |
| 196 | - 'class' => StatsMain::class,  | 
                                                        |
| 197 | - 'actions' => array(),  | 
                                                        |
| 198 | - ),  | 
                                                        |
| 199 | - 'statistics/fastCloses' =>  | 
                                                        |
| 200 | - array(  | 
                                                        |
| 201 | - 'class' => StatsFastCloses::class,  | 
                                                        |
| 202 | - 'actions' => array(),  | 
                                                        |
| 203 | - ),  | 
                                                        |
| 204 | - 'statistics/inactiveUsers' =>  | 
                                                        |
| 205 | - array(  | 
                                                        |
| 206 | - 'class' => StatsInactiveUsers::class,  | 
                                                        |
| 207 | - 'actions' => array(),  | 
                                                        |
| 208 | - ),  | 
                                                        |
| 209 | - 'statistics/monthlyStats' =>  | 
                                                        |
| 210 | - array(  | 
                                                        |
| 211 | - 'class' => StatsMonthlyStats::class,  | 
                                                        |
| 212 | - 'actions' => array(),  | 
                                                        |
| 213 | - ),  | 
                                                        |
| 214 | - 'statistics/reservedRequests' =>  | 
                                                        |
| 215 | - array(  | 
                                                        |
| 216 | - 'class' => StatsReservedRequests::class,  | 
                                                        |
| 217 | - 'actions' => array(),  | 
                                                        |
| 218 | - ),  | 
                                                        |
| 219 | - 'statistics/templateStats' =>  | 
                                                        |
| 220 | - array(  | 
                                                        |
| 221 | - 'class' => StatsTemplateStats::class,  | 
                                                        |
| 222 | - 'actions' => array(),  | 
                                                        |
| 223 | - ),  | 
                                                        |
| 224 | - 'statistics/topCreators' =>  | 
                                                        |
| 225 | - array(  | 
                                                        |
| 226 | - 'class' => StatsTopCreators::class,  | 
                                                        |
| 227 | - 'actions' => array(),  | 
                                                        |
| 228 | - ),  | 
                                                        |
| 229 | - 'statistics/users' =>  | 
                                                        |
| 230 | - array(  | 
                                                        |
| 231 | - 'class' => StatsUsers::class,  | 
                                                        |
| 232 | -                'actions' => array('detail'), | 
                                                        |
| 233 | - ),  | 
                                                        |
| 234 | -  | 
                                                        |
| 235 | - //////////////////////////////////////////////////////////////////////////////////////////////////  | 
                                                        |
| 236 | - // Zoom page  | 
                                                        |
| 237 | - 'viewRequest' =>  | 
                                                        |
| 238 | - array(  | 
                                                        |
| 239 | - 'class' => PageViewRequest::class,  | 
                                                        |
| 240 | - 'actions' => array(),  | 
                                                        |
| 241 | - ),  | 
                                                        |
| 242 | - 'viewRequest/reserve' =>  | 
                                                        |
| 243 | - array(  | 
                                                        |
| 244 | - 'class' => PageReservation::class,  | 
                                                        |
| 245 | - 'actions' => array(),  | 
                                                        |
| 246 | - ),  | 
                                                        |
| 247 | - 'viewRequest/breakReserve' =>  | 
                                                        |
| 248 | - array(  | 
                                                        |
| 249 | - 'class' => PageBreakReservation::class,  | 
                                                        |
| 250 | - 'actions' => array(),  | 
                                                        |
| 251 | - ),  | 
                                                        |
| 252 | - 'viewRequest/defer' =>  | 
                                                        |
| 253 | - array(  | 
                                                        |
| 254 | - 'class' => PageDeferRequest::class,  | 
                                                        |
| 255 | - 'actions' => array(),  | 
                                                        |
| 256 | - ),  | 
                                                        |
| 257 | - 'viewRequest/comment' =>  | 
                                                        |
| 258 | - array(  | 
                                                        |
| 259 | - 'class' => PageComment::class,  | 
                                                        |
| 260 | - 'actions' => array(),  | 
                                                        |
| 261 | - ),  | 
                                                        |
| 262 | - 'viewRequest/sendToUser' =>  | 
                                                        |
| 263 | - array(  | 
                                                        |
| 264 | - 'class' => PageSendToUser::class,  | 
                                                        |
| 265 | - 'actions' => array(),  | 
                                                        |
| 266 | - ),  | 
                                                        |
| 267 | - 'viewRequest/close' =>  | 
                                                        |
| 268 | - array(  | 
                                                        |
| 269 | - 'class' => PageCloseRequest::class,  | 
                                                        |
| 270 | - 'actions' => array(),  | 
                                                        |
| 271 | - ),  | 
                                                        |
| 272 | - 'viewRequest/drop' =>  | 
                                                        |
| 273 | - array(  | 
                                                        |
| 274 | - 'class' => PageDropRequest::class,  | 
                                                        |
| 275 | - 'actions' => array(),  | 
                                                        |
| 276 | - ),  | 
                                                        |
| 277 | - 'viewRequest/custom' =>  | 
                                                        |
| 278 | - array(  | 
                                                        |
| 279 | - 'class' => PageCustomClose::class,  | 
                                                        |
| 280 | - 'actions' => array(),  | 
                                                        |
| 281 | - ),  | 
                                                        |
| 282 | - 'editComment' =>  | 
                                                        |
| 283 | - array(  | 
                                                        |
| 284 | - 'class' => PageEditComment::class,  | 
                                                        |
| 285 | - 'actions' => array(),  | 
                                                        |
| 286 | - ),  | 
                                                        |
| 287 | -  | 
                                                        |
| 288 | - //////////////////////////////////////////////////////////////////////////////////////////////////  | 
                                                        |
| 289 | - // Misc stuff  | 
                                                        |
| 290 | - 'team' =>  | 
                                                        |
| 291 | - array(  | 
                                                        |
| 292 | - 'class' => PageTeam::class,  | 
                                                        |
| 293 | - 'actions' => array(),  | 
                                                        |
| 294 | - ),  | 
                                                        |
| 295 | - 'requestList' =>  | 
                                                        |
| 296 | - array(  | 
                                                        |
| 297 | - 'class' => PageExpandedRequestList::class,  | 
                                                        |
| 298 | - 'actions' => array(),  | 
                                                        |
| 299 | - ),  | 
                                                        |
| 300 | - );  | 
                                                        |
| 301 | -  | 
                                                        |
| 302 | - /**  | 
                                                        |
| 303 | - * @return IRoutedTask  | 
                                                        |
| 304 | - * @throws Exception  | 
                                                        |
| 305 | - */  | 
                                                        |
| 306 | - final public function route()  | 
                                                        |
| 307 | -    { | 
                                                        |
| 308 | - $pathInfo = WebRequest::pathInfo();  | 
                                                        |
| 309 | -  | 
                                                        |
| 310 | - list($pageClass, $action) = $this->getRouteFromPath($pathInfo);  | 
                                                        |
| 311 | -  | 
                                                        |
| 312 | - /** @var IRoutedTask $page */  | 
                                                        |
| 313 | - $page = new $pageClass();  | 
                                                        |
| 314 | -  | 
                                                        |
| 315 | - // Dynamic creation, so we've got to be careful here. We can't use built-in language type protection, so  | 
                                                        |
| 316 | - // let's use our own.  | 
                                                        |
| 317 | -        if (!($page instanceof IRoutedTask)) { | 
                                                        |
| 318 | -            throw new Exception('Expected a page, but this is not a page.'); | 
                                                        |
| 319 | - }  | 
                                                        |
| 320 | -  | 
                                                        |
| 321 | - // OK, I'm happy at this point that we know we're running a page, and we know it's probably what we want if it  | 
                                                        |
| 322 | - // inherits PageBase and has been created from the routing map.  | 
                                                        |
| 323 | - $page->setRoute($action);  | 
                                                        |
| 324 | -  | 
                                                        |
| 325 | - return $page;  | 
                                                        |
| 326 | - }  | 
                                                        |
| 327 | -  | 
                                                        |
| 328 | - /**  | 
                                                        |
| 329 | - * @param $pathInfo  | 
                                                        |
| 330 | - *  | 
                                                        |
| 331 | - * @return array  | 
                                                        |
| 332 | - */  | 
                                                        |
| 333 | - protected function getRouteFromPath($pathInfo)  | 
                                                        |
| 334 | -    { | 
                                                        |
| 335 | -        if (count($pathInfo) === 0) { | 
                                                        |
| 336 | - // No pathInfo, so no page to load. Load the main page.  | 
                                                        |
| 337 | - return $this->getDefaultRoute();  | 
                                                        |
| 338 | - }  | 
                                                        |
| 339 | -        elseif (count($pathInfo) === 1) { | 
                                                        |
| 340 | - // Exactly one path info segment, it's got to be a page.  | 
                                                        |
| 341 | - $classSegment = $pathInfo[0];  | 
                                                        |
| 342 | -  | 
                                                        |
| 343 | - return $this->routeSinglePathSegment($classSegment);  | 
                                                        |
| 344 | - }  | 
                                                        |
| 345 | -  | 
                                                        |
| 346 | - // OK, we have two or more segments now.  | 
                                                        |
| 347 | -        if (count($pathInfo) > 2) { | 
                                                        |
| 348 | - // Let's handle more than two, and collapse it down into two.  | 
                                                        |
| 349 | - $requestedAction = array_pop($pathInfo);  | 
                                                        |
| 350 | -            $classSegment = implode('/', $pathInfo); | 
                                                        |
| 351 | - }  | 
                                                        |
| 352 | -        else { | 
                                                        |
| 353 | - // Two path info segments.  | 
                                                        |
| 354 | - $classSegment = $pathInfo[0];  | 
                                                        |
| 355 | - $requestedAction = $pathInfo[1];  | 
                                                        |
| 356 | - }  | 
                                                        |
| 357 | -  | 
                                                        |
| 358 | - $routeMap = $this->routePathSegments($classSegment, $requestedAction);  | 
                                                        |
| 359 | -  | 
                                                        |
| 360 | -        if ($routeMap[0] === Page404::class) { | 
                                                        |
| 361 | - $routeMap = $this->routeSinglePathSegment($classSegment . '/' . $requestedAction);  | 
                                                        |
| 362 | - }  | 
                                                        |
| 363 | -  | 
                                                        |
| 364 | - return $routeMap;  | 
                                                        |
| 365 | - }  | 
                                                        |
| 366 | -  | 
                                                        |
| 367 | - /**  | 
                                                        |
| 368 | - * @param $classSegment  | 
                                                        |
| 369 | - *  | 
                                                        |
| 370 | - * @return array  | 
                                                        |
| 371 | - */  | 
                                                        |
| 372 | - final protected function routeSinglePathSegment($classSegment)  | 
                                                        |
| 373 | -    { | 
                                                        |
| 374 | - $routeMap = $this->getRouteMap();  | 
                                                        |
| 375 | -        if (array_key_exists($classSegment, $routeMap)) { | 
                                                        |
| 376 | - // Route exists, but we don't have an action in path info, so default to main.  | 
                                                        |
| 377 | - $pageClass = $routeMap[$classSegment]['class'];  | 
                                                        |
| 378 | - $action = 'main';  | 
                                                        |
| 379 | -  | 
                                                        |
| 380 | - return array($pageClass, $action);  | 
                                                        |
| 381 | - }  | 
                                                        |
| 382 | -        else { | 
                                                        |
| 383 | - // Doesn't exist in map. Fall back to 404  | 
                                                        |
| 384 | - $pageClass = Page404::class;  | 
                                                        |
| 385 | - $action = "main";  | 
                                                        |
| 386 | -  | 
                                                        |
| 387 | - return array($pageClass, $action);  | 
                                                        |
| 388 | - }  | 
                                                        |
| 389 | - }  | 
                                                        |
| 390 | -  | 
                                                        |
| 391 | - /**  | 
                                                        |
| 392 | - * @param $classSegment  | 
                                                        |
| 393 | - * @param $requestedAction  | 
                                                        |
| 394 | - *  | 
                                                        |
| 395 | - * @return array  | 
                                                        |
| 396 | - */  | 
                                                        |
| 397 | - final protected function routePathSegments($classSegment, $requestedAction)  | 
                                                        |
| 398 | -    { | 
                                                        |
| 399 | - $routeMap = $this->getRouteMap();  | 
                                                        |
| 400 | -        if (array_key_exists($classSegment, $routeMap)) { | 
                                                        |
| 401 | - // Route exists, but we don't have an action in path info, so default to main.  | 
                                                        |
| 402 | -  | 
                                                        |
| 403 | - if (isset($routeMap[$classSegment]['actions'])  | 
                                                        |
| 404 | - && array_search($requestedAction, $routeMap[$classSegment]['actions']) !== false  | 
                                                        |
| 405 | -            ) { | 
                                                        |
| 406 | - // Action exists in allowed action list. Allow both the page and the action  | 
                                                        |
| 407 | - $pageClass = $routeMap[$classSegment]['class'];  | 
                                                        |
| 408 | - $action = $requestedAction;  | 
                                                        |
| 409 | -  | 
                                                        |
| 410 | - return array($pageClass, $action);  | 
                                                        |
| 411 | - }  | 
                                                        |
| 412 | -            else { | 
                                                        |
| 413 | - // Valid page, invalid action. 404 our way out.  | 
                                                        |
| 414 | - $pageClass = Page404::class;  | 
                                                        |
| 415 | - $action = 'main';  | 
                                                        |
| 416 | -  | 
                                                        |
| 417 | - return array($pageClass, $action);  | 
                                                        |
| 418 | - }  | 
                                                        |
| 419 | - }  | 
                                                        |
| 420 | -        else { | 
                                                        |
| 421 | - // Class doesn't exist in map. Fall back to 404  | 
                                                        |
| 422 | - $pageClass = Page404::class;  | 
                                                        |
| 423 | - $action = 'main';  | 
                                                        |
| 424 | -  | 
                                                        |
| 425 | - return array($pageClass, $action);  | 
                                                        |
| 426 | - }  | 
                                                        |
| 427 | - }  | 
                                                        |
| 428 | -  | 
                                                        |
| 429 | - /**  | 
                                                        |
| 430 | - * @return array  | 
                                                        |
| 431 | - */  | 
                                                        |
| 432 | - protected function getRouteMap()  | 
                                                        |
| 433 | -    { | 
                                                        |
| 434 | - return $this->routeMap;  | 
                                                        |
| 435 | - }  | 
                                                        |
| 436 | -  | 
                                                        |
| 437 | - /**  | 
                                                        |
| 438 | - * @return callable  | 
                                                        |
| 439 | - */  | 
                                                        |
| 440 | - protected function getDefaultRoute()  | 
                                                        |
| 441 | -    { | 
                                                        |
| 442 | - return array(PageMain::class, "main");  | 
                                                        |
| 443 | - }  | 
                                                        |
| 57 | + /**  | 
                                                        |
| 58 | + * This is the core routing table for the application. The basic idea is:  | 
                                                        |
| 59 | + *  | 
                                                        |
| 60 | + * array(  | 
                                                        |
| 61 | + * "foo" =>  | 
                                                        |
| 62 | + * array(  | 
                                                        |
| 63 | + * "class" => PageFoo::class,  | 
                                                        |
| 64 | +	 *                  "actions" => array("bar", "other") | 
                                                        |
| 65 | + * ),  | 
                                                        |
| 66 | + * );  | 
                                                        |
| 67 | + *  | 
                                                        |
| 68 | + * Things to note:  | 
                                                        |
| 69 | + * - If no page is requested, we go to PageMain. PageMain can't have actions defined.  | 
                                                        |
| 70 | + *  | 
                                                        |
| 71 | + * - If a page is defined and requested, but no action is requested, go to that page's main() method  | 
                                                        |
| 72 | + * - If a page is defined and requested, and an action is defined and requested, go to that action's method.  | 
                                                        |
| 73 | + * - If a page is defined and requested, and an action NOT defined and requested, go to Page404 and it's main()  | 
                                                        |
| 74 | + * method.  | 
                                                        |
| 75 | + * - If a page is NOT defined and requested, go to Page404 and it's main() method.  | 
                                                        |
| 76 | + *  | 
                                                        |
| 77 | + * - Query parameters are ignored.  | 
                                                        |
| 78 | + *  | 
                                                        |
| 79 | + * The key point here is request routing with validation that this is allowed, before we start hitting the  | 
                                                        |
| 80 | + * filesystem through the AutoLoader, and opening random files. Also, so that we validate the action requested  | 
                                                        |
| 81 | + * before we start calling random methods through the web UI.  | 
                                                        |
| 82 | + *  | 
                                                        |
| 83 | + * Examples:  | 
                                                        |
| 84 | + * /internal.php => returns instance of PageMain, routed to main()  | 
                                                        |
| 85 | + * /internal.php?query => returns instance of PageMain, routed to main()  | 
                                                        |
| 86 | + * /internal.php/foo => returns instance of PageFoo, routed to main()  | 
                                                        |
| 87 | + * /internal.php/foo?query => returns instance of PageFoo, routed to main()  | 
                                                        |
| 88 | + * /internal.php/foo/bar => returns instance of PageFoo, routed to bar()  | 
                                                        |
| 89 | + * /internal.php/foo/bar?query => returns instance of PageFoo, routed to bar()  | 
                                                        |
| 90 | + * /internal.php/foo/baz => returns instance of Page404, routed to main()  | 
                                                        |
| 91 | + * /internal.php/foo/baz?query => returns instance of Page404, routed to main()  | 
                                                        |
| 92 | + * /internal.php/bar => returns instance of Page404, routed to main()  | 
                                                        |
| 93 | + * /internal.php/bar?query => returns instance of Page404, routed to main()  | 
                                                        |
| 94 | + * /internal.php/bar/baz => returns instance of Page404, routed to main()  | 
                                                        |
| 95 | + * /internal.php/bar/baz?query => returns instance of Page404, routed to main()  | 
                                                        |
| 96 | + *  | 
                                                        |
| 97 | + * Take care when changing this - a lot of places rely on the array key for redirects and other links. If you need  | 
                                                        |
| 98 | + * to change the key, then you'll likely have to update a lot of files.  | 
                                                        |
| 99 | + *  | 
                                                        |
| 100 | + * @var array  | 
                                                        |
| 101 | + */  | 
                                                        |
| 102 | + private $routeMap = array(  | 
                                                        |
| 103 | +  | 
                                                        |
| 104 | + //////////////////////////////////////////////////////////////////////////////////////////////////  | 
                                                        |
| 105 | + // Login and registration  | 
                                                        |
| 106 | + 'logout' =>  | 
                                                        |
| 107 | + array(  | 
                                                        |
| 108 | + 'class' => PageLogout::class,  | 
                                                        |
| 109 | + 'actions' => array(),  | 
                                                        |
| 110 | + ),  | 
                                                        |
| 111 | + 'login' =>  | 
                                                        |
| 112 | + array(  | 
                                                        |
| 113 | + 'class' => PageLogin::class,  | 
                                                        |
| 114 | + 'actions' => array(),  | 
                                                        |
| 115 | + ),  | 
                                                        |
| 116 | + 'forgotPassword' =>  | 
                                                        |
| 117 | + array(  | 
                                                        |
| 118 | + 'class' => PageForgotPassword::class,  | 
                                                        |
| 119 | +				'actions' => array('reset'), | 
                                                        |
| 120 | + ),  | 
                                                        |
| 121 | + 'register' =>  | 
                                                        |
| 122 | + array(  | 
                                                        |
| 123 | + 'class' => PageRegister::class,  | 
                                                        |
| 124 | +				'actions' => array('done'), | 
                                                        |
| 125 | + ),  | 
                                                        |
| 126 | +  | 
                                                        |
| 127 | + //////////////////////////////////////////////////////////////////////////////////////////////////  | 
                                                        |
| 128 | + // Discovery  | 
                                                        |
| 129 | + 'search' =>  | 
                                                        |
| 130 | + array(  | 
                                                        |
| 131 | + 'class' => PageSearch::class,  | 
                                                        |
| 132 | + 'actions' => array(),  | 
                                                        |
| 133 | + ),  | 
                                                        |
| 134 | + 'logs' =>  | 
                                                        |
| 135 | + array(  | 
                                                        |
| 136 | + 'class' => PageLog::class,  | 
                                                        |
| 137 | + 'actions' => array(),  | 
                                                        |
| 138 | + ),  | 
                                                        |
| 139 | +  | 
                                                        |
| 140 | + //////////////////////////////////////////////////////////////////////////////////////////////////  | 
                                                        |
| 141 | + // Administration  | 
                                                        |
| 142 | + 'bans' =>  | 
                                                        |
| 143 | + array(  | 
                                                        |
| 144 | + 'class' => PageBan::class,  | 
                                                        |
| 145 | +				'actions' => array('set', 'remove'), | 
                                                        |
| 146 | + ),  | 
                                                        |
| 147 | + 'userManagement' =>  | 
                                                        |
| 148 | + array(  | 
                                                        |
| 149 | + 'class' => PageUserManagement::class,  | 
                                                        |
| 150 | + 'actions' => array(  | 
                                                        |
| 151 | + 'approve',  | 
                                                        |
| 152 | + 'decline',  | 
                                                        |
| 153 | + 'rename',  | 
                                                        |
| 154 | + 'editUser',  | 
                                                        |
| 155 | + 'suspend',  | 
                                                        |
| 156 | + 'promote',  | 
                                                        |
| 157 | + 'demote',  | 
                                                        |
| 158 | + ),  | 
                                                        |
| 159 | + ),  | 
                                                        |
| 160 | + 'siteNotice' =>  | 
                                                        |
| 161 | + array(  | 
                                                        |
| 162 | + 'class' => PageSiteNotice::class,  | 
                                                        |
| 163 | + 'actions' => array(),  | 
                                                        |
| 164 | + ),  | 
                                                        |
| 165 | + 'emailManagement' =>  | 
                                                        |
| 166 | + array(  | 
                                                        |
| 167 | + 'class' => PageEmailManagement::class,  | 
                                                        |
| 168 | +				'actions' => array('create', 'edit', 'view'), | 
                                                        |
| 169 | + ),  | 
                                                        |
| 170 | +  | 
                                                        |
| 171 | + //////////////////////////////////////////////////////////////////////////////////////////////////  | 
                                                        |
| 172 | + // Personal preferences  | 
                                                        |
| 173 | + 'preferences' =>  | 
                                                        |
| 174 | + array(  | 
                                                        |
| 175 | + 'class' => PagePreferences::class,  | 
                                                        |
| 176 | +				'actions' => array('changePassword'), | 
                                                        |
| 177 | + ),  | 
                                                        |
| 178 | + 'oauth' =>  | 
                                                        |
| 179 | + array(  | 
                                                        |
| 180 | + 'class' => PageOAuth::class,  | 
                                                        |
| 181 | +				'actions' => array('detach', 'attach'), | 
                                                        |
| 182 | + ),  | 
                                                        |
| 183 | +  | 
                                                        |
| 184 | + //////////////////////////////////////////////////////////////////////////////////////////////////  | 
                                                        |
| 185 | + // Welcomer configuration  | 
                                                        |
| 186 | + 'welcomeTemplates' =>  | 
                                                        |
| 187 | + array(  | 
                                                        |
| 188 | + 'class' => PageWelcomeTemplateManagement::class,  | 
                                                        |
| 189 | +				'actions' => array('select', 'edit', 'delete', 'add', 'view'), | 
                                                        |
| 190 | + ),  | 
                                                        |
| 191 | +  | 
                                                        |
| 192 | + //////////////////////////////////////////////////////////////////////////////////////////////////  | 
                                                        |
| 193 | + // Statistics  | 
                                                        |
| 194 | + 'statistics' =>  | 
                                                        |
| 195 | + array(  | 
                                                        |
| 196 | + 'class' => StatsMain::class,  | 
                                                        |
| 197 | + 'actions' => array(),  | 
                                                        |
| 198 | + ),  | 
                                                        |
| 199 | + 'statistics/fastCloses' =>  | 
                                                        |
| 200 | + array(  | 
                                                        |
| 201 | + 'class' => StatsFastCloses::class,  | 
                                                        |
| 202 | + 'actions' => array(),  | 
                                                        |
| 203 | + ),  | 
                                                        |
| 204 | + 'statistics/inactiveUsers' =>  | 
                                                        |
| 205 | + array(  | 
                                                        |
| 206 | + 'class' => StatsInactiveUsers::class,  | 
                                                        |
| 207 | + 'actions' => array(),  | 
                                                        |
| 208 | + ),  | 
                                                        |
| 209 | + 'statistics/monthlyStats' =>  | 
                                                        |
| 210 | + array(  | 
                                                        |
| 211 | + 'class' => StatsMonthlyStats::class,  | 
                                                        |
| 212 | + 'actions' => array(),  | 
                                                        |
| 213 | + ),  | 
                                                        |
| 214 | + 'statistics/reservedRequests' =>  | 
                                                        |
| 215 | + array(  | 
                                                        |
| 216 | + 'class' => StatsReservedRequests::class,  | 
                                                        |
| 217 | + 'actions' => array(),  | 
                                                        |
| 218 | + ),  | 
                                                        |
| 219 | + 'statistics/templateStats' =>  | 
                                                        |
| 220 | + array(  | 
                                                        |
| 221 | + 'class' => StatsTemplateStats::class,  | 
                                                        |
| 222 | + 'actions' => array(),  | 
                                                        |
| 223 | + ),  | 
                                                        |
| 224 | + 'statistics/topCreators' =>  | 
                                                        |
| 225 | + array(  | 
                                                        |
| 226 | + 'class' => StatsTopCreators::class,  | 
                                                        |
| 227 | + 'actions' => array(),  | 
                                                        |
| 228 | + ),  | 
                                                        |
| 229 | + 'statistics/users' =>  | 
                                                        |
| 230 | + array(  | 
                                                        |
| 231 | + 'class' => StatsUsers::class,  | 
                                                        |
| 232 | +				'actions' => array('detail'), | 
                                                        |
| 233 | + ),  | 
                                                        |
| 234 | +  | 
                                                        |
| 235 | + //////////////////////////////////////////////////////////////////////////////////////////////////  | 
                                                        |
| 236 | + // Zoom page  | 
                                                        |
| 237 | + 'viewRequest' =>  | 
                                                        |
| 238 | + array(  | 
                                                        |
| 239 | + 'class' => PageViewRequest::class,  | 
                                                        |
| 240 | + 'actions' => array(),  | 
                                                        |
| 241 | + ),  | 
                                                        |
| 242 | + 'viewRequest/reserve' =>  | 
                                                        |
| 243 | + array(  | 
                                                        |
| 244 | + 'class' => PageReservation::class,  | 
                                                        |
| 245 | + 'actions' => array(),  | 
                                                        |
| 246 | + ),  | 
                                                        |
| 247 | + 'viewRequest/breakReserve' =>  | 
                                                        |
| 248 | + array(  | 
                                                        |
| 249 | + 'class' => PageBreakReservation::class,  | 
                                                        |
| 250 | + 'actions' => array(),  | 
                                                        |
| 251 | + ),  | 
                                                        |
| 252 | + 'viewRequest/defer' =>  | 
                                                        |
| 253 | + array(  | 
                                                        |
| 254 | + 'class' => PageDeferRequest::class,  | 
                                                        |
| 255 | + 'actions' => array(),  | 
                                                        |
| 256 | + ),  | 
                                                        |
| 257 | + 'viewRequest/comment' =>  | 
                                                        |
| 258 | + array(  | 
                                                        |
| 259 | + 'class' => PageComment::class,  | 
                                                        |
| 260 | + 'actions' => array(),  | 
                                                        |
| 261 | + ),  | 
                                                        |
| 262 | + 'viewRequest/sendToUser' =>  | 
                                                        |
| 263 | + array(  | 
                                                        |
| 264 | + 'class' => PageSendToUser::class,  | 
                                                        |
| 265 | + 'actions' => array(),  | 
                                                        |
| 266 | + ),  | 
                                                        |
| 267 | + 'viewRequest/close' =>  | 
                                                        |
| 268 | + array(  | 
                                                        |
| 269 | + 'class' => PageCloseRequest::class,  | 
                                                        |
| 270 | + 'actions' => array(),  | 
                                                        |
| 271 | + ),  | 
                                                        |
| 272 | + 'viewRequest/drop' =>  | 
                                                        |
| 273 | + array(  | 
                                                        |
| 274 | + 'class' => PageDropRequest::class,  | 
                                                        |
| 275 | + 'actions' => array(),  | 
                                                        |
| 276 | + ),  | 
                                                        |
| 277 | + 'viewRequest/custom' =>  | 
                                                        |
| 278 | + array(  | 
                                                        |
| 279 | + 'class' => PageCustomClose::class,  | 
                                                        |
| 280 | + 'actions' => array(),  | 
                                                        |
| 281 | + ),  | 
                                                        |
| 282 | + 'editComment' =>  | 
                                                        |
| 283 | + array(  | 
                                                        |
| 284 | + 'class' => PageEditComment::class,  | 
                                                        |
| 285 | + 'actions' => array(),  | 
                                                        |
| 286 | + ),  | 
                                                        |
| 287 | +  | 
                                                        |
| 288 | + //////////////////////////////////////////////////////////////////////////////////////////////////  | 
                                                        |
| 289 | + // Misc stuff  | 
                                                        |
| 290 | + 'team' =>  | 
                                                        |
| 291 | + array(  | 
                                                        |
| 292 | + 'class' => PageTeam::class,  | 
                                                        |
| 293 | + 'actions' => array(),  | 
                                                        |
| 294 | + ),  | 
                                                        |
| 295 | + 'requestList' =>  | 
                                                        |
| 296 | + array(  | 
                                                        |
| 297 | + 'class' => PageExpandedRequestList::class,  | 
                                                        |
| 298 | + 'actions' => array(),  | 
                                                        |
| 299 | + ),  | 
                                                        |
| 300 | + );  | 
                                                        |
| 301 | +  | 
                                                        |
| 302 | + /**  | 
                                                        |
| 303 | + * @return IRoutedTask  | 
                                                        |
| 304 | + * @throws Exception  | 
                                                        |
| 305 | + */  | 
                                                        |
| 306 | + final public function route()  | 
                                                        |
| 307 | +	{ | 
                                                        |
| 308 | + $pathInfo = WebRequest::pathInfo();  | 
                                                        |
| 309 | +  | 
                                                        |
| 310 | + list($pageClass, $action) = $this->getRouteFromPath($pathInfo);  | 
                                                        |
| 311 | +  | 
                                                        |
| 312 | + /** @var IRoutedTask $page */  | 
                                                        |
| 313 | + $page = new $pageClass();  | 
                                                        |
| 314 | +  | 
                                                        |
| 315 | + // Dynamic creation, so we've got to be careful here. We can't use built-in language type protection, so  | 
                                                        |
| 316 | + // let's use our own.  | 
                                                        |
| 317 | +		if (!($page instanceof IRoutedTask)) { | 
                                                        |
| 318 | +			throw new Exception('Expected a page, but this is not a page.'); | 
                                                        |
| 319 | + }  | 
                                                        |
| 320 | +  | 
                                                        |
| 321 | + // OK, I'm happy at this point that we know we're running a page, and we know it's probably what we want if it  | 
                                                        |
| 322 | + // inherits PageBase and has been created from the routing map.  | 
                                                        |
| 323 | + $page->setRoute($action);  | 
                                                        |
| 324 | +  | 
                                                        |
| 325 | + return $page;  | 
                                                        |
| 326 | + }  | 
                                                        |
| 327 | +  | 
                                                        |
| 328 | + /**  | 
                                                        |
| 329 | + * @param $pathInfo  | 
                                                        |
| 330 | + *  | 
                                                        |
| 331 | + * @return array  | 
                                                        |
| 332 | + */  | 
                                                        |
| 333 | + protected function getRouteFromPath($pathInfo)  | 
                                                        |
| 334 | +	{ | 
                                                        |
| 335 | +		if (count($pathInfo) === 0) { | 
                                                        |
| 336 | + // No pathInfo, so no page to load. Load the main page.  | 
                                                        |
| 337 | + return $this->getDefaultRoute();  | 
                                                        |
| 338 | + }  | 
                                                        |
| 339 | +		elseif (count($pathInfo) === 1) { | 
                                                        |
| 340 | + // Exactly one path info segment, it's got to be a page.  | 
                                                        |
| 341 | + $classSegment = $pathInfo[0];  | 
                                                        |
| 342 | +  | 
                                                        |
| 343 | + return $this->routeSinglePathSegment($classSegment);  | 
                                                        |
| 344 | + }  | 
                                                        |
| 345 | +  | 
                                                        |
| 346 | + // OK, we have two or more segments now.  | 
                                                        |
| 347 | +		if (count($pathInfo) > 2) { | 
                                                        |
| 348 | + // Let's handle more than two, and collapse it down into two.  | 
                                                        |
| 349 | + $requestedAction = array_pop($pathInfo);  | 
                                                        |
| 350 | +			$classSegment = implode('/', $pathInfo); | 
                                                        |
| 351 | + }  | 
                                                        |
| 352 | +		else { | 
                                                        |
| 353 | + // Two path info segments.  | 
                                                        |
| 354 | + $classSegment = $pathInfo[0];  | 
                                                        |
| 355 | + $requestedAction = $pathInfo[1];  | 
                                                        |
| 356 | + }  | 
                                                        |
| 357 | +  | 
                                                        |
| 358 | + $routeMap = $this->routePathSegments($classSegment, $requestedAction);  | 
                                                        |
| 359 | +  | 
                                                        |
| 360 | +		if ($routeMap[0] === Page404::class) { | 
                                                        |
| 361 | + $routeMap = $this->routeSinglePathSegment($classSegment . '/' . $requestedAction);  | 
                                                        |
| 362 | + }  | 
                                                        |
| 363 | +  | 
                                                        |
| 364 | + return $routeMap;  | 
                                                        |
| 365 | + }  | 
                                                        |
| 366 | +  | 
                                                        |
| 367 | + /**  | 
                                                        |
| 368 | + * @param $classSegment  | 
                                                        |
| 369 | + *  | 
                                                        |
| 370 | + * @return array  | 
                                                        |
| 371 | + */  | 
                                                        |
| 372 | + final protected function routeSinglePathSegment($classSegment)  | 
                                                        |
| 373 | +	{ | 
                                                        |
| 374 | + $routeMap = $this->getRouteMap();  | 
                                                        |
| 375 | +		if (array_key_exists($classSegment, $routeMap)) { | 
                                                        |
| 376 | + // Route exists, but we don't have an action in path info, so default to main.  | 
                                                        |
| 377 | + $pageClass = $routeMap[$classSegment]['class'];  | 
                                                        |
| 378 | + $action = 'main';  | 
                                                        |
| 379 | +  | 
                                                        |
| 380 | + return array($pageClass, $action);  | 
                                                        |
| 381 | + }  | 
                                                        |
| 382 | +		else { | 
                                                        |
| 383 | + // Doesn't exist in map. Fall back to 404  | 
                                                        |
| 384 | + $pageClass = Page404::class;  | 
                                                        |
| 385 | + $action = "main";  | 
                                                        |
| 386 | +  | 
                                                        |
| 387 | + return array($pageClass, $action);  | 
                                                        |
| 388 | + }  | 
                                                        |
| 389 | + }  | 
                                                        |
| 390 | +  | 
                                                        |
| 391 | + /**  | 
                                                        |
| 392 | + * @param $classSegment  | 
                                                        |
| 393 | + * @param $requestedAction  | 
                                                        |
| 394 | + *  | 
                                                        |
| 395 | + * @return array  | 
                                                        |
| 396 | + */  | 
                                                        |
| 397 | + final protected function routePathSegments($classSegment, $requestedAction)  | 
                                                        |
| 398 | +	{ | 
                                                        |
| 399 | + $routeMap = $this->getRouteMap();  | 
                                                        |
| 400 | +		if (array_key_exists($classSegment, $routeMap)) { | 
                                                        |
| 401 | + // Route exists, but we don't have an action in path info, so default to main.  | 
                                                        |
| 402 | +  | 
                                                        |
| 403 | + if (isset($routeMap[$classSegment]['actions'])  | 
                                                        |
| 404 | + && array_search($requestedAction, $routeMap[$classSegment]['actions']) !== false  | 
                                                        |
| 405 | +			) { | 
                                                        |
| 406 | + // Action exists in allowed action list. Allow both the page and the action  | 
                                                        |
| 407 | + $pageClass = $routeMap[$classSegment]['class'];  | 
                                                        |
| 408 | + $action = $requestedAction;  | 
                                                        |
| 409 | +  | 
                                                        |
| 410 | + return array($pageClass, $action);  | 
                                                        |
| 411 | + }  | 
                                                        |
| 412 | +			else { | 
                                                        |
| 413 | + // Valid page, invalid action. 404 our way out.  | 
                                                        |
| 414 | + $pageClass = Page404::class;  | 
                                                        |
| 415 | + $action = 'main';  | 
                                                        |
| 416 | +  | 
                                                        |
| 417 | + return array($pageClass, $action);  | 
                                                        |
| 418 | + }  | 
                                                        |
| 419 | + }  | 
                                                        |
| 420 | +		else { | 
                                                        |
| 421 | + // Class doesn't exist in map. Fall back to 404  | 
                                                        |
| 422 | + $pageClass = Page404::class;  | 
                                                        |
| 423 | + $action = 'main';  | 
                                                        |
| 424 | +  | 
                                                        |
| 425 | + return array($pageClass, $action);  | 
                                                        |
| 426 | + }  | 
                                                        |
| 427 | + }  | 
                                                        |
| 428 | +  | 
                                                        |
| 429 | + /**  | 
                                                        |
| 430 | + * @return array  | 
                                                        |
| 431 | + */  | 
                                                        |
| 432 | + protected function getRouteMap()  | 
                                                        |
| 433 | +	{ | 
                                                        |
| 434 | + return $this->routeMap;  | 
                                                        |
| 435 | + }  | 
                                                        |
| 436 | +  | 
                                                        |
| 437 | + /**  | 
                                                        |
| 438 | + * @return callable  | 
                                                        |
| 439 | + */  | 
                                                        |
| 440 | + protected function getDefaultRoute()  | 
                                                        |
| 441 | +	{ | 
                                                        |
| 442 | + return array(PageMain::class, "main");  | 
                                                        |
| 443 | + }  | 
                                                        |
| 444 | 444 | }  | 
                                                        
| 445 | 445 | \ No newline at end of file  | 
                                                        
@@ -358,7 +358,7 @@  | 
                                                    ||
| 358 | 358 | $routeMap = $this->routePathSegments($classSegment, $requestedAction);  | 
                                                        
| 359 | 359 | |
| 360 | 360 |          if ($routeMap[0] === Page404::class) { | 
                                                        
| 361 | - $routeMap = $this->routeSinglePathSegment($classSegment . '/' . $requestedAction);  | 
                                                        |
| 361 | + $routeMap = $this->routeSinglePathSegment($classSegment.'/'.$requestedAction);  | 
                                                        |
| 362 | 362 | }  | 
                                                        
| 363 | 363 | |
| 364 | 364 | return $routeMap;  | 
                                                        
@@ -196,24 +196,24 @@ discard block  | 
                                                    ||
| 196 | 196 | |
| 197 | 197 | // request states  | 
                                                        
| 198 | 198 | $availableRequestStates = array(  | 
                                                        
| 199 | - 'Open' => array(  | 
                                                        |
| 200 | - 'defertolog' => 'users', // don't change or you'll break old logs  | 
                                                        |
| 201 | - 'deferto' => 'users',  | 
                                                        |
| 202 | - 'header' => 'Open requests',  | 
                                                        |
| 203 | - 'api' => "open",  | 
                                                        |
| 204 | - ),  | 
                                                        |
| 205 | - 'Flagged users' => array(  | 
                                                        |
| 206 | - 'defertolog' => 'flagged users', // don't change or you'll break old logs  | 
                                                        |
| 207 | - 'deferto' => 'flagged users',  | 
                                                        |
| 208 | - 'header' => 'Flagged user needed',  | 
                                                        |
| 209 | - 'api' => "admin",  | 
                                                        |
| 210 | - ),  | 
                                                        |
| 211 | - 'Checkuser' => array(  | 
                                                        |
| 212 | - 'defertolog' => 'checkusers', // don't change or you'll break old logs  | 
                                                        |
| 213 | - 'deferto' => 'checkusers',  | 
                                                        |
| 214 | - 'header' => 'Checkuser needed',  | 
                                                        |
| 215 | - 'api' => "checkuser",  | 
                                                        |
| 216 | - ),  | 
                                                        |
| 199 | + 'Open' => array(  | 
                                                        |
| 200 | + 'defertolog' => 'users', // don't change or you'll break old logs  | 
                                                        |
| 201 | + 'deferto' => 'users',  | 
                                                        |
| 202 | + 'header' => 'Open requests',  | 
                                                        |
| 203 | + 'api' => "open",  | 
                                                        |
| 204 | + ),  | 
                                                        |
| 205 | + 'Flagged users' => array(  | 
                                                        |
| 206 | + 'defertolog' => 'flagged users', // don't change or you'll break old logs  | 
                                                        |
| 207 | + 'deferto' => 'flagged users',  | 
                                                        |
| 208 | + 'header' => 'Flagged user needed',  | 
                                                        |
| 209 | + 'api' => "admin",  | 
                                                        |
| 210 | + ),  | 
                                                        |
| 211 | + 'Checkuser' => array(  | 
                                                        |
| 212 | + 'defertolog' => 'checkusers', // don't change or you'll break old logs  | 
                                                        |
| 213 | + 'deferto' => 'checkusers',  | 
                                                        |
| 214 | + 'header' => 'Checkuser needed',  | 
                                                        |
| 215 | + 'api' => "checkuser",  | 
                                                        |
| 216 | + ),  | 
                                                        |
| 217 | 217 | );  | 
                                                        
| 218 | 218 | |
| 219 | 219 | $defaultRequestStateKey = 'Open';  | 
                                                        
@@ -252,21 +252,21 @@ discard block  | 
                                                    ||
| 252 | 252 |  require_once('config.local.inc.php'); | 
                                                        
| 253 | 253 | |
| 254 | 254 | $cDatabaseConfig = array(  | 
                                                        
| 255 | - "acc" => array(  | 
                                                        |
| 256 | - "dsrcname" => "mysql:host=" . $toolserver_host . ";dbname=" . $toolserver_database,  | 
                                                        |
| 257 | - "username" => $toolserver_username,  | 
                                                        |
| 258 | - "password" => $toolserver_password,  | 
                                                        |
| 259 | - ),  | 
                                                        |
| 260 | - "wikipedia" => array(  | 
                                                        |
| 261 | - "dsrcname" => "mysql:host=" . $antispoof_host . ";dbname=" . $antispoof_db,  | 
                                                        |
| 262 | - "username" => $toolserver_username,  | 
                                                        |
| 263 | - "password" => $toolserver_password,  | 
                                                        |
| 264 | - ),  | 
                                                        |
| 265 | - "notifications" => array(  | 
                                                        |
| 266 | - "dsrcname" => "mysql:host=" . $toolserver_notification_dbhost . ";dbname=" . $toolserver_notification_database,  | 
                                                        |
| 267 | - "username" => $notifications_username,  | 
                                                        |
| 268 | - "password" => $notifications_password,  | 
                                                        |
| 269 | - ),  | 
                                                        |
| 255 | + "acc" => array(  | 
                                                        |
| 256 | + "dsrcname" => "mysql:host=" . $toolserver_host . ";dbname=" . $toolserver_database,  | 
                                                        |
| 257 | + "username" => $toolserver_username,  | 
                                                        |
| 258 | + "password" => $toolserver_password,  | 
                                                        |
| 259 | + ),  | 
                                                        |
| 260 | + "wikipedia" => array(  | 
                                                        |
| 261 | + "dsrcname" => "mysql:host=" . $antispoof_host . ";dbname=" . $antispoof_db,  | 
                                                        |
| 262 | + "username" => $toolserver_username,  | 
                                                        |
| 263 | + "password" => $toolserver_password,  | 
                                                        |
| 264 | + ),  | 
                                                        |
| 265 | + "notifications" => array(  | 
                                                        |
| 266 | + "dsrcname" => "mysql:host=" . $toolserver_notification_dbhost . ";dbname=" . $toolserver_notification_database,  | 
                                                        |
| 267 | + "username" => $notifications_username,  | 
                                                        |
| 268 | + "password" => $notifications_password,  | 
                                                        |
| 269 | + ),  | 
                                                        |
| 270 | 270 | );  | 
                                                        
| 271 | 271 | |
| 272 | 272 | // //Keep the included files from being executed.  | 
                                                        
@@ -278,18 +278,18 @@ discard block  | 
                                                    ||
| 278 | 278 |  ini_set('user_agent', $toolUserAgent); | 
                                                        
| 279 | 279 | |
| 280 | 280 | foreach (array(  | 
                                                        
| 281 | - "mbstring", // unicode and stuff  | 
                                                        |
| 282 | - "pdo",  | 
                                                        |
| 283 | - "pdo_mysql", // new database module  | 
                                                        |
| 284 | - "session",  | 
                                                        |
| 285 | - "date",  | 
                                                        |
| 286 | - "pcre", // core stuff  | 
                                                        |
| 287 | - "curl", // mediawiki api access etc  | 
                                                        |
| 288 | - "openssl", // token generation  | 
                                                        |
| 281 | + "mbstring", // unicode and stuff  | 
                                                        |
| 282 | + "pdo",  | 
                                                        |
| 283 | + "pdo_mysql", // new database module  | 
                                                        |
| 284 | + "session",  | 
                                                        |
| 285 | + "date",  | 
                                                        |
| 286 | + "pcre", // core stuff  | 
                                                        |
| 287 | + "curl", // mediawiki api access etc  | 
                                                        |
| 288 | + "openssl", // token generation  | 
                                                        |
| 289 | 289 |  ) as $x) { | 
                                                        
| 290 | -    if (!extension_loaded($x)) { | 
                                                        |
| 291 | -        die("extension $x is required."); | 
                                                        |
| 292 | - }  | 
                                                        |
| 290 | +	if (!extension_loaded($x)) { | 
                                                        |
| 291 | +		die("extension $x is required."); | 
                                                        |
| 292 | + }  | 
                                                        |
| 293 | 293 | }  | 
                                                        
| 294 | 294 | |
| 295 | 295 | // Set up the AutoLoader  | 
                                                        
@@ -316,32 +316,32 @@ discard block  | 
                                                    ||
| 316 | 316 | $siteConfiguration = new \Waca\SiteConfiguration();  | 
                                                        
| 317 | 317 | |
| 318 | 318 | $siteConfiguration->setBaseUrl($baseurl)  | 
                                                        
| 319 | - ->setFilePath(__DIR__)  | 
                                                        |
| 320 | - ->setDebuggingTraceEnabled($enableErrorTrace)  | 
                                                        |
| 321 | - ->setForceIdentification($forceIdentification)  | 
                                                        |
| 322 | - ->setIdentificationCacheExpiry($identificationCacheExpiry)  | 
                                                        |
| 323 | - ->setMediawikiScriptPath($mediawikiScriptPath)  | 
                                                        |
| 324 | - ->setMediawikiWebServiceEndpoint($mediawikiWebServiceEndpoint)  | 
                                                        |
| 325 | - ->setMetaWikimediaWebServiceEndpoint($metaWikimediaWebServiceEndpoint)  | 
                                                        |
| 326 | - ->setEnforceOAuth($enforceOAuth)  | 
                                                        |
| 327 | - ->setEmailConfirmationEnabled($enableEmailConfirm == 1)  | 
                                                        |
| 328 | - ->setEmailConfirmationExpiryDays($emailConfirmationExpiryDays)  | 
                                                        |
| 329 | - ->setMiserModeLimit($requestLimitShowOnly)  | 
                                                        |
| 330 | - ->setRequestStates($availableRequestStates)  | 
                                                        |
| 331 | - ->setSquidList($squidIpList)  | 
                                                        |
| 332 | - ->setDefaultCreatedTemplateId($createdid)  | 
                                                        |
| 333 | - ->setDefaultRequestStateKey($defaultRequestStateKey)  | 
                                                        |
| 334 | - ->setUseStrictTransportSecurity($strictTransportSecurityExpiry)  | 
                                                        |
| 335 | - ->setUserAgent($toolUserAgent)  | 
                                                        |
| 336 | - ->setCurlDisableVerifyPeer($curlDisableSSLVerifyPeer)  | 
                                                        |
| 337 | - ->setUseOAuthSignup($useOauthSignup)  | 
                                                        |
| 338 | - ->setOAuthBaseUrl($oauthBaseUrl)  | 
                                                        |
| 339 | - ->setOAuthConsumerToken($oauthConsumerToken)  | 
                                                        |
| 340 | - ->setOAuthConsumerSecret($oauthSecretToken)  | 
                                                        |
| 341 | - ->setDataClearInterval($dataclear_interval)  | 
                                                        |
| 342 | - ->setXffTrustedHostsFile($xff_trusted_hosts_file)  | 
                                                        |
| 343 | - ->setIrcNotificationsEnabled($ircBotNotificationsEnabled == 1)  | 
                                                        |
| 344 | - ->setIrcNotificationType($ircBotNotificationType)  | 
                                                        |
| 345 | - ->setIrcNotificationsInstance($whichami)  | 
                                                        |
| 346 | - ->setTitleBlacklistEnabled($enableTitleblacklist == 1)  | 
                                                        |
| 347 | -    ->setTorExitPaths(array_merge(gethostbynamel('en.wikipedia.org'), gethostbynamel('accounts.wmflabs.org'))); | 
                                                        |
| 319 | + ->setFilePath(__DIR__)  | 
                                                        |
| 320 | + ->setDebuggingTraceEnabled($enableErrorTrace)  | 
                                                        |
| 321 | + ->setForceIdentification($forceIdentification)  | 
                                                        |
| 322 | + ->setIdentificationCacheExpiry($identificationCacheExpiry)  | 
                                                        |
| 323 | + ->setMediawikiScriptPath($mediawikiScriptPath)  | 
                                                        |
| 324 | + ->setMediawikiWebServiceEndpoint($mediawikiWebServiceEndpoint)  | 
                                                        |
| 325 | + ->setMetaWikimediaWebServiceEndpoint($metaWikimediaWebServiceEndpoint)  | 
                                                        |
| 326 | + ->setEnforceOAuth($enforceOAuth)  | 
                                                        |
| 327 | + ->setEmailConfirmationEnabled($enableEmailConfirm == 1)  | 
                                                        |
| 328 | + ->setEmailConfirmationExpiryDays($emailConfirmationExpiryDays)  | 
                                                        |
| 329 | + ->setMiserModeLimit($requestLimitShowOnly)  | 
                                                        |
| 330 | + ->setRequestStates($availableRequestStates)  | 
                                                        |
| 331 | + ->setSquidList($squidIpList)  | 
                                                        |
| 332 | + ->setDefaultCreatedTemplateId($createdid)  | 
                                                        |
| 333 | + ->setDefaultRequestStateKey($defaultRequestStateKey)  | 
                                                        |
| 334 | + ->setUseStrictTransportSecurity($strictTransportSecurityExpiry)  | 
                                                        |
| 335 | + ->setUserAgent($toolUserAgent)  | 
                                                        |
| 336 | + ->setCurlDisableVerifyPeer($curlDisableSSLVerifyPeer)  | 
                                                        |
| 337 | + ->setUseOAuthSignup($useOauthSignup)  | 
                                                        |
| 338 | + ->setOAuthBaseUrl($oauthBaseUrl)  | 
                                                        |
| 339 | + ->setOAuthConsumerToken($oauthConsumerToken)  | 
                                                        |
| 340 | + ->setOAuthConsumerSecret($oauthSecretToken)  | 
                                                        |
| 341 | + ->setDataClearInterval($dataclear_interval)  | 
                                                        |
| 342 | + ->setXffTrustedHostsFile($xff_trusted_hosts_file)  | 
                                                        |
| 343 | + ->setIrcNotificationsEnabled($ircBotNotificationsEnabled == 1)  | 
                                                        |
| 344 | + ->setIrcNotificationType($ircBotNotificationType)  | 
                                                        |
| 345 | + ->setIrcNotificationsInstance($whichami)  | 
                                                        |
| 346 | + ->setTitleBlacklistEnabled($enableTitleblacklist == 1)  | 
                                                        |
| 347 | +	->setTorExitPaths(array_merge(gethostbynamel('en.wikipedia.org'), gethostbynamel('accounts.wmflabs.org'))); | 
                                                        |
@@ -130,7 +130,7 @@ discard block  | 
                                                    ||
| 130 | 130 | |
| 131 | 131 | $BUbasefile = "backup"; // The basefile's name.  | 
                                                        
| 132 | 132 | $BUdir = "/home/project/a/c/c/acc/backups"; // The directory where backups should be stored.  | 
                                                        
| 133 | -$BUmonthdir = $BUdir . "/monthly"; // The directory where monthly backups should be stored.  | 
                                                        |
| 133 | +$BUmonthdir = $BUdir."/monthly"; // The directory where monthly backups should be stored.  | 
                                                        |
| 134 | 134 | $BUdumper = "/opt/ts/mysql/5.1/bin/mysqldump --defaults-file=~/.my.cnf p_acc_live"; // Add parameters here if they are needed.  | 
                                                        
| 135 | 135 | $BUgzip = "/usr/bin/gzip"; // Add the gzip parameters here if needed.  | 
                                                        
| 136 | 136 | $BUtar = "/bin/tar -cvf"; // Add the tar parameters here if needed.  | 
                                                        
@@ -253,17 +253,17 @@ discard block  | 
                                                    ||
| 253 | 253 | |
| 254 | 254 | $cDatabaseConfig = array(  | 
                                                        
| 255 | 255 | "acc" => array(  | 
                                                        
| 256 | - "dsrcname" => "mysql:host=" . $toolserver_host . ";dbname=" . $toolserver_database,  | 
                                                        |
| 256 | + "dsrcname" => "mysql:host=".$toolserver_host.";dbname=".$toolserver_database,  | 
                                                        |
| 257 | 257 | "username" => $toolserver_username,  | 
                                                        
| 258 | 258 | "password" => $toolserver_password,  | 
                                                        
| 259 | 259 | ),  | 
                                                        
| 260 | 260 | "wikipedia" => array(  | 
                                                        
| 261 | - "dsrcname" => "mysql:host=" . $antispoof_host . ";dbname=" . $antispoof_db,  | 
                                                        |
| 261 | + "dsrcname" => "mysql:host=".$antispoof_host.";dbname=".$antispoof_db,  | 
                                                        |
| 262 | 262 | "username" => $toolserver_username,  | 
                                                        
| 263 | 263 | "password" => $toolserver_password,  | 
                                                        
| 264 | 264 | ),  | 
                                                        
| 265 | 265 | "notifications" => array(  | 
                                                        
| 266 | - "dsrcname" => "mysql:host=" . $toolserver_notification_dbhost . ";dbname=" . $toolserver_notification_database,  | 
                                                        |
| 266 | + "dsrcname" => "mysql:host=".$toolserver_notification_dbhost.";dbname=".$toolserver_notification_database,  | 
                                                        |
| 267 | 267 | "username" => $notifications_username,  | 
                                                        
| 268 | 268 | "password" => $notifications_password,  | 
                                                        
| 269 | 269 | ),  | 
                                                        
@@ -293,13 +293,13 @@ discard block  | 
                                                    ||
| 293 | 293 | }  | 
                                                        
| 294 | 294 | |
| 295 | 295 | // Set up the AutoLoader  | 
                                                        
| 296 | -require_once(__DIR__ . "/includes/AutoLoader.php");  | 
                                                        |
| 296 | +require_once(__DIR__."/includes/AutoLoader.php");  | 
                                                        |
| 297 | 297 |  spl_autoload_register('Waca\\AutoLoader::load'); | 
                                                        
| 298 | -require_once(__DIR__ . '/vendor/autoload.php');  | 
                                                        |
| 298 | +require_once(__DIR__.'/vendor/autoload.php');  | 
                                                        |
| 299 | 299 | |
| 300 | 300 | // Extra includes which are just plain awkward wherever they are.  | 
                                                        
| 301 | -require_once(__DIR__ . '/lib/mediawiki-extensions-OAuth/lib/OAuth.php');  | 
                                                        |
| 302 | -require_once(__DIR__ . '/lib/mediawiki-extensions-OAuth/lib/JWT.php');  | 
                                                        |
| 301 | +require_once(__DIR__.'/lib/mediawiki-extensions-OAuth/lib/OAuth.php');  | 
                                                        |
| 302 | +require_once(__DIR__.'/lib/mediawiki-extensions-OAuth/lib/JWT.php');  | 
                                                        |
| 303 | 303 | |
| 304 | 304 | // Crap that's needed for libraries. >:(  | 
                                                        
| 305 | 305 | /**  | 
                                                        
@@ -22,521 +22,521 @@  | 
                                                    ||
| 22 | 22 | */  | 
                                                        
| 23 | 23 | class WebRequest  | 
                                                        
| 24 | 24 |  { | 
                                                        
| 25 | - /**  | 
                                                        |
| 26 | - * @var \Waca\Providers\GlobalState\IGlobalStateProvider Provides access to the global state.  | 
                                                        |
| 27 | - */  | 
                                                        |
| 28 | - private static $globalStateProvider;  | 
                                                        |
| 29 | -  | 
                                                        |
| 30 | - /**  | 
                                                        |
| 31 | - * Returns a boolean value if the request was submitted with the HTTP POST method.  | 
                                                        |
| 32 | - * @return bool  | 
                                                        |
| 33 | - */  | 
                                                        |
| 34 | - public static function wasPosted()  | 
                                                        |
| 35 | -    { | 
                                                        |
| 36 | - return self::method() === 'POST';  | 
                                                        |
| 37 | - }  | 
                                                        |
| 38 | -  | 
                                                        |
| 39 | - /**  | 
                                                        |
| 40 | - * Gets the HTTP Method used  | 
                                                        |
| 41 | - * @return string|null  | 
                                                        |
| 42 | - */  | 
                                                        |
| 43 | - public static function method()  | 
                                                        |
| 44 | -    { | 
                                                        |
| 45 | - $server = &self::$globalStateProvider->getServerSuperGlobal();  | 
                                                        |
| 46 | -  | 
                                                        |
| 47 | -        if (isset($server['REQUEST_METHOD'])) { | 
                                                        |
| 48 | - return $server['REQUEST_METHOD'];  | 
                                                        |
| 49 | - }  | 
                                                        |
| 50 | -  | 
                                                        |
| 51 | - return null;  | 
                                                        |
| 52 | - }  | 
                                                        |
| 53 | -  | 
                                                        |
| 54 | - /**  | 
                                                        |
| 55 | - * Gets a boolean value stating whether the request was served over HTTPS or not.  | 
                                                        |
| 56 | - * @return bool  | 
                                                        |
| 57 | - */  | 
                                                        |
| 58 | - public static function isHttps()  | 
                                                        |
| 59 | -    { | 
                                                        |
| 60 | - $server = &self::$globalStateProvider->getServerSuperGlobal();  | 
                                                        |
| 61 | -  | 
                                                        |
| 62 | -        if (isset($server['HTTP_X_FORWARDED_PROTO'])) { | 
                                                        |
| 63 | -            if ($server['HTTP_X_FORWARDED_PROTO'] === 'https') { | 
                                                        |
| 64 | - // Client <=> Proxy is encrypted  | 
                                                        |
| 65 | - return true;  | 
                                                        |
| 66 | - }  | 
                                                        |
| 67 | -            else { | 
                                                        |
| 68 | - // Proxy <=> Server link unknown, Client <=> Proxy is not encrypted.  | 
                                                        |
| 69 | - return false;  | 
                                                        |
| 70 | - }  | 
                                                        |
| 71 | - }  | 
                                                        |
| 72 | -  | 
                                                        |
| 73 | -        if (isset($server['HTTPS'])) { | 
                                                        |
| 74 | -            if ($server['HTTPS'] === 'off') { | 
                                                        |
| 75 | - // ISAPI on IIS breaks the spec. :(  | 
                                                        |
| 76 | - return false;  | 
                                                        |
| 77 | - }  | 
                                                        |
| 78 | -  | 
                                                        |
| 79 | -            if ($server['HTTPS'] !== '') { | 
                                                        |
| 80 | - // Set to a non-empty value  | 
                                                        |
| 81 | - return true;  | 
                                                        |
| 82 | - }  | 
                                                        |
| 83 | - }  | 
                                                        |
| 84 | -  | 
                                                        |
| 85 | - return false;  | 
                                                        |
| 86 | - }  | 
                                                        |
| 87 | -  | 
                                                        |
| 88 | - /**  | 
                                                        |
| 89 | - * Gets the path info  | 
                                                        |
| 90 | - *  | 
                                                        |
| 91 | - * @return array Array of path info segments  | 
                                                        |
| 92 | - */  | 
                                                        |
| 93 | - public static function pathInfo()  | 
                                                        |
| 94 | -    { | 
                                                        |
| 95 | - $server = &self::$globalStateProvider->getServerSuperGlobal();  | 
                                                        |
| 96 | -        if (!isset($server['PATH_INFO'])) { | 
                                                        |
| 97 | - return array();  | 
                                                        |
| 98 | - }  | 
                                                        |
| 99 | -  | 
                                                        |
| 100 | -        $exploded = explode('/', $server['PATH_INFO']); | 
                                                        |
| 101 | -  | 
                                                        |
| 102 | - // filter out empty values, and reindex from zero. Notably, the first element is always zero, since it starts  | 
                                                        |
| 103 | - // with a /  | 
                                                        |
| 104 | - return array_values(array_filter($exploded));  | 
                                                        |
| 105 | - }  | 
                                                        |
| 106 | -  | 
                                                        |
| 107 | - /**  | 
                                                        |
| 108 | - * Gets the remote address of the web request  | 
                                                        |
| 109 | - * @return null|string  | 
                                                        |
| 110 | - */  | 
                                                        |
| 111 | - public static function remoteAddress()  | 
                                                        |
| 112 | -    { | 
                                                        |
| 113 | - $server = &self::$globalStateProvider->getServerSuperGlobal();  | 
                                                        |
| 114 | -  | 
                                                        |
| 115 | -        if (isset($server['REMOTE_ADDR'])) { | 
                                                        |
| 116 | - return $server['REMOTE_ADDR'];  | 
                                                        |
| 117 | - }  | 
                                                        |
| 118 | -  | 
                                                        |
| 119 | - return null;  | 
                                                        |
| 120 | - }  | 
                                                        |
| 121 | -  | 
                                                        |
| 122 | - /**  | 
                                                        |
| 123 | - * Gets the XFF header contents for the web request  | 
                                                        |
| 124 | - * @return null|string  | 
                                                        |
| 125 | - */  | 
                                                        |
| 126 | - public static function forwardedAddress()  | 
                                                        |
| 127 | -    { | 
                                                        |
| 128 | - $server = &self::$globalStateProvider->getServerSuperGlobal();  | 
                                                        |
| 129 | -  | 
                                                        |
| 130 | -        if (isset($server['HTTP_X_FORWARDED_FOR'])) { | 
                                                        |
| 131 | - return $server['HTTP_X_FORWARDED_FOR'];  | 
                                                        |
| 132 | - }  | 
                                                        |
| 133 | -  | 
                                                        |
| 134 | - return null;  | 
                                                        |
| 135 | - }  | 
                                                        |
| 136 | -  | 
                                                        |
| 137 | - /**  | 
                                                        |
| 138 | - * Sets the global state provider.  | 
                                                        |
| 139 | - *  | 
                                                        |
| 140 | - * Almost guaranteed this is not the method you want in production code.  | 
                                                        |
| 141 | - *  | 
                                                        |
| 142 | - * @param \Waca\Providers\GlobalState\IGlobalStateProvider $globalState  | 
                                                        |
| 143 | - */  | 
                                                        |
| 144 | - public static function setGlobalStateProvider($globalState)  | 
                                                        |
| 145 | -    { | 
                                                        |
| 146 | - self::$globalStateProvider = $globalState;  | 
                                                        |
| 147 | - }  | 
                                                        |
| 148 | -  | 
                                                        |
| 149 | - #region POST variables  | 
                                                        |
| 150 | -  | 
                                                        |
| 151 | - /**  | 
                                                        |
| 152 | - * @param string $key  | 
                                                        |
| 153 | - *  | 
                                                        |
| 154 | - * @return null|string  | 
                                                        |
| 155 | - */  | 
                                                        |
| 156 | - public static function postString($key)  | 
                                                        |
| 157 | -    { | 
                                                        |
| 158 | - $post = &self::$globalStateProvider->getPostSuperGlobal();  | 
                                                        |
| 159 | -        if (!array_key_exists($key, $post)) { | 
                                                        |
| 160 | - return null;  | 
                                                        |
| 161 | - }  | 
                                                        |
| 162 | -  | 
                                                        |
| 163 | -        if ($post[$key] === "") { | 
                                                        |
| 164 | - return null;  | 
                                                        |
| 165 | - }  | 
                                                        |
| 166 | -  | 
                                                        |
| 167 | - return (string)$post[$key];  | 
                                                        |
| 168 | - }  | 
                                                        |
| 169 | -  | 
                                                        |
| 170 | - /**  | 
                                                        |
| 171 | - * @param string $key  | 
                                                        |
| 172 | - *  | 
                                                        |
| 173 | - * @return null|string  | 
                                                        |
| 174 | - */  | 
                                                        |
| 175 | - public static function postEmail($key)  | 
                                                        |
| 176 | -    { | 
                                                        |
| 177 | - $post = &self::$globalStateProvider->getPostSuperGlobal();  | 
                                                        |
| 178 | -        if (!array_key_exists($key, $post)) { | 
                                                        |
| 179 | - return null;  | 
                                                        |
| 180 | - }  | 
                                                        |
| 181 | -  | 
                                                        |
| 182 | - $filteredValue = filter_var($post[$key], FILTER_SANITIZE_EMAIL);  | 
                                                        |
| 183 | -  | 
                                                        |
| 184 | -        if ($filteredValue === false) { | 
                                                        |
| 185 | - return null;  | 
                                                        |
| 186 | - }  | 
                                                        |
| 187 | -  | 
                                                        |
| 188 | - return (string)$filteredValue;  | 
                                                        |
| 189 | - }  | 
                                                        |
| 190 | -  | 
                                                        |
| 191 | - /**  | 
                                                        |
| 192 | - * @param string $key  | 
                                                        |
| 193 | - *  | 
                                                        |
| 194 | - * @return int|null  | 
                                                        |
| 195 | - */  | 
                                                        |
| 196 | - public static function postInt($key)  | 
                                                        |
| 197 | -    { | 
                                                        |
| 198 | - $post = &self::$globalStateProvider->getPostSuperGlobal();  | 
                                                        |
| 199 | -        if (!array_key_exists($key, $post)) { | 
                                                        |
| 200 | - return null;  | 
                                                        |
| 201 | - }  | 
                                                        |
| 202 | -  | 
                                                        |
| 203 | - $filteredValue = filter_var($post[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);  | 
                                                        |
| 204 | -  | 
                                                        |
| 205 | -        if ($filteredValue === null) { | 
                                                        |
| 206 | - return null;  | 
                                                        |
| 207 | - }  | 
                                                        |
| 208 | -  | 
                                                        |
| 209 | - return (int)$filteredValue;  | 
                                                        |
| 210 | - }  | 
                                                        |
| 211 | -  | 
                                                        |
| 212 | - /**  | 
                                                        |
| 213 | - * @param string $key  | 
                                                        |
| 214 | - *  | 
                                                        |
| 215 | - * @return bool  | 
                                                        |
| 216 | - */  | 
                                                        |
| 217 | - public static function postBoolean($key)  | 
                                                        |
| 218 | -    { | 
                                                        |
| 219 | - $get = &self::$globalStateProvider->getPostSuperGlobal();  | 
                                                        |
| 220 | -        if (!array_key_exists($key, $get)) { | 
                                                        |
| 221 | - return false;  | 
                                                        |
| 222 | - }  | 
                                                        |
| 223 | -  | 
                                                        |
| 224 | - // presence of parameter only  | 
                                                        |
| 225 | -        if ($get[$key] === "") { | 
                                                        |
| 226 | - return true;  | 
                                                        |
| 227 | - }  | 
                                                        |
| 228 | -  | 
                                                        |
| 229 | -        if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { | 
                                                        |
| 230 | - return false;  | 
                                                        |
| 231 | - }  | 
                                                        |
| 232 | -  | 
                                                        |
| 233 | - return true;  | 
                                                        |
| 234 | - }  | 
                                                        |
| 235 | -  | 
                                                        |
| 236 | - #endregion  | 
                                                        |
| 237 | -  | 
                                                        |
| 238 | - #region GET variables  | 
                                                        |
| 239 | -  | 
                                                        |
| 240 | - /**  | 
                                                        |
| 241 | - * @param string $key  | 
                                                        |
| 242 | - *  | 
                                                        |
| 243 | - * @return bool  | 
                                                        |
| 244 | - */  | 
                                                        |
| 245 | - public static function getBoolean($key)  | 
                                                        |
| 246 | -    { | 
                                                        |
| 247 | - $get = &self::$globalStateProvider->getGetSuperGlobal();  | 
                                                        |
| 248 | -        if (!array_key_exists($key, $get)) { | 
                                                        |
| 249 | - return false;  | 
                                                        |
| 250 | - }  | 
                                                        |
| 251 | -  | 
                                                        |
| 252 | - // presence of parameter only  | 
                                                        |
| 253 | -        if ($get[$key] === "") { | 
                                                        |
| 254 | - return true;  | 
                                                        |
| 255 | - }  | 
                                                        |
| 256 | -  | 
                                                        |
| 257 | -        if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { | 
                                                        |
| 258 | - return false;  | 
                                                        |
| 259 | - }  | 
                                                        |
| 260 | -  | 
                                                        |
| 261 | - return true;  | 
                                                        |
| 262 | - }  | 
                                                        |
| 263 | -  | 
                                                        |
| 264 | - /**  | 
                                                        |
| 265 | - * @param string $key  | 
                                                        |
| 266 | - *  | 
                                                        |
| 267 | - * @return int|null  | 
                                                        |
| 268 | - */  | 
                                                        |
| 269 | - public static function getInt($key)  | 
                                                        |
| 270 | -    { | 
                                                        |
| 271 | - $get = &self::$globalStateProvider->getGetSuperGlobal();  | 
                                                        |
| 272 | -        if (!array_key_exists($key, $get)) { | 
                                                        |
| 273 | - return null;  | 
                                                        |
| 274 | - }  | 
                                                        |
| 275 | -  | 
                                                        |
| 276 | - $filteredValue = filter_var($get[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);  | 
                                                        |
| 277 | -  | 
                                                        |
| 278 | -        if ($filteredValue === null) { | 
                                                        |
| 279 | - return null;  | 
                                                        |
| 280 | - }  | 
                                                        |
| 281 | -  | 
                                                        |
| 282 | - return (int)$filteredValue;  | 
                                                        |
| 283 | - }  | 
                                                        |
| 284 | -  | 
                                                        |
| 285 | - /**  | 
                                                        |
| 286 | - * @param string $key  | 
                                                        |
| 287 | - *  | 
                                                        |
| 288 | - * @return null|string  | 
                                                        |
| 289 | - */  | 
                                                        |
| 290 | - public static function getString($key)  | 
                                                        |
| 291 | -    { | 
                                                        |
| 292 | - $get = &self::$globalStateProvider->getGetSuperGlobal();  | 
                                                        |
| 293 | -        if (!array_key_exists($key, $get)) { | 
                                                        |
| 294 | - return null;  | 
                                                        |
| 295 | - }  | 
                                                        |
| 296 | -  | 
                                                        |
| 297 | -        if ($get[$key] === "") { | 
                                                        |
| 298 | - return null;  | 
                                                        |
| 299 | - }  | 
                                                        |
| 300 | -  | 
                                                        |
| 301 | - return (string)$get[$key];  | 
                                                        |
| 302 | - }  | 
                                                        |
| 303 | -  | 
                                                        |
| 304 | - #endregion  | 
                                                        |
| 305 | -  | 
                                                        |
| 306 | - /**  | 
                                                        |
| 307 | - * Sets the logged-in user to the specified user.  | 
                                                        |
| 308 | - *  | 
                                                        |
| 309 | - * @param User $user  | 
                                                        |
| 310 | - */  | 
                                                        |
| 311 | - public static function setLoggedInUser(User $user)  | 
                                                        |
| 312 | -    { | 
                                                        |
| 313 | - $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 314 | -  | 
                                                        |
| 315 | - $session['userID'] = $user->getId();  | 
                                                        |
| 316 | - unset($session['partialLogin']);  | 
                                                        |
| 317 | - }  | 
                                                        |
| 318 | -  | 
                                                        |
| 319 | - /**  | 
                                                        |
| 320 | - * Sets the post-login redirect  | 
                                                        |
| 321 | - */  | 
                                                        |
| 322 | - public static function setPostLoginRedirect()  | 
                                                        |
| 323 | -    { | 
                                                        |
| 324 | - $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 325 | - $session['returnTo'] = self::requestUri();  | 
                                                        |
| 326 | - }  | 
                                                        |
| 327 | -  | 
                                                        |
| 328 | - /**  | 
                                                        |
| 329 | - * @return string|null  | 
                                                        |
| 330 | - */  | 
                                                        |
| 331 | - public static function requestUri()  | 
                                                        |
| 332 | -    { | 
                                                        |
| 333 | - $server = &self::$globalStateProvider->getServerSuperGlobal();  | 
                                                        |
| 334 | -  | 
                                                        |
| 335 | -        if (isset($server['REQUEST_URI'])) { | 
                                                        |
| 336 | - return $server['REQUEST_URI'];  | 
                                                        |
| 337 | - }  | 
                                                        |
| 338 | -  | 
                                                        |
| 339 | - return null;  | 
                                                        |
| 340 | - }  | 
                                                        |
| 341 | -  | 
                                                        |
| 342 | - /**  | 
                                                        |
| 343 | - * Clears the post-login redirect  | 
                                                        |
| 344 | - * @return string  | 
                                                        |
| 345 | - */  | 
                                                        |
| 346 | - public static function clearPostLoginRedirect()  | 
                                                        |
| 347 | -    { | 
                                                        |
| 348 | - $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 349 | -        if (array_key_exists('returnTo', $session)) { | 
                                                        |
| 350 | - $path = $session['returnTo'];  | 
                                                        |
| 351 | - unset($session['returnTo']);  | 
                                                        |
| 352 | -  | 
                                                        |
| 353 | - return $path;  | 
                                                        |
| 354 | - }  | 
                                                        |
| 355 | -  | 
                                                        |
| 356 | - return null;  | 
                                                        |
| 357 | - }  | 
                                                        |
| 358 | -  | 
                                                        |
| 359 | - /**  | 
                                                        |
| 360 | - * @return string|null  | 
                                                        |
| 361 | - */  | 
                                                        |
| 362 | - public static function serverName()  | 
                                                        |
| 363 | -    { | 
                                                        |
| 364 | - $server = &self::$globalStateProvider->getServerSuperGlobal();  | 
                                                        |
| 365 | -  | 
                                                        |
| 366 | -        if (isset($server['SERVER_NAME'])) { | 
                                                        |
| 367 | - return $server['SERVER_NAME'];  | 
                                                        |
| 368 | - }  | 
                                                        |
| 369 | -  | 
                                                        |
| 370 | - return null;  | 
                                                        |
| 371 | - }  | 
                                                        |
| 372 | -  | 
                                                        |
| 373 | - /**  | 
                                                        |
| 374 | - * You probably only want to deal with this through SessionAlert.  | 
                                                        |
| 375 | - * @return void  | 
                                                        |
| 376 | - */  | 
                                                        |
| 377 | - public static function clearSessionAlertData()  | 
                                                        |
| 378 | -    { | 
                                                        |
| 379 | - $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 380 | -        if (array_key_exists('alerts', $session)) { | 
                                                        |
| 381 | - unset($session['alerts']);  | 
                                                        |
| 382 | - }  | 
                                                        |
| 383 | - }  | 
                                                        |
| 384 | -  | 
                                                        |
| 385 | - /**  | 
                                                        |
| 386 | - * You probably only want to deal with this through SessionAlert.  | 
                                                        |
| 387 | - *  | 
                                                        |
| 388 | - * @return string[]  | 
                                                        |
| 389 | - */  | 
                                                        |
| 390 | - public static function getSessionAlertData()  | 
                                                        |
| 391 | -    { | 
                                                        |
| 392 | - $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 393 | -        if (array_key_exists('alerts', $session)) { | 
                                                        |
| 394 | - return $session['alerts'];  | 
                                                        |
| 395 | - }  | 
                                                        |
| 396 | -  | 
                                                        |
| 397 | - return array();  | 
                                                        |
| 398 | - }  | 
                                                        |
| 399 | -  | 
                                                        |
| 400 | - /**  | 
                                                        |
| 401 | - * You probably only want to deal with this through SessionAlert.  | 
                                                        |
| 402 | - *  | 
                                                        |
| 403 | - * @param string[] $data  | 
                                                        |
| 404 | - */  | 
                                                        |
| 405 | - public static function setSessionAlertData($data)  | 
                                                        |
| 406 | -    { | 
                                                        |
| 407 | - $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 408 | - $session['alerts'] = $data;  | 
                                                        |
| 409 | - }  | 
                                                        |
| 410 | -  | 
                                                        |
| 411 | - /**  | 
                                                        |
| 412 | - * You probably only want to deal with this through TokenManager.  | 
                                                        |
| 413 | - *  | 
                                                        |
| 414 | - * @return string[]  | 
                                                        |
| 415 | - */  | 
                                                        |
| 416 | - public static function getSessionTokenData()  | 
                                                        |
| 417 | -    { | 
                                                        |
| 418 | - $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 419 | -        if (array_key_exists('tokens', $session)) { | 
                                                        |
| 420 | - return $session['tokens'];  | 
                                                        |
| 421 | - }  | 
                                                        |
| 422 | -  | 
                                                        |
| 423 | - return array();  | 
                                                        |
| 424 | - }  | 
                                                        |
| 425 | -  | 
                                                        |
| 426 | - /**  | 
                                                        |
| 427 | - * You probably only want to deal with this through TokenManager.  | 
                                                        |
| 428 | - *  | 
                                                        |
| 429 | - * @param string[] $data  | 
                                                        |
| 430 | - */  | 
                                                        |
| 431 | - public static function setSessionTokenData($data)  | 
                                                        |
| 432 | -    { | 
                                                        |
| 433 | - $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 434 | - $session['tokens'] = $data;  | 
                                                        |
| 435 | - }  | 
                                                        |
| 436 | -  | 
                                                        |
| 437 | - /**  | 
                                                        |
| 438 | - * @param string $key  | 
                                                        |
| 439 | - *  | 
                                                        |
| 440 | - * @return mixed  | 
                                                        |
| 441 | - */  | 
                                                        |
| 442 | - public static function getSessionContext($key)  | 
                                                        |
| 443 | -    { | 
                                                        |
| 444 | - $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 445 | -  | 
                                                        |
| 446 | -        if (!isset($session['context'])) { | 
                                                        |
| 447 | - $session['context'] = array();  | 
                                                        |
| 448 | - }  | 
                                                        |
| 449 | -  | 
                                                        |
| 450 | -        if (!isset($session['context'][$key])) { | 
                                                        |
| 451 | - return null;  | 
                                                        |
| 452 | - }  | 
                                                        |
| 453 | -  | 
                                                        |
| 454 | - return $session['context'][$key];  | 
                                                        |
| 455 | - }  | 
                                                        |
| 456 | -  | 
                                                        |
| 457 | - /**  | 
                                                        |
| 458 | - * @param string $key  | 
                                                        |
| 459 | - * @param mixed $data  | 
                                                        |
| 460 | - */  | 
                                                        |
| 461 | - public static function setSessionContext($key, $data)  | 
                                                        |
| 462 | -    { | 
                                                        |
| 463 | - $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 464 | -  | 
                                                        |
| 465 | -        if (!isset($session['context'])) { | 
                                                        |
| 466 | - $session['context'] = array();  | 
                                                        |
| 467 | - }  | 
                                                        |
| 468 | -  | 
                                                        |
| 469 | - $session['context'][$key] = $data;  | 
                                                        |
| 470 | - }  | 
                                                        |
| 471 | -  | 
                                                        |
| 472 | - /**  | 
                                                        |
| 473 | - * @return int|null  | 
                                                        |
| 474 | - */  | 
                                                        |
| 475 | - public static function getSessionUserId()  | 
                                                        |
| 476 | -    { | 
                                                        |
| 477 | - $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 478 | -  | 
                                                        |
| 479 | - return isset($session['userID']) ? (int)$session['userID'] : null;  | 
                                                        |
| 480 | - }  | 
                                                        |
| 481 | -  | 
                                                        |
| 482 | - /**  | 
                                                        |
| 483 | - * @param User $user  | 
                                                        |
| 484 | - */  | 
                                                        |
| 485 | - public static function setPartialLogin(User $user)  | 
                                                        |
| 486 | -    { | 
                                                        |
| 487 | - $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 488 | - $session['partialLogin'] = $user->getId();  | 
                                                        |
| 489 | - }  | 
                                                        |
| 490 | -  | 
                                                        |
| 491 | - /**  | 
                                                        |
| 492 | - * @return int|null  | 
                                                        |
| 493 | - */  | 
                                                        |
| 494 | - public static function getPartialLogin()  | 
                                                        |
| 495 | -    { | 
                                                        |
| 496 | - $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 497 | -  | 
                                                        |
| 498 | - return isset($session['partialLogin']) ? (int)$session['partialLogin'] : null;  | 
                                                        |
| 499 | - }  | 
                                                        |
| 500 | -  | 
                                                        |
| 501 | - /**  | 
                                                        |
| 502 | - * @return null|string  | 
                                                        |
| 503 | - */  | 
                                                        |
| 504 | - public static function userAgent()  | 
                                                        |
| 505 | -    { | 
                                                        |
| 506 | - $server = &self::$globalStateProvider->getServerSuperGlobal();  | 
                                                        |
| 507 | -  | 
                                                        |
| 508 | -        if (isset($server['HTTP_USER_AGENT'])) { | 
                                                        |
| 509 | - return $server['HTTP_USER_AGENT'];  | 
                                                        |
| 510 | - }  | 
                                                        |
| 511 | -  | 
                                                        |
| 512 | - return null;  | 
                                                        |
| 513 | - }  | 
                                                        |
| 514 | -  | 
                                                        |
| 515 | - /**  | 
                                                        |
| 516 | - * @return null|string  | 
                                                        |
| 517 | - */  | 
                                                        |
| 518 | - public static function scriptName()  | 
                                                        |
| 519 | -    { | 
                                                        |
| 520 | - $server = &self::$globalStateProvider->getServerSuperGlobal();  | 
                                                        |
| 521 | -  | 
                                                        |
| 522 | -        if (isset($server['SCRIPT_NAME'])) { | 
                                                        |
| 523 | - return $server['SCRIPT_NAME'];  | 
                                                        |
| 524 | - }  | 
                                                        |
| 525 | -  | 
                                                        |
| 526 | - return null;  | 
                                                        |
| 527 | - }  | 
                                                        |
| 528 | -  | 
                                                        |
| 529 | - /**  | 
                                                        |
| 530 | - * @return null|string  | 
                                                        |
| 531 | - */  | 
                                                        |
| 532 | - public static function origin()  | 
                                                        |
| 533 | -    { | 
                                                        |
| 534 | - $server = &self::$globalStateProvider->getServerSuperGlobal();  | 
                                                        |
| 535 | -  | 
                                                        |
| 536 | -        if (isset($server['HTTP_ORIGIN'])) { | 
                                                        |
| 537 | - return $server['HTTP_ORIGIN'];  | 
                                                        |
| 538 | - }  | 
                                                        |
| 539 | -  | 
                                                        |
| 540 | - return null;  | 
                                                        |
| 541 | - }  | 
                                                        |
| 25 | + /**  | 
                                                        |
| 26 | + * @var \Waca\Providers\GlobalState\IGlobalStateProvider Provides access to the global state.  | 
                                                        |
| 27 | + */  | 
                                                        |
| 28 | + private static $globalStateProvider;  | 
                                                        |
| 29 | +  | 
                                                        |
| 30 | + /**  | 
                                                        |
| 31 | + * Returns a boolean value if the request was submitted with the HTTP POST method.  | 
                                                        |
| 32 | + * @return bool  | 
                                                        |
| 33 | + */  | 
                                                        |
| 34 | + public static function wasPosted()  | 
                                                        |
| 35 | +	{ | 
                                                        |
| 36 | + return self::method() === 'POST';  | 
                                                        |
| 37 | + }  | 
                                                        |
| 38 | +  | 
                                                        |
| 39 | + /**  | 
                                                        |
| 40 | + * Gets the HTTP Method used  | 
                                                        |
| 41 | + * @return string|null  | 
                                                        |
| 42 | + */  | 
                                                        |
| 43 | + public static function method()  | 
                                                        |
| 44 | +	{ | 
                                                        |
| 45 | + $server = &self::$globalStateProvider->getServerSuperGlobal();  | 
                                                        |
| 46 | +  | 
                                                        |
| 47 | +		if (isset($server['REQUEST_METHOD'])) { | 
                                                        |
| 48 | + return $server['REQUEST_METHOD'];  | 
                                                        |
| 49 | + }  | 
                                                        |
| 50 | +  | 
                                                        |
| 51 | + return null;  | 
                                                        |
| 52 | + }  | 
                                                        |
| 53 | +  | 
                                                        |
| 54 | + /**  | 
                                                        |
| 55 | + * Gets a boolean value stating whether the request was served over HTTPS or not.  | 
                                                        |
| 56 | + * @return bool  | 
                                                        |
| 57 | + */  | 
                                                        |
| 58 | + public static function isHttps()  | 
                                                        |
| 59 | +	{ | 
                                                        |
| 60 | + $server = &self::$globalStateProvider->getServerSuperGlobal();  | 
                                                        |
| 61 | +  | 
                                                        |
| 62 | +		if (isset($server['HTTP_X_FORWARDED_PROTO'])) { | 
                                                        |
| 63 | +			if ($server['HTTP_X_FORWARDED_PROTO'] === 'https') { | 
                                                        |
| 64 | + // Client <=> Proxy is encrypted  | 
                                                        |
| 65 | + return true;  | 
                                                        |
| 66 | + }  | 
                                                        |
| 67 | +			else { | 
                                                        |
| 68 | + // Proxy <=> Server link unknown, Client <=> Proxy is not encrypted.  | 
                                                        |
| 69 | + return false;  | 
                                                        |
| 70 | + }  | 
                                                        |
| 71 | + }  | 
                                                        |
| 72 | +  | 
                                                        |
| 73 | +		if (isset($server['HTTPS'])) { | 
                                                        |
| 74 | +			if ($server['HTTPS'] === 'off') { | 
                                                        |
| 75 | + // ISAPI on IIS breaks the spec. :(  | 
                                                        |
| 76 | + return false;  | 
                                                        |
| 77 | + }  | 
                                                        |
| 78 | +  | 
                                                        |
| 79 | +			if ($server['HTTPS'] !== '') { | 
                                                        |
| 80 | + // Set to a non-empty value  | 
                                                        |
| 81 | + return true;  | 
                                                        |
| 82 | + }  | 
                                                        |
| 83 | + }  | 
                                                        |
| 84 | +  | 
                                                        |
| 85 | + return false;  | 
                                                        |
| 86 | + }  | 
                                                        |
| 87 | +  | 
                                                        |
| 88 | + /**  | 
                                                        |
| 89 | + * Gets the path info  | 
                                                        |
| 90 | + *  | 
                                                        |
| 91 | + * @return array Array of path info segments  | 
                                                        |
| 92 | + */  | 
                                                        |
| 93 | + public static function pathInfo()  | 
                                                        |
| 94 | +	{ | 
                                                        |
| 95 | + $server = &self::$globalStateProvider->getServerSuperGlobal();  | 
                                                        |
| 96 | +		if (!isset($server['PATH_INFO'])) { | 
                                                        |
| 97 | + return array();  | 
                                                        |
| 98 | + }  | 
                                                        |
| 99 | +  | 
                                                        |
| 100 | +		$exploded = explode('/', $server['PATH_INFO']); | 
                                                        |
| 101 | +  | 
                                                        |
| 102 | + // filter out empty values, and reindex from zero. Notably, the first element is always zero, since it starts  | 
                                                        |
| 103 | + // with a /  | 
                                                        |
| 104 | + return array_values(array_filter($exploded));  | 
                                                        |
| 105 | + }  | 
                                                        |
| 106 | +  | 
                                                        |
| 107 | + /**  | 
                                                        |
| 108 | + * Gets the remote address of the web request  | 
                                                        |
| 109 | + * @return null|string  | 
                                                        |
| 110 | + */  | 
                                                        |
| 111 | + public static function remoteAddress()  | 
                                                        |
| 112 | +	{ | 
                                                        |
| 113 | + $server = &self::$globalStateProvider->getServerSuperGlobal();  | 
                                                        |
| 114 | +  | 
                                                        |
| 115 | +		if (isset($server['REMOTE_ADDR'])) { | 
                                                        |
| 116 | + return $server['REMOTE_ADDR'];  | 
                                                        |
| 117 | + }  | 
                                                        |
| 118 | +  | 
                                                        |
| 119 | + return null;  | 
                                                        |
| 120 | + }  | 
                                                        |
| 121 | +  | 
                                                        |
| 122 | + /**  | 
                                                        |
| 123 | + * Gets the XFF header contents for the web request  | 
                                                        |
| 124 | + * @return null|string  | 
                                                        |
| 125 | + */  | 
                                                        |
| 126 | + public static function forwardedAddress()  | 
                                                        |
| 127 | +	{ | 
                                                        |
| 128 | + $server = &self::$globalStateProvider->getServerSuperGlobal();  | 
                                                        |
| 129 | +  | 
                                                        |
| 130 | +		if (isset($server['HTTP_X_FORWARDED_FOR'])) { | 
                                                        |
| 131 | + return $server['HTTP_X_FORWARDED_FOR'];  | 
                                                        |
| 132 | + }  | 
                                                        |
| 133 | +  | 
                                                        |
| 134 | + return null;  | 
                                                        |
| 135 | + }  | 
                                                        |
| 136 | +  | 
                                                        |
| 137 | + /**  | 
                                                        |
| 138 | + * Sets the global state provider.  | 
                                                        |
| 139 | + *  | 
                                                        |
| 140 | + * Almost guaranteed this is not the method you want in production code.  | 
                                                        |
| 141 | + *  | 
                                                        |
| 142 | + * @param \Waca\Providers\GlobalState\IGlobalStateProvider $globalState  | 
                                                        |
| 143 | + */  | 
                                                        |
| 144 | + public static function setGlobalStateProvider($globalState)  | 
                                                        |
| 145 | +	{ | 
                                                        |
| 146 | + self::$globalStateProvider = $globalState;  | 
                                                        |
| 147 | + }  | 
                                                        |
| 148 | +  | 
                                                        |
| 149 | + #region POST variables  | 
                                                        |
| 150 | +  | 
                                                        |
| 151 | + /**  | 
                                                        |
| 152 | + * @param string $key  | 
                                                        |
| 153 | + *  | 
                                                        |
| 154 | + * @return null|string  | 
                                                        |
| 155 | + */  | 
                                                        |
| 156 | + public static function postString($key)  | 
                                                        |
| 157 | +	{ | 
                                                        |
| 158 | + $post = &self::$globalStateProvider->getPostSuperGlobal();  | 
                                                        |
| 159 | +		if (!array_key_exists($key, $post)) { | 
                                                        |
| 160 | + return null;  | 
                                                        |
| 161 | + }  | 
                                                        |
| 162 | +  | 
                                                        |
| 163 | +		if ($post[$key] === "") { | 
                                                        |
| 164 | + return null;  | 
                                                        |
| 165 | + }  | 
                                                        |
| 166 | +  | 
                                                        |
| 167 | + return (string)$post[$key];  | 
                                                        |
| 168 | + }  | 
                                                        |
| 169 | +  | 
                                                        |
| 170 | + /**  | 
                                                        |
| 171 | + * @param string $key  | 
                                                        |
| 172 | + *  | 
                                                        |
| 173 | + * @return null|string  | 
                                                        |
| 174 | + */  | 
                                                        |
| 175 | + public static function postEmail($key)  | 
                                                        |
| 176 | +	{ | 
                                                        |
| 177 | + $post = &self::$globalStateProvider->getPostSuperGlobal();  | 
                                                        |
| 178 | +		if (!array_key_exists($key, $post)) { | 
                                                        |
| 179 | + return null;  | 
                                                        |
| 180 | + }  | 
                                                        |
| 181 | +  | 
                                                        |
| 182 | + $filteredValue = filter_var($post[$key], FILTER_SANITIZE_EMAIL);  | 
                                                        |
| 183 | +  | 
                                                        |
| 184 | +		if ($filteredValue === false) { | 
                                                        |
| 185 | + return null;  | 
                                                        |
| 186 | + }  | 
                                                        |
| 187 | +  | 
                                                        |
| 188 | + return (string)$filteredValue;  | 
                                                        |
| 189 | + }  | 
                                                        |
| 190 | +  | 
                                                        |
| 191 | + /**  | 
                                                        |
| 192 | + * @param string $key  | 
                                                        |
| 193 | + *  | 
                                                        |
| 194 | + * @return int|null  | 
                                                        |
| 195 | + */  | 
                                                        |
| 196 | + public static function postInt($key)  | 
                                                        |
| 197 | +	{ | 
                                                        |
| 198 | + $post = &self::$globalStateProvider->getPostSuperGlobal();  | 
                                                        |
| 199 | +		if (!array_key_exists($key, $post)) { | 
                                                        |
| 200 | + return null;  | 
                                                        |
| 201 | + }  | 
                                                        |
| 202 | +  | 
                                                        |
| 203 | + $filteredValue = filter_var($post[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);  | 
                                                        |
| 204 | +  | 
                                                        |
| 205 | +		if ($filteredValue === null) { | 
                                                        |
| 206 | + return null;  | 
                                                        |
| 207 | + }  | 
                                                        |
| 208 | +  | 
                                                        |
| 209 | + return (int)$filteredValue;  | 
                                                        |
| 210 | + }  | 
                                                        |
| 211 | +  | 
                                                        |
| 212 | + /**  | 
                                                        |
| 213 | + * @param string $key  | 
                                                        |
| 214 | + *  | 
                                                        |
| 215 | + * @return bool  | 
                                                        |
| 216 | + */  | 
                                                        |
| 217 | + public static function postBoolean($key)  | 
                                                        |
| 218 | +	{ | 
                                                        |
| 219 | + $get = &self::$globalStateProvider->getPostSuperGlobal();  | 
                                                        |
| 220 | +		if (!array_key_exists($key, $get)) { | 
                                                        |
| 221 | + return false;  | 
                                                        |
| 222 | + }  | 
                                                        |
| 223 | +  | 
                                                        |
| 224 | + // presence of parameter only  | 
                                                        |
| 225 | +		if ($get[$key] === "") { | 
                                                        |
| 226 | + return true;  | 
                                                        |
| 227 | + }  | 
                                                        |
| 228 | +  | 
                                                        |
| 229 | +		if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { | 
                                                        |
| 230 | + return false;  | 
                                                        |
| 231 | + }  | 
                                                        |
| 232 | +  | 
                                                        |
| 233 | + return true;  | 
                                                        |
| 234 | + }  | 
                                                        |
| 235 | +  | 
                                                        |
| 236 | + #endregion  | 
                                                        |
| 237 | +  | 
                                                        |
| 238 | + #region GET variables  | 
                                                        |
| 239 | +  | 
                                                        |
| 240 | + /**  | 
                                                        |
| 241 | + * @param string $key  | 
                                                        |
| 242 | + *  | 
                                                        |
| 243 | + * @return bool  | 
                                                        |
| 244 | + */  | 
                                                        |
| 245 | + public static function getBoolean($key)  | 
                                                        |
| 246 | +	{ | 
                                                        |
| 247 | + $get = &self::$globalStateProvider->getGetSuperGlobal();  | 
                                                        |
| 248 | +		if (!array_key_exists($key, $get)) { | 
                                                        |
| 249 | + return false;  | 
                                                        |
| 250 | + }  | 
                                                        |
| 251 | +  | 
                                                        |
| 252 | + // presence of parameter only  | 
                                                        |
| 253 | +		if ($get[$key] === "") { | 
                                                        |
| 254 | + return true;  | 
                                                        |
| 255 | + }  | 
                                                        |
| 256 | +  | 
                                                        |
| 257 | +		if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { | 
                                                        |
| 258 | + return false;  | 
                                                        |
| 259 | + }  | 
                                                        |
| 260 | +  | 
                                                        |
| 261 | + return true;  | 
                                                        |
| 262 | + }  | 
                                                        |
| 263 | +  | 
                                                        |
| 264 | + /**  | 
                                                        |
| 265 | + * @param string $key  | 
                                                        |
| 266 | + *  | 
                                                        |
| 267 | + * @return int|null  | 
                                                        |
| 268 | + */  | 
                                                        |
| 269 | + public static function getInt($key)  | 
                                                        |
| 270 | +	{ | 
                                                        |
| 271 | + $get = &self::$globalStateProvider->getGetSuperGlobal();  | 
                                                        |
| 272 | +		if (!array_key_exists($key, $get)) { | 
                                                        |
| 273 | + return null;  | 
                                                        |
| 274 | + }  | 
                                                        |
| 275 | +  | 
                                                        |
| 276 | + $filteredValue = filter_var($get[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);  | 
                                                        |
| 277 | +  | 
                                                        |
| 278 | +		if ($filteredValue === null) { | 
                                                        |
| 279 | + return null;  | 
                                                        |
| 280 | + }  | 
                                                        |
| 281 | +  | 
                                                        |
| 282 | + return (int)$filteredValue;  | 
                                                        |
| 283 | + }  | 
                                                        |
| 284 | +  | 
                                                        |
| 285 | + /**  | 
                                                        |
| 286 | + * @param string $key  | 
                                                        |
| 287 | + *  | 
                                                        |
| 288 | + * @return null|string  | 
                                                        |
| 289 | + */  | 
                                                        |
| 290 | + public static function getString($key)  | 
                                                        |
| 291 | +	{ | 
                                                        |
| 292 | + $get = &self::$globalStateProvider->getGetSuperGlobal();  | 
                                                        |
| 293 | +		if (!array_key_exists($key, $get)) { | 
                                                        |
| 294 | + return null;  | 
                                                        |
| 295 | + }  | 
                                                        |
| 296 | +  | 
                                                        |
| 297 | +		if ($get[$key] === "") { | 
                                                        |
| 298 | + return null;  | 
                                                        |
| 299 | + }  | 
                                                        |
| 300 | +  | 
                                                        |
| 301 | + return (string)$get[$key];  | 
                                                        |
| 302 | + }  | 
                                                        |
| 303 | +  | 
                                                        |
| 304 | + #endregion  | 
                                                        |
| 305 | +  | 
                                                        |
| 306 | + /**  | 
                                                        |
| 307 | + * Sets the logged-in user to the specified user.  | 
                                                        |
| 308 | + *  | 
                                                        |
| 309 | + * @param User $user  | 
                                                        |
| 310 | + */  | 
                                                        |
| 311 | + public static function setLoggedInUser(User $user)  | 
                                                        |
| 312 | +	{ | 
                                                        |
| 313 | + $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 314 | +  | 
                                                        |
| 315 | + $session['userID'] = $user->getId();  | 
                                                        |
| 316 | + unset($session['partialLogin']);  | 
                                                        |
| 317 | + }  | 
                                                        |
| 318 | +  | 
                                                        |
| 319 | + /**  | 
                                                        |
| 320 | + * Sets the post-login redirect  | 
                                                        |
| 321 | + */  | 
                                                        |
| 322 | + public static function setPostLoginRedirect()  | 
                                                        |
| 323 | +	{ | 
                                                        |
| 324 | + $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 325 | + $session['returnTo'] = self::requestUri();  | 
                                                        |
| 326 | + }  | 
                                                        |
| 327 | +  | 
                                                        |
| 328 | + /**  | 
                                                        |
| 329 | + * @return string|null  | 
                                                        |
| 330 | + */  | 
                                                        |
| 331 | + public static function requestUri()  | 
                                                        |
| 332 | +	{ | 
                                                        |
| 333 | + $server = &self::$globalStateProvider->getServerSuperGlobal();  | 
                                                        |
| 334 | +  | 
                                                        |
| 335 | +		if (isset($server['REQUEST_URI'])) { | 
                                                        |
| 336 | + return $server['REQUEST_URI'];  | 
                                                        |
| 337 | + }  | 
                                                        |
| 338 | +  | 
                                                        |
| 339 | + return null;  | 
                                                        |
| 340 | + }  | 
                                                        |
| 341 | +  | 
                                                        |
| 342 | + /**  | 
                                                        |
| 343 | + * Clears the post-login redirect  | 
                                                        |
| 344 | + * @return string  | 
                                                        |
| 345 | + */  | 
                                                        |
| 346 | + public static function clearPostLoginRedirect()  | 
                                                        |
| 347 | +	{ | 
                                                        |
| 348 | + $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 349 | +		if (array_key_exists('returnTo', $session)) { | 
                                                        |
| 350 | + $path = $session['returnTo'];  | 
                                                        |
| 351 | + unset($session['returnTo']);  | 
                                                        |
| 352 | +  | 
                                                        |
| 353 | + return $path;  | 
                                                        |
| 354 | + }  | 
                                                        |
| 355 | +  | 
                                                        |
| 356 | + return null;  | 
                                                        |
| 357 | + }  | 
                                                        |
| 358 | +  | 
                                                        |
| 359 | + /**  | 
                                                        |
| 360 | + * @return string|null  | 
                                                        |
| 361 | + */  | 
                                                        |
| 362 | + public static function serverName()  | 
                                                        |
| 363 | +	{ | 
                                                        |
| 364 | + $server = &self::$globalStateProvider->getServerSuperGlobal();  | 
                                                        |
| 365 | +  | 
                                                        |
| 366 | +		if (isset($server['SERVER_NAME'])) { | 
                                                        |
| 367 | + return $server['SERVER_NAME'];  | 
                                                        |
| 368 | + }  | 
                                                        |
| 369 | +  | 
                                                        |
| 370 | + return null;  | 
                                                        |
| 371 | + }  | 
                                                        |
| 372 | +  | 
                                                        |
| 373 | + /**  | 
                                                        |
| 374 | + * You probably only want to deal with this through SessionAlert.  | 
                                                        |
| 375 | + * @return void  | 
                                                        |
| 376 | + */  | 
                                                        |
| 377 | + public static function clearSessionAlertData()  | 
                                                        |
| 378 | +	{ | 
                                                        |
| 379 | + $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 380 | +		if (array_key_exists('alerts', $session)) { | 
                                                        |
| 381 | + unset($session['alerts']);  | 
                                                        |
| 382 | + }  | 
                                                        |
| 383 | + }  | 
                                                        |
| 384 | +  | 
                                                        |
| 385 | + /**  | 
                                                        |
| 386 | + * You probably only want to deal with this through SessionAlert.  | 
                                                        |
| 387 | + *  | 
                                                        |
| 388 | + * @return string[]  | 
                                                        |
| 389 | + */  | 
                                                        |
| 390 | + public static function getSessionAlertData()  | 
                                                        |
| 391 | +	{ | 
                                                        |
| 392 | + $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 393 | +		if (array_key_exists('alerts', $session)) { | 
                                                        |
| 394 | + return $session['alerts'];  | 
                                                        |
| 395 | + }  | 
                                                        |
| 396 | +  | 
                                                        |
| 397 | + return array();  | 
                                                        |
| 398 | + }  | 
                                                        |
| 399 | +  | 
                                                        |
| 400 | + /**  | 
                                                        |
| 401 | + * You probably only want to deal with this through SessionAlert.  | 
                                                        |
| 402 | + *  | 
                                                        |
| 403 | + * @param string[] $data  | 
                                                        |
| 404 | + */  | 
                                                        |
| 405 | + public static function setSessionAlertData($data)  | 
                                                        |
| 406 | +	{ | 
                                                        |
| 407 | + $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 408 | + $session['alerts'] = $data;  | 
                                                        |
| 409 | + }  | 
                                                        |
| 410 | +  | 
                                                        |
| 411 | + /**  | 
                                                        |
| 412 | + * You probably only want to deal with this through TokenManager.  | 
                                                        |
| 413 | + *  | 
                                                        |
| 414 | + * @return string[]  | 
                                                        |
| 415 | + */  | 
                                                        |
| 416 | + public static function getSessionTokenData()  | 
                                                        |
| 417 | +	{ | 
                                                        |
| 418 | + $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 419 | +		if (array_key_exists('tokens', $session)) { | 
                                                        |
| 420 | + return $session['tokens'];  | 
                                                        |
| 421 | + }  | 
                                                        |
| 422 | +  | 
                                                        |
| 423 | + return array();  | 
                                                        |
| 424 | + }  | 
                                                        |
| 425 | +  | 
                                                        |
| 426 | + /**  | 
                                                        |
| 427 | + * You probably only want to deal with this through TokenManager.  | 
                                                        |
| 428 | + *  | 
                                                        |
| 429 | + * @param string[] $data  | 
                                                        |
| 430 | + */  | 
                                                        |
| 431 | + public static function setSessionTokenData($data)  | 
                                                        |
| 432 | +	{ | 
                                                        |
| 433 | + $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 434 | + $session['tokens'] = $data;  | 
                                                        |
| 435 | + }  | 
                                                        |
| 436 | +  | 
                                                        |
| 437 | + /**  | 
                                                        |
| 438 | + * @param string $key  | 
                                                        |
| 439 | + *  | 
                                                        |
| 440 | + * @return mixed  | 
                                                        |
| 441 | + */  | 
                                                        |
| 442 | + public static function getSessionContext($key)  | 
                                                        |
| 443 | +	{ | 
                                                        |
| 444 | + $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 445 | +  | 
                                                        |
| 446 | +		if (!isset($session['context'])) { | 
                                                        |
| 447 | + $session['context'] = array();  | 
                                                        |
| 448 | + }  | 
                                                        |
| 449 | +  | 
                                                        |
| 450 | +		if (!isset($session['context'][$key])) { | 
                                                        |
| 451 | + return null;  | 
                                                        |
| 452 | + }  | 
                                                        |
| 453 | +  | 
                                                        |
| 454 | + return $session['context'][$key];  | 
                                                        |
| 455 | + }  | 
                                                        |
| 456 | +  | 
                                                        |
| 457 | + /**  | 
                                                        |
| 458 | + * @param string $key  | 
                                                        |
| 459 | + * @param mixed $data  | 
                                                        |
| 460 | + */  | 
                                                        |
| 461 | + public static function setSessionContext($key, $data)  | 
                                                        |
| 462 | +	{ | 
                                                        |
| 463 | + $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 464 | +  | 
                                                        |
| 465 | +		if (!isset($session['context'])) { | 
                                                        |
| 466 | + $session['context'] = array();  | 
                                                        |
| 467 | + }  | 
                                                        |
| 468 | +  | 
                                                        |
| 469 | + $session['context'][$key] = $data;  | 
                                                        |
| 470 | + }  | 
                                                        |
| 471 | +  | 
                                                        |
| 472 | + /**  | 
                                                        |
| 473 | + * @return int|null  | 
                                                        |
| 474 | + */  | 
                                                        |
| 475 | + public static function getSessionUserId()  | 
                                                        |
| 476 | +	{ | 
                                                        |
| 477 | + $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 478 | +  | 
                                                        |
| 479 | + return isset($session['userID']) ? (int)$session['userID'] : null;  | 
                                                        |
| 480 | + }  | 
                                                        |
| 481 | +  | 
                                                        |
| 482 | + /**  | 
                                                        |
| 483 | + * @param User $user  | 
                                                        |
| 484 | + */  | 
                                                        |
| 485 | + public static function setPartialLogin(User $user)  | 
                                                        |
| 486 | +	{ | 
                                                        |
| 487 | + $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 488 | + $session['partialLogin'] = $user->getId();  | 
                                                        |
| 489 | + }  | 
                                                        |
| 490 | +  | 
                                                        |
| 491 | + /**  | 
                                                        |
| 492 | + * @return int|null  | 
                                                        |
| 493 | + */  | 
                                                        |
| 494 | + public static function getPartialLogin()  | 
                                                        |
| 495 | +	{ | 
                                                        |
| 496 | + $session = &self::$globalStateProvider->getSessionSuperGlobal();  | 
                                                        |
| 497 | +  | 
                                                        |
| 498 | + return isset($session['partialLogin']) ? (int)$session['partialLogin'] : null;  | 
                                                        |
| 499 | + }  | 
                                                        |
| 500 | +  | 
                                                        |
| 501 | + /**  | 
                                                        |
| 502 | + * @return null|string  | 
                                                        |
| 503 | + */  | 
                                                        |
| 504 | + public static function userAgent()  | 
                                                        |
| 505 | +	{ | 
                                                        |
| 506 | + $server = &self::$globalStateProvider->getServerSuperGlobal();  | 
                                                        |
| 507 | +  | 
                                                        |
| 508 | +		if (isset($server['HTTP_USER_AGENT'])) { | 
                                                        |
| 509 | + return $server['HTTP_USER_AGENT'];  | 
                                                        |
| 510 | + }  | 
                                                        |
| 511 | +  | 
                                                        |
| 512 | + return null;  | 
                                                        |
| 513 | + }  | 
                                                        |
| 514 | +  | 
                                                        |
| 515 | + /**  | 
                                                        |
| 516 | + * @return null|string  | 
                                                        |
| 517 | + */  | 
                                                        |
| 518 | + public static function scriptName()  | 
                                                        |
| 519 | +	{ | 
                                                        |
| 520 | + $server = &self::$globalStateProvider->getServerSuperGlobal();  | 
                                                        |
| 521 | +  | 
                                                        |
| 522 | +		if (isset($server['SCRIPT_NAME'])) { | 
                                                        |
| 523 | + return $server['SCRIPT_NAME'];  | 
                                                        |
| 524 | + }  | 
                                                        |
| 525 | +  | 
                                                        |
| 526 | + return null;  | 
                                                        |
| 527 | + }  | 
                                                        |
| 528 | +  | 
                                                        |
| 529 | + /**  | 
                                                        |
| 530 | + * @return null|string  | 
                                                        |
| 531 | + */  | 
                                                        |
| 532 | + public static function origin()  | 
                                                        |
| 533 | +	{ | 
                                                        |
| 534 | + $server = &self::$globalStateProvider->getServerSuperGlobal();  | 
                                                        |
| 535 | +  | 
                                                        |
| 536 | +		if (isset($server['HTTP_ORIGIN'])) { | 
                                                        |
| 537 | + return $server['HTTP_ORIGIN'];  | 
                                                        |
| 538 | + }  | 
                                                        |
| 539 | +  | 
                                                        |
| 540 | + return null;  | 
                                                        |
| 541 | + }  | 
                                                        |
| 542 | 542 | }  | 
                                                        
| 543 | 543 | \ No newline at end of file  | 
                                                        
@@ -12,21 +12,21 @@  | 
                                                    ||
| 12 | 12 | |
| 13 | 13 | interface IRoutedTask extends ITask  | 
                                                        
| 14 | 14 |  { | 
                                                        
| 15 | - /**  | 
                                                        |
| 16 | - * Sets the route the request will take. Only should be called from the request router.  | 
                                                        |
| 17 | - *  | 
                                                        |
| 18 | - * @param $routeName string  | 
                                                        |
| 19 | - *  | 
                                                        |
| 20 | - * @return void  | 
                                                        |
| 21 | - *  | 
                                                        |
| 22 | - * @throws Exception  | 
                                                        |
| 23 | - * @category Security-Critical  | 
                                                        |
| 24 | - */  | 
                                                        |
| 25 | - public function setRoute($routeName);  | 
                                                        |
| 15 | + /**  | 
                                                        |
| 16 | + * Sets the route the request will take. Only should be called from the request router.  | 
                                                        |
| 17 | + *  | 
                                                        |
| 18 | + * @param $routeName string  | 
                                                        |
| 19 | + *  | 
                                                        |
| 20 | + * @return void  | 
                                                        |
| 21 | + *  | 
                                                        |
| 22 | + * @throws Exception  | 
                                                        |
| 23 | + * @category Security-Critical  | 
                                                        |
| 24 | + */  | 
                                                        |
| 25 | + public function setRoute($routeName);  | 
                                                        |
| 26 | 26 | |
| 27 | - /**  | 
                                                        |
| 28 | - * Gets the name of the route that has been passed from the request router.  | 
                                                        |
| 29 | - * @return string  | 
                                                        |
| 30 | - */  | 
                                                        |
| 31 | - public function getRouteName();  | 
                                                        |
| 27 | + /**  | 
                                                        |
| 28 | + * Gets the name of the route that has been passed from the request router.  | 
                                                        |
| 29 | + * @return string  | 
                                                        |
| 30 | + */  | 
                                                        |
| 31 | + public function getRouteName();  | 
                                                        |
| 32 | 32 | }  | 
                                                        
| 33 | 33 | \ No newline at end of file  | 
                                                        
@@ -22,215 +22,215 @@  | 
                                                    ||
| 22 | 22 | |
| 23 | 23 | abstract class InternalPageBase extends PageBase  | 
                                                        
| 24 | 24 |  { | 
                                                        
| 25 | - /** @var IdentificationVerifier */  | 
                                                        |
| 26 | - private $identificationVerifier;  | 
                                                        |
| 27 | - /** @var ITypeAheadHelper */  | 
                                                        |
| 28 | - private $typeAheadHelper;  | 
                                                        |
| 29 | - /** @var SecurityManager */  | 
                                                        |
| 30 | - private $securityManager;  | 
                                                        |
| 31 | - /** @var IBlacklistHelper */  | 
                                                        |
| 32 | - private $blacklistHelper;  | 
                                                        |
| 33 | -  | 
                                                        |
| 34 | - /**  | 
                                                        |
| 35 | - * @return ITypeAheadHelper  | 
                                                        |
| 36 | - */  | 
                                                        |
| 37 | - public function getTypeAheadHelper()  | 
                                                        |
| 38 | -    { | 
                                                        |
| 39 | - return $this->typeAheadHelper;  | 
                                                        |
| 40 | - }  | 
                                                        |
| 41 | -  | 
                                                        |
| 42 | - /**  | 
                                                        |
| 43 | - * Sets up the internal IdentificationVerifier instance. Intended to be called from WebStart::setupHelpers().  | 
                                                        |
| 44 | - *  | 
                                                        |
| 45 | - * @param IdentificationVerifier $identificationVerifier  | 
                                                        |
| 46 | - *  | 
                                                        |
| 47 | - * @return void  | 
                                                        |
| 48 | - */  | 
                                                        |
| 49 | - public function setIdentificationVerifier(IdentificationVerifier $identificationVerifier)  | 
                                                        |
| 50 | -    { | 
                                                        |
| 51 | - $this->identificationVerifier = $identificationVerifier;  | 
                                                        |
| 52 | - }  | 
                                                        |
| 53 | -  | 
                                                        |
| 54 | - /**  | 
                                                        |
| 55 | - * @param ITypeAheadHelper $typeAheadHelper  | 
                                                        |
| 56 | - */  | 
                                                        |
| 57 | - public function setTypeAheadHelper(ITypeAheadHelper $typeAheadHelper)  | 
                                                        |
| 58 | -    { | 
                                                        |
| 59 | - $this->typeAheadHelper = $typeAheadHelper;  | 
                                                        |
| 60 | - }  | 
                                                        |
| 61 | -  | 
                                                        |
| 62 | - /**  | 
                                                        |
| 63 | - * Runs the page code  | 
                                                        |
| 64 | - *  | 
                                                        |
| 65 | - * @throws Exception  | 
                                                        |
| 66 | - * @category Security-Critical  | 
                                                        |
| 67 | - */  | 
                                                        |
| 68 | - final public function execute()  | 
                                                        |
| 69 | -    { | 
                                                        |
| 70 | -        if ($this->getRouteName() === null) { | 
                                                        |
| 71 | -            throw new Exception("Request is unrouted."); | 
                                                        |
| 72 | - }  | 
                                                        |
| 73 | -  | 
                                                        |
| 74 | -        if ($this->getSiteConfiguration() === null) { | 
                                                        |
| 75 | -            throw new Exception("Page has no configuration!"); | 
                                                        |
| 76 | - }  | 
                                                        |
| 77 | -  | 
                                                        |
| 78 | - $this->setupPage();  | 
                                                        |
| 79 | -  | 
                                                        |
| 80 | - $this->touchUserLastActive();  | 
                                                        |
| 81 | -  | 
                                                        |
| 82 | - // Get the current security configuration  | 
                                                        |
| 83 | - $securityConfiguration = $this->getSecurityConfiguration();  | 
                                                        |
| 84 | -        if ($securityConfiguration === null) { | 
                                                        |
| 85 | - // page hasn't been written properly.  | 
                                                        |
| 86 | - throw new AccessDeniedException();  | 
                                                        |
| 87 | - }  | 
                                                        |
| 88 | -  | 
                                                        |
| 89 | - $currentUser = User::getCurrent($this->getDatabase());  | 
                                                        |
| 90 | -  | 
                                                        |
| 91 | - // Security barrier.  | 
                                                        |
| 92 | - //  | 
                                                        |
| 93 | - // This code essentially doesn't care if the user is logged in or not, as the  | 
                                                        |
| 94 | -        if ($this->getSecurityManager()->allows($securityConfiguration, $currentUser)) { | 
                                                        |
| 95 | - // We're allowed to run the page, so let's run it.  | 
                                                        |
| 96 | - $this->runPage();  | 
                                                        |
| 97 | - }  | 
                                                        |
| 98 | -        else { | 
                                                        |
| 99 | - $this->handleAccessDenied();  | 
                                                        |
| 100 | -  | 
                                                        |
| 101 | - // Send the headers  | 
                                                        |
| 102 | - $this->sendResponseHeaders();  | 
                                                        |
| 103 | - }  | 
                                                        |
| 104 | - }  | 
                                                        |
| 105 | -  | 
                                                        |
| 106 | - /**  | 
                                                        |
| 107 | - * Performs final tasks needed before rendering the page.  | 
                                                        |
| 108 | - */  | 
                                                        |
| 109 | - final public function finalisePage()  | 
                                                        |
| 110 | -    { | 
                                                        |
| 111 | - parent::finalisePage();  | 
                                                        |
| 112 | -  | 
                                                        |
| 113 | -        $this->assign('typeAheadBlock', $this->getTypeAheadHelper()->getTypeAheadScriptBlock()); | 
                                                        |
| 114 | -  | 
                                                        |
| 115 | - $database = $this->getDatabase();  | 
                                                        |
| 116 | -  | 
                                                        |
| 117 | -        if (!User::getCurrent($database)->isCommunityUser()) { | 
                                                        |
| 118 | - $sql = 'SELECT * FROM user WHERE lastactive > DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL 5 MINUTE);';  | 
                                                        |
| 119 | - $statement = $database->query($sql);  | 
                                                        |
| 120 | - $activeUsers = $statement->fetchAll(PDO::FETCH_CLASS, User::class);  | 
                                                        |
| 121 | -            $this->assign('onlineusers', $activeUsers); | 
                                                        |
| 122 | - }  | 
                                                        |
| 123 | - }  | 
                                                        |
| 124 | -  | 
                                                        |
| 125 | - /**  | 
                                                        |
| 126 | - * Sets up the security for this page. If certain actions have different permissions, this should be reflected in  | 
                                                        |
| 127 | - * the return value from this function.  | 
                                                        |
| 128 | - *  | 
                                                        |
| 129 | - * If this page even supports actions, you will need to check the route  | 
                                                        |
| 130 | - *  | 
                                                        |
| 131 | - * @return SecurityConfiguration  | 
                                                        |
| 132 | - * @category Security-Critical  | 
                                                        |
| 133 | - */  | 
                                                        |
| 134 | - abstract protected function getSecurityConfiguration();  | 
                                                        |
| 135 | -  | 
                                                        |
| 136 | - protected function handleAccessDenied()  | 
                                                        |
| 137 | -    { | 
                                                        |
| 138 | - $currentUser = User::getCurrent($this->getDatabase());  | 
                                                        |
| 139 | -  | 
                                                        |
| 140 | - // Not allowed to access this resource.  | 
                                                        |
| 141 | - // Firstly, let's check if we're even logged in.  | 
                                                        |
| 142 | -        if ($currentUser->isCommunityUser()) { | 
                                                        |
| 143 | - // Not logged in, redirect to login page  | 
                                                        |
| 144 | - WebRequest::setPostLoginRedirect();  | 
                                                        |
| 145 | -            $this->redirect("login"); | 
                                                        |
| 146 | -  | 
                                                        |
| 147 | - return;  | 
                                                        |
| 148 | - }  | 
                                                        |
| 149 | -        else { | 
                                                        |
| 150 | - // Decide whether this was a rights failure, or an identification failure.  | 
                                                        |
| 151 | -  | 
                                                        |
| 152 | - if ($this->getSiteConfiguration()->getForceIdentification()  | 
                                                        |
| 153 | - && $currentUser->isIdentified($this->identificationVerifier) !== true  | 
                                                        |
| 154 | -            ) { | 
                                                        |
| 155 | - // Not identified  | 
                                                        |
| 156 | - throw new NotIdentifiedException();  | 
                                                        |
| 157 | - }  | 
                                                        |
| 158 | -            else { | 
                                                        |
| 159 | - // Nope, plain old access denied  | 
                                                        |
| 160 | - throw new AccessDeniedException();  | 
                                                        |
| 161 | - }  | 
                                                        |
| 162 | - }  | 
                                                        |
| 163 | - }  | 
                                                        |
| 164 | -  | 
                                                        |
| 165 | - /**  | 
                                                        |
| 166 | - * Tests the security barrier for a specified action.  | 
                                                        |
| 167 | - *  | 
                                                        |
| 168 | - * Intended to be used from within templates  | 
                                                        |
| 169 | - *  | 
                                                        |
| 170 | - * @param string $action  | 
                                                        |
| 171 | - *  | 
                                                        |
| 172 | - * @return boolean  | 
                                                        |
| 173 | - * @category Security-Critical  | 
                                                        |
| 174 | - */  | 
                                                        |
| 175 | - final public function barrierTest($action)  | 
                                                        |
| 176 | -    { | 
                                                        |
| 177 | - $tmpRouteName = $this->getRouteName();  | 
                                                        |
| 178 | -  | 
                                                        |
| 179 | -        try { | 
                                                        |
| 180 | - $this->setRoute($action, true);  | 
                                                        |
| 181 | -  | 
                                                        |
| 182 | - $securityConfiguration = $this->getSecurityConfiguration();  | 
                                                        |
| 183 | - $currentUser = User::getCurrent($this->getDatabase());  | 
                                                        |
| 184 | -  | 
                                                        |
| 185 | - $allowed = $this->getSecurityManager()->allows($securityConfiguration, $currentUser);  | 
                                                        |
| 186 | -  | 
                                                        |
| 187 | - return $allowed;  | 
                                                        |
| 188 | - }  | 
                                                        |
| 189 | -        finally { | 
                                                        |
| 190 | - $this->setRoute($tmpRouteName);  | 
                                                        |
| 191 | - }  | 
                                                        |
| 192 | - }  | 
                                                        |
| 193 | -  | 
                                                        |
| 194 | - /**  | 
                                                        |
| 195 | - * Updates the lastactive timestamp  | 
                                                        |
| 196 | - */  | 
                                                        |
| 197 | - private function touchUserLastActive()  | 
                                                        |
| 198 | -    { | 
                                                        |
| 199 | -        if (WebRequest::getSessionUserId() !== null) { | 
                                                        |
| 200 | - $query = 'UPDATE user SET lastactive = CURRENT_TIMESTAMP() WHERE id = :id;';  | 
                                                        |
| 201 | -            $this->getDatabase()->prepare($query)->execute(array(":id" => WebRequest::getSessionUserId())); | 
                                                        |
| 202 | - }  | 
                                                        |
| 203 | - }  | 
                                                        |
| 204 | -  | 
                                                        |
| 205 | - /**  | 
                                                        |
| 206 | - * @return SecurityManager  | 
                                                        |
| 207 | - */  | 
                                                        |
| 208 | - public function getSecurityManager()  | 
                                                        |
| 209 | -    { | 
                                                        |
| 210 | - return $this->securityManager;  | 
                                                        |
| 211 | - }  | 
                                                        |
| 212 | -  | 
                                                        |
| 213 | - /**  | 
                                                        |
| 214 | - * @param SecurityManager $securityManager  | 
                                                        |
| 215 | - */  | 
                                                        |
| 216 | - public function setSecurityManager(SecurityManager $securityManager)  | 
                                                        |
| 217 | -    { | 
                                                        |
| 218 | - $this->securityManager = $securityManager;  | 
                                                        |
| 219 | - }  | 
                                                        |
| 220 | -  | 
                                                        |
| 221 | - /**  | 
                                                        |
| 222 | - * @return IBlacklistHelper  | 
                                                        |
| 223 | - */  | 
                                                        |
| 224 | - public function getBlacklistHelper()  | 
                                                        |
| 225 | -    { | 
                                                        |
| 226 | - return $this->blacklistHelper;  | 
                                                        |
| 227 | - }  | 
                                                        |
| 228 | -  | 
                                                        |
| 229 | - /**  | 
                                                        |
| 230 | - * @param IBlacklistHelper $blacklistHelper  | 
                                                        |
| 231 | - */  | 
                                                        |
| 232 | - public function setBlacklistHelper(IBlacklistHelper $blacklistHelper)  | 
                                                        |
| 233 | -    { | 
                                                        |
| 234 | - $this->blacklistHelper = $blacklistHelper;  | 
                                                        |
| 235 | - }  | 
                                                        |
| 25 | + /** @var IdentificationVerifier */  | 
                                                        |
| 26 | + private $identificationVerifier;  | 
                                                        |
| 27 | + /** @var ITypeAheadHelper */  | 
                                                        |
| 28 | + private $typeAheadHelper;  | 
                                                        |
| 29 | + /** @var SecurityManager */  | 
                                                        |
| 30 | + private $securityManager;  | 
                                                        |
| 31 | + /** @var IBlacklistHelper */  | 
                                                        |
| 32 | + private $blacklistHelper;  | 
                                                        |
| 33 | +  | 
                                                        |
| 34 | + /**  | 
                                                        |
| 35 | + * @return ITypeAheadHelper  | 
                                                        |
| 36 | + */  | 
                                                        |
| 37 | + public function getTypeAheadHelper()  | 
                                                        |
| 38 | +	{ | 
                                                        |
| 39 | + return $this->typeAheadHelper;  | 
                                                        |
| 40 | + }  | 
                                                        |
| 41 | +  | 
                                                        |
| 42 | + /**  | 
                                                        |
| 43 | + * Sets up the internal IdentificationVerifier instance. Intended to be called from WebStart::setupHelpers().  | 
                                                        |
| 44 | + *  | 
                                                        |
| 45 | + * @param IdentificationVerifier $identificationVerifier  | 
                                                        |
| 46 | + *  | 
                                                        |
| 47 | + * @return void  | 
                                                        |
| 48 | + */  | 
                                                        |
| 49 | + public function setIdentificationVerifier(IdentificationVerifier $identificationVerifier)  | 
                                                        |
| 50 | +	{ | 
                                                        |
| 51 | + $this->identificationVerifier = $identificationVerifier;  | 
                                                        |
| 52 | + }  | 
                                                        |
| 53 | +  | 
                                                        |
| 54 | + /**  | 
                                                        |
| 55 | + * @param ITypeAheadHelper $typeAheadHelper  | 
                                                        |
| 56 | + */  | 
                                                        |
| 57 | + public function setTypeAheadHelper(ITypeAheadHelper $typeAheadHelper)  | 
                                                        |
| 58 | +	{ | 
                                                        |
| 59 | + $this->typeAheadHelper = $typeAheadHelper;  | 
                                                        |
| 60 | + }  | 
                                                        |
| 61 | +  | 
                                                        |
| 62 | + /**  | 
                                                        |
| 63 | + * Runs the page code  | 
                                                        |
| 64 | + *  | 
                                                        |
| 65 | + * @throws Exception  | 
                                                        |
| 66 | + * @category Security-Critical  | 
                                                        |
| 67 | + */  | 
                                                        |
| 68 | + final public function execute()  | 
                                                        |
| 69 | +	{ | 
                                                        |
| 70 | +		if ($this->getRouteName() === null) { | 
                                                        |
| 71 | +			throw new Exception("Request is unrouted."); | 
                                                        |
| 72 | + }  | 
                                                        |
| 73 | +  | 
                                                        |
| 74 | +		if ($this->getSiteConfiguration() === null) { | 
                                                        |
| 75 | +			throw new Exception("Page has no configuration!"); | 
                                                        |
| 76 | + }  | 
                                                        |
| 77 | +  | 
                                                        |
| 78 | + $this->setupPage();  | 
                                                        |
| 79 | +  | 
                                                        |
| 80 | + $this->touchUserLastActive();  | 
                                                        |
| 81 | +  | 
                                                        |
| 82 | + // Get the current security configuration  | 
                                                        |
| 83 | + $securityConfiguration = $this->getSecurityConfiguration();  | 
                                                        |
| 84 | +		if ($securityConfiguration === null) { | 
                                                        |
| 85 | + // page hasn't been written properly.  | 
                                                        |
| 86 | + throw new AccessDeniedException();  | 
                                                        |
| 87 | + }  | 
                                                        |
| 88 | +  | 
                                                        |
| 89 | + $currentUser = User::getCurrent($this->getDatabase());  | 
                                                        |
| 90 | +  | 
                                                        |
| 91 | + // Security barrier.  | 
                                                        |
| 92 | + //  | 
                                                        |
| 93 | + // This code essentially doesn't care if the user is logged in or not, as the  | 
                                                        |
| 94 | +		if ($this->getSecurityManager()->allows($securityConfiguration, $currentUser)) { | 
                                                        |
| 95 | + // We're allowed to run the page, so let's run it.  | 
                                                        |
| 96 | + $this->runPage();  | 
                                                        |
| 97 | + }  | 
                                                        |
| 98 | +		else { | 
                                                        |
| 99 | + $this->handleAccessDenied();  | 
                                                        |
| 100 | +  | 
                                                        |
| 101 | + // Send the headers  | 
                                                        |
| 102 | + $this->sendResponseHeaders();  | 
                                                        |
| 103 | + }  | 
                                                        |
| 104 | + }  | 
                                                        |
| 105 | +  | 
                                                        |
| 106 | + /**  | 
                                                        |
| 107 | + * Performs final tasks needed before rendering the page.  | 
                                                        |
| 108 | + */  | 
                                                        |
| 109 | + final public function finalisePage()  | 
                                                        |
| 110 | +	{ | 
                                                        |
| 111 | + parent::finalisePage();  | 
                                                        |
| 112 | +  | 
                                                        |
| 113 | +		$this->assign('typeAheadBlock', $this->getTypeAheadHelper()->getTypeAheadScriptBlock()); | 
                                                        |
| 114 | +  | 
                                                        |
| 115 | + $database = $this->getDatabase();  | 
                                                        |
| 116 | +  | 
                                                        |
| 117 | +		if (!User::getCurrent($database)->isCommunityUser()) { | 
                                                        |
| 118 | + $sql = 'SELECT * FROM user WHERE lastactive > DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL 5 MINUTE);';  | 
                                                        |
| 119 | + $statement = $database->query($sql);  | 
                                                        |
| 120 | + $activeUsers = $statement->fetchAll(PDO::FETCH_CLASS, User::class);  | 
                                                        |
| 121 | +			$this->assign('onlineusers', $activeUsers); | 
                                                        |
| 122 | + }  | 
                                                        |
| 123 | + }  | 
                                                        |
| 124 | +  | 
                                                        |
| 125 | + /**  | 
                                                        |
| 126 | + * Sets up the security for this page. If certain actions have different permissions, this should be reflected in  | 
                                                        |
| 127 | + * the return value from this function.  | 
                                                        |
| 128 | + *  | 
                                                        |
| 129 | + * If this page even supports actions, you will need to check the route  | 
                                                        |
| 130 | + *  | 
                                                        |
| 131 | + * @return SecurityConfiguration  | 
                                                        |
| 132 | + * @category Security-Critical  | 
                                                        |
| 133 | + */  | 
                                                        |
| 134 | + abstract protected function getSecurityConfiguration();  | 
                                                        |
| 135 | +  | 
                                                        |
| 136 | + protected function handleAccessDenied()  | 
                                                        |
| 137 | +	{ | 
                                                        |
| 138 | + $currentUser = User::getCurrent($this->getDatabase());  | 
                                                        |
| 139 | +  | 
                                                        |
| 140 | + // Not allowed to access this resource.  | 
                                                        |
| 141 | + // Firstly, let's check if we're even logged in.  | 
                                                        |
| 142 | +		if ($currentUser->isCommunityUser()) { | 
                                                        |
| 143 | + // Not logged in, redirect to login page  | 
                                                        |
| 144 | + WebRequest::setPostLoginRedirect();  | 
                                                        |
| 145 | +			$this->redirect("login"); | 
                                                        |
| 146 | +  | 
                                                        |
| 147 | + return;  | 
                                                        |
| 148 | + }  | 
                                                        |
| 149 | +		else { | 
                                                        |
| 150 | + // Decide whether this was a rights failure, or an identification failure.  | 
                                                        |
| 151 | +  | 
                                                        |
| 152 | + if ($this->getSiteConfiguration()->getForceIdentification()  | 
                                                        |
| 153 | + && $currentUser->isIdentified($this->identificationVerifier) !== true  | 
                                                        |
| 154 | +			) { | 
                                                        |
| 155 | + // Not identified  | 
                                                        |
| 156 | + throw new NotIdentifiedException();  | 
                                                        |
| 157 | + }  | 
                                                        |
| 158 | +			else { | 
                                                        |
| 159 | + // Nope, plain old access denied  | 
                                                        |
| 160 | + throw new AccessDeniedException();  | 
                                                        |
| 161 | + }  | 
                                                        |
| 162 | + }  | 
                                                        |
| 163 | + }  | 
                                                        |
| 164 | +  | 
                                                        |
| 165 | + /**  | 
                                                        |
| 166 | + * Tests the security barrier for a specified action.  | 
                                                        |
| 167 | + *  | 
                                                        |
| 168 | + * Intended to be used from within templates  | 
                                                        |
| 169 | + *  | 
                                                        |
| 170 | + * @param string $action  | 
                                                        |
| 171 | + *  | 
                                                        |
| 172 | + * @return boolean  | 
                                                        |
| 173 | + * @category Security-Critical  | 
                                                        |
| 174 | + */  | 
                                                        |
| 175 | + final public function barrierTest($action)  | 
                                                        |
| 176 | +	{ | 
                                                        |
| 177 | + $tmpRouteName = $this->getRouteName();  | 
                                                        |
| 178 | +  | 
                                                        |
| 179 | +		try { | 
                                                        |
| 180 | + $this->setRoute($action, true);  | 
                                                        |
| 181 | +  | 
                                                        |
| 182 | + $securityConfiguration = $this->getSecurityConfiguration();  | 
                                                        |
| 183 | + $currentUser = User::getCurrent($this->getDatabase());  | 
                                                        |
| 184 | +  | 
                                                        |
| 185 | + $allowed = $this->getSecurityManager()->allows($securityConfiguration, $currentUser);  | 
                                                        |
| 186 | +  | 
                                                        |
| 187 | + return $allowed;  | 
                                                        |
| 188 | + }  | 
                                                        |
| 189 | +		finally { | 
                                                        |
| 190 | + $this->setRoute($tmpRouteName);  | 
                                                        |
| 191 | + }  | 
                                                        |
| 192 | + }  | 
                                                        |
| 193 | +  | 
                                                        |
| 194 | + /**  | 
                                                        |
| 195 | + * Updates the lastactive timestamp  | 
                                                        |
| 196 | + */  | 
                                                        |
| 197 | + private function touchUserLastActive()  | 
                                                        |
| 198 | +	{ | 
                                                        |
| 199 | +		if (WebRequest::getSessionUserId() !== null) { | 
                                                        |
| 200 | + $query = 'UPDATE user SET lastactive = CURRENT_TIMESTAMP() WHERE id = :id;';  | 
                                                        |
| 201 | +			$this->getDatabase()->prepare($query)->execute(array(":id" => WebRequest::getSessionUserId())); | 
                                                        |
| 202 | + }  | 
                                                        |
| 203 | + }  | 
                                                        |
| 204 | +  | 
                                                        |
| 205 | + /**  | 
                                                        |
| 206 | + * @return SecurityManager  | 
                                                        |
| 207 | + */  | 
                                                        |
| 208 | + public function getSecurityManager()  | 
                                                        |
| 209 | +	{ | 
                                                        |
| 210 | + return $this->securityManager;  | 
                                                        |
| 211 | + }  | 
                                                        |
| 212 | +  | 
                                                        |
| 213 | + /**  | 
                                                        |
| 214 | + * @param SecurityManager $securityManager  | 
                                                        |
| 215 | + */  | 
                                                        |
| 216 | + public function setSecurityManager(SecurityManager $securityManager)  | 
                                                        |
| 217 | +	{ | 
                                                        |
| 218 | + $this->securityManager = $securityManager;  | 
                                                        |
| 219 | + }  | 
                                                        |
| 220 | +  | 
                                                        |
| 221 | + /**  | 
                                                        |
| 222 | + * @return IBlacklistHelper  | 
                                                        |
| 223 | + */  | 
                                                        |
| 224 | + public function getBlacklistHelper()  | 
                                                        |
| 225 | +	{ | 
                                                        |
| 226 | + return $this->blacklistHelper;  | 
                                                        |
| 227 | + }  | 
                                                        |
| 228 | +  | 
                                                        |
| 229 | + /**  | 
                                                        |
| 230 | + * @param IBlacklistHelper $blacklistHelper  | 
                                                        |
| 231 | + */  | 
                                                        |
| 232 | + public function setBlacklistHelper(IBlacklistHelper $blacklistHelper)  | 
                                                        |
| 233 | +	{ | 
                                                        |
| 234 | + $this->blacklistHelper = $blacklistHelper;  | 
                                                        |
| 235 | + }  | 
                                                        |
| 236 | 236 | }  | 
                                                        
| 237 | 237 | \ No newline at end of file  | 
                                                        
@@ -23,149 +23,149 @@  | 
                                                    ||
| 23 | 23 | |
| 24 | 24 | interface ITask  | 
                                                        
| 25 | 25 |  { | 
                                                        
| 26 | - /**  | 
                                                        |
| 27 | - * @return IEmailHelper  | 
                                                        |
| 28 | - */  | 
                                                        |
| 29 | - public function getEmailHelper();  | 
                                                        |
| 30 | -  | 
                                                        |
| 31 | - /**  | 
                                                        |
| 32 | - * @param IEmailHelper $emailHelper  | 
                                                        |
| 33 | - *  | 
                                                        |
| 34 | - * @return void  | 
                                                        |
| 35 | - */  | 
                                                        |
| 36 | - public function setEmailHelper($emailHelper);  | 
                                                        |
| 37 | -  | 
                                                        |
| 38 | - /**  | 
                                                        |
| 39 | - * @return HttpHelper  | 
                                                        |
| 40 | - */  | 
                                                        |
| 41 | - public function getHttpHelper();  | 
                                                        |
| 42 | -  | 
                                                        |
| 43 | - /**  | 
                                                        |
| 44 | - * @param HttpHelper $httpHelper  | 
                                                        |
| 45 | - *  | 
                                                        |
| 46 | - * @return void  | 
                                                        |
| 47 | - */  | 
                                                        |
| 48 | - public function setHttpHelper($httpHelper);  | 
                                                        |
| 49 | -  | 
                                                        |
| 50 | - /**  | 
                                                        |
| 51 | - * @return WikiTextHelper  | 
                                                        |
| 52 | - */  | 
                                                        |
| 53 | - public function getWikiTextHelper();  | 
                                                        |
| 54 | -  | 
                                                        |
| 55 | - /**  | 
                                                        |
| 56 | - * @param WikiTextHelper $wikiTextHelper  | 
                                                        |
| 57 | - *  | 
                                                        |
| 58 | - * @return void  | 
                                                        |
| 59 | - */  | 
                                                        |
| 60 | - public function setWikiTextHelper($wikiTextHelper);  | 
                                                        |
| 61 | -  | 
                                                        |
| 62 | - /**  | 
                                                        |
| 63 | - * @return ILocationProvider  | 
                                                        |
| 64 | - */  | 
                                                        |
| 65 | - public function getLocationProvider();  | 
                                                        |
| 66 | -  | 
                                                        |
| 67 | - /**  | 
                                                        |
| 68 | - * @param ILocationProvider $locationProvider  | 
                                                        |
| 69 | - *  | 
                                                        |
| 70 | - * @return void  | 
                                                        |
| 71 | - */  | 
                                                        |
| 72 | - public function setLocationProvider(ILocationProvider $locationProvider);  | 
                                                        |
| 73 | -  | 
                                                        |
| 74 | - /**  | 
                                                        |
| 75 | - * @return IXffTrustProvider  | 
                                                        |
| 76 | - */  | 
                                                        |
| 77 | - public function getXffTrustProvider();  | 
                                                        |
| 78 | -  | 
                                                        |
| 79 | - /**  | 
                                                        |
| 80 | - * @param IXffTrustProvider $xffTrustProvider  | 
                                                        |
| 81 | - *  | 
                                                        |
| 82 | - * @return void  | 
                                                        |
| 83 | - */  | 
                                                        |
| 84 | - public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider);  | 
                                                        |
| 85 | -  | 
                                                        |
| 86 | - /**  | 
                                                        |
| 87 | - * @return IRDnsProvider  | 
                                                        |
| 88 | - */  | 
                                                        |
| 89 | - public function getRdnsProvider();  | 
                                                        |
| 90 | -  | 
                                                        |
| 91 | - /**  | 
                                                        |
| 92 | - * @param IRDnsProvider $rdnsProvider  | 
                                                        |
| 93 | - *  | 
                                                        |
| 94 | - * @return void  | 
                                                        |
| 95 | - */  | 
                                                        |
| 96 | - public function setRdnsProvider($rdnsProvider);  | 
                                                        |
| 97 | -  | 
                                                        |
| 98 | - /**  | 
                                                        |
| 99 | - * @return IAntiSpoofProvider  | 
                                                        |
| 100 | - */  | 
                                                        |
| 101 | - public function getAntiSpoofProvider();  | 
                                                        |
| 102 | -  | 
                                                        |
| 103 | - /**  | 
                                                        |
| 104 | - * @param IAntiSpoofProvider $antiSpoofProvider  | 
                                                        |
| 105 | - *  | 
                                                        |
| 106 | - * @return void  | 
                                                        |
| 107 | - */  | 
                                                        |
| 108 | - public function setAntiSpoofProvider($antiSpoofProvider);  | 
                                                        |
| 109 | -  | 
                                                        |
| 110 | - /**  | 
                                                        |
| 111 | - * @return PdoDatabase  | 
                                                        |
| 112 | - */  | 
                                                        |
| 113 | - public function getDatabase();  | 
                                                        |
| 114 | -  | 
                                                        |
| 115 | - /**  | 
                                                        |
| 116 | - * @param PdoDatabase $database  | 
                                                        |
| 117 | - *  | 
                                                        |
| 118 | - * @return void  | 
                                                        |
| 119 | - */  | 
                                                        |
| 120 | - public function setDatabase($database);  | 
                                                        |
| 121 | -  | 
                                                        |
| 122 | - /**  | 
                                                        |
| 123 | - * @return IOAuthHelper  | 
                                                        |
| 124 | - */  | 
                                                        |
| 125 | - public function getOAuthHelper();  | 
                                                        |
| 126 | -  | 
                                                        |
| 127 | - /**  | 
                                                        |
| 128 | - * @param IOAuthHelper $oauthHelper  | 
                                                        |
| 129 | - *  | 
                                                        |
| 130 | - * @return void  | 
                                                        |
| 131 | - */  | 
                                                        |
| 132 | - public function setOAuthHelper($oauthHelper);  | 
                                                        |
| 133 | -  | 
                                                        |
| 134 | - /**  | 
                                                        |
| 135 | - * @return void  | 
                                                        |
| 136 | - */  | 
                                                        |
| 137 | - public function execute();  | 
                                                        |
| 138 | -  | 
                                                        |
| 139 | - /**  | 
                                                        |
| 140 | - * Sets the site configuration object for this page  | 
                                                        |
| 141 | - *  | 
                                                        |
| 142 | - * @param SiteConfiguration $configuration  | 
                                                        |
| 143 | - *  | 
                                                        |
| 144 | - * @return void  | 
                                                        |
| 145 | - */  | 
                                                        |
| 146 | - public function setSiteConfiguration($configuration);  | 
                                                        |
| 147 | -  | 
                                                        |
| 148 | - /**  | 
                                                        |
| 149 | - * @return IrcNotificationHelper  | 
                                                        |
| 150 | - */  | 
                                                        |
| 151 | - public function getNotificationHelper();  | 
                                                        |
| 152 | -  | 
                                                        |
| 153 | - /**  | 
                                                        |
| 154 | - * @param IrcNotificationHelper $notificationHelper  | 
                                                        |
| 155 | - *  | 
                                                        |
| 156 | - * @return void  | 
                                                        |
| 157 | - */  | 
                                                        |
| 158 | - public function setNotificationHelper($notificationHelper);  | 
                                                        |
| 159 | -  | 
                                                        |
| 160 | - /**  | 
                                                        |
| 161 | - * @return TorExitProvider  | 
                                                        |
| 162 | - */  | 
                                                        |
| 163 | - public function getTorExitProvider();  | 
                                                        |
| 164 | -  | 
                                                        |
| 165 | - /**  | 
                                                        |
| 166 | - * @param TorExitProvider $torExitProvider  | 
                                                        |
| 167 | - *  | 
                                                        |
| 168 | - * @return void  | 
                                                        |
| 169 | - */  | 
                                                        |
| 170 | - public function setTorExitProvider($torExitProvider);  | 
                                                        |
| 26 | + /**  | 
                                                        |
| 27 | + * @return IEmailHelper  | 
                                                        |
| 28 | + */  | 
                                                        |
| 29 | + public function getEmailHelper();  | 
                                                        |
| 30 | +  | 
                                                        |
| 31 | + /**  | 
                                                        |
| 32 | + * @param IEmailHelper $emailHelper  | 
                                                        |
| 33 | + *  | 
                                                        |
| 34 | + * @return void  | 
                                                        |
| 35 | + */  | 
                                                        |
| 36 | + public function setEmailHelper($emailHelper);  | 
                                                        |
| 37 | +  | 
                                                        |
| 38 | + /**  | 
                                                        |
| 39 | + * @return HttpHelper  | 
                                                        |
| 40 | + */  | 
                                                        |
| 41 | + public function getHttpHelper();  | 
                                                        |
| 42 | +  | 
                                                        |
| 43 | + /**  | 
                                                        |
| 44 | + * @param HttpHelper $httpHelper  | 
                                                        |
| 45 | + *  | 
                                                        |
| 46 | + * @return void  | 
                                                        |
| 47 | + */  | 
                                                        |
| 48 | + public function setHttpHelper($httpHelper);  | 
                                                        |
| 49 | +  | 
                                                        |
| 50 | + /**  | 
                                                        |
| 51 | + * @return WikiTextHelper  | 
                                                        |
| 52 | + */  | 
                                                        |
| 53 | + public function getWikiTextHelper();  | 
                                                        |
| 54 | +  | 
                                                        |
| 55 | + /**  | 
                                                        |
| 56 | + * @param WikiTextHelper $wikiTextHelper  | 
                                                        |
| 57 | + *  | 
                                                        |
| 58 | + * @return void  | 
                                                        |
| 59 | + */  | 
                                                        |
| 60 | + public function setWikiTextHelper($wikiTextHelper);  | 
                                                        |
| 61 | +  | 
                                                        |
| 62 | + /**  | 
                                                        |
| 63 | + * @return ILocationProvider  | 
                                                        |
| 64 | + */  | 
                                                        |
| 65 | + public function getLocationProvider();  | 
                                                        |
| 66 | +  | 
                                                        |
| 67 | + /**  | 
                                                        |
| 68 | + * @param ILocationProvider $locationProvider  | 
                                                        |
| 69 | + *  | 
                                                        |
| 70 | + * @return void  | 
                                                        |
| 71 | + */  | 
                                                        |
| 72 | + public function setLocationProvider(ILocationProvider $locationProvider);  | 
                                                        |
| 73 | +  | 
                                                        |
| 74 | + /**  | 
                                                        |
| 75 | + * @return IXffTrustProvider  | 
                                                        |
| 76 | + */  | 
                                                        |
| 77 | + public function getXffTrustProvider();  | 
                                                        |
| 78 | +  | 
                                                        |
| 79 | + /**  | 
                                                        |
| 80 | + * @param IXffTrustProvider $xffTrustProvider  | 
                                                        |
| 81 | + *  | 
                                                        |
| 82 | + * @return void  | 
                                                        |
| 83 | + */  | 
                                                        |
| 84 | + public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider);  | 
                                                        |
| 85 | +  | 
                                                        |
| 86 | + /**  | 
                                                        |
| 87 | + * @return IRDnsProvider  | 
                                                        |
| 88 | + */  | 
                                                        |
| 89 | + public function getRdnsProvider();  | 
                                                        |
| 90 | +  | 
                                                        |
| 91 | + /**  | 
                                                        |
| 92 | + * @param IRDnsProvider $rdnsProvider  | 
                                                        |
| 93 | + *  | 
                                                        |
| 94 | + * @return void  | 
                                                        |
| 95 | + */  | 
                                                        |
| 96 | + public function setRdnsProvider($rdnsProvider);  | 
                                                        |
| 97 | +  | 
                                                        |
| 98 | + /**  | 
                                                        |
| 99 | + * @return IAntiSpoofProvider  | 
                                                        |
| 100 | + */  | 
                                                        |
| 101 | + public function getAntiSpoofProvider();  | 
                                                        |
| 102 | +  | 
                                                        |
| 103 | + /**  | 
                                                        |
| 104 | + * @param IAntiSpoofProvider $antiSpoofProvider  | 
                                                        |
| 105 | + *  | 
                                                        |
| 106 | + * @return void  | 
                                                        |
| 107 | + */  | 
                                                        |
| 108 | + public function setAntiSpoofProvider($antiSpoofProvider);  | 
                                                        |
| 109 | +  | 
                                                        |
| 110 | + /**  | 
                                                        |
| 111 | + * @return PdoDatabase  | 
                                                        |
| 112 | + */  | 
                                                        |
| 113 | + public function getDatabase();  | 
                                                        |
| 114 | +  | 
                                                        |
| 115 | + /**  | 
                                                        |
| 116 | + * @param PdoDatabase $database  | 
                                                        |
| 117 | + *  | 
                                                        |
| 118 | + * @return void  | 
                                                        |
| 119 | + */  | 
                                                        |
| 120 | + public function setDatabase($database);  | 
                                                        |
| 121 | +  | 
                                                        |
| 122 | + /**  | 
                                                        |
| 123 | + * @return IOAuthHelper  | 
                                                        |
| 124 | + */  | 
                                                        |
| 125 | + public function getOAuthHelper();  | 
                                                        |
| 126 | +  | 
                                                        |
| 127 | + /**  | 
                                                        |
| 128 | + * @param IOAuthHelper $oauthHelper  | 
                                                        |
| 129 | + *  | 
                                                        |
| 130 | + * @return void  | 
                                                        |
| 131 | + */  | 
                                                        |
| 132 | + public function setOAuthHelper($oauthHelper);  | 
                                                        |
| 133 | +  | 
                                                        |
| 134 | + /**  | 
                                                        |
| 135 | + * @return void  | 
                                                        |
| 136 | + */  | 
                                                        |
| 137 | + public function execute();  | 
                                                        |
| 138 | +  | 
                                                        |
| 139 | + /**  | 
                                                        |
| 140 | + * Sets the site configuration object for this page  | 
                                                        |
| 141 | + *  | 
                                                        |
| 142 | + * @param SiteConfiguration $configuration  | 
                                                        |
| 143 | + *  | 
                                                        |
| 144 | + * @return void  | 
                                                        |
| 145 | + */  | 
                                                        |
| 146 | + public function setSiteConfiguration($configuration);  | 
                                                        |
| 147 | +  | 
                                                        |
| 148 | + /**  | 
                                                        |
| 149 | + * @return IrcNotificationHelper  | 
                                                        |
| 150 | + */  | 
                                                        |
| 151 | + public function getNotificationHelper();  | 
                                                        |
| 152 | +  | 
                                                        |
| 153 | + /**  | 
                                                        |
| 154 | + * @param IrcNotificationHelper $notificationHelper  | 
                                                        |
| 155 | + *  | 
                                                        |
| 156 | + * @return void  | 
                                                        |
| 157 | + */  | 
                                                        |
| 158 | + public function setNotificationHelper($notificationHelper);  | 
                                                        |
| 159 | +  | 
                                                        |
| 160 | + /**  | 
                                                        |
| 161 | + * @return TorExitProvider  | 
                                                        |
| 162 | + */  | 
                                                        |
| 163 | + public function getTorExitProvider();  | 
                                                        |
| 164 | +  | 
                                                        |
| 165 | + /**  | 
                                                        |
| 166 | + * @param TorExitProvider $torExitProvider  | 
                                                        |
| 167 | + *  | 
                                                        |
| 168 | + * @return void  | 
                                                        |
| 169 | + */  | 
                                                        |
| 170 | + public function setTorExitProvider($torExitProvider);  | 
                                                        |
| 171 | 171 | }  | 
                                                        
| 172 | 172 | \ No newline at end of file  | 
                                                        
@@ -23,229 +23,229 @@  | 
                                                    ||
| 23 | 23 | |
| 24 | 24 | abstract class TaskBase implements ITask  | 
                                                        
| 25 | 25 |  { | 
                                                        
| 26 | - /** @var SiteConfiguration */  | 
                                                        |
| 27 | - private $siteConfiguration;  | 
                                                        |
| 28 | - /** @var IEmailHelper */  | 
                                                        |
| 29 | - private $emailHelper;  | 
                                                        |
| 30 | - /** @var HttpHelper */  | 
                                                        |
| 31 | - private $httpHelper;  | 
                                                        |
| 32 | - /** @var WikiTextHelper */  | 
                                                        |
| 33 | - private $wikiTextHelper;  | 
                                                        |
| 34 | - /** @var ILocationProvider */  | 
                                                        |
| 35 | - private $locationProvider;  | 
                                                        |
| 36 | - /** @var IXffTrustProvider */  | 
                                                        |
| 37 | - private $xffTrustProvider;  | 
                                                        |
| 38 | - /** @var IRDnsProvider */  | 
                                                        |
| 39 | - private $rdnsProvider;  | 
                                                        |
| 40 | - /** @var IAntiSpoofProvider */  | 
                                                        |
| 41 | - private $antiSpoofProvider;  | 
                                                        |
| 42 | - /** @var IOAuthHelper */  | 
                                                        |
| 43 | - private $oauthHelper;  | 
                                                        |
| 44 | - /** @var PdoDatabase */  | 
                                                        |
| 45 | - private $database;  | 
                                                        |
| 46 | - /** @var IrcNotificationHelper */  | 
                                                        |
| 47 | - private $notificationHelper;  | 
                                                        |
| 48 | - /** @var TorExitProvider */  | 
                                                        |
| 49 | - private $torExitProvider;  | 
                                                        |
| 50 | -  | 
                                                        |
| 51 | - /**  | 
                                                        |
| 52 | - * @return IEmailHelper  | 
                                                        |
| 53 | - */  | 
                                                        |
| 54 | - final public function getEmailHelper()  | 
                                                        |
| 55 | -    { | 
                                                        |
| 56 | - return $this->emailHelper;  | 
                                                        |
| 57 | - }  | 
                                                        |
| 58 | -  | 
                                                        |
| 59 | - /**  | 
                                                        |
| 60 | - * @param IEmailHelper $emailHelper  | 
                                                        |
| 61 | - */  | 
                                                        |
| 62 | - final public function setEmailHelper($emailHelper)  | 
                                                        |
| 63 | -    { | 
                                                        |
| 64 | - $this->emailHelper = $emailHelper;  | 
                                                        |
| 65 | - }  | 
                                                        |
| 66 | -  | 
                                                        |
| 67 | - /**  | 
                                                        |
| 68 | - * @return HttpHelper  | 
                                                        |
| 69 | - */  | 
                                                        |
| 70 | - final public function getHttpHelper()  | 
                                                        |
| 71 | -    { | 
                                                        |
| 72 | - return $this->httpHelper;  | 
                                                        |
| 73 | - }  | 
                                                        |
| 74 | -  | 
                                                        |
| 75 | - /**  | 
                                                        |
| 76 | - * @param HttpHelper $httpHelper  | 
                                                        |
| 77 | - */  | 
                                                        |
| 78 | - final public function setHttpHelper($httpHelper)  | 
                                                        |
| 79 | -    { | 
                                                        |
| 80 | - $this->httpHelper = $httpHelper;  | 
                                                        |
| 81 | - }  | 
                                                        |
| 82 | -  | 
                                                        |
| 83 | - /**  | 
                                                        |
| 84 | - * @return WikiTextHelper  | 
                                                        |
| 85 | - */  | 
                                                        |
| 86 | - final public function getWikiTextHelper()  | 
                                                        |
| 87 | -    { | 
                                                        |
| 88 | - return $this->wikiTextHelper;  | 
                                                        |
| 89 | - }  | 
                                                        |
| 90 | -  | 
                                                        |
| 91 | - /**  | 
                                                        |
| 92 | - * @param WikiTextHelper $wikiTextHelper  | 
                                                        |
| 93 | - */  | 
                                                        |
| 94 | - final public function setWikiTextHelper($wikiTextHelper)  | 
                                                        |
| 95 | -    { | 
                                                        |
| 96 | - $this->wikiTextHelper = $wikiTextHelper;  | 
                                                        |
| 97 | - }  | 
                                                        |
| 98 | -  | 
                                                        |
| 99 | - /**  | 
                                                        |
| 100 | - * @return ILocationProvider  | 
                                                        |
| 101 | - */  | 
                                                        |
| 102 | - final public function getLocationProvider()  | 
                                                        |
| 103 | -    { | 
                                                        |
| 104 | - return $this->locationProvider;  | 
                                                        |
| 105 | - }  | 
                                                        |
| 106 | -  | 
                                                        |
| 107 | - /**  | 
                                                        |
| 108 | - * @param ILocationProvider $locationProvider  | 
                                                        |
| 109 | - */  | 
                                                        |
| 110 | - final public function setLocationProvider(ILocationProvider $locationProvider)  | 
                                                        |
| 111 | -    { | 
                                                        |
| 112 | - $this->locationProvider = $locationProvider;  | 
                                                        |
| 113 | - }  | 
                                                        |
| 114 | -  | 
                                                        |
| 115 | - /**  | 
                                                        |
| 116 | - * @return IXffTrustProvider  | 
                                                        |
| 117 | - */  | 
                                                        |
| 118 | - final public function getXffTrustProvider()  | 
                                                        |
| 119 | -    { | 
                                                        |
| 120 | - return $this->xffTrustProvider;  | 
                                                        |
| 121 | - }  | 
                                                        |
| 122 | -  | 
                                                        |
| 123 | - /**  | 
                                                        |
| 124 | - * @param IXffTrustProvider $xffTrustProvider  | 
                                                        |
| 125 | - */  | 
                                                        |
| 126 | - final public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider)  | 
                                                        |
| 127 | -    { | 
                                                        |
| 128 | - $this->xffTrustProvider = $xffTrustProvider;  | 
                                                        |
| 129 | - }  | 
                                                        |
| 130 | -  | 
                                                        |
| 131 | - /**  | 
                                                        |
| 132 | - * @return IRDnsProvider  | 
                                                        |
| 133 | - */  | 
                                                        |
| 134 | - final public function getRdnsProvider()  | 
                                                        |
| 135 | -    { | 
                                                        |
| 136 | - return $this->rdnsProvider;  | 
                                                        |
| 137 | - }  | 
                                                        |
| 138 | -  | 
                                                        |
| 139 | - /**  | 
                                                        |
| 140 | - * @param IRDnsProvider $rdnsProvider  | 
                                                        |
| 141 | - */  | 
                                                        |
| 142 | - public function setRdnsProvider($rdnsProvider)  | 
                                                        |
| 143 | -    { | 
                                                        |
| 144 | - $this->rdnsProvider = $rdnsProvider;  | 
                                                        |
| 145 | - }  | 
                                                        |
| 146 | -  | 
                                                        |
| 147 | - /**  | 
                                                        |
| 148 | - * @return IAntiSpoofProvider  | 
                                                        |
| 149 | - */  | 
                                                        |
| 150 | - public function getAntiSpoofProvider()  | 
                                                        |
| 151 | -    { | 
                                                        |
| 152 | - return $this->antiSpoofProvider;  | 
                                                        |
| 153 | - }  | 
                                                        |
| 154 | -  | 
                                                        |
| 155 | - /**  | 
                                                        |
| 156 | - * @param IAntiSpoofProvider $antiSpoofProvider  | 
                                                        |
| 157 | - */  | 
                                                        |
| 158 | - public function setAntiSpoofProvider($antiSpoofProvider)  | 
                                                        |
| 159 | -    { | 
                                                        |
| 160 | - $this->antiSpoofProvider = $antiSpoofProvider;  | 
                                                        |
| 161 | - }  | 
                                                        |
| 162 | -  | 
                                                        |
| 163 | - /**  | 
                                                        |
| 164 | - * @return PdoDatabase  | 
                                                        |
| 165 | - */  | 
                                                        |
| 166 | - final public function getDatabase()  | 
                                                        |
| 167 | -    { | 
                                                        |
| 168 | - return $this->database;  | 
                                                        |
| 169 | - }  | 
                                                        |
| 170 | -  | 
                                                        |
| 171 | - /**  | 
                                                        |
| 172 | - * @param PdoDatabase $database  | 
                                                        |
| 173 | - */  | 
                                                        |
| 174 | - final public function setDatabase($database)  | 
                                                        |
| 175 | -    { | 
                                                        |
| 176 | - $this->database = $database;  | 
                                                        |
| 177 | - }  | 
                                                        |
| 178 | -  | 
                                                        |
| 179 | - /**  | 
                                                        |
| 180 | - * @return IOAuthHelper  | 
                                                        |
| 181 | - */  | 
                                                        |
| 182 | - public function getOAuthHelper()  | 
                                                        |
| 183 | -    { | 
                                                        |
| 184 | - return $this->oauthHelper;  | 
                                                        |
| 185 | - }  | 
                                                        |
| 186 | -  | 
                                                        |
| 187 | - /**  | 
                                                        |
| 188 | - * @param IOAuthHelper $oauthHelper  | 
                                                        |
| 189 | - */  | 
                                                        |
| 190 | - public function setOAuthHelper($oauthHelper)  | 
                                                        |
| 191 | -    { | 
                                                        |
| 192 | - $this->oauthHelper = $oauthHelper;  | 
                                                        |
| 193 | - }  | 
                                                        |
| 194 | -  | 
                                                        |
| 195 | - /**  | 
                                                        |
| 196 | - * @return void  | 
                                                        |
| 197 | - */  | 
                                                        |
| 198 | - abstract public function execute();  | 
                                                        |
| 199 | -  | 
                                                        |
| 200 | - /**  | 
                                                        |
| 201 | - * @return IrcNotificationHelper  | 
                                                        |
| 202 | - */  | 
                                                        |
| 203 | - public function getNotificationHelper()  | 
                                                        |
| 204 | -    { | 
                                                        |
| 205 | - return $this->notificationHelper;  | 
                                                        |
| 206 | - }  | 
                                                        |
| 207 | -  | 
                                                        |
| 208 | - /**  | 
                                                        |
| 209 | - * @param IrcNotificationHelper $notificationHelper  | 
                                                        |
| 210 | - */  | 
                                                        |
| 211 | - public function setNotificationHelper($notificationHelper)  | 
                                                        |
| 212 | -    { | 
                                                        |
| 213 | - $this->notificationHelper = $notificationHelper;  | 
                                                        |
| 214 | - }  | 
                                                        |
| 215 | -  | 
                                                        |
| 216 | - /**  | 
                                                        |
| 217 | - * @return TorExitProvider  | 
                                                        |
| 218 | - */  | 
                                                        |
| 219 | - public function getTorExitProvider()  | 
                                                        |
| 220 | -    { | 
                                                        |
| 221 | - return $this->torExitProvider;  | 
                                                        |
| 222 | - }  | 
                                                        |
| 223 | -  | 
                                                        |
| 224 | - /**  | 
                                                        |
| 225 | - * @param TorExitProvider $torExitProvider  | 
                                                        |
| 226 | - */  | 
                                                        |
| 227 | - public function setTorExitProvider($torExitProvider)  | 
                                                        |
| 228 | -    { | 
                                                        |
| 229 | - $this->torExitProvider = $torExitProvider;  | 
                                                        |
| 230 | - }  | 
                                                        |
| 231 | -  | 
                                                        |
| 232 | - /**  | 
                                                        |
| 233 | - * Gets the site configuration object  | 
                                                        |
| 234 | - *  | 
                                                        |
| 235 | - * @return SiteConfiguration  | 
                                                        |
| 236 | - */  | 
                                                        |
| 237 | - final protected function getSiteConfiguration()  | 
                                                        |
| 238 | -    { | 
                                                        |
| 239 | - return $this->siteConfiguration;  | 
                                                        |
| 240 | - }  | 
                                                        |
| 241 | -  | 
                                                        |
| 242 | - /**  | 
                                                        |
| 243 | - * Sets the site configuration object for this page  | 
                                                        |
| 244 | - *  | 
                                                        |
| 245 | - * @param SiteConfiguration $configuration  | 
                                                        |
| 246 | - */  | 
                                                        |
| 247 | - final public function setSiteConfiguration($configuration)  | 
                                                        |
| 248 | -    { | 
                                                        |
| 249 | - $this->siteConfiguration = $configuration;  | 
                                                        |
| 250 | - }  | 
                                                        |
| 26 | + /** @var SiteConfiguration */  | 
                                                        |
| 27 | + private $siteConfiguration;  | 
                                                        |
| 28 | + /** @var IEmailHelper */  | 
                                                        |
| 29 | + private $emailHelper;  | 
                                                        |
| 30 | + /** @var HttpHelper */  | 
                                                        |
| 31 | + private $httpHelper;  | 
                                                        |
| 32 | + /** @var WikiTextHelper */  | 
                                                        |
| 33 | + private $wikiTextHelper;  | 
                                                        |
| 34 | + /** @var ILocationProvider */  | 
                                                        |
| 35 | + private $locationProvider;  | 
                                                        |
| 36 | + /** @var IXffTrustProvider */  | 
                                                        |
| 37 | + private $xffTrustProvider;  | 
                                                        |
| 38 | + /** @var IRDnsProvider */  | 
                                                        |
| 39 | + private $rdnsProvider;  | 
                                                        |
| 40 | + /** @var IAntiSpoofProvider */  | 
                                                        |
| 41 | + private $antiSpoofProvider;  | 
                                                        |
| 42 | + /** @var IOAuthHelper */  | 
                                                        |
| 43 | + private $oauthHelper;  | 
                                                        |
| 44 | + /** @var PdoDatabase */  | 
                                                        |
| 45 | + private $database;  | 
                                                        |
| 46 | + /** @var IrcNotificationHelper */  | 
                                                        |
| 47 | + private $notificationHelper;  | 
                                                        |
| 48 | + /** @var TorExitProvider */  | 
                                                        |
| 49 | + private $torExitProvider;  | 
                                                        |
| 50 | +  | 
                                                        |
| 51 | + /**  | 
                                                        |
| 52 | + * @return IEmailHelper  | 
                                                        |
| 53 | + */  | 
                                                        |
| 54 | + final public function getEmailHelper()  | 
                                                        |
| 55 | +	{ | 
                                                        |
| 56 | + return $this->emailHelper;  | 
                                                        |
| 57 | + }  | 
                                                        |
| 58 | +  | 
                                                        |
| 59 | + /**  | 
                                                        |
| 60 | + * @param IEmailHelper $emailHelper  | 
                                                        |
| 61 | + */  | 
                                                        |
| 62 | + final public function setEmailHelper($emailHelper)  | 
                                                        |
| 63 | +	{ | 
                                                        |
| 64 | + $this->emailHelper = $emailHelper;  | 
                                                        |
| 65 | + }  | 
                                                        |
| 66 | +  | 
                                                        |
| 67 | + /**  | 
                                                        |
| 68 | + * @return HttpHelper  | 
                                                        |
| 69 | + */  | 
                                                        |
| 70 | + final public function getHttpHelper()  | 
                                                        |
| 71 | +	{ | 
                                                        |
| 72 | + return $this->httpHelper;  | 
                                                        |
| 73 | + }  | 
                                                        |
| 74 | +  | 
                                                        |
| 75 | + /**  | 
                                                        |
| 76 | + * @param HttpHelper $httpHelper  | 
                                                        |
| 77 | + */  | 
                                                        |
| 78 | + final public function setHttpHelper($httpHelper)  | 
                                                        |
| 79 | +	{ | 
                                                        |
| 80 | + $this->httpHelper = $httpHelper;  | 
                                                        |
| 81 | + }  | 
                                                        |
| 82 | +  | 
                                                        |
| 83 | + /**  | 
                                                        |
| 84 | + * @return WikiTextHelper  | 
                                                        |
| 85 | + */  | 
                                                        |
| 86 | + final public function getWikiTextHelper()  | 
                                                        |
| 87 | +	{ | 
                                                        |
| 88 | + return $this->wikiTextHelper;  | 
                                                        |
| 89 | + }  | 
                                                        |
| 90 | +  | 
                                                        |
| 91 | + /**  | 
                                                        |
| 92 | + * @param WikiTextHelper $wikiTextHelper  | 
                                                        |
| 93 | + */  | 
                                                        |
| 94 | + final public function setWikiTextHelper($wikiTextHelper)  | 
                                                        |
| 95 | +	{ | 
                                                        |
| 96 | + $this->wikiTextHelper = $wikiTextHelper;  | 
                                                        |
| 97 | + }  | 
                                                        |
| 98 | +  | 
                                                        |
| 99 | + /**  | 
                                                        |
| 100 | + * @return ILocationProvider  | 
                                                        |
| 101 | + */  | 
                                                        |
| 102 | + final public function getLocationProvider()  | 
                                                        |
| 103 | +	{ | 
                                                        |
| 104 | + return $this->locationProvider;  | 
                                                        |
| 105 | + }  | 
                                                        |
| 106 | +  | 
                                                        |
| 107 | + /**  | 
                                                        |
| 108 | + * @param ILocationProvider $locationProvider  | 
                                                        |
| 109 | + */  | 
                                                        |
| 110 | + final public function setLocationProvider(ILocationProvider $locationProvider)  | 
                                                        |
| 111 | +	{ | 
                                                        |
| 112 | + $this->locationProvider = $locationProvider;  | 
                                                        |
| 113 | + }  | 
                                                        |
| 114 | +  | 
                                                        |
| 115 | + /**  | 
                                                        |
| 116 | + * @return IXffTrustProvider  | 
                                                        |
| 117 | + */  | 
                                                        |
| 118 | + final public function getXffTrustProvider()  | 
                                                        |
| 119 | +	{ | 
                                                        |
| 120 | + return $this->xffTrustProvider;  | 
                                                        |
| 121 | + }  | 
                                                        |
| 122 | +  | 
                                                        |
| 123 | + /**  | 
                                                        |
| 124 | + * @param IXffTrustProvider $xffTrustProvider  | 
                                                        |
| 125 | + */  | 
                                                        |
| 126 | + final public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider)  | 
                                                        |
| 127 | +	{ | 
                                                        |
| 128 | + $this->xffTrustProvider = $xffTrustProvider;  | 
                                                        |
| 129 | + }  | 
                                                        |
| 130 | +  | 
                                                        |
| 131 | + /**  | 
                                                        |
| 132 | + * @return IRDnsProvider  | 
                                                        |
| 133 | + */  | 
                                                        |
| 134 | + final public function getRdnsProvider()  | 
                                                        |
| 135 | +	{ | 
                                                        |
| 136 | + return $this->rdnsProvider;  | 
                                                        |
| 137 | + }  | 
                                                        |
| 138 | +  | 
                                                        |
| 139 | + /**  | 
                                                        |
| 140 | + * @param IRDnsProvider $rdnsProvider  | 
                                                        |
| 141 | + */  | 
                                                        |
| 142 | + public function setRdnsProvider($rdnsProvider)  | 
                                                        |
| 143 | +	{ | 
                                                        |
| 144 | + $this->rdnsProvider = $rdnsProvider;  | 
                                                        |
| 145 | + }  | 
                                                        |
| 146 | +  | 
                                                        |
| 147 | + /**  | 
                                                        |
| 148 | + * @return IAntiSpoofProvider  | 
                                                        |
| 149 | + */  | 
                                                        |
| 150 | + public function getAntiSpoofProvider()  | 
                                                        |
| 151 | +	{ | 
                                                        |
| 152 | + return $this->antiSpoofProvider;  | 
                                                        |
| 153 | + }  | 
                                                        |
| 154 | +  | 
                                                        |
| 155 | + /**  | 
                                                        |
| 156 | + * @param IAntiSpoofProvider $antiSpoofProvider  | 
                                                        |
| 157 | + */  | 
                                                        |
| 158 | + public function setAntiSpoofProvider($antiSpoofProvider)  | 
                                                        |
| 159 | +	{ | 
                                                        |
| 160 | + $this->antiSpoofProvider = $antiSpoofProvider;  | 
                                                        |
| 161 | + }  | 
                                                        |
| 162 | +  | 
                                                        |
| 163 | + /**  | 
                                                        |
| 164 | + * @return PdoDatabase  | 
                                                        |
| 165 | + */  | 
                                                        |
| 166 | + final public function getDatabase()  | 
                                                        |
| 167 | +	{ | 
                                                        |
| 168 | + return $this->database;  | 
                                                        |
| 169 | + }  | 
                                                        |
| 170 | +  | 
                                                        |
| 171 | + /**  | 
                                                        |
| 172 | + * @param PdoDatabase $database  | 
                                                        |
| 173 | + */  | 
                                                        |
| 174 | + final public function setDatabase($database)  | 
                                                        |
| 175 | +	{ | 
                                                        |
| 176 | + $this->database = $database;  | 
                                                        |
| 177 | + }  | 
                                                        |
| 178 | +  | 
                                                        |
| 179 | + /**  | 
                                                        |
| 180 | + * @return IOAuthHelper  | 
                                                        |
| 181 | + */  | 
                                                        |
| 182 | + public function getOAuthHelper()  | 
                                                        |
| 183 | +	{ | 
                                                        |
| 184 | + return $this->oauthHelper;  | 
                                                        |
| 185 | + }  | 
                                                        |
| 186 | +  | 
                                                        |
| 187 | + /**  | 
                                                        |
| 188 | + * @param IOAuthHelper $oauthHelper  | 
                                                        |
| 189 | + */  | 
                                                        |
| 190 | + public function setOAuthHelper($oauthHelper)  | 
                                                        |
| 191 | +	{ | 
                                                        |
| 192 | + $this->oauthHelper = $oauthHelper;  | 
                                                        |
| 193 | + }  | 
                                                        |
| 194 | +  | 
                                                        |
| 195 | + /**  | 
                                                        |
| 196 | + * @return void  | 
                                                        |
| 197 | + */  | 
                                                        |
| 198 | + abstract public function execute();  | 
                                                        |
| 199 | +  | 
                                                        |
| 200 | + /**  | 
                                                        |
| 201 | + * @return IrcNotificationHelper  | 
                                                        |
| 202 | + */  | 
                                                        |
| 203 | + public function getNotificationHelper()  | 
                                                        |
| 204 | +	{ | 
                                                        |
| 205 | + return $this->notificationHelper;  | 
                                                        |
| 206 | + }  | 
                                                        |
| 207 | +  | 
                                                        |
| 208 | + /**  | 
                                                        |
| 209 | + * @param IrcNotificationHelper $notificationHelper  | 
                                                        |
| 210 | + */  | 
                                                        |
| 211 | + public function setNotificationHelper($notificationHelper)  | 
                                                        |
| 212 | +	{ | 
                                                        |
| 213 | + $this->notificationHelper = $notificationHelper;  | 
                                                        |
| 214 | + }  | 
                                                        |
| 215 | +  | 
                                                        |
| 216 | + /**  | 
                                                        |
| 217 | + * @return TorExitProvider  | 
                                                        |
| 218 | + */  | 
                                                        |
| 219 | + public function getTorExitProvider()  | 
                                                        |
| 220 | +	{ | 
                                                        |
| 221 | + return $this->torExitProvider;  | 
                                                        |
| 222 | + }  | 
                                                        |
| 223 | +  | 
                                                        |
| 224 | + /**  | 
                                                        |
| 225 | + * @param TorExitProvider $torExitProvider  | 
                                                        |
| 226 | + */  | 
                                                        |
| 227 | + public function setTorExitProvider($torExitProvider)  | 
                                                        |
| 228 | +	{ | 
                                                        |
| 229 | + $this->torExitProvider = $torExitProvider;  | 
                                                        |
| 230 | + }  | 
                                                        |
| 231 | +  | 
                                                        |
| 232 | + /**  | 
                                                        |
| 233 | + * Gets the site configuration object  | 
                                                        |
| 234 | + *  | 
                                                        |
| 235 | + * @return SiteConfiguration  | 
                                                        |
| 236 | + */  | 
                                                        |
| 237 | + final protected function getSiteConfiguration()  | 
                                                        |
| 238 | +	{ | 
                                                        |
| 239 | + return $this->siteConfiguration;  | 
                                                        |
| 240 | + }  | 
                                                        |
| 241 | +  | 
                                                        |
| 242 | + /**  | 
                                                        |
| 243 | + * Sets the site configuration object for this page  | 
                                                        |
| 244 | + *  | 
                                                        |
| 245 | + * @param SiteConfiguration $configuration  | 
                                                        |
| 246 | + */  | 
                                                        |
| 247 | + final public function setSiteConfiguration($configuration)  | 
                                                        |
| 248 | +	{ | 
                                                        |
| 249 | + $this->siteConfiguration = $configuration;  | 
                                                        |
| 250 | + }  | 
                                                        |
| 251 | 251 | }  | 
                                                        
| 252 | 252 | \ No newline at end of file  |