Ideas for improved versions.
[toast/cookiecaptcha.git] / ConfirmEditHooks.php
1 <?php
2
3 class ConfirmEditHooks {
4         /**
5          * Get the global Captcha instance
6          *
7          * @return Captcha|SimpleCaptcha
8          */
9         static function getInstance() {
10                 global $wgCaptcha, $wgCaptchaClass;
11
12                 static $done = false;
13
14                 if ( !$done ) {
15                         $done = true;
16                         $wgCaptcha = new $wgCaptchaClass;
17                 }
18
19                 return $wgCaptcha;
20         }
21
22         static function confirmEditMerged( $editPage, $newtext ) {
23                 return self::getInstance()->confirmEditMerged( $editPage, $newtext );
24         }
25
26         static function confirmEditAPI( $editPage, $newtext, &$resultArr ) {
27                 return self::getInstance()->confirmEditAPI( $editPage, $newtext, $resultArr );
28         }
29
30         static function injectUserCreate( &$template ) {
31                 return self::getInstance()->injectUserCreate( $template );
32         }
33
34         static function confirmUserCreate( $u, &$message ) {
35                 return self::getInstance()->confirmUserCreate( $u, $message );
36         }
37
38         static function triggerUserLogin( $user, $password, $retval ) {
39                 return self::getInstance()->triggerUserLogin( $user, $password, $retval );
40         }
41
42         static function injectUserLogin( &$template ) {
43                 return self::getInstance()->injectUserLogin( $template );
44         }
45
46         static function confirmUserLogin( $u, $pass, &$retval ) {
47                 return self::getInstance()->confirmUserLogin( $u, $pass, $retval );
48         }
49
50         static function injectEmailUser( &$form ) {
51                 return self::getInstance()->injectEmailUser( $form );
52         }
53
54         static function confirmEmailUser( $from, $to, $subject, $text, &$error ) {
55                 return self::getInstance()->confirmEmailUser( $from, $to, $subject, $text, $error );
56         }
57
58         public static function APIGetAllowedParams( &$module, &$params ) {
59                 return self::getInstance()->APIGetAllowedParams( $module, $params );
60         }
61
62         public static function APIGetParamDescription( &$module, &$desc ) {
63                 return self::getInstance()->APIGetParamDescription( $module, $desc );
64         }
65 }
66
67 class CaptchaSpecialPage extends UnlistedSpecialPage {
68         public function __construct() {
69                 parent::__construct( 'Captcha' );
70         }
71
72         function execute( $par ) {
73                 $this->setHeaders();
74
75                 $instance = ConfirmEditHooks::getInstance();
76
77                 switch( $par ) {
78                         case "image":
79                                 if ( method_exists( $instance, 'showImage' ) ) {
80                                         return $instance->showImage();
81                                 }
82                         case "help":
83                         default:
84                                 return $instance->showHelp();
85                 }
86         }
87 }