Index: trunk/extensions/ConfirmEdit/Captcha.php |
— | — | @@ -1,9 +1,19 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | class SimpleCaptcha { |
| 5 | + |
| 6 | + /** |
| 7 | + * @var CaptchaStore |
| 8 | + */ |
| 9 | + protected $storage; |
| 10 | + |
5 | 11 | function __construct() { |
6 | 12 | global $wgCaptchaStorageClass; |
7 | | - $this->storage = new $wgCaptchaStorageClass; |
| 13 | + if( in_array( 'CaptchaStore', class_implements( $wgCaptchaStorageClass ) ) ) { |
| 14 | + $this->storage = new $wgCaptchaStorageClass; |
| 15 | + } else { |
| 16 | + throw new MWException( "Invalid CaptchaStore class $wgCaptchaStorageClass" ); |
| 17 | + } |
8 | 18 | } |
9 | 19 | |
10 | 20 | function getCaptcha() { |
— | — | @@ -81,7 +91,7 @@ |
82 | 92 | /** |
83 | 93 | * Inject whazawhoo |
84 | 94 | * @fixme if multiple thingies insert a header, could break |
85 | | - * @param HTMLForm |
| 95 | + * @param $form HTMLForm |
86 | 96 | * @return bool true to keep running callbacks |
87 | 97 | */ |
88 | 98 | function injectEmailUser( &$form ) { |
— | — | @@ -103,7 +113,7 @@ |
104 | 114 | /** |
105 | 115 | * Inject whazawhoo |
106 | 116 | * @fixme if multiple thingies insert a header, could break |
107 | | - * @param SimpleTemplate $template |
| 117 | + * @param QuickTemplate $template |
108 | 118 | * @return bool true to keep running callbacks |
109 | 119 | */ |
110 | 120 | function injectUserCreate( &$template ) { |
— | — | @@ -126,7 +136,7 @@ |
127 | 137 | * Inject a captcha into the user login form after a failed |
128 | 138 | * password attempt as a speedbump for mass attacks. |
129 | 139 | * @fixme if multiple thingies insert a header, could break |
130 | | - * @param SimpleTemplate $template |
| 140 | + * @param $template QuickTemplate |
131 | 141 | * @return bool true to keep running callbacks |
132 | 142 | */ |
133 | 143 | function injectUserLogin( &$template ) { |
— | — | @@ -410,6 +420,8 @@ |
411 | 421 | |
412 | 422 | /** |
413 | 423 | * Load external links from the externallinks table |
| 424 | + * @param $title Title |
| 425 | + * @return Array |
414 | 426 | */ |
415 | 427 | function getLinksFromTracker( $title ) { |
416 | 428 | $dbr = wfGetDB( DB_SLAVE ); |
Index: trunk/extensions/ConfirmEdit/ConfirmEdit.php |
— | — | @@ -202,6 +202,7 @@ |
203 | 203 | |
204 | 204 | $wgAutoloadClasses['ConfirmEditHooks'] = "$wgConfirmEditIP/ConfirmEditHooks.php"; |
205 | 205 | $wgAutoloadClasses['SimpleCaptcha']= "$wgConfirmEditIP/Captcha.php"; |
| 206 | +$wgAutoloadClasses['CaptchaStore']= "$wgConfirmEditIP/CaptchaStore.php"; |
206 | 207 | $wgAutoloadClasses['CaptchaSessionStore']= "$wgConfirmEditIP/CaptchaStore.php"; |
207 | 208 | $wgAutoloadClasses['CaptchaCacheStore']= "$wgConfirmEditIP/CaptchaStore.php"; |
208 | 209 | $wgAutoloadClasses['CaptchaSpecialPage'] = "$wgConfirmEditIP/ConfirmEditHooks.php"; |
Index: trunk/extensions/ConfirmEdit/ConfirmEditHooks.php |
— | — | @@ -1,6 +1,12 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | class ConfirmEditHooks { |
| 5 | + |
| 6 | + /** |
| 7 | + * Get the global Captcha instance |
| 8 | + * |
| 9 | + * @return Captcha |
| 10 | + */ |
5 | 11 | static function getInstance() { |
6 | 12 | global $wgCaptcha, $wgCaptchaClass; |
7 | 13 | static $done = false; |
Index: trunk/extensions/ConfirmEdit/CaptchaStore.php |
— | — | @@ -1,6 +1,64 @@ |
2 | 2 | <?php |
3 | | -class CaptchaSessionStore { |
4 | 3 | |
| 4 | +abstract class CaptchaStore { |
| 5 | + /** |
| 6 | + * Store the correct answer for a given captcha |
| 7 | + * @param $index String |
| 8 | + * @param $info String the captcha result |
| 9 | + */ |
| 10 | + public abstract function store( $index, $info ); |
| 11 | + |
| 12 | + /** |
| 13 | + * Retrieve the answer for a given captcha |
| 14 | + * @param $index String |
| 15 | + * @return String |
| 16 | + */ |
| 17 | + public abstract function retrieve( $index ); |
| 18 | + |
| 19 | + /** |
| 20 | + * Delete a result once the captcha has been used, so it cannot be reused |
| 21 | + * @param $index |
| 22 | + */ |
| 23 | + public abstract function clear( $index ); |
| 24 | + |
| 25 | + /** |
| 26 | + * Whether this type of CaptchaStore needs cookies |
| 27 | + * @return Bool |
| 28 | + */ |
| 29 | + public abstract function cookiesNeeded(); |
| 30 | + |
| 31 | + /** |
| 32 | + * The singleton instance |
| 33 | + * @var CaptchaStore |
| 34 | + */ |
| 35 | + private static $instance; |
| 36 | + |
| 37 | + /** |
| 38 | + * Get somewhere to store captcha data that will persist between requests |
| 39 | + * |
| 40 | + * @throws MWException |
| 41 | + * @return CaptchaStore |
| 42 | + */ |
| 43 | + public final static function get() { |
| 44 | + if( !self::$instance instanceof self ){ |
| 45 | + global $wgCaptchaStorageClass; |
| 46 | + if( in_array( 'CaptchaStore', class_implements( $wgCaptchaStorageClass ) ) ) { |
| 47 | + self::$instance = new $wgCaptchaStorageClass; |
| 48 | + } else { |
| 49 | + throw new MWException( "Invalid CaptchaStore class $wgCaptchaStorageClass" ); |
| 50 | + } |
| 51 | + } |
| 52 | + return self::$instance; |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Protected constructor: no creating instances except through the factory method above |
| 57 | + */ |
| 58 | + protected function __construct(){} |
| 59 | +} |
| 60 | + |
| 61 | +class CaptchaSessionStore extends CaptchaStore { |
| 62 | + |
5 | 63 | function store( $index, $info ) { |
6 | 64 | $_SESSION['captcha' . $info['index']] = $info; |
7 | 65 | } |
— | — | @@ -22,7 +80,7 @@ |
23 | 81 | } |
24 | 82 | } |
25 | 83 | |
26 | | -class CaptchaCacheStore { |
| 84 | +class CaptchaCacheStore extends CaptchaStore { |
27 | 85 | |
28 | 86 | function store( $index, $info ) { |
29 | 87 | global $wgMemc, $wgCaptchaSessionExpiration; |
Index: trunk/extensions/ConfirmEdit/FancyCaptcha.class.php |
— | — | @@ -44,7 +44,7 @@ |
45 | 45 | function getForm() { |
46 | 46 | $info = $this->pickImage(); |
47 | 47 | if ( !$info ) { |
48 | | - die( "out of captcha images; this shouldn't happen" ); |
| 48 | + throw new MWException( "Ran out of captcha images" ); |
49 | 49 | } |
50 | 50 | |
51 | 51 | // Generate a random key for use of this captcha image in this session. |