From 1bbd72e5fd08c28a5b1b72dca811ed84fe8ef470 Mon Sep 17 00:00:00 2001 From: Happy-melon Date: Sat, 23 Apr 2011 11:44:47 +0000 Subject: [PATCH] Reorganise files in ConfirmEdit --- ConfirmEdit_body.php => Captcha.php | 119 ---------------------------- CaptchaStore.php | 51 ++++++++++++ ConfirmEdit.php | 11 ++- ConfirmEditHooks.php | 72 +++++++++++++++++ 4 files changed, 128 insertions(+), 125 deletions(-) rename ConfirmEdit_body.php => Captcha.php (87%) create mode 100644 CaptchaStore.php create mode 100644 ConfirmEditHooks.php diff --git a/ConfirmEdit_body.php b/Captcha.php similarity index 87% rename from ConfirmEdit_body.php rename to Captcha.php index e94f307e8..6bbb60715 100644 --- a/ConfirmEdit_body.php +++ b/Captcha.php @@ -1,75 +1,5 @@ confirmEdit( $editPage, $newtext, $section ); - } - - static function confirmEditMerged( $editPage, $newtext ) { - return self::getInstance()->confirmEditMerged( $editPage, $newtext ); - } - - static function confirmEditAPI( $editPage, $newtext, &$resultArr ) { - return self::getInstance()->confirmEditAPI( $editPage, $newtext, $resultArr ); - } - - static function injectUserCreate( &$template ) { - return self::getInstance()->injectUserCreate( $template ); - } - - static function confirmUserCreate( $u, &$message ) { - return self::getInstance()->confirmUserCreate( $u, $message ); - } - - static function triggerUserLogin( $user, $password, $retval ) { - return self::getInstance()->triggerUserLogin( $user, $password, $retval ); - } - - static function injectUserLogin( &$template ) { - return self::getInstance()->injectUserLogin( $template ); - } - - static function confirmUserLogin( $u, $pass, &$retval ) { - return self::getInstance()->confirmUserLogin( $u, $pass, $retval ); - } - - static function injectEmailUser( &$form ) { - return self::getInstance()->injectEmailUser( $form ); - } - - static function confirmEmailUser( $from, $to, $subject, $text, &$error ) { - return self::getInstance()->confirmEmailUser( $from, $to, $subject, $text, $error ); - } -} - -class CaptchaSpecialPage extends UnlistedSpecialPage { - public function __construct(){ - parent::__construct( 'Captcha' ); - } - function execute( $par ) { - $this->setHeaders(); - $instance = ConfirmEditHooks::getInstance(); - switch( $par ) { - case "image": - if ( method_exists( $instance, 'showImage' ) ) - return $instance->showImage(); - case "help": - default: - return $instance->showHelp(); - } - } -} - class SimpleCaptcha { function __construct() { global $wgCaptchaStorageClass; @@ -748,52 +678,3 @@ class SimpleCaptcha { } } } - -class CaptchaSessionStore { - function store( $index, $info ) { - $_SESSION['captcha' . $info['index']] = $info; - } - - function retrieve( $index ) { - if ( isset( $_SESSION['captcha' . $index] ) ) { - return $_SESSION['captcha' . $index]; - } else { - return false; - } - } - - function clear( $index ) { - unset( $_SESSION['captcha' . $index] ); - } - - function cookiesNeeded() { - return true; - } -} - -class CaptchaCacheStore { - function store( $index, $info ) { - global $wgMemc, $wgCaptchaSessionExpiration; - $wgMemc->set( wfMemcKey( 'captcha', $index ), $info, - $wgCaptchaSessionExpiration ); - } - - function retrieve( $index ) { - global $wgMemc; - $info = $wgMemc->get( wfMemcKey( 'captcha', $index ) ); - if ( $info ) { - return $info; - } else { - return false; - } - } - - function clear( $index ) { - global $wgMemc; - $wgMemc->delete( wfMemcKey( 'captcha', $index ) ); - } - - function cookiesNeeded() { - return false; - } -} diff --git a/CaptchaStore.php b/CaptchaStore.php new file mode 100644 index 000000000..b32d637b7 --- /dev/null +++ b/CaptchaStore.php @@ -0,0 +1,51 @@ +set( wfMemcKey( 'captcha', $index ), $info, + $wgCaptchaSessionExpiration ); + } + + function retrieve( $index ) { + global $wgMemc; + $info = $wgMemc->get( wfMemcKey( 'captcha', $index ) ); + if ( $info ) { + return $info; + } else { + return false; + } + } + + function clear( $index ) { + global $wgMemc; + $wgMemc->delete( wfMemcKey( 'captcha', $index ) ); + } + + function cookiesNeeded() { + return false; + } +} diff --git a/ConfirmEdit.php b/ConfirmEdit.php index 446ed6b0b..004c95eb4 100644 --- a/ConfirmEdit.php +++ b/ConfirmEdit.php @@ -200,12 +200,11 @@ $wgHooks['EmailUser'][] = 'ConfirmEditHooks::confirmEmailUser'; # Register API hook $wgHooks['APIEditBeforeSave'][] = 'ConfirmEditHooks::confirmEditAPI'; -$wgAutoloadClasses['ConfirmEditHooks'] - = $wgAutoloadClasses['SimpleCaptcha'] - = $wgAutoloadClasses['CaptchaSessionStore'] - = $wgAutoloadClasses['CaptchaCacheStore'] - = $wgAutoloadClasses['CaptchaSpecialPage'] - = "$wgConfirmEditIP/ConfirmEdit_body.php"; +$wgAutoloadClasses['ConfirmEditHooks'] = "$wgConfirmEditIP/ConfirmEditHooks.php"; +$wgAutoloadClasses['SimpleCaptcha']= "$wgConfirmEditIP/Captcha.php"; +$wgAutoloadClasses['CaptchaSessionStore']= "$wgConfirmEditIP/CaptchaStore.php"; +$wgAutoloadClasses['CaptchaCacheStore']= "$wgConfirmEditIP/CaptchaStore.php"; +$wgAutoloadClasses['CaptchaSpecialPage'] = "$wgConfirmEditIP/ConfirmEditHooks.php"; /** * Set up $wgWhitelistRead diff --git a/ConfirmEditHooks.php b/ConfirmEditHooks.php new file mode 100644 index 000000000..7a4f5ba6e --- /dev/null +++ b/ConfirmEditHooks.php @@ -0,0 +1,72 @@ +confirmEdit( $editPage, $newtext, $section ); + } + + static function confirmEditMerged( $editPage, $newtext ) { + return self::getInstance()->confirmEditMerged( $editPage, $newtext ); + } + + static function confirmEditAPI( $editPage, $newtext, &$resultArr ) { + return self::getInstance()->confirmEditAPI( $editPage, $newtext, $resultArr ); + } + + static function injectUserCreate( &$template ) { + return self::getInstance()->injectUserCreate( $template ); + } + + static function confirmUserCreate( $u, &$message ) { + return self::getInstance()->confirmUserCreate( $u, $message ); + } + + static function triggerUserLogin( $user, $password, $retval ) { + return self::getInstance()->triggerUserLogin( $user, $password, $retval ); + } + + static function injectUserLogin( &$template ) { + return self::getInstance()->injectUserLogin( $template ); + } + + static function confirmUserLogin( $u, $pass, &$retval ) { + return self::getInstance()->confirmUserLogin( $u, $pass, $retval ); + } + + static function injectEmailUser( &$form ) { + return self::getInstance()->injectEmailUser( $form ); + } + + static function confirmEmailUser( $from, $to, $subject, $text, &$error ) { + return self::getInstance()->confirmEmailUser( $from, $to, $subject, $text, $error ); + } +} + +class CaptchaSpecialPage extends UnlistedSpecialPage { + public function __construct(){ + parent::__construct( 'Captcha' ); + } + function execute( $par ) { + $this->setHeaders(); + $instance = ConfirmEditHooks::getInstance(); + switch( $par ) { + case "image": + if ( method_exists( $instance, 'showImage' ) ) + return $instance->showImage(); + case "help": + default: + return $instance->showHelp(); + } + } +} +