Abspeichern des Namen funktioniert

This commit is contained in:
root
2017-09-27 22:17:59 +02:00
parent eda1e4d82e
commit f103b057aa
6 changed files with 1985 additions and 1938 deletions

View File

@@ -1,52 +1,56 @@
<?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'
)
);
}
}
<?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'
)
);
}
}

View File

@@ -1,73 +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' );
}
}
$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'
)
);
}
}
<?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'
)
);
}
}