Florianschmidtwelzow has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/300557

Change subject: Convert this extension to AuthManager
......................................................................

Convert this extension to AuthManager

Don't use a deprecated hook anymore. Instead, implement a 
PreAuthenticationProvider
and fail in the testUserForCreation() method, if the username does not have the
minimum length.

Bug: T137684
Change-Id: I5b3b00537dfc87a658e3975877a0ac810fd43a77
---
M CHANGELOG
D MinimumNameLength.class.php
M extension.json
A includes/auth/MinimumNameLengthPreAuthenticationProvider.php
4 files changed, 33 insertions(+), 37 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MinimumNameLength 
refs/changes/57/300557/1

diff --git a/CHANGELOG b/CHANGELOG
index a7f1e0d..659b5aa 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,7 @@
 
 == Version 1.2.3 ==
 * Converted the extension to use extension registration, instead of PHP entry 
point.
+* Converted extension to use a PreAuthenticationProvider
 
 == Version 1.2.2 ==
 
diff --git a/MinimumNameLength.class.php b/MinimumNameLength.class.php
deleted file mode 100644
index 9340fed..0000000
--- a/MinimumNameLength.class.php
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-/**
- * MinimumNameLength
- *
- * @file
- * @ingroup Extensions
- *
- * @license http://www.opensource.org/licenses/BSD-2-Clause BSD 2-clause
- *
- */
-
-/**
- * Hooks account creation and checks the username length, cancelling with an 
error
- * if the username is too short
- *
- * @param User $user User object being created
- * @param string $error Reference to error message to show
- * @return bool
- */
-
-class MinimumNameLength {
-
-       public static function onAbortNewAccount( $user, &$error ) {
-               global $wgMinimumUsernameLength;
-
-               if( mb_strlen( $user->getName() ) < $wgMinimumUsernameLength ) {
-
-                       $error = wfMessage( 'minimumnamelength-error' 
)->numParams( $wgMinimumUsernameLength )->plain();
-                       return false;
-               }
-
-               return true;
-       }
-}
diff --git a/extension.json b/extension.json
index 07925d0..c6844cc 100644
--- a/extension.json
+++ b/extension.json
@@ -6,6 +6,9 @@
                "Karsten Hoffmeyer",
                "..."
        ],
+       "requires": {
+               "MediaWiki": ">= 1.27.0"
+       },
        "url": "https://www.mediawiki.org/wiki/Extension:Minimum_Name_Length";,
        "descriptionmsg": "minimumnamelength-desc",
        "license-name": "BSD-2-Clause",
@@ -16,10 +19,14 @@
                ]
        },
        "AutoloadClasses": {
-               "MinimumNameLength": "MinimumNameLength.class.php"
+               "MinimumNameLengthPreAuthenticationProvider": 
"includes/auth/MinimumNameLengthPreAuthenticationProvider.php"
        },
-       "Hooks": {
-               "AbortNewAccount": "MinimumNameLength::onAbortNewAccount"
+       "AuthManagerAutoConfig": {
+               "preauth": {
+                       "MinimumNameLengthPreAuthenticationProvider": {
+                               "class": 
"MinimumNameLengthPreAuthenticationProvider"
+                       }
+               }
        },
        "config": {
                "MinimumUsernameLength": 10
diff --git a/includes/auth/MinimumNameLengthPreAuthenticationProvider.php 
b/includes/auth/MinimumNameLengthPreAuthenticationProvider.php
new file mode 100644
index 0000000..68daa1e
--- /dev/null
+++ b/includes/auth/MinimumNameLengthPreAuthenticationProvider.php
@@ -0,0 +1,22 @@
+<?php
+/**
+ * Implements the PreAuthenticationProvider interface for the 
MinimumNameLength extension.
+ */
+
+/**
+ * Class MinimumNameLengthPreAuthenticationProvider
+ */
+class MinimumNameLengthPreAuthenticationProvider extends
+       \MediaWiki\Auth\AbstractPreAuthenticationProvider {
+       public function testUserForCreation( $user, $autocreate, array $options 
= [] ) {
+               global $wgMinimumUsernameLength;
+
+               $value = StatusValue::newGood();
+               if( strlen( $user->getName() ) < $wgMinimumUsernameLength ) {
+                       $value = StatusValue::newFatal(
+                               wfMessage( 'minimumnamelength-error' 
)->numParams( $wgMinimumUsernameLength )
+                       );
+               }
+               return $value;
+       }
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5b3b00537dfc87a658e3975877a0ac810fd43a77
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MinimumNameLength
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com>

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

Reply via email to