/** * Adds hidden field to form for JavaScript test * @return string */ public static function AddJSCode() { global $wgCTHiddenFieldName, $wgCTHiddenFieldDefault, $wgCTExtName; $ct_checkjs_key = CTBody::getJSChallenge(); $field_id = $wgCTHiddenFieldName . '_' . md5(rand(0, 1000)); $html = ' <input type="hidden" id="%s" name="%s" value="%s" /> <script type="text/javascript"> // <![CDATA[ var ct_input_name = \'%s\'; var ct_input_value = document.getElementById(ct_input_name).value; var ct_input_challenge = \'%s\'; document.getElementById(ct_input_name).value = document.getElementById(ct_input_name).value.replace(ct_input_value, ct_input_challenge); if (document.getElementById(ct_input_name).value == ct_input_value) { document.getElementById(ct_input_name).value = ct_set_challenge(ct_input_challenge); } function ct_set_challenge(val) { return val; }; // ]]> </script> '; $html = sprintf($html, $field_id, $wgCTHiddenFieldName, $wgCTHiddenFieldDefault, $field_id, $ct_checkjs_key); $html .= '<noscript><p><b>Please enable JavaScript to pass anti-spam protection!</b><br />Here are the instructions how to enable JavaScript in your web browser <a href="http://www.enable-javascript.com" rel="nofollow" target="_blank">http://www.enable-javascript.com</a>.<br />' . $wgCTExtName . '.</p></noscript>'; return $html; }
/** * Account spam test * @return bool */ public static function onAbortNewAccount($user, &$message) { global $wgCTAccessKey, $wgCTServerURL, $wgRequest, $wgCTAgent, $wgCTExtName; $allowAccount = true; // The facility in which to store the query parameters $ctRequest = new CleantalkRequest(); $ctRequest->auth_key = $wgCTAccessKey; $ctRequest->sender_email = $user->mEmail; $ctRequest->sender_nickname = $user->mName; $ctRequest->agent = $wgCTAgent; $ctRequest->sender_ip = $wgRequest->getIP(); $ctRequest->js_on = CTBody::JSTest(); $ctRequest->submit_time = CTBody::SubmitTimeTest(); $ctRequest->sender_info = json_encode(array('page_url' => htmlspecialchars(@$_SERVER['SERVER_NAME'] . @$_SERVER['REQUEST_URI']))); $ct = new Cleantalk(); $ct->server_url = $wgCTServerURL; // Check $ctResult = $ct->isAllowUser($ctRequest); // Allow account if we have any API errors if ($ctResult->errno != 0) { if (CTBody::JSTest() != 1) { $ctResult->allow = 0; $ctResult->comment = "Forbidden. Please, enable Javascript."; } else { $ctResult->allow = 1; } } // Disallow account with CleanTalk comment if ($ctResult->allow == 0) { $allowAccount = false; $message = $ctResult->comment; } if ($ctResult->inactive === 1) { CTBody::SendAdminEmail($wgCTExtName, $ctResult->comment); } return $allowAccount; }