neue Version für Mediawiki ab Version 1.32
This commit is contained in:
@@ -1,56 +1,52 @@
|
||||
<?php
|
||||
|
||||
class CommentBlockAPI extends ApiBase {
|
||||
|
||||
public function execute() {
|
||||
// Do nothing when the database is in read-only mode
|
||||
if ( wfReadOnly() ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Load user_name and user_id for person we want to block from the comment it originated from
|
||||
$dbr = wfGetDB( DB_SLAVE );
|
||||
$s = $dbr->selectRow(
|
||||
'Comments',
|
||||
array( 'comment_username', 'comment_user_id' ),
|
||||
array( 'CommentID' => $this->getMain()->getVal( 'commentID' ) ),
|
||||
__METHOD__
|
||||
);
|
||||
if ( $s !== false ) {
|
||||
$userID = $s->comment_user_id;
|
||||
$username = $s->comment_username;
|
||||
}
|
||||
|
||||
CommentFunctions::blockUser( $this->getUser(), $userID, $username );
|
||||
|
||||
if ( class_exists( 'UserStatsTrack' ) ) {
|
||||
$stats = new UserStatsTrack( $userID, $username );
|
||||
$stats->incStatField( 'comment_ignored' );
|
||||
}
|
||||
|
||||
$result = $this->getResult();
|
||||
$result->addValue( $this->getModuleName(), 'ok', 'ok' );
|
||||
return true;
|
||||
}
|
||||
|
||||
public function needsToken() {
|
||||
return 'csrf';
|
||||
}
|
||||
|
||||
public function isWriteMode() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getAllowedParams() {
|
||||
return array(
|
||||
'commentID' => array(
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
ApiBase::PARAM_TYPE => 'integer'
|
||||
),
|
||||
'UsernameKOK' => array(
|
||||
ApiBase::PARAM_REQUIRED => false,
|
||||
ApiBase::PARAM_TYPE => 'string'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
class CommentBlockAPI extends ApiBase {
|
||||
|
||||
public function execute() {
|
||||
// Do nothing when the database is in read-only mode
|
||||
if ( wfReadOnly() ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Load user_name and user_id for person we want to block from the comment it originated from
|
||||
$dbr = wfGetDB( DB_REPLICA );
|
||||
$s = $dbr->selectRow(
|
||||
'Comments',
|
||||
[ 'comment_username', 'comment_user_id' ],
|
||||
[ 'CommentID' => $this->getMain()->getVal( 'commentID' ) ],
|
||||
__METHOD__
|
||||
);
|
||||
if ( $s !== false ) {
|
||||
$userID = $s->comment_user_id;
|
||||
$username = $s->comment_username;
|
||||
}
|
||||
|
||||
CommentFunctions::blockUser( $this->getUser(), $userID, $username );
|
||||
|
||||
if ( class_exists( 'UserStatsTrack' ) ) {
|
||||
$stats = new UserStatsTrack( $userID, $username );
|
||||
$stats->incStatField( 'comment_ignored' );
|
||||
}
|
||||
|
||||
$result = $this->getResult();
|
||||
$result->addValue( $this->getModuleName(), 'ok', 'ok' );
|
||||
return true;
|
||||
}
|
||||
|
||||
public function needsToken() {
|
||||
return 'csrf';
|
||||
}
|
||||
|
||||
public function isWriteMode() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getAllowedParams() {
|
||||
return [
|
||||
'commentID' => [
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
ApiBase::PARAM_TYPE => 'integer'
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -4,17 +4,21 @@ class CommentDeleteAPI extends ApiBase {
|
||||
|
||||
public function execute() {
|
||||
$user = $this->getUser();
|
||||
|
||||
$comment = Comment::newFromID( $this->getMain()->getVal( 'commentID' ) );
|
||||
// Blocked users cannot delete comments, and neither can unprivileged ones.
|
||||
// Also check for database read-only status
|
||||
if (
|
||||
$user->isBlocked() ||
|
||||
!$user->isAllowed( 'commentadmin' ) ||
|
||||
!(
|
||||
$user->isAllowed( 'commentadmin' ) ||
|
||||
$user->isAllowed( 'comment-delete-own' ) && $comment->isOwner( $user )
|
||||
) ||
|
||||
wfReadOnly()
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$comment = Comment::newFromID( $this->getMain()->getVal( 'commentID' ) );
|
||||
$comment->delete();
|
||||
|
||||
$result = $this->getResult();
|
||||
@@ -31,11 +35,11 @@ class CommentDeleteAPI extends ApiBase {
|
||||
}
|
||||
|
||||
public function getAllowedParams() {
|
||||
return array(
|
||||
'commentID' => array(
|
||||
return [
|
||||
'commentID' => [
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
ApiBase::PARAM_TYPE => 'integer'
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,9 @@
|
||||
class CommentLatestIdAPI extends ApiBase {
|
||||
|
||||
public function execute() {
|
||||
// To avoid API warning, register the parameter used to bust browser cache
|
||||
$this->getMain()->getVal( '_' );
|
||||
|
||||
$pageID = $this->getMain()->getVal( 'pageID' );
|
||||
|
||||
$commentsPage = new CommentsPage( $pageID, RequestContext::getMain() );
|
||||
@@ -12,11 +15,11 @@ class CommentLatestIdAPI extends ApiBase {
|
||||
}
|
||||
|
||||
public function getAllowedParams() {
|
||||
return array(
|
||||
'pageID' => array(
|
||||
return [
|
||||
'pageID' => [
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
ApiBase::PARAM_TYPE => 'int'
|
||||
)
|
||||
);
|
||||
ApiBase::PARAM_TYPE => 'integer'
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -22,23 +22,23 @@ class CommentListAPI extends ApiBase {
|
||||
}
|
||||
|
||||
public function getAllowedParams() {
|
||||
return array(
|
||||
'pageID' => array(
|
||||
return [
|
||||
'pageID' => [
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
ApiBase::PARAM_TYPE => 'integer'
|
||||
),
|
||||
'order' => array(
|
||||
],
|
||||
'order' => [
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
ApiBase::PARAM_TYPE => 'boolean'
|
||||
),
|
||||
'pagerPage' => array(
|
||||
],
|
||||
'pagerPage' => [
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
ApiBase::PARAM_TYPE => 'integer'
|
||||
),
|
||||
'showForm' => array(
|
||||
],
|
||||
'showForm' => [
|
||||
ApiBase::PARAM_REQUIRED => false,
|
||||
ApiBase::PARAM_TYPE => 'integer'
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,79 +1,79 @@
|
||||
<?php
|
||||
|
||||
class CommentSubmitAPI extends ApiBase {
|
||||
|
||||
public function execute() {
|
||||
$user = $this->getUser();
|
||||
// Blocked users cannot submit new comments, and neither can those users
|
||||
// without the necessary privileges. Also prevent obvious cross-site request
|
||||
// forgeries (CSRF)
|
||||
if (
|
||||
$user->isBlocked() ||
|
||||
!$user->isAllowed( 'comment' ) ||
|
||||
wfReadOnly()
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$commentText = $this->getMain()->getVal( 'commentText' );
|
||||
|
||||
if ( $commentText != '' ) {
|
||||
// To protect against spam, it's necessary to check the supplied text
|
||||
// against spam filters (but comment admins are allowed to bypass the
|
||||
// spam filters)
|
||||
if ( !$user->isAllowed( 'commentadmin' ) && CommentFunctions::isSpam( $commentText ) ) {
|
||||
$this->dieUsage( wfMessage( 'comments-is-spam' )->plain(), 'comments-is-spam' );
|
||||
}
|
||||
|
||||
// If the comment contains links but the user isn't allowed to post
|
||||
// links, reject the submission
|
||||
if ( !$user->isAllowed( 'commentlinks' ) && CommentFunctions::haveLinks( $commentText ) ) {
|
||||
$this->dieUsage( wfMessage( 'comments-links-are-forbidden' )->plain(), 'comments-links-are-forbidden' );
|
||||
}
|
||||
|
||||
$page = new CommentsPage( $this->getMain()->getVal( 'pageID' ), $this->getContext() );
|
||||
|
||||
Comment::add( $commentText, $page, $user, $this->getMain()->getVal( 'parentID' ) );
|
||||
|
||||
if ( class_exists( 'UserStatsTrack' ) ) {
|
||||
$stats = new UserStatsTrack( $user->getID(), $user->getName() );
|
||||
$stats->incStatField( 'comment' );
|
||||
}
|
||||
}
|
||||
|
||||
$kok_username = $this->getMain()->getVal( 'UsernameKOK' );
|
||||
|
||||
$result = $this->getResult();
|
||||
$result->addValue( $this->getModuleName(), 'ok', 'ok' );
|
||||
return true;
|
||||
}
|
||||
|
||||
public function needsToken() {
|
||||
return 'csrf';
|
||||
}
|
||||
|
||||
public function isWriteMode() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getAllowedParams() {
|
||||
return array(
|
||||
'pageID' => array(
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
ApiBase::PARAM_TYPE => 'integer'
|
||||
),
|
||||
'parentID' => array(
|
||||
ApiBase::PARAM_REQUIRED => false,
|
||||
ApiBase::PARAM_TYPE => 'integer'
|
||||
),
|
||||
'commentText' => array(
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
ApiBase::PARAM_TYPE => 'string'
|
||||
),
|
||||
'UsernameKOK' => array(
|
||||
ApiBase::PARAM_REQUIRED => false,
|
||||
ApiBase::PARAM_TYPE => 'string'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
class CommentSubmitAPI extends ApiBase {
|
||||
|
||||
public function execute() {
|
||||
$user = $this->getUser();
|
||||
// Blocked users cannot submit new comments, and neither can those users
|
||||
// without the necessary privileges. Also prevent obvious cross-site request
|
||||
// forgeries (CSRF)
|
||||
if (
|
||||
$user->isBlocked() ||
|
||||
!$user->isAllowed( 'comment' ) ||
|
||||
wfReadOnly()
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$commentText = $this->getMain()->getVal( 'commentText' );
|
||||
|
||||
if ( $commentText != '' ) {
|
||||
// To protect against spam, it's necessary to check the supplied text
|
||||
// against spam filters (but comment admins are allowed to bypass the
|
||||
// spam filters)
|
||||
if ( !$user->isAllowed( 'commentadmin' ) && CommentFunctions::isSpam( $commentText ) ) {
|
||||
$this->dieWithError(
|
||||
$this->msg( 'comments-is-spam' )->plain(),
|
||||
'comments-is-spam'
|
||||
);
|
||||
}
|
||||
|
||||
// If the comment contains links but the user isn't allowed to post
|
||||
// links, reject the submission
|
||||
if ( !$user->isAllowed( 'commentlinks' ) && CommentFunctions::haveLinks( $commentText ) ) {
|
||||
$this->dieWithError(
|
||||
$this->msg( 'comments-links-are-forbidden' )->plain(),
|
||||
'comments-links-are-forbidden'
|
||||
);
|
||||
}
|
||||
|
||||
$page = new CommentsPage( $this->getMain()->getVal( 'pageID' ), $this->getContext() );
|
||||
|
||||
Comment::add( $commentText, $page, $user, $this->getMain()->getVal( 'parentID' ) );
|
||||
|
||||
if ( class_exists( 'UserStatsTrack' ) ) {
|
||||
$stats = new UserStatsTrack( $user->getId(), $user->getName() );
|
||||
$stats->incStatField( 'comment' );
|
||||
}
|
||||
}
|
||||
|
||||
$result = $this->getResult();
|
||||
$result->addValue( $this->getModuleName(), 'ok', 'ok' );
|
||||
return true;
|
||||
}
|
||||
|
||||
public function needsToken() {
|
||||
return 'csrf';
|
||||
}
|
||||
|
||||
public function isWriteMode() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getAllowedParams() {
|
||||
return [
|
||||
'pageID' => [
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
ApiBase::PARAM_TYPE => 'integer'
|
||||
],
|
||||
'parentID' => [
|
||||
ApiBase::PARAM_REQUIRED => false,
|
||||
ApiBase::PARAM_TYPE => 'integer'
|
||||
],
|
||||
'commentText' => [
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
ApiBase::PARAM_TYPE => 'string'
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,11 @@
|
||||
class CommentVoteAPI extends ApiBase {
|
||||
|
||||
public function execute() {
|
||||
$user = $this->getUser();
|
||||
// Blocked users cannot vote, obviously, and neither can those users without the necessary privileges
|
||||
if (
|
||||
$this->getUser()->isBlocked() ||
|
||||
!$this->getUser()->isAllowed( 'comment' ) ||
|
||||
$user->isBlocked() ||
|
||||
!$user->isAllowed( 'comment' ) ||
|
||||
wfReadOnly()
|
||||
) {
|
||||
return '';
|
||||
@@ -22,7 +23,7 @@ class CommentVoteAPI extends ApiBase {
|
||||
$html = htmlspecialchars( $html );
|
||||
|
||||
if ( class_exists( 'UserStatsTrack' ) ) {
|
||||
$stats = new UserStatsTrack( $this->getUser()->getID(), $this->getUser()->getName() );
|
||||
$stats = new UserStatsTrack( $user->getId(), $user->getName() );
|
||||
|
||||
// Must update stats for user doing the voting
|
||||
if ( $voteValue == 1 ) {
|
||||
@@ -58,15 +59,15 @@ class CommentVoteAPI extends ApiBase {
|
||||
}
|
||||
|
||||
public function getAllowedParams() {
|
||||
return array(
|
||||
'commentID' => array(
|
||||
return [
|
||||
'commentID' => [
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
ApiBase::PARAM_TYPE => 'integer'
|
||||
),
|
||||
'voteValue' => array(
|
||||
],
|
||||
'voteValue' => [
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
ApiBase::PARAM_TYPE => 'integer'
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user