Cicalese has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/360163 )

Change subject: Remove comment actions from RecentChanges and add to special 
log.
......................................................................


Remove comment actions from RecentChanges and add to special log.

T167448
Change-Id: Ia234353cd4db8c55f4af37b27725e33cdddc44e4
---
M i18n/en.json
M i18n/qqq.json
M includes/ApiCSBase.php
M includes/ApiCSDeleteComment.php
M includes/ApiCSEditComment.php
M includes/ApiCSPostComment.php
M includes/ApiCSQueryComment.php
M includes/ApiCSVote.php
M includes/Comment.php
M includes/CommentStreamsHooks.php
10 files changed, 126 insertions(+), 36 deletions(-)

Approvals:
  Cicalese: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/i18n/en.json b/i18n/en.json
index db2f7bc..7372da8 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -94,5 +94,17 @@
        "right-cs-moderator-edit": "Edit comments by any user",
        "action-cs-moderator-edit": "edit comments by other users",
        "right-cs-moderator-delete": "Delete comments by any user",
-       "action-cs-moderator-delete": "delete comments by other users"
+       "action-cs-moderator-delete": "delete comments by other users",
+       "log-name-commentstreams": "CommentStreams log",
+       "log-description-commentstreams": "These events track when 
CommentStreams events happen.",
+       "logentry-commentstreams-comment-create": "$1 {{GENDER:$2|created}} 
comment $3",
+       "logentry-commentstreams-reply-create": "$1 {{GENDER:$2|created}} reply 
$3",
+       "logentry-commentstreams-comment-edit": "$1 {{GENDER:$2|edited}} 
comment $3",
+       "logentry-commentstreams-comment-moderator-edit": "$1 
{{GENDER:$2|(moderator) edited}} comment $3",
+       "logentry-commentstreams-reply-edit": "$1 {{GENDER:$2|edited}} reply 
$3",
+       "logentry-commentstreams-reply-moderator-edit": "$1 
{{GENDER:$2|(moderator) edited}} reply $3",
+       "logentry-commentstreams-comment-delete": "$1 {{GENDER:$2|deleted}} 
comment $3",
+       "logentry-commentstreams-comment-moderator-delete": "$1 
{{GENDER:$2|(moderator) deleted}} comment $3",
+       "logentry-commentstreams-reply-delete": "$1 {{GENDER:$2|deleted}} reply 
$3",
+       "logentry-commentstreams-reply-moderator-delete": "$1 
{{GENDER:$2|(moderator) deleted}} reply $3"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index fc8ce87..b10351b 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -94,5 +94,17 @@
        "right-cs-moderator-edit": "{{doc-right|csedit}}",
        "action-cs-moderator-edit": "{{doc-action|csedit}}",
        "right-cs-moderator-delete": "{{doc-right|csdelete}}",
-       "action-cs-moderator-delete": "{{doc-action|csdelete}}"
+       "action-cs-moderator-delete": "{{doc-action|csdelete}}",
+       "log-name-commentstreams": "The Special:Log log name that appears in 
the drop-down on the Special:Log page",
+       "log-description-commentstreams": "The Special:Log description that 
appears on the Special:Log page when you filter logs on this specific log name",
+       "logentry-commentstreams-comment-create": "The template of the log 
entry message",
+       "logentry-commentstreams-reply-create": "The template of the log entry 
message",
+       "logentry-commentstreams-comment-edit": "The template of the log entry 
message",
+       "logentry-commentstreams-comment-moderator-edit": "The template of the 
log entry message",
+       "logentry-commentstreams-reply-edit": "The template of the log entry 
message",
+       "logentry-commentstreams-reply-moderator-edit": "The template of the 
log entry message",
+       "logentry-commentstreams-comment-delete": "The template of the log 
entry message",
+       "logentry-commentstreams-comment-moderator-delete": "The template of 
the log entry message",
+       "logentry-commentstreams-reply-delete": "The template of the log entry 
message",
+       "logentry-commentstreams-reply-moderator-delete": "The template of the 
log entry message"
 }
