r109075 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109074‎ | r109075 | r109076 >
Date:23:12, 16 January 2012
Author:gregchiasson
Status:resolved (Comments)
Tags:aft 
Comment:
AFT5 - Add ability to 'delete' (super-hide, visible to oversight only) comments. Started plumbing the bits to allow updating the count queries when hiding feedback, but i need to noodle that one over a bit more.
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.i18n.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5Utils.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiFlagFeedbackArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.css (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/sql/ArticleFeedbackv5.sql (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/sql/alter.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/sql/ArticleFeedbackv5.sql
@@ -36,6 +36,7 @@
3737 -- Number of times the feedback was hidden or marked as abusive.
3838 af_abuse_count integer unsigned NOT NULL DEFAULT 0,
3939 af_hide_count integer unsigned NOT NULL DEFAULT 0,
 40+ af_delete_count integer unsigned NOT NULL DEFAULT 0,
4041 af_helpful_count integer unsigned NOT NULL DEFAULT 0
4142 ) /*$wgDBTableOptions*/;
4243 CREATE INDEX /*i*/af_page_user_token_id ON /*_*/aft_article_feedback (af_page_id, af_user_id, af_user_anon_token, af_id);
Index: trunk/extensions/ArticleFeedbackv5/sql/alter.sql
@@ -59,3 +59,4 @@
6060
6161 -- added 1/16 (greg)
6262 ALTER TABLE aft_article_feedback ADD COLUMN af_helpful_count integer unsigned NOT NULL DEFAULT 0;
 63+ALTER TABLE aft_article_feedback ADD COLUMN af_delete_count integer unsigned NOT NULL DEFAULT 0;
Index: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.i18n.php
@@ -46,10 +46,13 @@
4747 'articlefeedbackv5-form-tools-label' => 'Tools',
4848 'articlefeedbackv5-form-helpful-label' => 'Is this feedback helpful?',
4949 'articlefeedbackv5-special-add-feedback' => 'Add your feedback',
 50+ 'articlefeedbackv5-special-filter-all' => 'All ($1)',
5051 'articlefeedbackv5-special-filter-comment' => 'Comments only ($1)',
 52+ 'articlefeedbackv5-special-filter-deleted' => 'Deleted ($1)',
 53+ 'articlefeedbackv5-special-filter-abusive' => 'Abusive ($1)',
 54+ 'articlefeedbackv5-special-filter-helpful' => 'Helpful ($1)',
5155 'articlefeedbackv5-special-filter-visible' => 'Visible ($1)',
5256 'articlefeedbackv5-special-filter-invisible' => 'Invisible ($1)',
53 - 'articlefeedbackv5-special-filter-all' => 'All ($1)',
5457 'articlefeedbackv5-special-sort-newest' => 'Newest first',
5558 'articlefeedbackv5-special-sort-oldest' => 'Oldest first',
5659 'articlefeedbackv5-special-sort-label-before' => 'Order by:',
@@ -77,6 +80,7 @@
7881 'articlefeedbackv5-form5-header' => '$1 rated this page:',
7982 'articlefeedbackv5-form-not-shown' => 'User was not shown a feedback form.',
8083 'articlefeedbackv5-form-invalid' => 'Invalid feedback form ID.',
 84+ 'articlefeedbackv5-delet-saved' => '',
8185 'articlefeedbackv5-abuse-saved' => 'Flagged as abuse',
8286 'articlefeedbackv5-hide-saved' => 'Hide flag saved',
8387 'articlefeedbackv5-helpful-saved' => 'Marked as helpful',
Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.css
@@ -1,4 +1,3 @@
22 /* css here */
33 div.articleFeedbackv5-feedback { border:1px solid #CCC; background:#EEE; margin-top:10px; clear:both;}
44 div.articleFeedbackv5-feedback-tools { border:1px solid #CCD; background:#EEF; margin:10px; width:219px; float:right;}
5 -p.articleFeedbackv5-comment-head { border:1px solid #CCC; }
Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js
@@ -93,6 +93,10 @@
9494 $.articleFeedbackv5special.hideFeedback( $.articleFeedbackv5special.stripID( this, 'articleFeedbackv5-hide-link-' ) );
9595 return false;
9696 } );
 97+ $( '.articleFeedbackv5-delete-link' ).live( 'click', function( e ) {
 98+ $.articleFeedbackv5special.deleteFeedback( $.articleFeedbackv5special.stripID( this, 'articleFeedbackv5-delete-link-' ) );
 99+ return false;
 100+ } );
97101 $( '.articleFeedbackv5-helpful-link' ).live( 'click', function( e ) {
98102 $.articleFeedbackv5special.helpfulFeedback( $.articleFeedbackv5special.stripID( this, 'articleFeedbackv5-helpful-link-' ) );
99103 return false;
@@ -110,7 +114,7 @@
111115 // {{{ helpfulFeedback
112116
113117 /**
114 - * Hides a response
 118+ * Flags a response as helpful
115119 *
116120 * @param id int the feedback id
117121 */
@@ -118,7 +122,17 @@
119123 $.articleFeedbackv5special.flagFeedback( id, 'helpful' );
120124 }
121125
 126+ // {{{ hideFeedback
122127
 128+ /**
 129+ * "Deletes" a response - actually just super-hides so only admins see.
 130+ *
 131+ * @param id int the feedback id
 132+ */
 133+ $.articleFeedbackv5special.deleteFeedback = function ( id ) {
 134+ $.articleFeedbackv5special.flagFeedback( id, 'delete' );
 135+ }
 136+
123137 // {{{ hideFeedback
124138
125139 /**
@@ -157,6 +171,7 @@
158172 'type' : 'POST',
159173 'dataType': 'json',
160174 'data' : {
 175+ 'pageid' : $.articleFeedbackv5special.page,
161176 'feedbackid': id,
162177 'flagtype' : type,
163178 'format' : 'json',
Index: trunk/extensions/ArticleFeedbackv5/api/ApiFlagFeedbackArticleFeedbackv5.php
@@ -38,6 +38,7 @@
3939 array( 'af_id' => $params['feedbackid'] )
4040 );
4141
 42+ # TODO:
4243 if ( !$record->af_id ) {
4344 // no-op, because this is already broken
4445 $error = 'articlefeedbackv5-invalid-feedback-id';
@@ -47,6 +48,8 @@
4849 $update['af_hide_count'] = $record->af_hide_count + 1;
4950 } elseif ( $params['flagtype'] == 'helpful' ) {
5051 $update['af_helpful_count'] = $record->af_helpful_count + 1;
 52+ } elseif ( $params['flagtype'] == 'delete' ) {
 53+ $update['af_delete_count'] = $record->af_delete_count + 1;
5154 } else {
5255 $error = 'articlefeedbackv5-invalid-feedback-flag';
5356 }
@@ -85,6 +88,11 @@
8689 */
8790 public function getAllowedParams() {
8891 return array(
 92+ 'pageid' => array(
 93+ ApiBase::PARAM_REQUIRED => true,
 94+ ApiBase::PARAM_ISMULTI => false,
 95+ ApiBase::PARAM_TYPE => 'integer'
 96+ ),
8997 'feedbackid' => array(
9098 ApiBase::PARAM_REQUIRED => true,
9199 ApiBase::PARAM_ISMULTI => false,
@@ -94,7 +102,7 @@
95103 ApiBase::PARAM_REQUIRED => true,
96104 ApiBase::PARAM_ISMULTI => false,
97105 ApiBase::PARAM_TYPE => array(
98 - 'abuse', 'hide', 'helpful' )
 106+ 'abuse', 'hide', 'helpful', 'delete' )
99107 ),
100108 );
101109 }
Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php
@@ -267,54 +267,14 @@
268268 }
269269
270270 # Update the overall number of records for this page.
271 - $this->updateFilterCount( $pageId, 'all' );
272 - # If the feedbackrecord had a comment, update that fitler count.
 271+ ApiArticleFeedbackv5Utils::incrementFilterCount( $pageId, 'all' );
 272+ # If the feedbackrecord had a comment, update that filter count.
273273 if( $has_comment ) {
274 - $this->updateFilterCount( $pageId, 'comment' );
 274+ ApiArticleFeedbackv5Utils::incrementFilterCount( $pageId, 'comment' );
275275 }
276276 }
277277
278278 /**
279 - * Update the feedback count rollup table
280 - *
281 - * @param $pageId int the page id
282 - * @param $filterName string the name of the filter to update
283 - */
284 - private function updateFilterCount( $pageId, $filterName ) {
285 - $dbw = wfGetDB( DB_MASTER );
286 -
287 - $dbw->begin();
288 -
289 - # Try to insert the record, but ignore failures.
290 - # Ensures the count row exists.
291 - $dbw->insert(
292 - 'aft_article_filter_counts',
293 - array(
294 - 'afc_page_id' => $pageId,
295 - 'afc_filter_name' => $filterName,
296 - 'afc_filter_count' => 0
297 - ),
298 - __METHOD__,
299 - array( 'IGNORE' )
300 - );
301 -
302 - # Update the count row, incrementing the count.
303 - $dbw->update(
304 - 'aft_article_filter_counts',
305 - array(
306 - 'afc_filter_count = afc_filter_count + 1'
307 - ),
308 - array(
309 - 'afc_page_id' => $pageId,
310 - 'afc_filter_name' => $filterName
311 - ),
312 - __METHOD__
313 - );
314 -
315 - $dbw->commit();
316 - }
317 -
318 - /**
319279 * Update the rollup tables
320280 *
321281 * @param $page int the page id
Index: trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php
@@ -80,7 +80,6 @@
8181 $where = $this->getFilterCriteria( $filter );
8282 $order;
8383
84 - # Newest first is the only option right now.
8584 # TODO: The SQL needs to handle all sorts of weird cases.
8685 switch( $order ) {
8786 case 'oldest':
@@ -95,6 +94,8 @@
9695 }
9796
9897 $where['af_page_id'] = $pageId;
 98+ # the join is needed for the comment
 99+ $where[] = 'af_id = aa_feedback_id';
99100
100101 if( $continue !== null ) {
101102 $where[] = "$continueSql $continue";
@@ -106,8 +107,12 @@
107108 record until we fetch them, this is the only way to make
108109 sure we get all answers for the exact IDs we want. */
109110 $id_query = $dbr->select(
110 - 'aft_article_feedback', 'af_id', $where, __METHOD__,
111111 array(
 112+ 'aft_article_feedback',
 113+ 'aft_article_answer'
 114+ ),
 115+ 'DISTINCT af_id', $where, __METHOD__,
 116+ array(
112117 'LIMIT' => $limit,
113118 'ORDER BY' => $order
114119 )
@@ -130,7 +135,7 @@
131136 'aa_response_rating', 'aa_response_option_id',
132137 'afi_data_type', 'af_created', 'user_name',
133138 'af_user_ip', 'af_hide_count', 'af_abuse_count',
134 - 'af_helpful_count'
 139+ 'af_helpful_count', 'af_delete_count'
135140 ),
136141 array( 'af_id' => $ids ),
137142 __METHOD__,
@@ -173,6 +178,9 @@
174179 case 'invisible':
175180 $where = array( 'af_hide_count > 0' );
176181 break;
 182+ case 'comment':
 183+ $where = array( 'aa_response_text IS NOT NULL');
 184+ break;
