]> ToastFreeware Gitweb - toast/cookiecaptcha.git/blobdiff - ConfirmEdit_body.php
Link to page in content language instead of user language. It is unlikely that a...
[toast/cookiecaptcha.git] / ConfirmEdit_body.php
index 99c7a728aadef24ac168ce0feff53bfaac4da3b4..57655c681023ea56f4d4290919666a621bee7a3b 100644 (file)
@@ -54,7 +54,8 @@ class CaptchaSpecialPage extends UnlistedSpecialPage {
                $instance = ConfirmEditHooks::getInstance();
                switch( $par ) {
                case "image":
-                       return $instance->showImage();
+                       if( method_exists($instance,'showImage') )
+                               return $instance->showImage();
                case "help":
                default:
                        return $instance->showHelp();
@@ -102,12 +103,12 @@ class SimpleCaptcha {
                $index = $this->storeCaptcha( $captcha );
 
                return "<p><label for=\"wpCaptchaWord\">{$captcha['question']}</label> = " .
-                       wfElement( 'input', array(
+                       Xml::element( 'input', array(
                                'name' => 'wpCaptchaWord',
                                'id'   => 'wpCaptchaWord',
                                'tabindex' => 1 ) ) . // tab in before the edit textarea
                        "</p>\n" .
-                       wfElement( 'input', array(
+                       Xml::element( 'input', array(
                                'type'  => 'hidden',
                                'name'  => 'wpCaptchaId',
                                'id'    => 'wpCaptchaId',
@@ -212,6 +213,22 @@ class SimpleCaptcha {
                return intval( $wgMemc->get( $this->badLoginKey() ) ) >= $wgCaptchaBadLoginAttempts;
        }
        
+       /**
+        * Check if the IP is allowed to skip captchas
+        */
+       function isIPWhitelisted() {
+               global $wgCaptchaWhitelistIP;
+               if( !empty( $wgCaptchaWhitelistIP ) ) {
+                       $ip = wfGetIp();
+                       foreach ( $wgCaptchaWhitelistIP as $range ) {
+                               if ( IP::isInRange( $ip, $range ) ) {
+                                       return true;
+                               }
+                       }
+               }
+               return false;
+       }
+       
        /**
         * Internal cache key for badlogin checks.
         * @return string
@@ -267,15 +284,8 @@ class SimpleCaptcha {
                        wfDebug( "ConfirmEdit: user group allows skipping captcha\n" );
                        return false;
                }
-               global $wgCaptchaWhitelistIP;
-               if( !empty( $wgCaptchaWhitelistIP ) ) {
-                       $ip = wfGetIp();
-                       foreach ( $wgCaptchaWhitelistIP as $range ) {
-                               if ( IP::isInRange( $ip, $range ) ) {
-                                       return false;
-                               }
-                       }
-               }
+               if( $this->isIPWhitelisted() )
+                       return false;
 
 
                global $wgEmailAuthentication, $ceAllowConfirmedEmail;
@@ -479,8 +489,7 @@ class SimpleCaptcha {
         * @return bool true to continue saving, false to abort and show a captcha form
         */
        function confirmEdit( &$editPage, $newtext, $section, $merged = false ) {
-               global $wgTitle;
-               if( is_null( $wgTitle ) ) {
+               if( defined('MW_API') ) {
                        # API mode
                        # The CAPTCHA was already checked and approved 
                        return true;
@@ -523,6 +532,9 @@ class SimpleCaptcha {
                                wfDebug( "ConfirmEdit: user group allows skipping captcha on account creation\n" );
                                return true;
                        }
+                       if( $this->isIPWhitelisted() )
+                               return true;
+                               
                        $this->trigger = "new account '" . $u->getName() . "'";
                        if( !$this->passCaptcha() ) {
                                $message = wfMsg( 'captcha-createaccount-fail' );
@@ -540,6 +552,9 @@ class SimpleCaptcha {
         */
        function confirmUserLogin( $u, $pass, &$retval ) {
                if( $this->isBadLoginTriggered() ) {
+                       if( $this->isIPWhitelisted() )
+                               return true;
+                       
                        $this->trigger = "post-badlogin login '" . $u->getName() . "'";
                        if( !$this->passCaptcha() ) {
                                $message = wfMsg( 'captcha-badlogin-fail' );