| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
namespace MediaWiki\Extension\AbuseFilter\Api; |
| 20 |
|
| 21 |
use MediaWiki\Api\ApiBase; |
| 22 |
use MediaWiki\Api\ApiMain; |
| 23 |
use MediaWiki\Extension\AbuseFilter\AbuseFilterPermissionManager; |
| 24 |
use MediaWiki\Extension\AbuseFilter\Special\SpecialAbuseLog; |
| 25 |
use Wikimedia\ParamValidator\ParamValidator; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
class AbuseLogPrivateDetails extends ApiBase { |
| 34 |
|
| 35 |
|
| 36 |
private $afPermManager; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public function __construct( |
| 44 |
ApiMain $main, |
| 45 |
$action, |
| 46 |
AbuseFilterPermissionManager $afPermManager |
| 47 |
) { |
| 48 |
parent::__construct( $main, $action ); |
| 49 |
$this->afPermManager = $afPermManager; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public function mustBePosted() { |
| 57 |
return true; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public function isWriteMode() { |
| 65 |
return true; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
public function needsToken() { |
| 73 |
return 'csrf'; |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
public function execute() { |
| 80 |
$user = $this->getUser(); |
| 81 |
|
| 82 |
if ( !$this->afPermManager->canSeePrivateDetails( $user ) ) { |
| 83 |
$this->dieWithError( 'abusefilter-log-cannot-see-privatedetails' ); |
| 84 |
} |
| 85 |
$params = $this->extractRequestParams(); |
| 86 |
|
| 87 |
if ( !SpecialAbuseLog::checkPrivateDetailsAccessReason( $params['reason'] ) ) { |
| 88 |
|
| 89 |
$this->dieWithError( 'abusefilter-noreason' ); |
| 90 |
} |
| 91 |
$status = SpecialAbuseLog::getPrivateDetailsRow( $user, $params['logid'] ); |
| 92 |
if ( !$status->isGood() ) { |
| 93 |
$this->dieStatus( $status ); |
| 94 |
} |
| 95 |
$row = $status->getValue(); |
| 96 |
|
| 97 |
if ( $this->getConfig()->get( 'AbuseFilterLogPrivateDetailsAccess' ) ) { |
| 98 |
SpecialAbuseLog::addPrivateDetailsAccessLogEntry( |
| 99 |
$params['logid'], |
| 100 |
$params['reason'], |
| 101 |
$user |
| 102 |
); |
| 103 |
} |
| 104 |
|
| 105 |
$result = [ |
| 106 |
'log-id' => $params['logid'], |
| 107 |
'user' => $row->afl_user_text, |
| 108 |
'filter-id' => (int)$row->af_id, |
| 109 |
'filter-description' => $row->af_public_comments, |
| 110 |
'ip-address' => $row->afl_ip !== '' ? $row->afl_ip : null |
| 111 |
]; |
| 112 |
$this->getResult()->addValue( null, $this->getModuleName(), $result ); |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
public function getAllowedParams() { |
| 120 |
return [ |
| 121 |
'logid' => [ |
| 122 |
ParamValidator::PARAM_TYPE => 'integer' |
| 123 |
], |
| 124 |
'reason' => [ |
| 125 |
ParamValidator::PARAM_TYPE => 'string', |
| 126 |
ParamValidator::PARAM_REQUIRED => $this->getConfig()->get( 'AbuseFilterPrivateDetailsForceReason' ), |
| 127 |
ParamValidator::PARAM_DEFAULT => '', |
| 128 |
] |
| 129 |
]; |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
protected function getExamplesMessages() { |
| 137 |
return [ |
| 138 |
'action=abuselogprivatedetails&logid=1&reason=example&token=ABC123' |
| 139 |
=> 'apihelp-abuselogprivatedetails-example-1' |
| 140 |
]; |
| 141 |
} |
| 142 |
} |