Umherirrender has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/398638 )

Change subject: Move classes to own files
......................................................................

Move classes to own files

Makes MediaWiki.Files.OneClassPerFile.MultipleFound pass

Change-Id: I88b5112d84d8983e67be1bca9f4039486bcefc6f
---
M .phpcs.xml
M extension.json
D includes/CaptchaStore.php
A includes/store/CaptchaCacheStore.php
A includes/store/CaptchaHashStore.php
A includes/store/CaptchaSessionStore.php
A includes/store/CaptchaStore.php
7 files changed, 154 insertions(+), 152 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ConfirmEdit 
refs/changes/38/398638/1

diff --git a/.phpcs.xml b/.phpcs.xml
index a60b550..7e6cd14 100644
--- a/.phpcs.xml
+++ b/.phpcs.xml
@@ -5,7 +5,6 @@
                <exclude 
name="MediaWiki.Commenting.FunctionComment.MissingParamComment" />
                <exclude name="MediaWiki.Commenting.FunctionComment.WrongStyle" 
/>
                <exclude name="MediaWiki.Files.ClassMatchesFilename.NotMatch" />
-               <exclude name="MediaWiki.Files.OneClassPerFile.MultipleFound" />
                <exclude 
name="MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName"/>
                <exclude 
name="MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment"/>
        </rule>
