diff --git a/README.md b/README.md index e19ec40d..05ced148 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ Visit : https://www.open-csp.org/DevOps:Doc/FlexForm ### Changelog +* 1.1.6 : reCaptcha fixed. Rdy to test. https://github.com/WikibaseSolutions/FlexForm/issues/8 * 1.1.5 : Fixed slot creation bug * 1.1.4 : Instances changes * 1.1.3 : Added frame parsing for tokens. Form validation was set to input field validations.. Fixed! diff --git a/extension.json b/extension.json index 0b54acd8..6983a8ca 100644 --- a/extension.json +++ b/extension.json @@ -1,6 +1,6 @@ { "name": "FlexForm", - "version": "1.1.5", + "version": "1.1.6", "author": [ "[https://www.wikibase-solutions.com/author/charlot Sen-Sai]", "[https://www.wikibase-solutions.com/author/marijn Marijn]" diff --git a/i18n/en.json b/i18n/en.json index 697c0413..cddf4cf0 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -82,6 +82,7 @@ "flexform-unkown-slot" : "Unknown Content Slot", + "flexform-captcha-missing-config" : "reCaptcha settings not found in Config", "flexform-captcha-missing-details" : "no captcha details", "flexform-captcha-score-to-low" : "Your Captcha score is to low. You form is not submitted", diff --git a/src/Core/Core.php b/src/Core/Core.php index 3fd8ce21..abe16a78 100644 --- a/src/Core/Core.php +++ b/src/Core/Core.php @@ -494,7 +494,6 @@ public static function createHiddenField( string $name, $value ): string { "all" ); } - return '' . "\n"; } @@ -525,5 +524,4 @@ public static function addCheckSum( string $type, string $name, $value, string $ } } - } \ No newline at end of file diff --git a/src/Processors/Content/CreateUser.php b/src/Processors/Content/CreateUser.php index 71293e61..356545e1 100644 --- a/src/Processors/Content/CreateUser.php +++ b/src/Processors/Content/CreateUser.php @@ -4,9 +4,9 @@ use FlexForm\Core\Core; use FlexForm\FlexFormException; +use MediaWiki\HookContainer\HookRunner; use MediaWiki\MediaWikiServices; use PasswordError; -use SiteStatsUpdate; use User; class CreateUser { @@ -48,45 +48,6 @@ public function __construct() { * @throws FlexFormException */ public function addUser(): User { - /* - $user = User::newFromName( $this->getUserName() ); - if ( !is_object( $user ) ) { - throw new FlexFormException( - wfMessage( 'flexform-createuser-invalid-name' )->text(), - 0 - ); - } - $exists = ( $user->idForName() !== 0 ); - if ( $exists ) { - throw new FlexFormException( - wfMessage( 'flexform-createuser-username-exists', $this->getUserName() )->text(), - 0 - ); - } - - $user->setEmail( $this->getEmailAddress() ); - - if ( $this->getRealName() !== null ) { - $user->setRealName( $this->getRealName() ); - } - */ - /* - - $status = MediaWikiServices::getInstance()->getAuthManager()->autoCreateUser( - $user, - \MediaWiki\Auth\AuthManager::AUTOCREATE_SOURCE_MAINT, - false - ); - if ( !$status->isGood() ) { - throw new FlexFormException( - $status->getMessage( false, false, 'en' )->text(), - 0 - ); - } - # Increment site_stats.ss_users - $ssu = SiteStatsUpdate::factory( [ 'users' => 1 ] ); - $ssu->doUpdate(); - */ $user = User::createNew( $this->getUserName(), [ 'email' => $this->getEmailAddress(), 'email_authenticated' => null, @@ -98,6 +59,9 @@ public function addUser(): User { 0 ); } + $hookContainer = MediaWikiServices::getInstance()->getHookContainer(); + $hookRunner = new HookRunner( $hookContainer ); + $hookRunner->onLocalUserCreated( $user, false ); return $user; } @@ -141,9 +105,9 @@ private function setPassword( User $user ): User { /** * @param User $user - * @param string $pwd * * @return void + * @throws FlexFormException */ public function sendPassWordAndConfirmationLink( User $user ) { global $IP; diff --git a/src/Render/Recaptcha.php b/src/Render/Recaptcha.php index 93fcea83..d14cd08d 100644 --- a/src/Render/Recaptcha.php +++ b/src/Render/Recaptcha.php @@ -11,30 +11,35 @@ namespace FlexForm\Render; // TODO: Cleanup and move to theme +use FlexForm\Core\Config; + class Recaptcha { // TODO: Add to mwapi !! public static $rc_site_key = ''; public static $rc_secret_key = ''; - + /** + * @return void + */ public static function loadSettings() { - global $IP; - $serverName=''; - include( $IP . '/extensions/FlexForm/config/config.php' ); - if( isset( $config['rc_site_key'] ) && isset( $config['rc_secret_key'] ) ) { - self::$rc_site_key = $config['rc_site_key']; - self::$rc_secret_key = $config['rc_secret_key']; + self::$rc_site_key = Config::getConfigVariable( 'rc_site_key' ); + self::$rc_secret_key = Config::getConfigVariable( 'rc_secret_key' ); + if ( empty( self::$rc_site_key ) ) { + self::$rc_site_key = null; + } + if ( empty( self::$rc_secret_key ) ) { + self::$rc_secret_key = null; } } /** - * @brief Load reCaptcha JavaScript - * - * @return string Rendered HTML + * @return false|string */ public static function render() { self::loadSettings(); - if( self::$rc_site_key === '' || self::$rc_secret_key === false ) return false; + if ( self::$rc_site_key === null || self::$rc_secret_key === null ) { + return false; + } $ret = ' '; return $ret; } diff --git a/src/Render/TagHooks.php b/src/Render/TagHooks.php index 444deba7..c1e13854 100644 --- a/src/Render/TagHooks.php +++ b/src/Render/TagHooks.php @@ -60,9 +60,7 @@ public function __construct( ThemeStore $themeStore ) { public function renderForm( $input, array $args, Parser $parser, PPFrame $frame ) { global $wgUser, $wgEmailConfirmToEdit, $IP, $wgScript; $ret = ''; - Core::$securityId = uniqid(); - Core::$chkSums = []; - Core::includeTagsCSS( Core::getRealUrl() . '/Modules/ext.WSForm.css' ); + //$parser->getOutput()->addModuleStyles( 'ext.wsForm.general.styles' ); // Do we have some messages to show? @@ -97,6 +95,10 @@ public function renderForm( $input, array $args, Parser $parser, PPFrame $frame ]; } + Core::$securityId = uniqid(); + Core::$chkSums = []; + Core::includeTagsCSS( Core::getRealUrl() . '/Modules/ext.WSForm.css' ); + if ( isset( $args['messageonsuccess'] ) ) { $messageOnSuccess = $parser->recursiveTagParse( $args['messageonsuccess'], @@ -205,6 +207,7 @@ public function renderForm( $input, array $args, Parser $parser, PPFrame $frame $formId = bin2hex( random_bytes( 16 ) ); } + if ( isset( $args['recaptcha-v3-action'] ) ) { Core::$reCaptcha = $args['recaptcha-v3-action']; unset( $args['recaptcha-v3-action'] ); @@ -384,6 +387,8 @@ public function renderForm( $input, array $args, Parser $parser, PPFrame $frame if ( $captcha !== false ) { Core::addAsLoaded( 'google-captcha' ); $ret = $captcha . $ret; + } else { + return wfMessage( "flexform-captcha-missing-config" )->parse(); } } @@ -416,13 +421,13 @@ public function renderForm( $input, array $args, Parser $parser, PPFrame $frame Core::includeInlineScript( $rcaptcha ); Core::$reCaptcha = false; } else { + return wfMessage( "flexform-recaptcha-no-js" )->parse(); } } self::addInlineJavaScriptAndCSS(); - return [ $ret, "markerType" => 'nowiki'