r110012 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110011‎ | r110012 | r110013 >
Date:18:43, 25 January 2012
Author:gregchiasson
Status:resolved (Comments)
Tags:aft 
Comment:
AFT5 feedback page - add truncation to comments over 500 characters, with expand/collapse Javascript. Followup to r109967
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.hooks.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.i18n.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)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.i18n.php
@@ -132,6 +132,8 @@
133133 * Recent lows: pages that got 70% or more low (2 stars or lower) ratings in any category in the last 24 hours. Only pages that have received at least 10 ratings in the last 24 hours are included.",
134134 'articlefeedbackv5' => 'Article feedback dashboard',
135135 'articlefeedbackv5-desc' => 'Article feedback',
 136+ 'articlefeedbackv5-comment-more' => 'Label for the button to expand the truncated comment on feedback. Swaps to articlefeedbackv5-comment-less after being clicked.',
 137+ 'articlefeedbackv5-comment-less' => 'Previous label (articlefeedbackv5-comment-more) switches to this after being clicked. This is the label for collapsing the expanded comments.',
136138
137139 /* Feedback forms */
138140 /* Option 1 ("Did you find what you were looking for?") */
@@ -374,6 +376,8 @@
375377
376378 Please visit http://prototype.wikimedia.org/articleassess/Main_Page for a prototype installation.',
377379 'articlefeedbackv5-desc' => '{{desc}}',
 380+ 'articlefeedbackv5-comment-more' => 'More',
 381+ 'articlefeedbackv5-comment-less' => 'Less',
378382
379383 /* Feedback forms */
380384 /* Option 1 ("Did you find what you were looking for?") */
Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.css
@@ -317,3 +317,7 @@
318318 background-repeat: no-repeat;
319319 background-size: 11px 7px;
320320 }
 321+
 322+.articleFeedbackv5-comment-full {
 323+ display: none;
 324+}
Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js
@@ -114,6 +114,7 @@
115115 $.articleFeedbackv5special.loadFeedback( true );
116116 return false;
117117 } );
 118+
118119 $( '.articleFeedbackv5-sort-link' ).bind( 'click', function( e ) {
119120 id = $.articleFeedbackv5special.stripID( this, 'articleFeedbackv5-special-sort-' );
120121 oldId = $.articleFeedbackv5special.sort;
@@ -135,11 +136,18 @@
136137
137138 return false;
138139 } );
 140+
139141 $( '#articleFeedbackv5-show-more' ).bind( 'click', function( e ) {
140142 $.articleFeedbackv5special.loadFeedback( false );
141143 return false;
142144 } );
143145
 146+ $( '.articleFeedbackv5-comment-toggle' ).live( 'click', function( e ) {
 147+console.log('welp');
 148+ $.articleFeedbackv5special.toggleComment( $.articleFeedbackv5special.stripID( this, 'articleFeedbackv5-comment-toggle-' ) );
 149+ return false;
 150+ } );
 151+
