MediaWiki r115137 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r115136‎ | r115137 (on ViewVC)‎ | r115138 >
Date:16:15, 4 May 2012
Author:ashley
Status:new
Tags:
Comment:
Comments: bug #34345 - fix "Delete Comment" links so that deletion actually works. Based on patch by Edward.
Modified paths:

Diff [purge]

Index: trunk/extensions/Comments/Comments_AjaxFunctions.php
@@ -131,4 +131,20 @@
132132 }
133133
134134 return 'ok';
135 -}
\ No newline at end of file
 135+}
 136+
 137+$wgAjaxExportList[] = 'wfDeleteComment';
 138+function wfDeleteComment( $pageId, $commentId ) {
 139+ global $wgUser;
 140+
 141+ // Blocked users cannot delete comments, and neither can unprivileged ones
 142+ if( $wgUser->isBlocked() || !$wgUser->isAllowed( 'commentadmin' ) ) {
 143+ return '';
 144+ }
 145+
 146+ $comment = new Comment( $pageId );
 147+ $comment->setCommentID( $commentId );
 148+ $comment->delete();
 149+
 150+ return 'ok';
 151+}
Index: trunk/extensions/Comments/Comment.php
@@ -4,7 +4,7 @@
55 *
66 * @file
77 * @ingroup Extensions
8 - * @version 2.5
 8+ * @version 2.7
99 * @author David Pean <david.pean@gmail.com>
1010 * @author Misza <misza@shoutwiki.com>
1111 * @author Jack Phoenix <jack@countervandalism.net>
@@ -24,7 +24,7 @@
2525 // Extension credits that will show up on Special:Version
2626 $wgExtensionCredits['parserhook'][] = array(
2727 'name' => 'Comments',
28 - 'version' => '2.6',
 28+ 'version' => '2.7',
2929 'author' => array( 'David Pean', 'Misza', 'Jack Phoenix' ),
3030 'description' => 'Adds <tt>&lt;comments&gt;</tt> parser hook that allows commenting on articles',
3131 'url' => 'https://www.mediawiki.org/wiki/Extension:Comments'
@@ -38,7 +38,7 @@
3939 'comment-voted-label', 'comment-loading',
4040 'comment-auto-refresher-pause', 'comment-auto-refresher-enable',
4141 'comment-cancel-reply', 'comment-reply-to', 'comment-block-warning',
42 - 'comment-block-anon', 'comment-block-user'
 42+ 'comment-block-anon', 'comment-block-user', 'comment-delete-warning'
4343 ),
4444 'localBasePath' => dirname( __FILE__ ),
4545 'remoteExtPath' => 'Comments',
@@ -136,10 +136,6 @@
137137 $comment->setAllow( $allow );
138138 $comment->setVoting( $voting );
139139
140 - if( isset( $_POST['commentid'] ) ) { // isset added by misza
141 - $comment->setCommentID( $_POST['commentid'] );
142 - $comment->delete();
143 - }
144140 // This was originally commented out, I don't know why.
145141 // Uncommented to prevent E_NOTICE.
146142 $output = $comment->displayOrderForm();
Index: trunk/extensions/Comments/Comments.i18n.php
@@ -21,6 +21,7 @@
2222 'comment-reply-to' => 'Reply to',
2323 'comment-cancel-reply' => 'Cancel',
2424 'comment-block-warning' => 'Are you sure you want to permanently ignore all comments from',
 25+ 'comment-delete-warning' => 'Are you sure you want delete this comment?',
2526 'comment-block-anon' => 'this Anonymous user (via their IP address)',
2627 'comment-block-user' => 'user',
2728 'comment-sort-by-date' => 'Sort by Date',
@@ -78,6 +79,7 @@
7980 'comment-auto-refresher-enable' => 'Ota käyttöön kommenttien automaattinen päivitys',
8081 'comment-reply-to' => 'Vastaa käyttäjälle',
8182 'comment-cancel-reply' => 'Peruuta',
 83+ 'comment-delete-warning' => 'Oletko varma, että haluat poistaa tämän kommentin?',
8284 'comment-block-warning' => 'Oletko varma, että haluat lopullisesti jättää kaikki kommentit huomiotta',
8385 'comment-block-anon' => 'tältä anonyymiltä käyttäjältä (IP-osoitteensa perusteella)',
8486 'comment-block-user' => 'käyttäjältä',
Index: trunk/extensions/Comments/Comment.js
@@ -4,7 +4,7 @@
55 * object-oriented.
66 *
77 * @file
8 - * @date 7 January 2012
 8+ * @date 4 May 2012
99 */
1010 var Comment = {
1111 submitted: 0,
@@ -51,6 +51,22 @@
5252 },
5353
5454 /**
 55+ * This function is called whenever a user clicks on the "Delete Comment"
 56+ * link to delete a comment.
 57+ *
 58+ * @param c_id Integer: comment ID number
 59+ */
 60+ deleteComment: function( c_id ) {
 61+ var pageId = document.commentform.pid.value;
 62+ if( confirm( mw.msg( 'comment-delete-warning' ) ) ) {
 63+ sajax_request_type = 'POST';
 64+ sajax_do_call( 'wfDeleteComment', [ pageId, c_id ], function( response ) {
 65+ window.location.href = window.location;
 66+ });
 67+ }
 68+ },
 69+
 70+ /**
5571 * Vote for a comment.
5672 * Formerly called "cv"
5773 *
@@ -270,6 +286,16 @@
271287 } );
272288 } );
273289
 290+ // "Delete Comment" links
 291+ jQuery( 'a.comment-delete-link' ).each( function( index ) {
 292+ var that = jQuery( this );
 293+ that.click( function() {
 294+ Comment.deleteComment(
 295+ that.data( 'comment-id' )
 296+ );
 297+ } );
 298+ } );
 299+
274300 // "Show this hidden comment" -- comments made by people on the user's
275301 // personal block list
276302 jQuery( 'div.c-ignored-links a' ).each( function( index ) {
Index: trunk/extensions/Comments/CommentClass.php
@@ -501,6 +501,7 @@
502502 array( 'Comment_Vote_ID' => $this->CommentID ),
503503 __METHOD__
504504 );
 505+ $dbw->commit();
505506 $this->clearCommentListCache();
506507 wfRunHooks( 'Comment::delete', array( $this, $this->CommentID, $this->PageID ) );
507508 }
@@ -675,7 +676,7 @@
676677 if( $wgUser->isBlocked() ) {
677678 return '';
678679 }
679 - if ( ! $wgUser->isAllowed( 'comment' ) ) {
 680+ if ( !$wgUser->isAllowed( 'comment' ) ) {
680681 return '';
681682 }
682683
@@ -778,9 +779,13 @@
779780
780781 // Comment delete button for privileged users
781782 $dlt = '';
 783+
782784 if( $wgUser->isAllowed( 'commentadmin' ) ) {
783 - $dlt = " | <span class=\"c-delete\"><a href=\"javascript:document.commentform.commentid.value={$comment['CommentID']};document.commentform.submit();\">" .
784 - wfMsg( 'comment-delete-link' ) . '</a></span>';
 785+ //$dlt = " | <span class=\"c-delete\"><a href=\"javascript:document.commentform.commentid.value={$comment['CommentID']};document.commentform.submit();\">" .
 786+ $dlt = ' | <span class="c-delete">' .
 787+ '<a href="javascript:void(0);" rel="nofollow" class="comment-delete-link" data-comment-id="' .
 788+ $comment['CommentID'] . '">' .
 789+ wfMsg( 'comment-delete-link' ) . '</a></span>';
785790 }
786791
787792 // Reply Link (does not appear on child comments)