diff --git a/extension.json b/extension.json
index ce6ef61..2247452 100644
--- a/extension.json
+++ b/extension.json
@@ -52,10 +52,10 @@
        "AutoloadClasses": {
                "ConfirmEditHooks": "includes/ConfirmEditHooks.php",
                "SimpleCaptcha": "SimpleCaptcha/Captcha.php",
-               "CaptchaStore": "includes/CaptchaStore.php",
-               "CaptchaSessionStore": "includes/CaptchaStore.php",
-               "CaptchaCacheStore": "includes/CaptchaStore.php",
-               "CaptchaHashStore": "includes/CaptchaStore.php",
+               "CaptchaStore": "includes/store/CaptchaStore.php",
+               "CaptchaSessionStore": "includes/store/CaptchaSessionStore.php",
+               "CaptchaCacheStore": "includes/store/CaptchaCacheStore.php",
+               "CaptchaHashStore": "includes/store/CaptchaHashStore.php",
                "CaptchaTriggers": "includes/CaptchaTriggers.php",
                "CaptchaSpecialPage": "includes/specials/SpecialCaptcha.php",
                "CaptchaPreAuthenticationProvider": 
"includes/auth/CaptchaPreAuthenticationProvider.php",
diff --git a/includes/CaptchaStore.php b/includes/CaptchaStore.php
deleted file mode 100644
index 9eb5200..0000000
--- a/includes/CaptchaStore.php
+++ /dev/null
@@ -1,147 +0,0 @@
-<?php
-
-use MediaWiki\Session\SessionManager;
-
-abstract class CaptchaStore {
-       /**
-        * Store the correct answer for a given captcha
-        * @param string $index
-        * @param string $info the captcha result
-        */
-       abstract public function store( $index, $info );
-
-       /**
-        * Retrieve the answer for a given captcha
-        * @param string $index
-        * @return string|false
-        */
-       abstract public function retrieve( $index );
-
-       /**
-        * Delete a result once the captcha has been used, so it cannot be 
reused
-        * @param string $index
-        */
-       abstract public function clear( $index );
-
-       /**
-        * Whether this type of CaptchaStore needs cookies
-        * @return bool
-        */
-       abstract public function cookiesNeeded();
-
-       /**
-        * The singleton instance
-        * @var CaptchaStore
-        */
-       private static $instance;
-
-       /**
-        * Get somewhere to store captcha data that will persist between 
requests
-        *
-        * @throws Exception
-        * @return CaptchaStore
-        */
-       final public static function get() {
-               if ( !self::$instance instanceof self ) {
-                       global $wgCaptchaStorageClass;
-                       if ( in_array( 'CaptchaStore', class_parents( 
$wgCaptchaStorageClass ) ) ) {
-                               self::$instance = new $wgCaptchaStorageClass;
-                       } else {
-                               throw new Exception( "Invalid CaptchaStore 
class $wgCaptchaStorageClass" );
-                       }
-               }
-               return self::$instance;
-       }
-
-       final public static function unsetInstanceForTests() {
-               if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
-                       throw new MWException( 'Cannot unset ' . __CLASS__ . ' 
instance in operation.' );
-               }
-               self::$instance = null;
-       }
-
-       /**
-        * Protected constructor: no creating instances except through the 
factory method above
-        */
-       protected function __construct() {
-       }
-}
-
-class CaptchaSessionStore extends CaptchaStore {
-       protected function __construct() {
-               // Make sure the session is started
-               SessionManager::getGlobalSession()->persist();
-       }
-
-       function store( $index, $info ) {
-               SessionManager::getGlobalSession()->set( 'captcha' . $index, 
$info );
-       }
-
-       function retrieve( $index ) {
-               return SessionManager::getGlobalSession()->get( 'captcha' . 
$index, false );
-       }
-
-       function clear( $index ) {
-               SessionManager::getGlobalSession()->remove( 'captcha' . $index 
);
-       }
-
-       function cookiesNeeded() {
-               return true;
-       }
-}
-
-class CaptchaCacheStore extends CaptchaStore {
-       function store( $index, $info ) {
-               global $wgCaptchaSessionExpiration;
-
-               ObjectCache::getMainStashInstance()->set(
-                       wfMemcKey( 'captcha', $index ),
-                       $info,
-                       $wgCaptchaSessionExpiration
-               );
-       }
-
-       function retrieve( $index ) {
-               $info = ObjectCache::getMainStashInstance()->get( wfMemcKey( 
'captcha', $index ) );
-               if ( $info ) {
-                       return $info;
-               } else {
-                       return false;
-               }
-       }
-
-       function clear( $index ) {
-               ObjectCache::getMainStashInstance()->delete( wfMemcKey( 
'captcha', $index ) );
-       }
-
-       function cookiesNeeded() {
-               return false;
-       }
-}
-
-class CaptchaHashStore extends CaptchaStore {
-       protected $data = [];
-
-       public function store( $index, $info ) {
-               $this->data[$index] = $info;
-       }
-
-       public function retrieve( $index ) {
-               if ( array_key_exists( $index, $this->data ) ) {
-                       return $this->data[$index];
-               }
-               return false;
-       }
-
-       public function clear( $index ) {
-               unset( $this->data[$index] );
-       }
-
-       public function cookiesNeeded() {
-               return false;
-       }
-
-       public function clearAll() {
-               $this->data = [];
-       }
-}
diff --git a/includes/store/CaptchaCacheStore.php 
b/includes/store/CaptchaCacheStore.php
new file mode 100644
index 0000000..d6661b3
--- /dev/null
+++ b/includes/store/CaptchaCacheStore.php
@@ -0,0 +1,30 @@
+<?php
+
+class CaptchaCacheStore extends CaptchaStore {
+       function store( $index, $info ) {
+               global $wgCaptchaSessionExpiration;
+
+               ObjectCache::getMainStashInstance()->set(
+                       wfMemcKey( 'captcha', $index ),
+                       $info,
+                       $wgCaptchaSessionExpiration
+               );
+       }
+
+       function retrieve( $index ) {
+               $info = ObjectCache::getMainStashInstance()->get( wfMemcKey( 
'captcha', $index ) );
+               if ( $info ) {
+                       return $info;
+               } else {
+                       return false;
+               }
+       }
+
+       function clear( $index ) {
+               ObjectCache::getMainStashInstance()->delete( wfMemcKey( 
'captcha', $index ) );
+       }
+
+       function cookiesNeeded() {
+               return false;
+       }
+}
diff --git a/includes/store/CaptchaHashStore.php 
b/includes/store/CaptchaHashStore.php
new file mode 100644
index 0000000..f28d431
--- /dev/null
+++ b/includes/store/CaptchaHashStore.php
@@ -0,0 +1,28 @@
+<?php
+
+class CaptchaHashStore extends CaptchaStore {
+       protected $data = [];
+
+       public function store( $index, $info ) {
+               $this->data[$index] = $info;
+       }
+
+       public function retrieve( $index ) {
+               if ( array_key_exists( $index, $this->data ) ) {
+                       return $this->data[$index];
+               }
+               return false;
+       }
+
+       public function clear( $index ) {
+               unset( $this->data[$index] );
+       }
+
+       public function cookiesNeeded() {
+               return false;
+       }
+
+       public function clearAll() {
+               $this->data = [];
+       }
+}
diff --git a/includes/store/CaptchaSessionStore.php 
b/includes/store/CaptchaSessionStore.php
new file mode 100644
index 0000000..a02f569
--- /dev/null
+++ b/includes/store/CaptchaSessionStore.php
@@ -0,0 +1,26 @@
+<?php
+
+use MediaWiki\Session\SessionManager;
+
+class CaptchaSessionStore extends CaptchaStore {
+       protected function __construct() {
+               // Make sure the session is started
+               SessionManager::getGlobalSession()->persist();
+       }
+
+       function store( $index, $info ) {
+               SessionManager::getGlobalSession()->set( 'captcha' . $index, 
$info );
+       }
+
+       function retrieve( $index ) {
+               return SessionManager::getGlobalSession()->get( 'captcha' . 
$index, false );
+       }
+
+       function clear( $index ) {
+               SessionManager::getGlobalSession()->remove( 'captcha' . $index 
);
+       }
+
+       function cookiesNeeded() {
+               return true;
+       }
+}
diff --git a/includes/store/CaptchaStore.php b/includes/store/CaptchaStore.php
new file mode 100644
index 0000000..20cb6a2
--- /dev/null
+++ b/includes/store/CaptchaStore.php
@@ -0,0 +1,66 @@
+<?php
+
+abstract class CaptchaStore {
+       /**
+        * Store the correct answer for a given captcha
+        * @param string $index
+        * @param string $info the captcha result
+        */
+       abstract public function store( $index, $info );
+
+       /**
+        * Retrieve the answer for a given captcha
+        * @param string $index
+        * @return string|false
+        */
+       abstract public function retrieve( $index );
+
+       /**
+        * Delete a result once the captcha has been used, so it cannot be 
reused
+        * @param string $index
+        */
+       abstract public function clear( $index );
+
+       /**
+        * Whether this type of CaptchaStore needs cookies
+        * @return bool
+        */
+       abstract public function cookiesNeeded();
+
+       /**
+        * The singleton instance
+        * @var CaptchaStore
+        */
+       private static $instance;
+
+       /**
+        * Get somewhere to store captcha data that will persist between 
requests
+        *
+        * @throws Exception
+        * @return CaptchaStore
+        */
+       final public static function get() {
+               if ( !self::$instance instanceof self ) {
+                       global $wgCaptchaStorageClass;
+                       if ( in_array( 'CaptchaStore', class_parents( 
$wgCaptchaStorageClass ) ) ) {
+                               self::$instance = new $wgCaptchaStorageClass;
+                       } else {
+                               throw new Exception( "Invalid CaptchaStore 
class $wgCaptchaStorageClass" );
+                       }
+               }
+               return self::$instance;
+       }
+
+       final public static function unsetInstanceForTests() {
+               if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
+                       throw new MWException( 'Cannot unset ' . __CLASS__ . ' 
instance in operation.' );
+               }
+               self::$instance = null;
+       }
+
+       /**
+        * Protected constructor: no creating instances except through the 
factory method above
+        */
+       protected function __construct() {
+       }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/398638
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I88b5112d84d8983e67be1bca9f4039486bcefc6f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ConfirmEdit
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <umherirrender_de...@web.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to