[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/extensions/ConfirmEdit/ -> CaptchaStore.php (source)

   1  <?php
   2  
   3  abstract class CaptchaStore {
   4      /**
   5       * Store the correct answer for a given captcha
   6       * @param  $index String
   7       * @param  $info String the captcha result
   8       */
   9      public abstract function store( $index, $info );
  10  
  11      /**
  12       * Retrieve the answer for a given captcha
  13       * @param  $index String
  14       * @return String
  15       */
  16      public abstract function retrieve( $index );
  17  
  18      /**
  19       * Delete a result once the captcha has been used, so it cannot be reused
  20       * @param  $index
  21       */
  22      public abstract function clear( $index );
  23  
  24      /**
  25       * Whether this type of CaptchaStore needs cookies
  26       * @return Bool
  27       */
  28      public abstract function cookiesNeeded();
  29  
  30      /**
  31       * The singleton instance
  32       * @var CaptchaStore
  33       */
  34      private static $instance;
  35  
  36      /**
  37       * Get somewhere to store captcha data that will persist between requests
  38       *
  39       * @throws MWException
  40       * @return CaptchaStore
  41       */
  42  	public final static function get() {
  43          if ( !self::$instance instanceof self ) {
  44              global $wgCaptchaStorageClass;
  45              if ( in_array( 'CaptchaStore', class_parents( $wgCaptchaStorageClass ) ) ) {
  46                  self::$instance = new $wgCaptchaStorageClass;
  47              } else {
  48                  throw new MWException( "Invalid CaptchaStore class $wgCaptchaStorageClass" );
  49              }
  50          }
  51          return self::$instance;
  52      }
  53  
  54      /**
  55       * Protected constructor: no creating instances except through the factory method above
  56       */
  57  	protected function __construct() {}
  58  }
  59  
  60  class CaptchaSessionStore extends CaptchaStore {
  61  
  62  	protected function __construct() {
  63          // Make sure the session is started
  64          if ( session_id() === '' ) {
  65              wfSetupSession();
  66          }
  67      }
  68  
  69  	function store( $index, $info ) {
  70          $_SESSION['captcha' . $info['index']] = $info;
  71      }
  72  
  73  	function retrieve( $index ) {
  74          if ( isset( $_SESSION['captcha' . $index] ) ) {
  75              return $_SESSION['captcha' . $index];
  76          } else {
  77              return false;
  78          }
  79      }
  80  
  81  	function clear( $index ) {
  82          unset( $_SESSION['captcha' . $index] );
  83      }
  84  
  85  	function cookiesNeeded() {
  86          return true;
  87      }
  88  }
  89  
  90  class CaptchaCacheStore extends CaptchaStore {
  91  
  92  	function store( $index, $info ) {
  93          global $wgMemc, $wgCaptchaSessionExpiration;
  94          $wgMemc->set( wfMemcKey( 'captcha', $index ), $info,
  95              $wgCaptchaSessionExpiration );
  96      }
  97  
  98  	function retrieve( $index ) {
  99          global $wgMemc;
 100          $info = $wgMemc->get( wfMemcKey( 'captcha', $index ) );
 101          if ( $info ) {
 102              return $info;
 103          } else {
 104              return false;
 105          }
 106      }
 107  
 108  	function clear( $index ) {
 109          global $wgMemc;
 110          $wgMemc->delete( wfMemcKey( 'captcha', $index ) );
 111      }
 112  
 113  	function cookiesNeeded() {
 114          return false;
 115      }
 116  }


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