177185 case 'visible':
178186 default:
179187 $where = array( 'af_hide_count' => 0 );
@@ -206,20 +214,20 @@
207215
208216 $footer_links = Html::openElement( 'p', array( 'class' => 'articleFeedbackv5-comment-foot' ) )
209217 . Html::openElement( 'ul' )
 218+ . ( $can_upvote ? Html::rawElement( 'li', array(), Html::element( 'a', array(
 219+ 'id' => "articleFeedbackv5-helpful-link-$id",
 220+ 'class' => 'articleFeedbackv5-helpful-link'
 221+ ), wfMessage( 'articlefeedbackv5-form-helpful', $record[0]->af_helpful_count )->text() ) ) : '' )
210222 . ( $can_flag ? Html::rawElement( 'li', array(), Html::element( 'a', array(
211223 'id' => "articleFeedbackv5-abuse-link-$id",
212224 'class' => 'articleFeedbackv5-abuse-link'
213225 ), wfMessage( 'articlefeedbackv5-form-abuse', $record[0]->af_abuse_count )->text() ) ) : '' )
214 - . ( $can_upvote ? Html::rawElement( 'li', array(), Html::element( 'a', array(
215 - 'id' => "articleFeedbackv5-helpful-link-$id",
216 - 'class' => 'articleFeedbackv5-helpful-link'
217 - ), wfMessage( 'articlefeedbackv5-form-helpful', $record[0]->af_helpful_count )->text() ) ) : '' )
218226 . Html::closeElement( 'ul' )
219227 . Html::closeElement( 'p' );
220228
221 - $rate = Html::openElement( 'div', array( 'class' => 'articleFeedbackv5-feedback-rate' ) )
222 - . wfMessage( 'articlefeedbackv5-form-helpful-label' )->escaped()
223 - . Html::closeElement( 'div' );
 229+# $rate = Html::openElement( 'div', array( 'class' => 'articleFeedbackv5-feedback-rate' ) )
 230+# . wfMessage( 'articlefeedbackv5-form-helpful-label' )->escaped()
 231+# . Html::closeElement( 'div' );
