Cicalese has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/359794 )
Change subject: Fixed bug preventing deleting comments.
......................................................................
Fixed bug preventing deleting comments.
Change-Id: I7ee8ec054aa86b7a7e878de702ad8196f89a789b
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M includes/ApiCSDeleteComment.php
M includes/ApiCSEditComment.php
M includes/ApiCSPostComment.php
M includes/CommentStreams.php
M includes/CommentStreamsHooks.php
8 files changed, 81 insertions(+), 36 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CommentStreams
refs/changes/94/359794/1
diff --git a/extension.json b/extension.json
index 6cc58b6..30d4792 100644
--- a/extension.json
+++ b/extension.json
@@ -33,20 +33,21 @@
"mobile"
],
"messages": [
- "commentstreams-api-error-notloggedin",
"commentstreams-api-error-commentnotfound",
"commentstreams-api-error-notacomment",
"commentstreams-api-error-missingcommenttitle",
- "commentstreams-api-error-post-notloggedin",
+ "commentstreams-api-error-post-permissions",
"commentstreams-api-error-post-parentandtitle",
"commentstreams-api-error-post-parentpagedoesnotexist",
"commentstreams-api-error-post-associatedpageidmismatch",
"commentstreams-api-error-post-associatedpagedoesnotexist",
"commentstreams-api-error-post",
+ "commentstreams-api-error-edit-notloggedin",
"commentstreams-api-error-edit-permissions",
"commentstreams-api-error-edit",
- "commentstreams-api-error-delete-haschildren",
+ "commentstreams-api-error-delete-notloggedin",
"commentstreams-api-error-delete-permissions",
+ "commentstreams-api-error-delete-haschildren",
"commentstreams-api-error-delete",
"commentstreams-api-error-vote-notloggedin",
"commentstreams-api-error-vote-novoteonreply",
diff --git a/i18n/en.json b/i18n/en.json
index c04e9df..7985cca 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -37,20 +37,21 @@
"apihelp-csVote-param-vote": "vote (1, -1, or 0).",
"apihelp-csVote-pageid-example": "vote on comment with page ID 3",
"apihelp-csVote-title-example": "vote on comment with page title
CommentStreams:3",
- "commentstreams-api-error-notloggedin": "You must be logged in.",
"commentstreams-api-error-commentnotfound": "The requested comment was
not found.",
"commentstreams-api-error-notacomment": "The supplied page ID does not
refer to a valid comment.",
"commentstreams-api-error-missingcommenttitle": "A comment title must
be supplied for comments that are not replies.",
- "commentstreams-api-error-post-notloggedin": "You must be logged in to
add a comment.",
+ "commentstreams-api-error-post-permissions": "User does not have
permission to post a comment.",
"commentstreams-api-error-post-parentandtitle": "You may not specify
both the parent id and the comment title.",
"commentstreams-api-error-post-parentpagedoesnotexist": "The comment
being replied to does not exist.",
"commentstreams-api-error-post-associatedpageidmismatch": "The page
being commented on does not match the page the parent comment is commenting
on.",
"commentstreams-api-error-post-associatedpagedoesnotexist": "The page
being commented on does not exist.",
"commentstreams-api-error-post": "Error adding comment.",
+ "commentstreams-api-error-edit-notloggedin": "You must be logged in to
edit.",
"commentstreams-api-error-edit-permissions": "User does not have
permission to edit the comment.",
"commentstreams-api-error-edit": "Error editing comment.",
- "commentstreams-api-error-delete-haschildren": "Cannot delete a topic
that has replies. Please refresh the page to see updated comment stream.",
+ "commentstreams-api-error-delete-notloggedin": "You must be logged in
to delete.",
"commentstreams-api-error-delete-permissions": "User does not have
permission to delete the comment.",
+ "commentstreams-api-error-delete-haschildren": "Cannot delete a topic
that has replies. Please refresh the page to see updated comment stream.",
"commentstreams-api-error-delete": "Error deleting comment.",
"commentstreams-api-error-vote-notloggedin": "You must be logged in to
vote.",
"commentstreams-api-error-vote-novoteonreply": "Voting on replies is
not allowed.",
@@ -89,8 +90,8 @@
"group-csmoderator": "Moderators (CommentStreams)",
"group-csmoderator-member": "{{GENDER:$1|moderator (CommentStreams)}}",
"grouppage-csmoderator": "{{ns:project}}:Moderators (CommentStreams)",
- "right-csedit": "Edit comments by any user",
- "action-csedit": "edit comments by other users",
- "right-csdelete": "Delete comments by any user",
- "action-csdelete": "delete comments by other users"
+ "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"
}
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 912260d..ac20455 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -37,20 +37,21 @@
"apihelp-csVote-param-vote": "{{doc-apihelp-param|csVote|vote}}",
"apihelp-csVote-pageid-example": "{{doc-apihelp-example|csVote}}",
"apihelp-csVote-title-example": "{{doc-apihelp-example|csVote}}",
- "commentstreams-api-error-notloggedin": "Error message.",
"commentstreams-api-error-commentnotfound": "Error message.",
"commentstreams-api-error-notacomment": "Error message.",
"commentstreams-api-error-missingcommenttitle": "Error message.",
- "commentstreams-api-error-post-notloggedin": "Error message.",
+ "commentstreams-api-error-post-permissions": "Error message.",
"commentstreams-api-error-post-parentandtitle": "Error message.",
"commentstreams-api-error-post-parentpagedoesnotexist": "Error
message.",
"commentstreams-api-error-post-associatedpageidmismatch": "Error
message.",
"commentstreams-api-error-post-associatedpagedoesnotexist": "Error
message.",
"commentstreams-api-error-post": "Error message.",
+ "commentstreams-api-error-edit-notloggedin": "Error message.",
"commentstreams-api-error-edit-permissions": "Error message.",
"commentstreams-api-error-edit": "Error message.",
- "commentstreams-api-error-delete-haschildren": "Error message.",
+ "commentstreams-api-error-delete-notloggedin": "Error message.",
"commentstreams-api-error-delete-permissions": "Error message.",
+ "commentstreams-api-error-delete-haschildren": "Error message.",
"commentstreams-api-error-delete": "Error message.",
"commentstreams-api-error-vote-notloggedin": "Error message.",
"commentstreams-api-error-vote-novoteonreply": "Error message.",
@@ -89,8 +90,8 @@
"group-csmoderator": "{{doc-group|csmoderator|group}}",
"group-csmoderator-member": "{{doc-group|csmoderator|member}}",
"grouppage-csmoderator": "{{doc-group|csmoderator|page}}",
- "right-csedit": "{{doc-right|csedit}}",
- "action-csedit": "{{doc-action|csedit}}",
- "right-csdelete": "{{doc-right|csdelete}}",
- "action-csdelete": "{{doc-action|csdelete}}"
+ "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}}"
}
diff --git a/includes/ApiCSDeleteComment.php b/includes/ApiCSDeleteComment.php
index d1cad5c..6302bb9 100644
--- a/includes/ApiCSDeleteComment.php
+++ b/includes/ApiCSDeleteComment.php
@@ -38,8 +38,20 @@
* @return result of API request
*/
protected function executeBody( $comment ) {
- $wikipage = $comment->getWikiPage();
- if ( !$wikipage->getTitle()->userCan( 'delete',
$this->getUser() ) ) {
+ if ( $this->getUser()->isAnon() ) {
+ $this->dieCustomUsageMessage(
+ 'commentstreams-api-error-delete-notloggedin' );
+ }
+
+ if ( $this->getUser()->getId() ===
+ $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,
+ $this->getUser() ) ) {
$this->dieCustomUsageMessage(
'commentstreams-api-error-delete-permissions' );
}
diff --git a/includes/ApiCSEditComment.php b/includes/ApiCSEditComment.php
index 05374d6..919fe2d 100644
--- a/includes/ApiCSEditComment.php
+++ b/includes/ApiCSEditComment.php
@@ -38,7 +38,18 @@
* @return result of API request
*/
protected function executeBody( $comment ) {
- if ( !$comment->getWikiPage()->getTitle()->userCan( 'edit',
+ if ( $this->getUser()->isAnon() ) {
+ $this->dieCustomUsageMessage(
+ 'commentstreams-api-error-edit-notloggedin' );
+ }
+
+ if ( $this->getUser()->getId() ===
+ $comment->getWikiPage()->getOldestRevision()->getUser()
) {
+ $action = 'edit';
+ } else {
+ $action = 'cs-moderator-edit';
+ }
+ if ( !$comment->getWikiPage()->getTitle()->userCan( $action,
$this->getUser() ) ) {
$this->dieCustomUsageMessage(
'commentstreams-api-error-edit-permissions' );
diff --git a/includes/ApiCSPostComment.php b/includes/ApiCSPostComment.php
index c00b7bc..27c05f0 100644
--- a/includes/ApiCSPostComment.php
+++ b/includes/ApiCSPostComment.php
@@ -35,9 +35,10 @@
* execute the API request
*/
public function execute() {
- if ( $this->getUser()->isAnon() ) {
+ if ( !in_array( 'edit', $this->getUser()->getRights() ) ||
+ $this->getUser()->isBlocked() ) {
$this->dieCustomUsageMessage(
- 'commentstreams-api-error-post-notloggedin' );
+ 'commentstreams-api-error-post-permissions' );
}
$associatedid = $this->getMain()->getVal( 'associatedid' );
diff --git a/includes/CommentStreams.php b/includes/CommentStreams.php
index b26a05c..0d2b4cf 100644
--- a/includes/CommentStreams.php
+++ b/includes/CommentStreams.php
@@ -178,8 +178,10 @@
}
$commentStreamsParams = [
- 'moderatorEdit' => in_array( 'csedit',
$output->getUser()->getRights() ),
- 'moderatorDelete' => in_array( 'csdelete',
$output->getUser()->getRights() ),
+ 'moderatorEdit' => in_array( 'cs-moderator-edit',
+ $output->getUser()->getRights() ),
+ 'moderatorDelete' => in_array( 'cs-moderator-delete',
+ $output->getUser()->getRights() ),
'moderatorFastDelete' =>
$GLOBALS['wgCommentStreamsModeratorFastDelete']
? 1 : 0,
'userDisplayName' =>
diff --git a/includes/CommentStreamsHooks.php b/includes/CommentStreamsHooks.php
index c245245..38beae1 100644
--- a/includes/CommentStreamsHooks.php
+++ b/includes/CommentStreamsHooks.php
@@ -153,9 +153,13 @@
return true;
}
- if ( $action == 'edit' ) {
- if ( in_array( 'csedit', $user->getRights() ) ||
- $user->getId() ===
$wikipage->getOldestRevision()->getUser() ) {
+ if ( $user->isBlocked() ) {
+ $result = false;
+ return false;
+ }
+
+ if ( $action === 'edit' ) {
+ if ( $user->getId() ===
$wikipage->getOldestRevision()->getUser() ) {
$result = true;
} else {
$result = false;
@@ -163,9 +167,17 @@
return false;
}
- else if ( $action == 'delete' ) {
- if ( in_array( 'csdelete', $user->getRights() ) ||
- $user->getId() ===
$wikipage->getOldestRevision()->getUser() ) {
+ if ( $action === 'cs-moderator-edit' ) {
+ if ( in_array( 'cs-moderator-edit', $user->getRights()
) ) {
+ $result = true;
+ } else {
+ $result = false;
+ }
+ return false;
+ }
+
+ if ( $action === 'cs-moderator-delete' ) {
+ if ( in_array( 'cs-moderator-delete',
$user->getRights() ) ) {
$result = true;
} else {
$result = false;
@@ -279,14 +291,18 @@
$GLOBALS['wgCommentStreamsNamespaceIndex'] + 1 );
$GLOBALS['wgNamespacesToBeSearchedDefault'][NS_COMMENTSTREAMS]
= true;
$GLOBALS['smwgNamespacesWithSemanticLinks'][NS_COMMENTSTREAMS]
= true;
- if ( !isset(
$GLOBALS['wgGroupPermissions']['csmoderator']['csdelete'] ) ) {
-
$GLOBALS['wgGroupPermissions']['csmoderator']['csdelete'] = true;
+ if ( !isset( $GLOBALS['wgGroupPermissions']['csmoderator']
+ ['cs-moderator-delete'] ) ) {
+
$GLOBALS['wgGroupPermissions']['csmoderator']['cs-moderator-delete'] =
+ true;
}
- if ( !isset(
$GLOBALS['wgGroupPermissions']['csmoderator']['csedit'] ) ) {
- $GLOBALS['wgGroupPermissions']['csmoderator']['csedit']
= false;
+ if ( !isset( $GLOBALS['wgGroupPermissions']['csmoderator']
+ ['cs-moderator-edit'] ) ) {
+
$GLOBALS['wgGroupPermissions']['csmoderator']['cs-moderator-edit'] =
+ false;
}
- $GLOBALS['wgAvailableRights'][] = 'csedit';
- $GLOBALS['wgAvailableRights'][] = 'csdelete';
+ $GLOBALS['wgAvailableRights'][] = 'cs-moderator-edit';
+ $GLOBALS['wgAvailableRights'][] = 'cs-moderator-delete';
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/359794
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7ee8ec054aa86b7a7e878de702ad8196f89a789b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CommentStreams
Gerrit-Branch: master
Gerrit-Owner: Cicalese <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits