https://www.mediawiki.org/wiki/Special:Code/MediaWiki/109631
Revision: 109631
Author: gregchiasson
Date: 2012-01-20 18:38:23 +0000 (Fri, 20 Jan 2012)
Log Message:
-----------
AFT5 - sorting doesnt work right (feedbackpage) but the designers want the
latest HTML, so here it is.
Modified Paths:
--------------
trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.hooks.php
trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.i18n.php
trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php
trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js
Modified: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.hooks.php
===================================================================
--- trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.hooks.php
2012-01-20 18:31:54 UTC (rev 109630)
+++ trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.hooks.php
2012-01-20 18:38:23 UTC (rev 109631)
@@ -162,7 +162,9 @@
'articlefeedbackv5-delete-saved',
'articlefeedbackv5-helpful-saved',
'articlefeedbackv5-unhelpful-saved',
- 'articlefeedbackv5-comment-link'
+ 'articlefeedbackv5-comment-link',
+ 'articlefeedbackv5-special-sort-asc',
+ 'articlefeedbackv5-special-sort-desc'
),
),
);
Modified: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.i18n.php
===================================================================
--- trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.i18n.php
2012-01-20 18:31:54 UTC (rev 109630)
+++ trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.i18n.php
2012-01-20 18:38:23 UTC (rev 109631)
@@ -57,9 +57,11 @@
'articlefeedbackv5-special-filter-helpful' => 'Helpful ($1)',
'articlefeedbackv5-special-filter-visible' => 'Visible ($1)',
'articlefeedbackv5-special-filter-invisible' => 'Hidden ($1)',
- 'articlefeedbackv5-special-sort-newest' => 'Newest first',
- 'articlefeedbackv5-special-sort-oldest' => 'Oldest first',
- 'articlefeedbackv5-special-sort-helpful' => 'Most Helpful',
+ 'articlefeedbackv5-special-sort-asc' => '^',
+ 'articlefeedbackv5-special-sort-desc' => 'v',
+ 'articlefeedbackv5-special-sort-age' => 'Date',
+ 'articlefeedbackv5-special-sort-helpfulness' => 'Helpful',
+ 'articlefeedbackv5-special-sort-rating' => 'Rating',
'articlefeedbackv5-special-sort-label-before' => 'Sort by:',
'articlefeedbackv5-special-sort-label-after' => '',
'articlefeedbackv5-special-filter-label-before' => 'Show only:',
Modified:
trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php
===================================================================
--- trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php
2012-01-20 18:31:54 UTC (rev 109630)
+++ trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php
2012-01-20 18:38:23 UTC (rev 109631)
@@ -38,6 +38,7 @@
$params['filter'],
$params['filtervalue'],
$params['sort'],
+ $params['sortdirection'],
$params['limit'],
( $params['continue'] !== 'null' ? $params['continue']
: null )
);
@@ -75,28 +76,31 @@
}
public function fetchFeedback( $pageId,
- $filter = 'visible', $filterValue = null, $order = 'newest', $limit =
25, $continue = null ) {
+ $filter = 'visible', $filterValue = null, $sort = 'age', $sortOrder =
'desc', $limit = 25, $continue = null ) {
$dbr = wfGetDB( DB_SLAVE );
$ids = array();
$rows = array();
$rv = array();
$where = $this->getFilterCriteria( $filter, $filterValue );
+
+ $direction = strtolower( $sortOrder ) == 'asc' ? 'ASC'
: 'DESC';
+ $continueDirection = ( $direction == 'ASC' ? '>' : '<' );
$order;
+ $continue;
- # TODO: The SQL needs to handle all sorts of weird cases.
- switch( $order ) {
+ switch( $sort ) {
case 'helpful':
- $order = 'net_helpfulness DESC';
- $continueSql = 'net_helpfulness <';
+ $order = "net_helpfulness $direction";
+ $continueSql = "net_helpfulness
$continueDirection";
break;
- case 'oldest':
- $order = 'af_id ASC';
- $continueSql = 'af_id >';
+ case 'rating':
+ # For now, just fall through. Not specced out.
break;
- case 'newest':
+ case 'age':
+ # Default sort is by age.
default:
- $order = 'af_id DESC';
- $continueSql = 'af_id <';
+ $order = "af_id $direction";
+ $continueSql = "af_id $continueDirection";
break;
}
@@ -184,6 +188,27 @@
return $rv;
}
+ private function getContinue( $sort, $sortOrder ) {
+ $continue;
+ $direction = strtolower( $sortOrder ) == 'asc' ? '<' : '>';
+
+ switch( $sort ) {
+ case 'helpful':
+ $continue = 'net_helpfulness <';
+ break;
+ case 'rating':
+ # For now, just fall through. Not specced out.
+ break;
+ case 'age':
+ # Default sort is by age.
+ default:
+ $continue = 'af_id >';
+ break;
+ }
+
+ return $continue;
+ }
+
private function getFilterCriteria( $filter, $filterValue = null ) {
$where = array();
@@ -315,10 +340,14 @@
. Html::closeElement( 'div' );
return Html::openElement( 'div', array( 'class' =>
'articleFeedbackv5-feedback' ) )
+ . Html::openElement( 'div' => array(
+ 'class' => 'articleFeedbackv5-comment-wrap'
+ )
. $content
+ . $footer_links
+ . Html::closeElement( 'div' )
. $details
. $tools
- . $footer_links
. $rate
. Html::closeElement( 'div' );
}
@@ -409,34 +438,40 @@
*/
public function getAllowedParams() {
return array(
- 'pageid' => array(
+ 'pageid' => array(
ApiBase::PARAM_REQUIRED => true,
ApiBase::PARAM_ISMULTI => false,
ApiBase::PARAM_TYPE => 'integer'
),
- 'sort' => array(
+ 'sort' => array(
ApiBase::PARAM_REQUIRED => false,
ApiBase::PARAM_ISMULTI => false,
ApiBase::PARAM_TYPE => array(
- 'oldest', 'newest', 'helpful' )
+ 'age', 'helpfulness', 'rating' )
),
- 'filter' => array(
+ 'sortdirection' => array(
ApiBase::PARAM_REQUIRED => false,
ApiBase::PARAM_ISMULTI => false,
ApiBase::PARAM_TYPE => array(
+ 'desc', 'asc' )
+ ),
+ 'filter' => array(
+ ApiBase::PARAM_REQUIRED => false,
+ ApiBase::PARAM_ISMULTI => false,
+ ApiBase::PARAM_TYPE => array(
'all', 'invisible', 'visible', 'comment', 'id'
)
),
- 'filtervalue' => array(
+ 'filtervalue' => array(
ApiBase::PARAM_REQUIRED => false,
ApiBase::PARAM_ISMULTI => false,
ApiBase::PARAM_TYPE => 'string'
),
- 'limit' => array(
+ 'limit' => array(
ApiBase::PARAM_REQUIRED => false,
ApiBase::PARAM_ISMULTI => false,
ApiBase::PARAM_TYPE => 'integer'
),
- 'continue' => array(
+ 'continue' => array(
ApiBase::PARAM_REQUIRED => false,
ApiBase::PARAM_ISMULTI => false,
ApiBase::PARAM_TYPE => 'string'
Modified:
trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js
===================================================================
---
trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js
2012-01-20 18:31:54 UTC (rev 109630)
+++
trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js
2012-01-20 18:38:23 UTC (rev 109631)
@@ -50,9 +50,14 @@
/**
* The name of the sorting method used
*/
- $.articleFeedbackv5special.sort = 'newest';
+ $.articleFeedbackv5special.sort = 'age';
/**
+ * The dorection of the sorting method used
+ */
+ $.articleFeedbackv5special.sortDirection = 'desc';
+
+ /**
* The number of responses to display per data pull
*/
$.articleFeedbackv5special.limit = 25;
@@ -81,9 +86,24 @@
return false;
} );
$( '.articleFeedbackv5-sort-link' ).bind( 'click', function( e
) {
- $.articleFeedbackv5special.sort =
$.articleFeedbackv5special.stripID( this, 'articleFeedbackv5-special-sort-' );
- $.articleFeedbackv5special.continue = null;
+ id = $.articleFeedbackv5special.stripID( this,
'articleFeedbackv5-special-sort-' );
+ oldId = $.articleFeedbackv5special.sort;
+
+ // set direction = desc...
+ $.articleFeedbackv5special.sortDirection = 'desc';
+ $.articleFeedbackv5special.sort = id;
+ $.articleFeedbackv5special.continue = null;
$.articleFeedbackv5special.loadFeedback( true );
+
+ // unless we're flipping the direction on the current
sort.
+console.log('id is ' + id + ', old id is ' + oldId);
+ if( id == oldId
+ && $.articleFeedbackv5special.sortDirection == 'desc')
{
+ $.articleFeedbackv5special.sortDirection =
'asc';
+ }
+ // draw arrow
+ $.articleFeedbackv5special.drawSortArrow();
+
return false;
} );
$( '#articleFeedbackv5-show-more' ).bind( 'click', function( e
) {
@@ -113,6 +133,18 @@
} );
}
+ $.articleFeedbackv5special.drawSortArrow = function() {
+ id = $.articleFeedbackv5special.sort;
+ dir = $.articleFeedbackv5special.sortDirection;
+
+ $( '.articleFeedbackv5-sort-arrow' ).hide();
+
+ $( '#articleFeedbackv5-sort-arrow-' + id ).text(
+ mw.msg( 'articlefeedbackv5-special-sort-' + dir )
+ );
+ $( '#articleFeedbackv5-sort-arrow-' + id ).show();
+ }
+
// Utility method for stripping long IDs down to the specific bits we
care about.
$.articleFeedbackv5special.stripID = function( object, toRemove ) {
return $( object ).attr( 'id' ).replace( toRemove, '' );
@@ -188,12 +220,13 @@
'type' : 'GET',
'dataType': 'json',
'data' : {
- 'afvfpageid' :
$.articleFeedbackv5special.page,
- 'afvffilter' :
$.articleFeedbackv5special.filter,
- 'afvffiltervalue' :
$.articleFeedbackv5special.filterValue,
- 'afvfsort' :
$.articleFeedbackv5special.sort,
- 'afvflimit' :
$.articleFeedbackv5special.limit,
- 'afvfcontinue' :
$.articleFeedbackv5special.continue,
+ 'afvfpageid' :
$.articleFeedbackv5special.page,
+ 'afvffilter' :
$.articleFeedbackv5special.filter,
+ 'afvffiltervalue' :
$.articleFeedbackv5special.filterValue,
+ 'afvfsort' :
$.articleFeedbackv5special.sort,
+ 'afvfsortdirection' :
$.articleFeedbackv5special.sortDirection,
+ 'afvflimit' :
$.articleFeedbackv5special.limit,
+ 'afvfcontinue' :
$.articleFeedbackv5special.continue,
'action' : 'query',
'format' : 'json',
'list' : 'articlefeedbackv5-view-feedback',
@@ -253,6 +286,7 @@
// Initial load
$.articleFeedbackv5special.loadFeedback( true );
+ $.articleFeedbackv5special.drawSortArrow();
// }}}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs