summaryrefslogtreecommitdiff
path: root/extensions/ConfirmEdit/QuestyCaptcha.class.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2011-12-03 13:29:22 +0100
committerPierre Schmitz <pierre@archlinux.de>2011-12-03 13:29:22 +0100
commitca32f08966f1b51fcb19460f0996bb0c4048e6fe (patch)
treeec04cc15b867bc21eedca904cea9af0254531a11 /extensions/ConfirmEdit/QuestyCaptcha.class.php
parenta22fbfc60f36f5f7ee10d5ae6fe347340c2ee67c (diff)
Update to MediaWiki 1.18.0
* also update ArchLinux skin to chagnes in MonoBook * Use only css to hide our menu bar when printing
Diffstat (limited to 'extensions/ConfirmEdit/QuestyCaptcha.class.php')
-rw-r--r--extensions/ConfirmEdit/QuestyCaptcha.class.php71
1 files changed, 71 insertions, 0 deletions
diff --git a/extensions/ConfirmEdit/QuestyCaptcha.class.php b/extensions/ConfirmEdit/QuestyCaptcha.class.php
new file mode 100644
index 00000000..478fcf34
--- /dev/null
+++ b/extensions/ConfirmEdit/QuestyCaptcha.class.php
@@ -0,0 +1,71 @@
+<?php
+
+/**
+ * QuestyCaptcha class
+ *
+ * @file
+ * @author Benjamin Lees <emufarmers@gmail.com>
+ * @ingroup Extensions
+ */
+
+class QuestyCaptcha extends SimpleCaptcha {
+
+ /** Validate a captcha response */
+ function keyMatch( $answer, $info ) {
+ if ( is_array( $info['answer'] ) ) {
+ return in_array( strtolower( $answer ), $info['answer'] );
+ } else {
+ return strtolower( $answer ) == strtolower( $info['answer'] );
+ }
+ }
+
+ function addCaptchaAPI( &$resultArr ) {
+ $captcha = $this->getCaptcha();
+ $index = $this->storeCaptcha( $captcha );
+ $resultArr['captcha']['type'] = 'question';
+ $resultArr['captcha']['mime'] = 'text/plain';
+ $resultArr['captcha']['id'] = $index;
+ $resultArr['captcha']['question'] = $captcha['question'];
+ }
+
+ function getCaptcha() {
+ global $wgCaptchaQuestions;
+ return $wgCaptchaQuestions[mt_rand( 0, count( $wgCaptchaQuestions ) - 1 )]; // pick a question, any question
+ }
+
+ function getForm() {
+ $captcha = $this->getCaptcha();
+ if ( !$captcha ) {
+ die( "No questions found; set some in LocalSettings.php using the format from QuestyCaptcha.php." );
+ }
+ $index = $this->storeCaptcha( $captcha );
+ return "<p><label for=\"wpCaptchaWord\">{$captcha['question']}</label> " .
+ Xml::element( 'input', array(
+ 'name' => 'wpCaptchaWord',
+ 'id' => 'wpCaptchaWord',
+ 'tabindex' => 1 ) ) . // tab in before the edit textarea
+ "</p>\n" .
+ Xml::element( 'input', array(
+ 'type' => 'hidden',
+ 'name' => 'wpCaptchaId',
+ 'id' => 'wpCaptchaId',
+ 'value' => $index ) );
+ }
+
+ function getMessage( $action ) {
+ $name = 'questycaptcha-' . $action;
+ $text = wfMsg( $name );
+ # Obtain a more tailored message, if possible, otherwise, fall back to
+ # the default for edits
+ return wfEmptyMsg( $name, $text ) ? wfMsg( 'questycaptcha-edit' ) : $text;
+ }
+
+ function showHelp() {
+ global $wgOut;
+ $wgOut->setPageTitle( wfMsg( 'captchahelp-title' ) );
+ $wgOut->addWikiText( wfMsg( 'questycaptchahelp-text' ) );
+ if ( $this->storage->cookiesNeeded() ) {
+ $wgOut->addWikiText( wfMsg( 'captchahelp-cookies-needed' ) );
+ }
+ }
+}