FunPika has uploaded a new change for review.

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

Change subject: Add ignoreantispoof parameter to API
......................................................................

Add ignoreantispoof parameter to API

This allows the wpIgnoreAntiSpoof checkbox on the account creation form to be
used in the API.

Bug: T56899
Change-Id: I378f252477b59555652ffc0f759660f7d38184f4
---
M AntiSpoof.php
M AntiSpoofHooks.php
M i18n/en.json
M i18n/qqq.json
4 files changed, 45 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AntiSpoof 
refs/changes/45/181945/1

diff --git a/AntiSpoof.php b/AntiSpoof.php
index fbb7fab..57d37c5 100644
--- a/AntiSpoof.php
+++ b/AntiSpoof.php
@@ -65,4 +65,6 @@
 $wgHooks['AddNewAccount'][] = 'AntiSpoofHooks::asAddNewAccountHook';
 $wgHooks['RenameUserComplete'][] = 'AntiSpoofHooks::asAddRenameUserHook';
 $wgHooks['DeleteAccount'][] = 'AntiSpoofHooks::asDeleteAccount';
-$wgHooks['UnitTestsList'][] = 'AntiSpoofHooks::asUnitTestsList';
\ No newline at end of file
+$wgHooks['UnitTestsList'][] = 'AntiSpoofHooks::asUnitTestsList';
+$wgHooks['APIGetAllowedParams'][] = 'AntiSpoofHooks::onAPIGetAllowedParams';
+$wgHooks['AddNewAccountApiForm'][] = 'AntiSpoofHooks::addNewAccountApiForm';
diff --git a/AntiSpoofHooks.php b/AntiSpoofHooks.php
index 9a54eb8..bc604d5 100644
--- a/AntiSpoofHooks.php
+++ b/AntiSpoofHooks.php
@@ -141,4 +141,42 @@
                return true;
                // @codeCoverageIgnoreEnd
        }
+
+       /**
+        * @param ApiBase $module
+        * @param array $params
+        * @return bool
+        */
+       public static function onAPIGetAllowedParams( &$module, &$params ) {
+               if ( $module instanceof ApiCreateAccount ) {
+                       $params['ignoreantispoof'] = array(
+                                       ApiBase::PARAM_TYPE => 'boolean',
+                                       ApiBase::PARAM_DFLT => false
+                       );
+               }
+
+               return true;
+       }
+
+       /**
+        * Pass API parameter on to the login form when using
+        * API account creation.
+        *
+        * @param ApiBase $apiModule
+        * @param LoginForm $loginForm
+        * @return hook return value
+        */
+       public static function addNewAccountApiForm( $apiModule, $loginForm ) {
+               global $wgRequest;
+               $main = $apiModule->getMain();
+
+               if ( $main->getVal( 'ignoreantispoof' ) !== null ) {
+                       $wgRequest->setVal( 'wpIgnoreAntiSpoof', '1' );
+
+                       // Suppress "unrecognized parameter" warning:
+                       $main->getVal( 'wpIgnoreAntiSpoof' );
+               }
+
+               return true;
+       }
 }
diff --git a/i18n/en.json b/i18n/en.json
index f5b635b..b824a97 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -22,5 +22,6 @@
        "right-override-antispoof": "Override the spoofing checks",
        "apihelp-antispoof-description": "Check a username against AntiSpoof's 
normalisation checks.",
        "apihelp-antispoof-param-username": "The username to check against 
AntiSpoof.",
-       "apihelp-antispoof-example-1": "Check username \"Foo\" against 
AntiSpoof"
+       "apihelp-antispoof-example-1": "Check username \"Foo\" against 
AntiSpoof",
+       "apihelp-createaccount-param-ignoreantispoof": "Ignore spoofing checks 
(requires override-antispoof right)."
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index eeda488..dce6734 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -30,5 +30,6 @@
        "right-override-antispoof": "{{doc-right|override-antispoof}}",
        "apihelp-antispoof-description": 
"{{doc-apihelp-description|antispoof}}",
        "apihelp-antispoof-param-username": 
"{{doc-apihelp-param|antispoof|username}}",
-       "apihelp-antispoof-example-1": "{{doc-apihelp-example|antispoof}}"
+       "apihelp-antispoof-example-1": "{{doc-apihelp-example|antispoof}}",
+       "apihelp-createaccount-param-ignoreantispoof": 
"{{doc-apihelp-param|createaccount|ignoreantispoof}}"
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I378f252477b59555652ffc0f759660f7d38184f4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/AntiSpoof
Gerrit-Branch: master
Gerrit-Owner: FunPika <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to