first commit
This commit is contained in:
52
includes/api/CommentBlock.api.php
Normal file
52
includes/api/CommentBlock.api.php
Normal file
@@ -0,0 +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'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
41
includes/api/CommentDelete.api.php
Normal file
41
includes/api/CommentDelete.api.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
class CommentDeleteAPI extends ApiBase {
|
||||
|
||||
public function execute() {
|
||||
$user = $this->getUser();
|
||||
// Blocked users cannot delete comments, and neither can unprivileged ones.
|
||||
// Also check for database read-only status
|
||||
if (
|
||||
$user->isBlocked() ||
|
||||
!$user->isAllowed( 'commentadmin' ) ||
|
||||
wfReadOnly()
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$comment = Comment::newFromID( $this->getMain()->getVal( 'commentID' ) );
|
||||
$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() {
|
||||
return array(
|
||||
'commentID' => array(
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
ApiBase::PARAM_TYPE => 'integer'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
22
includes/api/CommentLatestID.api.php
Normal file
22
includes/api/CommentLatestID.api.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
class CommentLatestIdAPI extends ApiBase {
|
||||
|
||||
public function execute() {
|
||||
$pageID = $this->getMain()->getVal( 'pageID' );
|
||||
|
||||
$commentsPage = new CommentsPage( $pageID, RequestContext::getMain() );
|
||||
|
||||
$result = $this->getResult();
|
||||
$result->addValue( $this->getModuleName(), 'id', $commentsPage->getLatestCommentID() );
|
||||
}
|
||||
|
||||
public function getAllowedParams() {
|
||||
return array(
|
||||
'pageID' => array(
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
ApiBase::PARAM_TYPE => 'int'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
44
includes/api/CommentList.api.php
Normal file
44
includes/api/CommentList.api.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
class CommentListAPI extends ApiBase {
|
||||
|
||||
public function execute() {
|
||||
$commentsPage = new CommentsPage( $this->getMain()->getVal( 'pageID' ), RequestContext::getMain() );
|
||||
$commentsPage->orderBy = $this->getMain()->getVal( 'order' );
|
||||
$commentsPage->currentPagerPage = $this->getMain()->getVal( 'pagerPage' );
|
||||
|
||||
$output = '';
|
||||
if ( $this->getMain()->getVal( 'showForm' ) ) {
|
||||
$output .= $commentsPage->displayOrderForm();
|
||||
}
|
||||
$output .= $commentsPage->display();
|
||||
if ( $this->getMain()->getVal( 'showForm' ) ) {
|
||||
$output .= $commentsPage->displayForm();
|
||||
}
|
||||
|
||||
$result = $this->getResult();
|
||||
$result->addValue( $this->getModuleName(), 'html', $output );
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getAllowedParams() {
|
||||
return array(
|
||||
'pageID' => array(
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
ApiBase::PARAM_TYPE => 'integer'
|
||||
),
|
||||
'order' => array(
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
ApiBase::PARAM_TYPE => 'boolean'
|
||||
),
|
||||
'pagerPage' => array(
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
ApiBase::PARAM_TYPE => 'integer'
|
||||
),
|
||||
'showForm' => array(
|
||||
ApiBase::PARAM_REQUIRED => false,
|
||||
ApiBase::PARAM_TYPE => 'integer'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
73
includes/api/CommentSubmit.api.php
Normal file
73
includes/api/CommentSubmit.api.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?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' );
|
||||
}
|
||||
}
|
||||
|
||||
$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'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
72
includes/api/CommentVote.api.php
Normal file
72
includes/api/CommentVote.api.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
class CommentVoteAPI extends ApiBase {
|
||||
|
||||
public function execute() {
|
||||
// Blocked users cannot vote, obviously, and neither can those users without the necessary privileges
|
||||
if (
|
||||
$this->getUser()->isBlocked() ||
|
||||
!$this->getUser()->isAllowed( 'comment' ) ||
|
||||
wfReadOnly()
|
||||
) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$comment = Comment::newFromID( $this->getMain()->getVal( 'commentID' ) );
|
||||
$voteValue = $this->getMain()->getVal( 'voteValue' );
|
||||
|
||||
if ( $comment && is_numeric( $voteValue ) ) {
|
||||
$comment->vote( $voteValue );
|
||||
|
||||
$html = $comment->getScoreHTML();
|
||||
$html = htmlspecialchars( $html );
|
||||
|
||||
if ( class_exists( 'UserStatsTrack' ) ) {
|
||||
$stats = new UserStatsTrack( $this->getUser()->getID(), $this->getUser()->getName() );
|
||||
|
||||
// Must update stats for user doing the voting
|
||||
if ( $voteValue == 1 ) {
|
||||
$stats->incStatField( 'comment_give_plus' );
|
||||
}
|
||||
if ( $voteValue == -1 ) {
|
||||
$stats->incStatField( 'comment_give_neg' );
|
||||
}
|
||||
|
||||
// Also must update the stats for user receiving the vote
|
||||
$stats_comment_owner = new UserStatsTrack( $comment->userID, $comment->username );
|
||||
$stats_comment_owner->updateCommentScoreRec( $voteValue );
|
||||
|
||||
$stats_comment_owner->updateTotalPoints();
|
||||
if ( $voteValue === 1 ) {
|
||||
$stats_comment_owner->updateWeeklyPoints( $stats_comment_owner->point_values['comment_plus'] );
|
||||
$stats_comment_owner->updateMonthlyPoints( $stats_comment_owner->point_values['comment_plus'] );
|
||||
}
|
||||
}
|
||||
|
||||
$result = $this->getResult();
|
||||
$result->addValue( $this->getModuleName(), 'html', $html );
|
||||
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'
|
||||
),
|
||||
'voteValue' => array(
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
ApiBase::PARAM_TYPE => 'integer'
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user