https://www.mediawiki.org/wiki/Special:Code/MediaWiki/115137
Revision: 115137 Author: ashley Date: 2012-05-04 16:15:46 +0000 (Fri, 04 May 2012) Log Message: ----------- Comments: bug #34345 - fix "Delete Comment" links so that deletion actually works. Based on patch by Edward. Modified Paths: -------------- trunk/extensions/Comments/Comment.js trunk/extensions/Comments/Comment.php trunk/extensions/Comments/CommentClass.php trunk/extensions/Comments/Comments.i18n.php trunk/extensions/Comments/Comments_AjaxFunctions.php Modified: trunk/extensions/Comments/Comment.js =================================================================== --- trunk/extensions/Comments/Comment.js 2012-05-03 23:51:43 UTC (rev 115136) +++ trunk/extensions/Comments/Comment.js 2012-05-04 16:15:46 UTC (rev 115137) @@ -4,7 +4,7 @@ * object-oriented. * * @file - * @date 7 January 2012 + * @date 4 May 2012 */ var Comment = { submitted: 0, @@ -51,6 +51,22 @@ }, /** + * This function is called whenever a user clicks on the "Delete Comment" + * link to delete a comment. + * + * @param c_id Integer: comment ID number + */ + deleteComment: function( c_id ) { + var pageId = document.commentform.pid.value; + if( confirm( mw.msg( 'comment-delete-warning' ) ) ) { + sajax_request_type = 'POST'; + sajax_do_call( 'wfDeleteComment', [ pageId, c_id ], function( response ) { + window.location.href = window.location; + }); + } + }, + + /** * Vote for a comment. * Formerly called "cv" * @@ -270,6 +286,16 @@ } ); } ); + // "Delete Comment" links + jQuery( 'a.comment-delete-link' ).each( function( index ) { + var that = jQuery( this ); + that.click( function() { + Comment.deleteComment( + that.data( 'comment-id' ) + ); + } ); + } ); + // "Show this hidden comment" -- comments made by people on the user's // personal block list jQuery( 'div.c-ignored-links a' ).each( function( index ) { Modified: trunk/extensions/Comments/Comment.php =================================================================== --- trunk/extensions/Comments/Comment.php 2012-05-03 23:51:43 UTC (rev 115136) +++ trunk/extensions/Comments/Comment.php 2012-05-04 16:15:46 UTC (rev 115137) @@ -4,7 +4,7 @@ * * @file * @ingroup Extensions - * @version 2.5 + * @version 2.7 * @author David Pean <david.p...@gmail.com> * @author Misza <mi...@shoutwiki.com> * @author Jack Phoenix <j...@countervandalism.net> @@ -24,7 +24,7 @@ // Extension credits that will show up on Special:Version $wgExtensionCredits['parserhook'][] = array( 'name' => 'Comments', - 'version' => '2.6', + 'version' => '2.7', 'author' => array( 'David Pean', 'Misza', 'Jack Phoenix' ), 'description' => 'Adds <tt><comments></tt> parser hook that allows commenting on articles', 'url' => 'https://www.mediawiki.org/wiki/Extension:Comments' @@ -38,7 +38,7 @@ 'comment-voted-label', 'comment-loading', 'comment-auto-refresher-pause', 'comment-auto-refresher-enable', 'comment-cancel-reply', 'comment-reply-to', 'comment-block-warning', - 'comment-block-anon', 'comment-block-user' + 'comment-block-anon', 'comment-block-user', 'comment-delete-warning' ), 'localBasePath' => dirname( __FILE__ ), 'remoteExtPath' => 'Comments', @@ -136,10 +136,6 @@ $comment->setAllow( $allow ); $comment->setVoting( $voting ); - if( isset( $_POST['commentid'] ) ) { // isset added by misza - $comment->setCommentID( $_POST['commentid'] ); - $comment->delete(); - } // This was originally commented out, I don't know why. // Uncommented to prevent E_NOTICE. $output = $comment->displayOrderForm(); Modified: trunk/extensions/Comments/CommentClass.php =================================================================== --- trunk/extensions/Comments/CommentClass.php 2012-05-03 23:51:43 UTC (rev 115136) +++ trunk/extensions/Comments/CommentClass.php 2012-05-04 16:15:46 UTC (rev 115137) @@ -501,6 +501,7 @@ array( 'Comment_Vote_ID' => $this->CommentID ), __METHOD__ ); + $dbw->commit(); $this->clearCommentListCache(); wfRunHooks( 'Comment::delete', array( $this, $this->CommentID, $this->PageID ) ); } @@ -675,7 +676,7 @@ if( $wgUser->isBlocked() ) { return ''; } - if ( ! $wgUser->isAllowed( 'comment' ) ) { + if ( !$wgUser->isAllowed( 'comment' ) ) { return ''; } @@ -778,9 +779,13 @@ // Comment delete button for privileged users $dlt = ''; + if( $wgUser->isAllowed( 'commentadmin' ) ) { - $dlt = " | <span class=\"c-delete\"><a href=\"javascript:document.commentform.commentid.value={$comment['CommentID']};document.commentform.submit();\">" . - wfMsg( 'comment-delete-link' ) . '</a></span>'; + //$dlt = " | <span class=\"c-delete\"><a href=\"javascript:document.commentform.commentid.value={$comment['CommentID']};document.commentform.submit();\">" . + $dlt = ' | <span class="c-delete">' . + '<a href="javascript:void(0);" rel="nofollow" class="comment-delete-link" data-comment-id="' . + $comment['CommentID'] . '">' . + wfMsg( 'comment-delete-link' ) . '</a></span>'; } // Reply Link (does not appear on child comments) Modified: trunk/extensions/Comments/Comments.i18n.php =================================================================== --- trunk/extensions/Comments/Comments.i18n.php 2012-05-03 23:51:43 UTC (rev 115136) +++ trunk/extensions/Comments/Comments.i18n.php 2012-05-04 16:15:46 UTC (rev 115137) @@ -21,6 +21,7 @@ 'comment-reply-to' => 'Reply to', 'comment-cancel-reply' => 'Cancel', 'comment-block-warning' => 'Are you sure you want to permanently ignore all comments from', + 'comment-delete-warning' => 'Are you sure you want delete this comment?', 'comment-block-anon' => 'this Anonymous user (via their IP address)', 'comment-block-user' => 'user', 'comment-sort-by-date' => 'Sort by Date', @@ -78,6 +79,7 @@ 'comment-auto-refresher-enable' => 'Ota käyttöön kommenttien automaattinen päivitys', 'comment-reply-to' => 'Vastaa käyttäjälle', 'comment-cancel-reply' => 'Peruuta', + 'comment-delete-warning' => 'Oletko varma, että haluat poistaa tämän kommentin?', 'comment-block-warning' => 'Oletko varma, että haluat lopullisesti jättää kaikki kommentit huomiotta', 'comment-block-anon' => 'tältä anonyymiltä käyttäjältä (IP-osoitteensa perusteella)', 'comment-block-user' => 'käyttäjältä', Modified: trunk/extensions/Comments/Comments_AjaxFunctions.php =================================================================== --- trunk/extensions/Comments/Comments_AjaxFunctions.php 2012-05-03 23:51:43 UTC (rev 115136) +++ trunk/extensions/Comments/Comments_AjaxFunctions.php 2012-05-04 16:15:46 UTC (rev 115137) @@ -131,4 +131,20 @@ } return 'ok'; -} \ No newline at end of file +} + +$wgAjaxExportList[] = 'wfDeleteComment'; +function wfDeleteComment( $pageId, $commentId ) { + global $wgUser; + + // Blocked users cannot delete comments, and neither can unprivileged ones + if( $wgUser->isBlocked() || !$wgUser->isAllowed( 'commentadmin' ) ) { + return ''; + } + + $comment = new Comment( $pageId ); + $comment->setCommentID( $commentId ); + $comment->delete(); + + return 'ok'; +} _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs