Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 37 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ApiAntiSpoof | |
0.00% |
0 / 37 |
|
0.00% |
0 / 3 |
72 | |
0.00% |
0 / 1 |
| execute | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
42 | |||
| getAllowedParams | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| getExamplesMessages | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along |
| 14 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 16 | * http://www.gnu.org/copyleft/gpl.html |
| 17 | */ |
| 18 | |
| 19 | namespace MediaWiki\Extension\AntiSpoof; |
| 20 | |
| 21 | use MediaWiki\Api\ApiBase; |
| 22 | use MediaWiki\Api\ApiResult; |
| 23 | use MediaWiki\User\User; |
| 24 | use Wikimedia\ParamValidator\ParamValidator; |
| 25 | |
| 26 | /** |
| 27 | * API module to check a username against the AntiSpoof normalisation checks |
| 28 | * |
| 29 | * @ingroup API |
| 30 | * @ingroup Extensions |
| 31 | */ |
| 32 | class ApiAntiSpoof extends ApiBase { |
| 33 | |
| 34 | public function execute() { |
| 35 | $params = $this->extractRequestParams(); |
| 36 | |
| 37 | $res = $this->getResult(); |
| 38 | $res->addValue( null, $this->getModuleName(), [ 'username' => $params['username'] ] ); |
| 39 | |
| 40 | $spoof = new SpoofUser( $params['username'] ); |
| 41 | |
| 42 | if ( $spoof->isLegal() ) { |
| 43 | $normalized = $spoof->getNormalized(); |
| 44 | $res->addValue( null, $this->getModuleName(), [ 'normalised' => $normalized ] ); |
| 45 | |
| 46 | $unfilteredConflicts = $spoof->getConflicts(); |
| 47 | if ( !$unfilteredConflicts ) { |
| 48 | $res->addValue( null, $this->getModuleName(), [ 'result' => 'pass' ] ); |
| 49 | } else { |
| 50 | $hasSuppressed = false; |
| 51 | $conflicts = []; |
| 52 | foreach ( $unfilteredConflicts as $conflict ) { |
| 53 | if ( !User::newFromName( $conflict )->isHidden() ) { |
| 54 | $conflicts[] = $conflict; |
| 55 | } else { |
| 56 | $hasSuppressed = true; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | if ( $hasSuppressed ) { |
| 61 | $res->addValue( null, $this->getModuleName(), [ 'suppressed' => 'true' ] ); |
| 62 | } |
| 63 | |
| 64 | $res->addValue( null, $this->getModuleName(), [ 'result' => 'conflict' ] ); |
| 65 | |
| 66 | ApiResult::setIndexedTagName( $conflicts, 'u' ); |
| 67 | $res->addValue( [ $this->getModuleName() ], 'users', $conflicts ); |
| 68 | } |
| 69 | } else { |
| 70 | $errorStatus = $spoof->getErrorStatus(); |
| 71 | $res->addValue( 'antispoof', 'result', 'error' ); |
| 72 | $res->addValue( |
| 73 | 'antispoof', |
| 74 | 'error', |
| 75 | $errorStatus->getMessage( false, false, $this->getLanguage() )->text() |
| 76 | ); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | /** @inheritDoc */ |
| 81 | public function getAllowedParams() { |
| 82 | return [ |
| 83 | 'username' => [ |
| 84 | ParamValidator::PARAM_REQUIRED => true, |
| 85 | ], |
| 86 | ]; |
| 87 | } |
| 88 | |
| 89 | /** @inheritDoc */ |
| 90 | protected function getExamplesMessages() { |
| 91 | return [ |
| 92 | 'action=antispoof&username=Foo' |
| 93 | => 'apihelp-antispoof-example-1', |
| 94 | ]; |
| 95 | } |
| 96 | } |