Index: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.i18n.php |
— | — | @@ -57,9 +57,11 @@ |
58 | 58 | 'articlefeedbackv5-special-filter-helpful' => 'Helpful ($1)', |
59 | 59 | 'articlefeedbackv5-special-filter-visible' => 'Visible ($1)', |
60 | 60 | 'articlefeedbackv5-special-filter-invisible' => 'Hidden ($1)', |
61 | | - 'articlefeedbackv5-special-sort-newest' => 'Newest first', |
62 | | - 'articlefeedbackv5-special-sort-oldest' => 'Oldest first', |
63 | | - 'articlefeedbackv5-special-sort-helpful' => 'Most Helpful', |
| 61 | + 'articlefeedbackv5-special-sort-asc' => '^', |
| 62 | + 'articlefeedbackv5-special-sort-desc' => 'v', |
| 63 | + 'articlefeedbackv5-special-sort-age' => 'Date', |
| 64 | + 'articlefeedbackv5-special-sort-helpfulness' => 'Helpful', |
| 65 | + 'articlefeedbackv5-special-sort-rating' => 'Rating', |
64 | 66 | 'articlefeedbackv5-special-sort-label-before' => 'Sort by:', |
65 | 67 | 'articlefeedbackv5-special-sort-label-after' => '', |
66 | 68 | 'articlefeedbackv5-special-filter-label-before' => 'Show only:', |
Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js |
— | — | @@ -50,9 +50,14 @@ |
51 | 51 | /** |
52 | 52 | * The name of the sorting method used |
53 | 53 | */ |
54 | | - $.articleFeedbackv5special.sort = 'newest'; |
| 54 | + $.articleFeedbackv5special.sort = 'age'; |
55 | 55 | |
56 | 56 | /** |
| 57 | + * The dorection of the sorting method used |
| 58 | + */ |
| 59 | + $.articleFeedbackv5special.sortDirection = 'desc'; |
| 60 | + |
| 61 | + /** |
57 | 62 | * The number of responses to display per data pull |
58 | 63 | */ |
59 | 64 | $.articleFeedbackv5special.limit = 25; |
— | — | @@ -81,9 +86,24 @@ |
82 | 87 | return false; |
83 | 88 | } ); |
84 | 89 | $( '.articleFeedbackv5-sort-link' ).bind( 'click', function( e ) { |
85 | | - $.articleFeedbackv5special.sort = $.articleFeedbackv5special.stripID( this, 'articleFeedbackv5-special-sort-' ); |
86 | | - $.articleFeedbackv5special.continue = null; |
| 90 | + id = $.articleFeedbackv5special.stripID( this, 'articleFeedbackv5-special-sort-' ); |
| 91 | + oldId = $.articleFeedbackv5special.sort; |
| 92 | + |
| 93 | + // set direction = desc... |
| 94 | + $.articleFeedbackv5special.sortDirection = 'desc'; |
| 95 | + $.articleFeedbackv5special.sort = id; |
| 96 | + $.articleFeedbackv5special.continue = null; |
87 | 97 | $.articleFeedbackv5special.loadFeedback( true ); |
| 98 | + |
| 99 | + // unless we're flipping the direction on the current sort. |
| 100 | +console.log('id is ' + id + ', old id is ' + oldId); |
| 101 | + if( id == oldId |
| 102 | + && $.articleFeedbackv5special.sortDirection == 'desc') { |
| 103 | + $.articleFeedbackv5special.sortDirection = 'asc'; |
| 104 | + } |
| 105 | + // draw arrow |
| 106 | + $.articleFeedbackv5special.drawSortArrow(); |
| 107 | + |
88 | 108 | return false; |
89 | 109 | } ); |
90 | 110 | $( '#articleFeedbackv5-show-more' ).bind( 'click', function( e ) { |
— | — | @@ -113,6 +133,18 @@ |
114 | 134 | } ); |
115 | 135 | } |
116 | 136 | |
| 137 | + $.articleFeedbackv5special.drawSortArrow = function() { |
| 138 | + id = $.articleFeedbackv5special.sort; |
| 139 | + dir = $.articleFeedbackv5special.sortDirection; |
| 140 | + |
| 141 | + $( '.articleFeedbackv5-sort-arrow' ).hide(); |
| 142 | + |
| 143 | + $( '#articleFeedbackv5-sort-arrow-' + id ).text( |
| 144 | + mw.msg( 'articlefeedbackv5-special-sort-' + dir ) |
| 145 | + ); |
| 146 | + $( '#articleFeedbackv5-sort-arrow-' + id ).show(); |
| 147 | + } |
| 148 | + |
117 | 149 | // Utility method for stripping long IDs down to the specific bits we care about. |
118 | 150 | $.articleFeedbackv5special.stripID = function( object, toRemove ) { |
119 | 151 | return $( object ).attr( 'id' ).replace( toRemove, '' ); |
— | — | @@ -188,12 +220,13 @@ |
189 | 221 | 'type' : 'GET', |
190 | 222 | 'dataType': 'json', |
191 | 223 | 'data' : { |
192 | | - 'afvfpageid' : $.articleFeedbackv5special.page, |
193 | | - 'afvffilter' : $.articleFeedbackv5special.filter, |
194 | | - 'afvffiltervalue' : $.articleFeedbackv5special.filterValue, |
195 | | - 'afvfsort' : $.articleFeedbackv5special.sort, |
196 | | - 'afvflimit' : $.articleFeedbackv5special.limit, |
197 | | - 'afvfcontinue' : $.articleFeedbackv5special.continue, |
| 224 | + 'afvfpageid' : $.articleFeedbackv5special.page, |
| 225 | + 'afvffilter' : $.articleFeedbackv5special.filter, |
| 226 | + 'afvffiltervalue' : $.articleFeedbackv5special.filterValue, |
| 227 | + 'afvfsort' : $.articleFeedbackv5special.sort, |
| 228 | + 'afvfsortdirection' : $.articleFeedbackv5special.sortDirection, |
| 229 | + 'afvflimit' : $.articleFeedbackv5special.limit, |
| 230 | + 'afvfcontinue' : $.articleFeedbackv5special.continue, |
198 | 231 | 'action' : 'query', |
199 | 232 | 'format' : 'json', |
200 | 233 | 'list' : 'articlefeedbackv5-view-feedback', |
— | — | @@ -253,6 +286,7 @@ |
254 | 287 | |
255 | 288 | // Initial load |
256 | 289 | $.articleFeedbackv5special.loadFeedback( true ); |
| 290 | + $.articleFeedbackv5special.drawSortArrow(); |
257 | 291 | |
258 | 292 | // }}} |
259 | 293 | |
Index: trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php |
— | — | @@ -38,6 +38,7 @@ |
39 | 39 | $params['filter'], |
40 | 40 | $params['filtervalue'], |
41 | 41 | $params['sort'], |
| 42 | + $params['sortdirection'], |
42 | 43 | $params['limit'], |
43 | 44 | ( $params['continue'] !== 'null' ? $params['continue'] : null ) |
44 | 45 | ); |
— | — | @@ -75,28 +76,31 @@ |
76 | 77 | } |
77 | 78 | |
78 | 79 | public function fetchFeedback( $pageId, |
79 | | - $filter = 'visible', $filterValue = null, $order = 'newest', $limit = 25, $continue = null ) { |
| 80 | + $filter = 'visible', $filterValue = null, $sort = 'age', $sortOrder = 'desc', $limit = 25, $continue = null ) { |
80 | 81 | $dbr = wfGetDB( DB_SLAVE ); |
81 | 82 | $ids = array(); |
82 | 83 | $rows = array(); |
83 | 84 | $rv = array(); |
84 | 85 | $where = $this->getFilterCriteria( $filter, $filterValue ); |
| 86 | + |
| 87 | + $direction = strtolower( $sortOrder ) == 'asc' ? 'ASC' : 'DESC'; |
| 88 | + $continueDirection = ( $direction == 'ASC' ? '>' : '<' ); |
85 | 89 | $order; |
| 90 | + $continue; |
86 | 91 | |
87 | | - # TODO: The SQL needs to handle all sorts of weird cases. |
88 | | - switch( $order ) { |
| 92 | + switch( $sort ) { |
89 | 93 | case 'helpful': |
90 | | - $order = 'net_helpfulness DESC'; |
91 | | - $continueSql = 'net_helpfulness <'; |
| 94 | + $order = "net_helpfulness $direction"; |
| 95 | + $continueSql = "net_helpfulness $continueDirection"; |
92 | 96 | break; |
93 | | - case 'oldest': |
94 | | - $order = 'af_id ASC'; |
95 | | - $continueSql = 'af_id >'; |
| 97 | + case 'rating': |
| 98 | + # For now, just fall through. Not specced out. |
96 | 99 | break; |
97 | | - case 'newest': |
| 100 | + case 'age': |
| 101 | + # Default sort is by age. |
98 | 102 | default: |
99 | | - $order = 'af_id DESC'; |
100 | | - $continueSql = 'af_id <'; |
| 103 | + $order = "af_id $direction"; |
| 104 | + $continueSql = "af_id $continueDirection"; |
101 | 105 | break; |
102 | 106 | } |
103 | 107 | |
— | — | @@ -184,6 +188,27 @@ |
185 | 189 | return $rv; |
186 | 190 | } |
187 | 191 | |
| 192 | + private function getContinue( $sort, $sortOrder ) { |
| 193 | + $continue; |
| 194 | + $direction = strtolower( $sortOrder ) == 'asc' ? '<' : '>'; |
| 195 | + |
| 196 | + switch( $sort ) { |
| 197 | + case 'helpful': |
| 198 | + $continue = 'net_helpfulness <'; |
| 199 | + break; |
| 200 | + case 'rating': |
| 201 | + # For now, just fall through. Not specced out. |
| 202 | + break; |
| 203 | + case 'age': |
| 204 | + # Default sort is by age. |
| 205 | + default: |
| 206 | + $continue = 'af_id >'; |
| 207 | + break; |
| 208 | + } |
| 209 | + |
| 210 | + return $continue; |
| 211 | + } |
| 212 | + |
188 | 213 | private function getFilterCriteria( $filter, $filterValue = null ) { |
189 | 214 | $where = array(); |
190 | 215 | |
— | — | @@ -315,10 +340,14 @@ |
316 | 341 | . Html::closeElement( 'div' ); |
317 | 342 | |
318 | 343 | return Html::openElement( 'div', array( 'class' => 'articleFeedbackv5-feedback' ) ) |
| 344 | + . Html::openElement( 'div' => array( |
| 345 | + 'class' => 'articleFeedbackv5-comment-wrap' |
| 346 | + ) |
319 | 347 | . $content |
| 348 | + . $footer_links |
| 349 | + . Html::closeElement( 'div' ) |
320 | 350 | . $details |
321 | 351 | . $tools |
322 | | - . $footer_links |
323 | 352 | . $rate |
324 | 353 | . Html::closeElement( 'div' ); |
325 | 354 | } |
— | — | @@ -409,34 +438,40 @@ |
410 | 439 | */ |
411 | 440 | public function getAllowedParams() { |
412 | 441 | return array( |
413 | | - 'pageid' => array( |
| 442 | + 'pageid' => array( |
414 | 443 | ApiBase::PARAM_REQUIRED => true, |
415 | 444 | ApiBase::PARAM_ISMULTI => false, |
416 | 445 | ApiBase::PARAM_TYPE => 'integer' |
417 | 446 | ), |
418 | | - 'sort' => array( |
| 447 | + 'sort' => array( |
419 | 448 | ApiBase::PARAM_REQUIRED => false, |
420 | 449 | ApiBase::PARAM_ISMULTI => false, |
421 | 450 | ApiBase::PARAM_TYPE => array( |
422 | | - 'oldest', 'newest', 'helpful' ) |
| 451 | + 'age', 'helpfulness', 'rating' ) |
423 | 452 | ), |
424 | | - 'filter' => array( |
| 453 | + 'sortdirection' => array( |
425 | 454 | ApiBase::PARAM_REQUIRED => false, |
426 | 455 | ApiBase::PARAM_ISMULTI => false, |
427 | 456 | ApiBase::PARAM_TYPE => array( |
| 457 | + 'desc', 'asc' ) |
| 458 | + ), |
| 459 | + 'filter' => array( |
| 460 | + ApiBase::PARAM_REQUIRED => false, |
| 461 | + ApiBase::PARAM_ISMULTI => false, |
| 462 | + ApiBase::PARAM_TYPE => array( |
428 | 463 | 'all', 'invisible', 'visible', 'comment', 'id' ) |
429 | 464 | ), |
430 | | - 'filtervalue' => array( |
| 465 | + 'filtervalue' => array( |
431 | 466 | ApiBase::PARAM_REQUIRED => false, |
432 | 467 | ApiBase::PARAM_ISMULTI => false, |
433 | 468 | ApiBase::PARAM_TYPE => 'string' |
434 | 469 | ), |
435 | | - 'limit' => array( |
| 470 | + 'limit' => array( |
436 | 471 | ApiBase::PARAM_REQUIRED => false, |
437 | 472 | ApiBase::PARAM_ISMULTI => false, |
438 | 473 | ApiBase::PARAM_TYPE => 'integer' |
439 | 474 | ), |
440 | | - 'continue' => array( |
| 475 | + 'continue' => array( |
441 | 476 | ApiBase::PARAM_REQUIRED => false, |
442 | 477 | ApiBase::PARAM_ISMULTI => false, |
443 | 478 | ApiBase::PARAM_TYPE => 'string' |
Index: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.hooks.php |
— | — | @@ -162,7 +162,9 @@ |
163 | 163 | 'articlefeedbackv5-delete-saved', |
164 | 164 | 'articlefeedbackv5-helpful-saved', |
165 | 165 | 'articlefeedbackv5-unhelpful-saved', |
166 | | - 'articlefeedbackv5-comment-link' |
| 166 | + 'articlefeedbackv5-comment-link', |
| 167 | + 'articlefeedbackv5-special-sort-asc', |
| 168 | + 'articlefeedbackv5-special-sort-desc' |
167 | 169 | ), |
168 | 170 | ), |
169 | 171 | ); |