More maintenance for ConfirmEdit extension.
[toast/cookiecaptcha.git] / FancyCaptcha.class.php
index 26227aa30bc11fd0014bc8917e547d664d2baaa2..c6ee03c6ddf76b155bc8c1cd8c88a2162c7cf276 100644 (file)
@@ -57,22 +57,28 @@ class FancyCaptcha extends SimpleCaptcha {
                $title = SpecialPage::getTitleFor( 'Captcha', 'image' );
 
                return "<p>" .
-                       Xml::element( 'img', array(
+                       Html::element( 'img', array(
                                'src'    => $title->getLocalUrl( 'wpCaptchaId=' . urlencode( $index ) ),
                                'width'  => $info['width'],
                                'height' => $info['height'],
                                'alt'    => '' ) ) .
                        "</p>\n" .
-                       Xml::element( 'input', array(
+                       Html::element( 'input', array(
                                'type'  => 'hidden',
                                'name'  => 'wpCaptchaId',
                                'id'    => 'wpCaptchaId',
                                'value' => $index ) ) .
-                       "<p>" .
+                       '<p>' .
+                       Html::element( 'label', array(
+                               'for' => 'wpCaptchaWord',
+                       ), parent::getMessage( 'label' ) . wfMessage( 'colon-separator' )->text() ) .
                        Html::element( 'input', array(
                                'name' => 'wpCaptchaWord',
                                'id'   => 'wpCaptchaWord',
-                               'required',
+                               'type' => 'text',
+                               'autocorrect' => 'off',
+                               'autocapitalize' => 'off',
+                               'required' => 'required',
                                'tabindex' => 1 ) ) . // tab in before the edit textarea
                        "</p>\n";
        }
@@ -95,6 +101,9 @@ class FancyCaptcha extends SimpleCaptcha {
 
                        // Check which subdirs are actually present...
                        $dir = opendir( $directory );
+                       if ( !$dir ) {
+                               return false;
+                       }
                        while ( false !== ( $entry = readdir( $dir ) ) ) {
                                if ( ctype_xdigit( $entry ) && strlen( $entry ) == 1 ) {
                                        $dirs[] = $entry;
@@ -152,6 +161,7 @@ class FancyCaptcha extends SimpleCaptcha {
 
        /**
         * Count the number of files in a directory.
+        * @param $dirname
         * @return int
         */
        function countFiles( $dirname ) {
@@ -173,17 +183,8 @@ class FancyCaptcha extends SimpleCaptcha {
 
                $info = $this->retrieveCaptcha();
                if ( $info ) {
-                       /*
-                       // Be a little less restrictive for now; in at least some circumstances,
-                       // Konqueror tries to reload the image even if you haven't navigated
-                       // away from the page.
-                       if( $info['viewed'] ) {
-                               wfHttpError( 403, 'Access Forbidden', "Can't view captcha image a second time." );
-                               return false;
-                       }
-                       */
-
-                       $info['viewed'] = wfTimestamp();
+                       $timestamp = new MWTimestamp();
+                       $info['viewed'] = $timestamp->getTimestamp();
                        $this->storeCaptcha( $info );
 
                        $salt = $info['salt'];
@@ -194,7 +195,7 @@ class FancyCaptcha extends SimpleCaptcha {
                                global $IP;
                                require_once "$IP/includes/StreamFile.php";
                                header( "Cache-Control: private, s-maxage=0, max-age=3600" );
-                               wfStreamFile( $file );
+                               StreamFile::stream( $file );
                                return true;
                        }
                }
@@ -218,15 +219,15 @@ class FancyCaptcha extends SimpleCaptcha {
         * Show a message asking the user to enter a captcha on edit
         * The result will be treated as wiki text
         *
-        * @param $action Action being performed
+        * @param $action string Action being performed
         * @return string
         */
        function getMessage( $action ) {
                $name = 'fancycaptcha-' . $action;
-               $text = wfMsg( $name );
+               $text = wfMessage( $name )->text();
                # Obtain a more tailored message, if possible, otherwise, fall back to
                # the default for edits
-               return wfEmptyMsg( $name, $text ) ? wfMsg( 'fancycaptcha-edit' ) : $text;
+               return wfMessage( $name, $text )->isDisabled() ? wfMessage( 'fancycaptcha-edit' )->text() : $text;
        }
 
        /**