/** * 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; }