144152 $.each( ['unhide', 'undelete', 'oversight', 'hide', 'abuse', 'delete', 'helpful', 'unhelpful', 'unoversight'],
145153 function ( index, value ) {
146154 $( '.articleFeedbackv5-' + value + '-link' ).live( 'click', function( e ) {
@@ -153,6 +161,30 @@
154162 // }}}
155163 // {{{ Utility methods
156164
 165+
 166+
 167+ // {{{ toggleComment
 168+ $.articleFeedbackv5special.toggleComment = function( id ) {
 169+console.log('id is ' + id);
 170+ if( $( '#articleFeedbackv5-comment-toggle-' + id ).text()
 171+ == mw.msg( 'articlefeedbackv5-comment-more' ) ) {
 172+console.log('show full');
 173+ $( '#articleFeedbackv5-comment-short-' + id ).hide();
 174+ $( '#articleFeedbackv5-comment-full-' + id ).show();
 175+ $( '#articleFeedbackv5-comment-toggle-' + id ).text(
 176+ mw.msg( 'articlefeedbackv5-comment-less' )
 177+ );
 178+ } else {
 179+console.log('show short');
 180+ $( '#articleFeedbackv5-comment-short-' + id ).show();
 181+ $( '#articleFeedbackv5-comment-full-' + id ).hide();
 182+ $( '#articleFeedbackv5-comment-toggle-' + id ).text(
 183+ mw.msg( 'articlefeedbackv5-comment-more' )
 184+ );
 185+ }
 186+ }
 187+ // }}}
 188+
157189 // {{{ drawSortArrow
158190
159191 $.articleFeedbackv5special.drawSortArrow = function() {
Index: trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php
@@ -452,7 +452,7 @@
453453 }
454454
455455 return $this->feedbackHead( $msg, $class, $record[0] )
456 - . $this->renderComment( $record['comment']->aa_response_text );
 456+ . $this->renderComment( $record['comment']->aa_response_text, $record[0]->af_id );
457457 }
458458
459459
@@ -465,7 +465,7 @@
466466 // * articlefeedbackv5-form2-header-question
467467 // * articlefeedbackv5-form2-header-suggestion
468468 return $this->feedbackHead( "articlefeedbackv5-form2-header-$type", $class, $record[0], $type )
469 - . $this->renderComment( $record['comment']->aa_response_text );
 469+ . $this->renderComment( $record['comment']->aa_response_text, $record[0]->af_id );
470470 }
471471
472472 private function renderBucket3( $record ) {
@@ -474,7 +474,7 @@
475475 $class = $record['rating']->aa_response_rating >= 3 ? 'positive' : 'negative';
476476
477477 return $this->feedbackHead( 'articlefeedbackv5-form3-header', $class, $record[0], $record['rating']->aa_response_rating )
478 - . $this->renderComment( $record['comment']->aa_response_text );
 478+ . $this->renderComment( $record['comment']->aa_response_text, $record[0]->af_id );
479479 }
480480
481481 private function renderBucket4( $record ) {
@@ -535,16 +535,37 @@
536536 );
537537 }
538538
539 - private function renderComment( $text ) {
540 - if( strlen( $text ) <= 500 ) {
541 - $rv = "<blockquote>"
 539+ private function renderComment( $text, $feedbackId ) {
 540+ global $wgLang;
 541+
 542+ $short = $wgLang->truncate( $text, 500 );
 543+
 544+ $rv = Html::openElement( 'blockquote',
 545+ array(
 546+ 'class' => 'articleFeedbackv5-comment-short',
 547+ 'id' => "articleFeedbackv5-comment-short-$feedbackId"
 548+ ) )
 549+ . htmlspecialchars( $short )
 550+ . Html::closeElement( 'blockquote' );
 551+
 552+ // If the short string is the same size as the
 553+ // original, no truncation happened, so no
 554+ // controls are needed.
 555+ if( $short != $text ) {
 556+ // Show the short text, with the 'show more' control.
 557+ $rv .= Html::openElement( 'blockquote',
 558+ array(
 559+ 'class' => 'articleFeedbackv5-comment-full',
 560+ 'id' => "articleFeedbackv5-comment-full-$feedbackId"
 561+ ) )
542562 . htmlspecialchars( $text )
543 - . '</blockquote>';
544 - } else {
545 - $rv = "<blockquote>"
546 - . htmlspecialchars( $text )
547 - . '</blockquote>';
 563+ . Html::closeElement( 'blockquote' )
 564+ . Html::element( 'a', array(
 565+ 'class' => 'articleFeedbackv5-comment-toggle',
 566+ 'id' => "articleFeedbackv5-comment-toggle-$feedbackId"
 567+ ), wfMessage( 'articlefeedbackv5-comment-more' )->escaped() );
548568 }
 569+
549570 return $rv;
550571 }
551572
Index: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.hooks.php
@@ -177,7 +177,9 @@
178178 'articlefeedbackv5-unoversight-saved',
179179 'articlefeedbackv5-comment-link',
180180 'articlefeedbackv5-special-sort-asc',
181 - 'articlefeedbackv5-special-sort-desc'
 181+ 'articlefeedbackv5-special-sort-desc',
 182+ 'articlefeedbackv5-comment-more',
 183+ 'articlefeedbackv5-comment-less'
182184 ),
183185 'dependencies' => array(
184186 'mediawiki.util',

Follow-up revisions

RevisionCommit summaryAuthorDate
r110013AFT5 - well that as stupid. Put the en and qqq text in the right places. Fix ...gregchiasson18:46, 25 January 2012
r110399AFT5 fix double-escaping from r110301 and r110012gregchiasson16:21, 31 January 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r109967AFT5 feedback tool - move comment rendering into it's own function as prepera...gregchiasson23:26, 24 January 2012

Comments

#Comment by Catrope (talk | contribs)   07:24, 31 January 2012
+		$rv = Html::openElement( 'blockquote',
+		array(
+			'class' => 'articleFeedbackv5-comment-short',
+			'id'    => "articleFeedbackv5-comment-short-$feedbackId"
+		) )
+		. htmlspecialchars( $short )
+		. Html::closeElement( 'blockquote' );

You can use Html::element( 'blockquote', array( attributes ), $short ); here, that handles escaping for you.

+			), wfMessage( 'articlefeedbackv5-comment-more' )->escaped() );

Don't escape the argument to Html::element(), that'll escape it twice.

Status & tagging log