Stwalkerster has uploaded a new change for review.
https://gerrit.wikimedia.org/r/87546
Change subject: Add an API module for querying the AntiSpoof results without
having to attempt to create an account.
......................................................................
Add an API module for querying the AntiSpoof results without having to attempt
to create an account.
This is based on the related API module from TitleBlacklist.
Change-Id: Ic41b327308151a34158f4fa7c65d75936d0cf48e
---
M AntiSpoof.php
A api/ApiQueryAntiSpoof.php
2 files changed, 67 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AntiSpoof
refs/changes/46/87546/1
diff --git a/AntiSpoof.php b/AntiSpoof.php
index e125bd7..c7c0aed 100644
--- a/AntiSpoof.php
+++ b/AntiSpoof.php
@@ -38,6 +38,10 @@
$wgAutoloadClasses['SpoofUser'] = "$dir/SpoofUser.php";
$wgAutoloadClasses['BatchAntiSpoof'] = "$dir/maintenance/batchAntiSpoof.php";
+// Register the API method
+$wgAutoloadClasses['ApiQueryAntiSpoof'] = "$dir/api/ApiQueryAntiSpoof.php";
+$wgAPIModules['antispoof'] = 'ApiQueryAntiSpoof';
+
$wgHooks['LoadExtensionSchemaUpdates'][] = 'AntiSpoofHooks::asUpdateSchema';
$wgHooks['AbortNewAccount'][] = 'AntiSpoofHooks::asAbortNewAccountHook';
$wgHooks['UserCreateForm'][] = 'AntiSpoofHooks::asUserCreateFormHook';
diff --git a/api/ApiQueryAntiSpoof.php b/api/ApiQueryAntiSpoof.php
new file mode 100644
index 0000000..b9d5d35
--- /dev/null
+++ b/api/ApiQueryAntiSpoof.php
@@ -0,0 +1,63 @@
+<?php
+/**
+ * Query module check a username against the AntiSpoof normalisation checks
+ *
+ * @ingroup API
+ * @ingroup Extensions
+ */
+class ApiQueryAntiSpoof extends ApiBase {
+
+ public function __construct( $query, $moduleName ) {
+ parent::__construct( $query, $moduleName, 'as' );
+ }
+
+ public function execute() {
+ $params = $this->extractRequestParams();
+
+ $res = $this->getResult();
+ $res->addValue( null, $this->getModuleName(), array( 'username' =>
$params['username'] ) );
+
+ $spoof = new SpoofUser( $params['username'] );
+
+ if ( $spoof->isLegal() ) {
+ $normalized = $spoof->getNormalized();
+ $conflicts = $spoof->getConflicts();
+ if ( empty( $conflicts ) ) {
+ $res->addValue( null, $this->getModuleName(),
array( 'result' => 'pass' ));
+ } else {
+ $res->addValue( null, $this->getModuleName(),
array( 'result' => 'conflict' ));
+
+ $res->setIndexedTagName( $conflicts, 'u' );
+ $res->addValue( array( $this->getModuleName() ), 'users',
$conflicts);
+ }
+ } else {
+ $error = $spoof->getError();
+ $res->addValue( 'antispoof', 'result', 'error');
+ $res->addValue( 'antispoof', 'error',
$spoof->isLegal());
+ }
+ }
+
+ public function getAllowedParams() {
+ return array(
+ 'username' => array(
+ ApiBase::PARAM_REQUIRED => true,
+ ),
+ );
+ }
+
+ public function getParamDescription() {
+ return array(
+ 'username' => 'The username to check against AntiSpoof',
+ );
+ }
+
+ public function getDescription() {
+ return 'Check a username against AntiSpoof\'s normalisation
checks.';
+ }
+
+ public function getExamples() {
+ return array(
+ 'api.php?action=antispoof&asusername=Foo',
+ );
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/87546
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic41b327308151a34158f4fa7c65d75936d0cf48e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/AntiSpoof
Gerrit-Branch: master
Gerrit-Owner: Stwalkerster <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits