summaryrefslogtreecommitdiff
blob: 8a7b6fbfad3192ad89aabd1ab64c97e1e86b664f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
 * API module to check a username against the AntiSpoof normalisation checks
 *
 * @ingroup API
 * @ingroup Extensions
 */
class ApiAntiSpoof extends ApiBase {

	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();
			$res->addValue( null, $this->getModuleName(), array( 'normalised' => $normalized ) );

			$unfilteredConflicts = $spoof->getConflicts();
			if ( empty( $unfilteredConflicts ) ) {
				$res->addValue( null, $this->getModuleName(), array( 'result' => 'pass' ) );
			} else {
				$hasSuppressed = false;
				$conflicts = array();
				foreach ( $unfilteredConflicts as $conflict )
				{
					if ( !User::newFromName( $conflict )->isHidden() ) {
						$conflicts[] = $conflict;
					} else {
						$hasSuppressed = true;
					}
				}

				if ( $hasSuppressed ) {
					$res->addValue( null, $this->getModuleName(), array( 'suppressed' => 'true' ) );
				}

				$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', $error );
		}
	}

	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&username=Foo',
		);
	}
}