2017-09-27 17:53:26 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class CommentDeleteAPI extends ApiBase {
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
$user = $this->getUser();
|
2019-05-25 13:18:39 +02:00
|
|
|
|
|
|
|
$comment = Comment::newFromID( $this->getMain()->getVal( 'commentID' ) );
|
2017-09-27 17:53:26 +02:00
|
|
|
// Blocked users cannot delete comments, and neither can unprivileged ones.
|
|
|
|
// Also check for database read-only status
|
|
|
|
if (
|
|
|
|
$user->isBlocked() ||
|
2019-05-25 13:18:39 +02:00
|
|
|
!(
|
|
|
|
$user->isAllowed( 'commentadmin' ) ||
|
|
|
|
$user->isAllowed( 'comment-delete-own' ) && $comment->isOwner( $user )
|
|
|
|
) ||
|
2017-09-27 17:53:26 +02:00
|
|
|
wfReadOnly()
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$comment->delete();
|
|
|
|
|
|
|
|
$result = $this->getResult();
|
|
|
|
$result->addValue( $this->getModuleName(), 'ok', 'ok' );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function needsToken() {
|
|
|
|
return 'csrf';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isWriteMode() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAllowedParams() {
|
2019-05-25 13:18:39 +02:00
|
|
|
return [
|
|
|
|
'commentID' => [
|
2017-09-27 17:53:26 +02:00
|
|
|
ApiBase::PARAM_REQUIRED => true,
|
|
|
|
ApiBase::PARAM_TYPE => 'integer'
|
2019-05-25 13:18:39 +02:00
|
|
|
]
|
|
|
|
];
|
2017-09-27 17:53:26 +02:00
|
|
|
}
|
|
|
|
}
|