r104923 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104922‎ | r104923 | r104924 >
Date:23:54, 1 December 2011
Author:gregchiasson
Status:resolved (Comments)
Tags:
Comment:
AFTv5 feedback page shows correct numbers for showing and total counts, and the more button goes away when there's no more to show.
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/SpecialArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js
@@ -3,11 +3,12 @@
44
55 // TODO: Pass this in from the PHP side. Add it to mwConfig or w/e?
66 //$.articleFeedbackv5special.page = mw.config.get( 'wgPageId' );
7 - $.articleFeedbackv5special.page = hackPageId;
8 - $.articleFeedbackv5special.filter = 'all';
9 - $.articleFeedbackv5special.sort = 'newest';
10 - $.articleFeedbackv5special.limit = 5;
11 - $.articleFeedbackv5special.offset = 0;
 7+ $.articleFeedbackv5special.page = hackPageId;
 8+ $.articleFeedbackv5special.filter = 'all';
 9+ $.articleFeedbackv5special.sort = 'newest';
 10+ $.articleFeedbackv5special.limit = 5;
 11+ $.articleFeedbackv5special.offset = 0;
 12+ $.articleFeedbackv5special.showing = 0;
1213
1314 $.articleFeedbackv5special.apiUrl = mw.config.get( 'wgScriptPath' )
1415 + '/api.php';
@@ -24,7 +25,7 @@
2526 $.articleFeedbackv5special.loadFeedback();
2627 return false;
2728 } );
28 - $( '#aft5-more' ).bind( 'click', function(e) {
 29+ $( '#aft5-show-more' ).bind( 'click', function(e) {
2930 $.articleFeedbackv5special.offset +=
3031 $.articleFeedbackv5special.limit;
3132 $.articleFeedbackv5special.loadFeedback();
@@ -90,13 +91,25 @@
9192 'maxage' : 0,
9293 },
9394 'success': function ( data ) {
94 - // TODO check output and error if needed
95 - $( '#aft5-show-feedback' ).html(
96 -$( '#aft5-show-feedback' ).html() + data.query['articlefeedbackv5-view-feedback'].feedback
97 - );
 95+ if ( 'data' in data ) {
 96+ $( '#aft5-show-feedback' ).html(
 97+ $( '#aft5-show-feedback' ).html() + data.data.feedback
 98+ );
 99+
 100+ $.articleFeedbackv5special.showing += data.data.length;
 101+ $( '#aft5-feedback-count-shown' ).html( $.articleFeedbackv5special.showing );
 102+ $( '#aft5-feedback-count-total' ).html( data.data.count );
 103+ if ( $.articleFeedbackv5special.showing >= data.data.count ) {
 104+ $( '#aft5-show-more' ).hide();
 105+ }
 106+
 107+ } else {
 108+ // TODO: have error message
 109+ }
98110 }
99 - // TODO have a callback for failures.
 111+ // TODO: have a callback for failures.
100112 } );
 113+
101114 return false;
102115 }
103116 } )( jQuery );
Index: trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php
@@ -27,11 +27,12 @@
2828 */
2929 public function execute() {
3030 $params = $this->extractRequestParams();
31 - #error_log(print_r($params,1));
3231 $html = '';
3332 $result = $this->getResult();
34 - $path = array( 'query', $this->getModuleName() );
3533 $pageId = $params['pageid'];
 34+ $length = 0;
 35+ $count = $this->fetchFeedbackCount(
 36+ $params['pageid'], $params['filter'] );
3637 $feedback = $this->fetchFeedback(
3738 $params['pageid'],
3839 $params['filter'],
@@ -42,14 +43,12 @@
4344
4445 foreach ( $feedback as $record ) {
4546 $html .= $this->renderFeedback($record);
 47+ $length++;
4648 }
4749
48 - $result->addValue( $path, 'feedback', $html );
49 -
50 - $result->setIndexedTagName_internal(
51 - array( 'query', $this->getModuleName() ), 'aa'
52 - );
53 -
 50+ $result->addValue( 'data', 'length', $length );
 51+ $result->addValue( 'data', 'count', $count );
 52+ $result->addValue( 'data', 'feedback', $html );
5453 }
5554
5655 public function fetchOverallRating( $pageId ) {
@@ -79,14 +78,26 @@
8079 return $rv;
8180 }
8281
 82+ public function fetchFeedbackCount( $pageId, $filter ) {
 83+ $dbr = wfGetDB( DB_SLAVE );
 84+ $where = $this->getFilterCriteria( $filter );
8385
 86+ $where['af_page_id'] = $pageId;
 87+
 88+ return $dbr->selectField(
 89+ array( 'aft_article_feedback' ),
 90+ array( 'COUNT(*) AS count' ),
 91+ $where
 92+ );
 93+ }
 94+
8495 public function fetchFeedback( $pageId,
8596 $filter = 'visible', $order = 'newest', $limit = 5, $offset = 0 ) {
8697 $dbr = wfGetDB( DB_SLAVE );
8798 $ids = array();
8899 $rows = array();
89100 $rv = array();
90 - $where = array();
 101+ $where = $this->getFilterCriteria( $filter );
91102 $order;
92103
93104 switch($order) {
@@ -98,18 +109,6 @@
99110 break;
100111 }
101112
102 - switch($filter) {
103 - case 'all':
104 - $where = array();
105 - break;
106 - case 'visible':
107 - $where = array( 'af_hide_count' => 0 );
108 - break;
109 - default:
110 - $where = array();
111 - break;
112 - }
113 -
114113 $where['af_page_id'] = $pageId;
115114
116115 /* I'd really love to do this in one big query, but MySQL
@@ -144,7 +143,7 @@
145144 array( 'ORDER BY' => $order ),
146145 array(
147146 'aft_article_field' => array(
148 - 'JOIN', 'afi_id = aa_field_id'
 147+ 'LEFT JOIN', 'afi_id = aa_field_id'
149148 ),
150149 'aft_article_answer' => array(
151150 'LEFT JOIN', 'af_id = aa_feedback_id'
@@ -167,6 +166,22 @@
168167 return $rv;
169168 }
170169
 170+ private function getFilterCriteria( $filter ) {
 171+ $where = array();
 172+ switch($filter) {
 173+ case 'all':
 174+ $where = array();
 175+ break;
 176+ case 'visible':
 177+ $where = array( 'af_hide_count' => 0 );
 178+ break;
 179+ default:
 180+ $where = array();
 181+ break;
 182+ }
 183+ return $where;
 184+ }
 185+
171186 protected function renderFeedback( $record ) {
172187 $id = $record[0]->af_id;
173188 $rv = "<div class='aft5-feedback'><p>Feedback #$id"
@@ -178,7 +193,7 @@
179194 case 4: $rv .= $this->renderBucket4( $record ); break;
180195 case 5: $rv .= $this->renderBucket5( $record ); break;
181196 case 6: $rv .= $this->renderBucket6( $record ); break;
182 - default: return 'Invalid bucket id';
 197+ default: $rv .= $this->renderNoBucket( $record ); break;
183198 }
184199 $rv .= "<p>
185200 <a href='#' class='aft5-hide-link' id='aft5-hide-link-$id'>Hide this (".$record[0]->af_hide_count.")</a>
@@ -236,6 +251,10 @@
237252 return $this->renderBucket6( $record );
238253 }
239254
 255+ private function renderNoBucket( $record ) {
 256+ return 'Invalid form ID';
 257+ }
 258+
240259 private function renderBucket6( $record ) {
241260 return 'User was not shown a feedback form.';
242261 }
Index: trunk/extensions/ArticleFeedbackv5/SpecialArticleFeedbackv5.php
@@ -60,14 +60,13 @@
6161 -->
6262 <br>
6363 <span id="aft5-showing">
64 -Showing 0 posts (of 0)
 64+Showing <span id="aft5-feedback-count-shown">0</span> posts (of <span id="aft5-feedback-count-total">0</span>)
6565 </span>
6666 <br>
67 -<div style="border:1px solid red;" id="aft5-show-feedback">Loading...</div>
68 -<a href="#" id="aft5-more">More</a>
 67+<div style="border:1px solid red;" id="aft5-show-feedback"></div>
 68+<a href="#" id="aft5-show-more">More</a>
6969 EOH
7070 );
71 - # "more" link to load the next 50 and append it.
7271 }
7372
7473 protected static function formatNumber( $number ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r105029More internationalization on AFTv5 Feedback page.gregchiasson00:09, 3 December 2011

Comments

#Comment by Johnduhart (talk | contribs)   14:13, 2 December 2011

Spaces used for indents.

+	private function renderNoBucket( $record ) { 
+		return 'Invalid form ID';
+	}

Shouldn't that be localized?

#Comment by Gregchiasson (talk | contribs)   01:07, 9 December 2011

Fixed in r105029

#Comment by P858snake (talk | contribs)   06:10, 10 December 2011

Can someone un-fixme and manually add the follow up?

Status & tagging log