[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/extensions/ConfirmEdit/ -> QuestyCaptcha.class.php (source)

   1  <?php
   2  
   3  /**
   4   * QuestyCaptcha class
   5   *
   6   * @file
   7   * @author Benjamin Lees <[email protected]>
   8   * @ingroup Extensions
   9   */
  10  
  11  class QuestyCaptcha extends SimpleCaptcha {
  12  
  13      /** Validate a captcha response */
  14  	function keyMatch( $answer, $info ) {
  15          if ( is_array( $info['answer'] ) ) {
  16              return in_array( strtolower( $answer ), $info['answer'] );
  17          } else {
  18              return strtolower( $answer ) == strtolower( $info['answer'] );
  19          }
  20      }
  21  
  22  	function addCaptchaAPI( &$resultArr ) {
  23          $captcha = $this->getCaptcha();
  24          $index = $this->storeCaptcha( $captcha );
  25          $resultArr['captcha']['type'] = 'question';
  26          $resultArr['captcha']['mime'] = 'text/plain';
  27          $resultArr['captcha']['id'] = $index;
  28          $resultArr['captcha']['question'] = $captcha['question'];
  29      }
  30  
  31  	function getCaptcha() {
  32          global $wgCaptchaQuestions;
  33          return $wgCaptchaQuestions[mt_rand( 0, count( $wgCaptchaQuestions ) - 1 )]; // pick a question, any question
  34      }
  35  
  36  	function getForm() {
  37          $captcha = $this->getCaptcha();
  38          if ( !$captcha ) {
  39              die( "No questions found; set some in LocalSettings.php using the format from QuestyCaptcha.php." );
  40          }
  41          $index = $this->storeCaptcha( $captcha );
  42          return "<p><label for=\"wpCaptchaWord\">{$captcha['question']}</label> " .
  43              Html::element( 'input', array(
  44                  'name' => 'wpCaptchaWord',
  45                  'id'   => 'wpCaptchaWord',
  46                  'class' => 'mw-ui-input',
  47                  'required',
  48                  'autocomplete' => 'off',
  49                  'tabindex' => 1 ) ) . // tab in before the edit textarea
  50              "</p>\n" .
  51              Xml::element( 'input', array(
  52                  'type'  => 'hidden',
  53                  'name'  => 'wpCaptchaId',
  54                  'id'    => 'wpCaptchaId',
  55                  'value' => $index ) );
  56      }
  57  
  58  	function getMessage( $action ) {
  59          $name = 'questycaptcha-' . $action;
  60          $text = wfMessage( $name )->text();
  61          # Obtain a more tailored message, if possible, otherwise, fall back to
  62          # the default for edits
  63          return wfMessage( $name, $text )->isDisabled() ? wfMessage( 'questycaptcha-edit' )->text() : $text;
  64      }
  65  
  66  	function showHelp() {
  67          global $wgOut;
  68          $wgOut->setPageTitle( wfMessage( 'captchahelp-title' )->text() );
  69          $wgOut->addWikiMsg( 'questycaptchahelp-text' );
  70          if ( CaptchaStore::get()->cookiesNeeded() ) {
  71              $wgOut->addWikiMsg( 'captchahelp-cookies-needed' );
  72          }
  73      }
  74  }


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1