diff --git a/includes/ApiCSBase.php b/includes/ApiCSBase.php
index 3923be9..78ac2e2 100644
--- a/includes/ApiCSBase.php
+++ b/includes/ApiCSBase.php
@@ -21,9 +21,10 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-class ApiCSBase extends ApiBase {
+abstract class ApiCSBase extends ApiBase {
 
        private $edit;
+       protected $comment;
 
        /**
         * @param ApiMain $main main module
@@ -42,11 +43,11 @@
                $params = $this->extractRequestParams();
                $wikipage = $this->getTitleOrPageId( $params,
                        $this->edit ? 'frommasterdb' : 'fromdb' );
-               $comment = Comment::newFromWikiPage( $wikipage );
-               if ( is_null( $comment ) ) {
+               $this->comment = Comment::newFromWikiPage( $wikipage );
+               if ( is_null( $this->comment ) ) {
                        $this->dieCustomUsageMessage( 
'commentstreams-api-error-notacomment' );
                }
-               $result = $this->executeBody( $comment );
+               $result = $this->executeBody();
                if ( !is_null( $result ) ) {
                        $this->getResult()->addValue( null, 
$this->getModuleName(), $result );
                }
@@ -54,8 +55,8 @@
 
        /**
         * the real body of the execute function
-        /
-       protected abstract function executeBody( $comment );
+        */
+       protected abstract function executeBody();
 
        /**
         * @return array allowed parameters
@@ -97,6 +98,21 @@
        }
 
        /**
+        * log action
+        * @param string $action the name of the action to be logged
+        */
+       protected function logAction( $action, $title = null ) {
+               $logEntry = new ManualLogEntry( 'commentstreams', $action );
+               $logEntry->setPerformer( $this->getUser() );
+               if ( $title ) {
+                       $logEntry->setTarget( $title );
+               } else {
+                       $logEntry->setTarget( 
$this->comment->getWikiPage()->getTitle() );
+               }
+               $logid = $logEntry->insert();
+       }
+
+       /**
         * die with a custom usage message
         * @param string $message_name the name of the custom message
         */
diff --git a/includes/ApiCSDeleteComment.php b/includes/ApiCSDeleteComment.php
index 6302bb9..0943912 100644
--- a/includes/ApiCSDeleteComment.php
+++ b/includes/ApiCSDeleteComment.php
@@ -34,38 +34,50 @@
        /**
         * the real body of the execute function
         *
-        * @param Comment $comment the comment to execute the action upon
         * @return result of API request
         */
-       protected function executeBody( $comment ) {
+       protected function executeBody() {
                if ( $this->getUser()->isAnon() ) {
                        $this->dieCustomUsageMessage(
                                'commentstreams-api-error-delete-notloggedin' );
                }
 
                if ( $this->getUser()->getId() ===
-                       $comment->getWikiPage()->getOldestRevision()->getUser() 
) {
+                       
$this->comment->getWikiPage()->getOldestRevision()->getUser() ) {
                        $action = 'edit'; // need edit but not delete to delete 
a comment
                } else {
                        $action = 'cs-moderator-delete';
                }
 
-               if ( !$comment->getWikiPage()->getTitle()->userCan( $action,
+               if ( !$this->comment->getWikiPage()->getTitle()->userCan( 
$action,
                        $this->getUser() ) ) {
                        $this->dieCustomUsageMessage(
                                'commentstreams-api-error-delete-permissions' );
                }
 
-               $childCount = $comment->getNumReplies();
+               $childCount = $this->comment->getNumReplies();
                if ( $childCount > 0 ) {
                        if ( $GLOBALS['wgCommentStreamsModeratorFastDelete'] ) {
-                               $result = $this->recursiveDelete( $comment );
+                               $result = $this->recursiveDelete( 
$this->comment );
                        } else {
                                $this->dieCustomUsageMessage(
                                        
'commentstreams-api-error-delete-haschildren' );
                        }
                } else {
-                       $result = $comment->delete();
+                       $result = $this->comment->delete();
+                       if ( $action === 'edit' ) {
+                               if ( is_null( $this->comment->getParentId() ) ) 
{
+                                       $this->logAction( 'comment-delete' );
+                               } else {
+                                       $this->logAction( 'reply-delete' );
+                               }
+                       } else {
+                               if ( is_null( $this->comment->getParentId() ) ) 
{
+                                       $this->logAction( 
'comment-moderator-delete' );
+                               } else {
+                                       $this->logAction( 
'reply-moderator-delete' );
+                               }
+                       }
                }
 
                if ( !$result ) {
@@ -90,6 +102,12 @@
                        }
                }
                $result = $comment->delete();
+               $title = $comment->getWikiPage()->getTitle();
+               if ( is_null( $comment->getParentId() ) ) {
+                       $this->logAction( 'comment-moderator-delete', $title  );
+               } else {
+                       $this->logAction( 'reply-moderator-delete', $title  );
+               }
                return $result;
        }
 }
diff --git a/includes/ApiCSEditComment.php b/includes/ApiCSEditComment.php
index 919fe2d..87c8cf7 100644
--- a/includes/ApiCSEditComment.php
+++ b/includes/ApiCSEditComment.php
@@ -34,22 +34,21 @@
        /**
         * the real body of the execute function
         *
-        * @param Comment $comment the comment to execute the action upon
         * @return result of API request
         */
-       protected function executeBody( $comment ) {
+       protected function executeBody() {
                if ( $this->getUser()->isAnon() ) {
                        $this->dieCustomUsageMessage(
                                'commentstreams-api-error-edit-notloggedin' );
                }
 
                if ( $this->getUser()->getId() ===
-                       $comment->getWikiPage()->getOldestRevision()->getUser() 
) {
+                       
$this->comment->getWikiPage()->getOldestRevision()->getUser() ) {
                        $action = 'edit';
                } else {
                        $action = 'cs-moderator-edit';
                }
-               if ( !$comment->getWikiPage()->getTitle()->userCan( $action,
+               if ( !$this->comment->getWikiPage()->getTitle()->userCan( 
$action,
                        $this->getUser() ) ) {
                        $this->dieCustomUsageMessage(
                                'commentstreams-api-error-edit-permissions' );
@@ -58,21 +57,35 @@
                $comment_title = $this->getMain()->getVal( 'commenttitle' );
                $wikitext = $this->getMain()->getVal( 'wikitext' );
 
-               if ( is_null( $comment->getParentId() ) && is_null( 
$comment_title ) ) {
+               if ( is_null( $this->comment->getParentId() ) && is_null( 
$comment_title ) ) {
                        $this->dieCustomUsageMessage(
                                'commentstreams-api-error-missingcommenttitle' 
);
                }
 
-               $result = $comment->update( $comment_title, $wikitext, 
$this->getUser() );
+               $result = $this->comment->update( $comment_title, $wikitext, 
$this->getUser() );
                if ( !$result ) {
                        $this->dieCustomUsageMessage( 
'commentstreams-api-error-edit' );
                }
 
-               $json = $comment->getJSON();
+               if ( $action === 'edit' ) {
+                       if ( is_null( $this->comment->getParentId() ) ) {
+                               $this->logAction( 'comment-edit' );
+                       } else {
+                               $this->logAction( 'reply-edit' );
+                       }
+               } else {
+                       if ( is_null( $this->comment->getParentId() ) ) {
+                               $this->logAction( 'comment-moderator-edit' );
+                       } else {
+                               $this->logAction( 'reply-moderator-edit' );
+                       }
+               }
 
-               if ( is_null( $comment->getParentId() ) &&
+               $json = $this->comment->getJSON();
+
+               if ( is_null( $this->comment->getParentId() ) &&
                        $GLOBALS['wgCommentStreamsEnableVoting'] ) {
-                       $json['vote'] = $comment->getVote( $this->getUser() );
+                       $json['vote'] = $this->comment->getVote( 
$this->getUser() );
                }
 
                $this->getResult()->addValue( null, $this->getModuleName(), 
$json );
diff --git a/includes/ApiCSPostComment.php b/includes/ApiCSPostComment.php
index 27c05f0..d381d16 100644
--- a/includes/ApiCSPostComment.php
+++ b/includes/ApiCSPostComment.php
@@ -82,6 +82,13 @@
                        $this->dieCustomUsageMessage( 
'commentstreams-api-error-post' );
                }
 
+        $title = $comment->getWikiPage()->getTitle();
+               if ( is_null( $comment->getParentId() ) ) {
+                       $this->logAction( 'comment-create', $title );
+               } else {
+                       $this->logAction( 'reply-create', $title );
+               }
+
                $this->getResult()->addValue( null, $this->getModuleName(),
                        $comment->getJSON() );
 
@@ -192,6 +199,17 @@
        }
 
        /**
+        * log action
+        * @param string $action the name of the action to be logged
+        */
+       protected function logAction( $action, $title ) {
+               $logEntry = new ManualLogEntry( 'commentstreams', $action );
+               $logEntry->setPerformer( $this->getUser() );
+               $logEntry->setTarget( $title );
+               $logid = $logEntry->insert();
+       }
+
+       /**
         * die with a custom usage message
         * @param string $message_name the name of the custom message
         */
diff --git a/includes/ApiCSQueryComment.php b/includes/ApiCSQueryComment.php
index df99da6..d0d290f 100644
--- a/includes/ApiCSQueryComment.php
+++ b/includes/ApiCSQueryComment.php
@@ -34,10 +34,9 @@
        /**
         * the real body of the execute function
         *
-        * @param Comment $comment the comment to execute the action upon
         * @return result of API request
         */
-       protected function executeBody( $comment ) {
-               return $comment->getJSON();
+       protected function executeBody() {
+               return $this->comment->getJSON();
        }
 }
diff --git a/includes/ApiCSVote.php b/includes/ApiCSVote.php
index b952d14..e93021f 100644
--- a/includes/ApiCSVote.php
+++ b/includes/ApiCSVote.php
@@ -34,10 +34,9 @@
        /**
         * the real body of the execute function
         *
-        * @param Comment $comment the comment to execute the action upon
         * @return result of API request
         */
-       protected function executeBody( $comment ) {
+       protected function executeBody() {
                if ( $this->getUser()->isAnon() ) {
                        $this->dieCustomUsageMessage(
                                'commentstreams-api-error-vote-notloggedin' );
@@ -45,12 +44,12 @@
 
                $vote = $this->getMain()->getVal( 'vote' );
 
-               if ( !is_null( $comment->getParentId() ) ) {
+               if ( !is_null( $this->comment->getParentId() ) ) {
                        $this->dieCustomUsageMessage(
                                'commentstreams-api-error-vote-novoteonreply' );
                }
 
-               $result = $comment->vote( $vote, $this->getUser() );
+               $result = $this->comment->vote( $vote, $this->getUser() );
                if ( !$result ) {
                        $this->dieCustomUsageMessage( 
'commentstreams-api-error-vote' );
                }
diff --git a/includes/Comment.php b/includes/Comment.php
index 82d1e44..4ccc31c 100644
--- a/includes/Comment.php
+++ b/includes/Comment.php
@@ -112,8 +112,8 @@
                        $title = Title::newFromText( (string)$index, 
NS_COMMENTSTREAMS );
                        if ( !$title->isDeletedQuick() && !$title->exists() ) {
                                $wikipage = new WikiPage( $title );
-                               $status = $wikipage->doEditContent( $content, 
'', EDIT_NEW, false,
-                                       $user, null );
+                               $status = $wikipage->doEditContent( $content, 
'',
+                                       EDIT_NEW | EDIT_SUPPRESS_RC , false, 
$user, null );
                                if ( !$status->isOK() && !$status->isGood() ) {
                                        if ( $status->getMessage()->getKey() == 
'edit-already-exists' ) {
                                                $index = wfRandomString();
@@ -573,8 +573,8 @@
                        self::addAnnotations( $wikitext, $comment_title,
                                $this->getAssociatedId() );
                $content = new WikitextContent( $annotated_wikitext );
-               $status = $this->wikipage->doEditContent( $content, '', 
EDIT_UPDATE, false,
-                       $user, null );
+               $status = $this->wikipage->doEditContent( $content, '',
+                       EDIT_UPDATE | EDIT_SUPPRESS_RC , false, $user, null );
                if ( !$status->isOK() && !$status->isGood() ) {
                        return false;
                }
@@ -606,7 +606,7 @@
                $pageid = $this->getId();
 
                $status = $this->getWikiPage()->doDeleteArticleReal( 'comment 
deleted',
-                       false, 0 );
+                       true, 0 );
                if ( !$status->isOK() && !$status->isGood() ) {
                        return false;
                }
diff --git a/includes/CommentStreamsHooks.php b/includes/CommentStreamsHooks.php
index e057789..4e23e49 100644
--- a/includes/CommentStreamsHooks.php
+++ b/includes/CommentStreamsHooks.php
@@ -79,6 +79,7 @@
                switch ( $action ) {
                case 'info':
                case 'history':
+               case 'view':
                        return true;
                default:
                        $message =
@@ -307,6 +308,8 @@
                }
                $GLOBALS['wgAvailableRights'][] = 'cs-moderator-edit';
                $GLOBALS['wgAvailableRights'][] = 'cs-moderator-delete';
+               $GLOBALS['wgLogTypes'][] = 'commentstreams';
+               $GLOBALS['wgLogActionsHandlers']['commentstreams/*'] = 
'LogFormatter';
        }
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/360163
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia234353cd4db8c55f4af37b27725e33cdddc44e4
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/CommentStreams
Gerrit-Branch: master
Gerrit-Owner: Cicalese <[email protected]>
Gerrit-Reviewer: Cicalese <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to