r105632 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105631‎ | r105632 | r105633 >
Date:00:46, 9 December 2011
Author:gregchiasson
Status:ok
Tags:
Comment:
Enable sorting/filtering on AFTv5 feedback page, use a proper prefix on variable names, kill a few errors, better JS error reporting (still not great).
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php (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
@@ -39,6 +39,7 @@
4040 -- Create an index on the article_feedback.af_timestamp field
4141 CREATE INDEX /*i*/article_feedback_timestamp ON /*_*/aft_article_feedback (af_created);
4242 CREATE INDEX /*i*/af_page_id ON /*_*/aft_article_feedback (af_page_id, af_created);
 43+CREATE INDEX /*i*/af_page_feedback_id ON /*_*/aft_article_feedback (af_page_id, af_id);
4344
4445 -- Allows for organizing fields into fieldsets, for reporting or rendering.
4546 -- A group is just a name and an ID.
Index: trunk/extensions/ArticleFeedbackv5/sql/alter.sql
@@ -36,3 +36,6 @@
3737 ALTER TABLE aft_article_revision_feedback_ratings_rollup CHANGE COLUMN afrr_rating_id afrr_field_id integer unsigned NOT NULL;
3838 ALTER TABLE aft_article_feedback_ratings_rollup CHANGE COLUMN arr_rating_id arr_field_id integer unsigned NOT NULL;
3939 ALTER TABLE aft_article_feedback_select_rollup ADD COLUMN afsr_field_id int NOT NULL;
 40+
 41+-- added 12/8 (later)
 42+CREATE INDEX /*i*/af_page_feedback_id ON /*_*/aft_article_feedback (af_page_id, af_id);
Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js
@@ -3,7 +3,7 @@
44
55 // TODO: Pass this in better from the PHP side.
66 $.articleFeedbackv5special.page = hackPageId;
7 - $.articleFeedbackv5special.filter = 'all';
 7+ $.articleFeedbackv5special.filter = 'visible';
88 $.articleFeedbackv5special.sort = 'newest';
99 $.articleFeedbackv5special.limit = 25;
1010 $.articleFeedbackv5special.offset = 0;
@@ -13,18 +13,18 @@
1414 $.articleFeedbackv5special.setBinds = function() {
1515 $( '#aft5-filter' ).bind( 'change', function(e) {
1616 $.articleFeedbackv5special.filter = $(this).val();
17 - $.articleFeedbackv5special.loadFeedback();
 17+ $.articleFeedbackv5special.loadFeedback( true );
1818 return false;
1919 } );
2020 $( '#aft5-sort' ).bind( 'change', function(e) {
2121 $.articleFeedbackv5special.sort = $(this).val();
22 - $.articleFeedbackv5special.loadFeedback();
 22+ $.articleFeedbackv5special.loadFeedback( true );
2323 return false;
2424 } );
2525 $( '#aft5-show-more' ).bind( 'click', function(e) {
2626 $.articleFeedbackv5special.offset +=
2727 $.articleFeedbackv5special.limit;
28 - $.articleFeedbackv5special.loadFeedback();
 28+ $.articleFeedbackv5special.loadFeedback( false);
2929 return false;
3030 } );
3131 $( '.aft5-abuse-link' ).live( 'click', function(e) {
@@ -78,37 +78,46 @@
7979 return false;
8080 }
8181
82 - $.articleFeedbackv5special.loadFeedback = function () {
 82+ // ie, on loading next page, don't reset the view, but on sort/filter
 83+ // remove what was there and start over.
 84+ $.articleFeedbackv5special.loadFeedback = function ( resetContents ) {
8385 $.ajax( {
8486 'url' : $.articleFeedbackv5special.apiUrl,
8587 'type' : 'GET',
8688 'dataType': 'json',
8789 'data' : {
88 - 'afpageid': $.articleFeedbackv5special.page,
89 - 'affilter': $.articleFeedbackv5special.filter,
90 - 'afsort' : $.articleFeedbackv5special.sort,
91 - 'aflimit' : $.articleFeedbackv5special.limit,
92 - 'afoffset': $.articleFeedbackv5special.offset,
 90+ 'afvfpageid': $.articleFeedbackv5special.page,
 91+ 'afvffilter': $.articleFeedbackv5special.filter,
 92+ 'afvfsort' : $.articleFeedbackv5special.sort,
 93+ 'afvflimit' : $.articleFeedbackv5special.limit,
 94+ 'afvfoffset': $.articleFeedbackv5special.offset,
9395 'action' : 'query',
9496 'format' : 'json',
9597 'list' : 'articlefeedbackv5-view-feedback',
9698 'maxage' : 0
9799 },
98100 'success': function ( data ) {
99 - if ( 'data' in data ) {
100 - $( '#aft5-show-feedback' ).append( data.data.feedback);
101 - $.articleFeedbackv5special.showing += data.data.length;
 101+ if ( 'articlefeedbackv5-view-feedback' in data ) {
 102+ if ( resetContents ) {
 103+ $( '#aft5-show-feedback' ).html( data['articlefeedbackv5-view-feedback'].feedback);
 104+ $.articleFeedbackv5special.showing = data['articlefeedbackv5-view-feedback'].length;
 105+ } else {
 106+ $( '#aft5-show-feedback' ).append( data['articlefeedbackv5-view-feedback'].feedback);
 107+ $.articleFeedbackv5special.showing += data['articlefeedbackv5-view-feedback'].length;
 108+ }
102109 $( '#aft5-feedback-count-shown' ).text( $.articleFeedbackv5special.showing );
103 - $( '#aft5-feedback-count-total' ).text( data.data.count );
104 - if ( $.articleFeedbackv5special.showing >= data.data.count ) {
 110+ $( '#aft5-feedback-count-total' ).text( data['articlefeedbackv5-view-feedback'].count );
 111+ if ( $.articleFeedbackv5special.showing >= data['articlefeedbackv5-view-feedback'].count ) {
105112 $( '#aft5-show-more' ).hide();
106113 }
107114
108115 } else {
109116 $( '#aft5-show-feedback' ).text( mw.msg( 'articlefeedbackv5-error-loading-feedback' ) );
110117 }
 118+ },
 119+ 'failure': function ( data ) {
 120+ $( '#aft5-show-feedback' ).text( mw.msg( 'articlefeedbackv5-error-loading-feedback' ) );
111121 }
112 - // TODO: have a callback for failures.
113122 } );
114123
115124 return false;
@@ -120,10 +129,7 @@
121130 // I think it maky have been a race condition.
122131 $.articleFeedbackv5special.apiUrl = mw.util.wikiScript('api');
123132
124 - // Blank out the 'loading' text
125 - $( '#aft5-show-feedback' ).text( ' ' );
126 -
127133 // Set up event binds and do initial data fetch.
128134 $.articleFeedbackv5special.setBinds();
129 - $.articleFeedbackv5special.loadFeedback();
 135+ $.articleFeedbackv5special.loadFeedback( true );
130136 } );
Index: trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php
@@ -19,7 +19,7 @@
2020 * Constructor
2121 */
2222 public function __construct( $query, $moduleName ) {
23 - parent::__construct( $query, $moduleName, 'af' );
 23+ parent::__construct( $query, $moduleName, 'afvf' );
2424 }
2525
2626 /**
@@ -46,9 +46,9 @@
4747 $length++;
4848 }
4949
50 - $result->addValue( 'data', 'length', $length );
51 - $result->addValue( 'data', 'count', $count );
52 - $result->addValue( 'data', 'feedback', $html );
 50+ $result->addValue( $this->getModuleName(), 'length', $length );
 51+ $result->addValue( $this->getModuleName(), 'count', $count );
 52+ $result->addValue( $this->getModuleName(), 'feedback', $html );
5353 }
5454
5555 public function fetchFeedbackCount( $pageId, $filter ) {
@@ -75,6 +75,9 @@
7676
7777 # Newest first is the only option right now.
7878 switch($order) {
 79+ case 'oldest':
 80+ $order = 'af_id ASC';
 81+ break;
7982 case 'newest':
8083 default:
8184 $order = 'af_id DESC';
@@ -100,6 +103,10 @@
101104 $ids[] = $id->af_id;
102105 }
103106
 107+ if( !count( $ids ) ) {
 108+ return array();
 109+ }
 110+
104111 $rows = $dbr->select(
105112 array( 'aft_article_feedback', 'aft_article_answer',
106113 'aft_article_field', 'aft_article_field_option',
@@ -149,11 +156,12 @@
150157 case 'all':
151158 $where = array();
152159 break;
 160+ case 'invisible':
 161+ $where = array( 'af_hide_count > 0' );
 162+ break;
153163 case 'visible':
 164+ default:
154165 $where = array( 'af_hide_count' => 0 );
155 - break;
156 - default:
157 - $where = array();
158166 break;
159167 }
160168 return $where;
@@ -267,13 +275,13 @@
268276 ApiBase::PARAM_REQUIRED => false,
269277 ApiBase::PARAM_ISMULTI => false,
270278 ApiBase::PARAM_TYPE => array(
271 - 'oldest', 'newest', 'etc' )
 279+ 'oldest', 'newest' )
272280 ),
273281 'filter' => array(
274282 ApiBase::PARAM_REQUIRED => false,
275283 ApiBase::PARAM_ISMULTI => false,
276284 ApiBase::PARAM_TYPE => array(
277 - 'all', 'hidden', 'visible' )
 285+ 'all', 'invisible', 'visible' )
278286 ),
279287 'limit' => array(
280288 ApiBase::PARAM_REQUIRED => false,

Status & tagging log