]> ToastFreeware Gitweb - toast/cookiecaptcha.git/blobdiff - ConfirmEdit_body.php
Localisation updates for extension messages from Betawiki (2008-12-09 08:38 CET)
[toast/cookiecaptcha.git] / ConfirmEdit_body.php
index e905640cf23b8bafb119fecba564e462a397effc..99c7a728aadef24ac168ce0feff53bfaac4da3b4 100644 (file)
@@ -83,6 +83,7 @@ class SimpleCaptcha {
                $captcha = $this->getCaptcha();
                $index = $this->storeCaptcha( $captcha );
                $resultArr['captcha']['type'] = 'simple';
+               $resultArr['captcha']['mime'] = 'text/plain';
                $resultArr['captcha']['id'] = $index;
                $resultArr['captcha']['question'] = $captcha['question'];
        }
@@ -144,8 +145,12 @@ class SimpleCaptcha {
         * @return bool true to keep running callbacks
         */
        function injectUserCreate( &$template ) {
-               global $wgCaptchaTriggers, $wgOut;
+               global $wgCaptchaTriggers, $wgOut, $wgUser;
                if( $wgCaptchaTriggers['createaccount'] ) {
+                       if( $wgUser->isAllowed( 'skipcaptcha' ) ) {
+                               wfDebug( "ConfirmEdit: user group allows skipping captcha on account creation\n" );
+                               return true;
+                       }
                        $template->set( 'header',
                                "<div class='captcha'>" .
                                $wgOut->parse( $this->getMessage( 'createaccount' ) ) .
@@ -203,8 +208,8 @@ class SimpleCaptcha {
         * @access private
         */
        function isBadLoginTriggered() {
-               global $wgMemc;
-               return intval( $wgMemc->get( $this->badLoginKey() ) ) > 0;
+               global $wgMemc, $wgCaptchaBadLoginAttempts;
+               return intval( $wgMemc->get( $this->badLoginKey() ) ) >= $wgCaptchaBadLoginAttempts;
        }
        
        /**
@@ -313,8 +318,8 @@ class SimpleCaptcha {
                        } else {
                                // Get link changes in the slowest way known to man
                                $oldtext = $this->loadText( $editPage, $section );
-                               $oldLinks = $this->findLinks( $oldtext );
-                               $newLinks = $this->findLinks( $newtext );
+                               $oldLinks = $this->findLinks( $editPage, $oldtext );
+                               $newLinks = $this->findLinks( $editPage, $newtext );
                        }
 
                        $unknownLinks = array_filter( $newLinks, array( &$this, 'filterLink' ) );
@@ -407,7 +412,7 @@ class SimpleCaptcha {
                        //$regex = 'http://+[a-z0-9_\-.]*(' . implode( '|', $lines ) . ')';
                        //return '/' . str_replace( '/', '\/', preg_replace('|\\\*/|', '/', $regex) ) . '/Si';
                        $regexes = '';
-                       $regexStart = '/http:\/\/+[a-z0-9_\-.]*(';
+                       $regexStart = '/^https?:\/\/+[a-z0-9_\-.]*(';
                        $regexEnd = ')/Si';
                        $regexMax = 4096;
                        $build = false;
@@ -512,8 +517,12 @@ class SimpleCaptcha {
         * @return bool true to continue, false to abort user creation
         */
        function confirmUserCreate( $u, &$message ) {
-               global $wgCaptchaTriggers;
+               global $wgCaptchaTriggers, $wgUser;
                if( $wgCaptchaTriggers['createaccount'] ) {
+                       if( $wgUser->isAllowed( 'skipcaptcha' ) ) {
+                               wfDebug( "ConfirmEdit: user group allows skipping captcha on account creation\n" );
+                               return true;
+                       }
                        $this->trigger = "new account '" . $u->getName() . "'";
                        if( !$this->passCaptcha() ) {
                                $message = wfMsg( 'captcha-createaccount-fail' );
@@ -638,12 +647,12 @@ class SimpleCaptcha {
         * @param string $text
         * @return array of strings
         */
-       function findLinks( $text ) {
-               global $wgParser, $wgTitle, $wgUser;
+       function findLinks( &$editpage, $text ) {
+               global $wgParser, $wgUser;
 
                $options = new ParserOptions();
-               $text = $wgParser->preSaveTransform( $text, $wgTitle, $wgUser, $options );
-               $out = $wgParser->parse( $text, $wgTitle, $options );
+               $text = $wgParser->preSaveTransform( $text, $editpage->mTitle, $wgUser, $options );
+               $out = $wgParser->parse( $text, $editpage->mTitle, $options );
 
                return array_keys( $out->getExternalLinks() );
        }