224232
225233
226234 $tools = Html::openElement( 'div', array( 'class' => 'articleFeedbackv5-feedback-tools' ) )
Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5Utils.php
@@ -149,5 +149,46 @@
150150 }
151151 return $rv;
152152 }
 153+
 154+ /**
 155+ * Increments the per-page-per-filter count rollups used on the feedback
 156+ * page.
 157+ *
 158+ * @param $pageId int the ID of the page (page.page_id)
 159+ * @param $filterName string name of the filter to increment
 160+ */
 161+ public static function incrementFilterCount( $pageId, $filterName ) {
 162+ $dbw = wfGetDB( DB_MASTER );
 163+
 164+ $dbw->begin();
 165+
 166+ # Try to insert the record, but ignore failures.
 167+ # Ensures the count row exists.
 168+ $dbw->insert(
 169+ 'aft_article_filter_count',
 170+ array(
 171+ 'afc_page_id' => $pageId,
 172+ 'afc_filter_name' => $filterName,
 173+ 'afc_filter_count' => 0
 174+ ),
 175+ __METHOD__,
 176+ array( 'IGNORE' )
 177+ );
 178+
 179+ # Update the count row, incrementing the count.
 180+ $dbw->update(
 181+ 'aft_article_filter_count',
 182+ array(
 183+ 'afc_filter_count = afc_filter_count + 1'
 184+ ),
 185+ array(
 186+ 'afc_page_id' => $pageId,
 187+ 'afc_filter_name' => $filterName
 188+ ),
 189+ __METHOD__
 190+ );
 191+
 192+ $dbw->commit();
 193+ }
153194 }
154195

Follow-up revisions

RevisionCommit summaryAuthorDate
r109116r109075: Ignore empty messageraymond07:58, 17 January 2012
r109156AFT5 - spell translations properly, and add them to the list of messages load...gregchiasson16:07, 17 January 2012
r109964AFT5 - Add some qqq translation explanation, as a followup to r109075gregchiasson22:37, 24 January 2012

Comments

#Comment by Nikerabbit (talk | contribs)   08:41, 17 January 2012

Where is articlefeedbackv5-delet-saved used?

#Comment by Gregchiasson (talk | contribs)   15:06, 17 January 2012

That's a typo. It should be "articlefeedbackv5-delete-saved", and it's used in modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js (or it will be, when I fix it).

#Comment by Raymond (talk | contribs)   17:07, 17 January 2012

Please add message documentation for the newly added messages. Thanks.

#Comment by Catrope (talk | contribs)   01:23, 26 January 2012

OK other than the message docs thing.

Status & tagging log