r108881 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108880‎ | r108881 | r108882 >
Date:23:52, 13 January 2012
Author:gregchiasson
Status:resolved (Comments)
Tags:aft 
Comment:
AFTv5 Special page work - get rid of the COUNT and OFFSET queries via an additional rollup table (which works) and a continue parameter (which has some, uhh, issues). Tweaks to HTML and JS, to make class/ID names consistent, and make sure the CSS file works.
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.i18n.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/SpecialArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.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)
  • /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
@@ -140,6 +140,17 @@
141141 PRIMARY KEY (arfsr_page_id, arfsr_field_id, arfsr_revision_id, arfsr_option_id)
142142 ) /*$wgDBTableOptions*/;
143143
 144+-- Exists to provide counts on filters for the feedback page, and toggle the "more" button"
 145+CREATE TABLE IF NOT EXISTS /*_*/aft_article_filter_count (
 146+ -- Keys to page.page_id
 147+ afc_page_id integer unsigned NOT NULL,
 148+ -- The name of the filter (must be matched by the fitler select on feedback page)
 149+ afc_filter_name varchar(64) NOT NULL,
 150+ -- Number of aft_article_feedback records that match this filter.
 151+ afc_filter_count integer unsigned NOT NULL,
 152+ PRIMARY KEY (afc_page_id, afc_filter_name)
 153+);
 154+
144155 -- Directly taken from AFTv4
145156 CREATE TABLE IF NOT EXISTS /*_*/aft_article_feedback_properties (
146157 -- Keys to article_feedback.aa_id
Index: trunk/extensions/ArticleFeedbackv5/sql/alter.sql
@@ -48,3 +48,11 @@
4949
5050 -- added 12/16 (Roan)
5151 ALTER TABLE aft_article_feedback MODIFY COLUMN af_user_ip varchar(32) NULL;
 52+
 53+-- added 1/13 (greg)
 54+CREATE TABLE IF NOT EXISTS /*_*/aft_article_filter_count (
 55+ afc_page_id integer unsigned NOT NULL,
 56+ afc_filter_name varchar(64) NOT NULL,
 57+ afc_filter_count integer unsigned NOT NULL,
 58+ PRIMARY KEY (afc_page_id, afc_filter_name)
 59+);
Index: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.i18n.php
@@ -42,12 +42,14 @@
4343 'articlefeedbackv5-error-flagging' => 'Error flagging feedback.',
4444
4545 // Article Feedback special page.
 46+ 'articlefeedbackv5-error-loading-feedback' => 'Error loading article feedback.',
4647 'articlefeedbackv5-form-tools-label' => 'Tools',
4748 'articlefeedbackv5-form-helpful-label' => 'Is this feedback helpful?',
4849 'articlefeedbackv5-special-add-feedback' => 'Add your feedback',
49 - 'articlefeedbackv5-special-filter-visible' => 'Visible',
50 - 'articlefeedbackv5-special-filter-invisible' => 'Invisible',
51 - 'articlefeedbackv5-special-filter-all' => 'All',
 50+ 'articlefeedbackv5-special-filter-comment' => 'Comments only ($1)',
 51+ 'articlefeedbackv5-special-filter-visible' => 'Visible ($1)',
 52+ 'articlefeedbackv5-special-filter-invisible' => 'Invisible ($1)',
 53+ 'articlefeedbackv5-special-filter-all' => 'All ($1)',
5254 'articlefeedbackv5-special-sort-newest' => 'Newest first',
5355 'articlefeedbackv5-special-sort-oldest' => 'Oldest first',
5456 'articlefeedbackv5-special-sort-label-before' => 'Order by:',
Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.css
@@ -1,2 +1,2 @@
22 /* css here */
3 -div.aft5-feedback { border:1px solid red; }
 3+div.articleFeedbackv5-feedback { border:1px solid #CCC; background:#EEE; margin-top:10px; }
Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js
@@ -50,12 +50,12 @@
5151 /**
5252 * The number of responses to display per data pull
5353 */
54 - $.articleFeedbackv5special.limit = 25;
 54+ $.articleFeedbackv5special.limit = 5;
5555
5656 /**
5757 * The index at which to start the pull
5858 */
59 - $.articleFeedbackv5special.offset = 0;
 59+ $.articleFeedbackv5special.continue = null;
6060
6161 /**
6262 * The url to which to send the request
@@ -69,27 +69,26 @@
7070 * Binds events for each of the controls
7171 */
7272 $.articleFeedbackv5special.setBinds = function() {
73 - $( '#aft5-filter' ).bind( 'change', function( e ) {
 73+ $( '#articleFeedbackv5-filter' ).bind( 'change', function( e ) {
7474 $.articleFeedbackv5special.filter = $(this).val();
7575 $.articleFeedbackv5special.loadFeedback( true );
7676 return false;
7777 } );
78 - $( '.aft5-sort-link' ).bind( 'click', function( e ) {
79 - $.articleFeedbackv5special.sort = $.articleFeedbackv5special.stripID( this, 'articlefeedbackv5-special-sort-' );
 78+ $( '.articleFeedbackv5-sort-link' ).bind( 'click', function( e ) {
 79+ $.articleFeedbackv5special.sort = $.articleFeedbackv5special.stripID( this, 'articleFeedbackv5-special-sort-' );
8080 $.articleFeedbackv5special.loadFeedback( true );
8181 return false;
8282 } );
83 - $( '#aft5-show-more' ).bind( 'click', function( e ) {
84 - $.articleFeedbackv5special.offset += $.articleFeedbackv5special.limit;
 83+ $( '#articleFeedbackv5-show-more' ).bind( 'click', function( e ) {
8584 $.articleFeedbackv5special.loadFeedback( false );
8685 return false;
8786 } );
88 - $( '.aft5-abuse-link' ).live( 'click', function( e ) {
89 - $.articleFeedbackv5special.abuseFeedback( $.articleFeedbackv5special.stripID( this, 'aft5-abuse-link-' ) );
 87+ $( '.articleFeedbackv5-abuse-link' ).live( 'click', function( e ) {
 88+ $.articleFeedbackv5special.abuseFeedback( $.articleFeedbackv5special.stripID( this, 'articleFeedbackv5-abuse-link-' ) );
9089 return false;
9190 } );
92 - $( '.aft5-hide-link' ).live( 'click', function( e ) {
93 - $.articleFeedbackv5special.hideFeedback( $.articleFeedbackv5special.stripID( this, 'aft5-hide-link-' ) );
 91+ $( '.articleFeedbackv5-hide-link' ).live( 'click', function( e ) {
 92+ $.articleFeedbackv5special.hideFeedback( $.articleFeedbackv5special.stripID( this, 'articleFeedbackv5-hide-link-' ) );
9493 return false;
9594 } );
9695 }
@@ -156,10 +155,10 @@
157156 }
158157 }
159158 }
160 - $( '#aft5-' + type + '-link-' + id ).text( mw.msg( msg ) );
 159+ $( '#articleFeedbackv5-' + type + '-link-' + id ).text( mw.msg( msg ) );
161160 },
162161 'error': function ( data ) {
163 - $( '#aft5-' + type + '-link-' + id ).text( mw.msg( 'articlefeedbackv5-error-flagging' ) );
 162+ $( '#articleFeedbackv5-' + type + '-link-' + id ).text( mw.msg( 'articlefeedbackv5-error-flagging' ) );
164163 }
165164 } );
166165 return false;
@@ -187,11 +186,11 @@
188187 'type' : 'GET',
189188 'dataType': 'json',
190189 'data' : {
191 - 'afvfpageid': $.articleFeedbackv5special.page,
192 - 'afvffilter': $.articleFeedbackv5special.filter,
193 - 'afvfsort' : $.articleFeedbackv5special.sort,
194 - 'afvflimit' : $.articleFeedbackv5special.limit,
195 - 'afvfoffset': $.articleFeedbackv5special.offset,
 190+ 'afvfpageid' : $.articleFeedbackv5special.page,
 191+ 'afvffilter' : $.articleFeedbackv5special.filter,
 192+ 'afvfsort' : $.articleFeedbackv5special.sort,
 193+ 'afvflimit' : $.articleFeedbackv5special.limit,
 194+ 'afvfcontinue': $.articleFeedbackv5special.continue,
196195 'action' : 'query',
197196 'format' : 'json',
198197 'list' : 'articlefeedbackv5-view-feedback',
@@ -200,17 +199,18 @@
201200 'success': function ( data ) {
202201 if ( 'articlefeedbackv5-view-feedback' in data ) {
203202 if ( resetContents ) {
204 - $( '#aft5-show-feedback' ).html( data['articlefeedbackv5-view-feedback'].feedback);
 203+ $( '#articleFeedbackv5-show-feedback' ).html( data['articlefeedbackv5-view-feedback'].feedback);
205204 } else {
206 - $( '#aft5-show-feedback' ).append( data['articlefeedbackv5-view-feedback'].feedback);
 205+ $( '#articleFeedbackv5-show-feedback' ).append( data['articlefeedbackv5-view-feedback'].feedback);
207206 }
208 - $( '#aft5-feedback-count-total' ).text( data['articlefeedbackv5-view-feedback'].count );
 207+ $( '#articleFeedbackv5-feedback-count-total' ).text( data['articlefeedbackv5-view-feedback'].count );
 208+ $.articleFeedbackv5special.continue = data['articlefeedbackv5-view-feedback'].continue;
209209 } else {
210 - $( '#aft5-show-feedback' ).text( mw.msg( 'articlefeedbackv5-error-loading-feedback' ) );
 210+ $( '#articleFeedbackv5-show-feedback' ).text( mw.msg( 'articlefeedbackv5-error-loading-feedback' ) );
211211 }
212212 },
213213 'error': function ( data ) {
214 - $( '#aft5-show-feedback' ).text( mw.msg( 'articlefeedbackv5-error-loading-feedback' ) );
 214+ $( '#articleFeedbackv5-show-feedback' ).text( mw.msg( 'articlefeedbackv5-error-loading-feedback' ) );
215215 }
216216 } );
217217
Index: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php
@@ -257,11 +257,11 @@
258258 $wgHooks['ArticleSaveComplete'][] = 'ArticleFeedbackv5Hooks::trackEditSuccess';
259259
260260 // API Registration
261 -// $wgAPIListModules['articlefeedbackv5-view-ratings'] = 'ApiViewRatingsArticleFeedbackv5';
262 -// $wgAPIListModules['articlefeedbackv5-view-feedback'] = 'ApiViewFeedbackArticleFeedbackv5';
263 -// $wgAPIModules['articlefeedbackv5-flag-feedback'] = 'ApiFlagFeedbackArticleFeedbackv5';
 261+$wgAPIListModules['articlefeedbackv5-view-ratings'] = 'ApiViewRatingsArticleFeedbackv5';
 262+$wgAPIListModules['articlefeedbackv5-view-feedback'] = 'ApiViewFeedbackArticleFeedbackv5';
 263+$wgAPIModules['articlefeedbackv5-flag-feedback'] = 'ApiFlagFeedbackArticleFeedbackv5';
264264 $wgAPIModules['articlefeedbackv5'] = 'ApiArticleFeedbackv5';
265265
266266 // Special Page
267 -// $wgSpecialPages['ArticleFeedbackv5'] = 'SpecialArticleFeedbackv5';
268 -// $wgSpecialPageGroups['ArticleFeedbackv5'] = 'other';
 267+$wgSpecialPages['ArticleFeedbackv5'] = 'SpecialArticleFeedbackv5';
 268+$wgSpecialPageGroups['ArticleFeedbackv5'] = 'other';
Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php
@@ -46,9 +46,9 @@
4747 $bucket = $params['bucket'];
4848 $revisionId = $params['revid'];
4949 $error = null;
50 - $user_answers = array();
 50+ $userAnswers = array();
5151 $fields = ApiArticleFeedbackv5Utils::getFields();
52 - $email_data = array(
 52+ $emailData = array(
5353 'ratingData' => array(),
5454 'pageID' => $pageId,
5555 'bucketId' => $bucket
@@ -78,8 +78,8 @@
7979 foreach ( array( 'rating', 'text', 'boolean', 'option_id' ) as $t ) {
8080 $data["aa_response_$t"] = $t == $type ? $value : null;
8181 }
82 - $user_answers[] = $data;
83 - $email_data['ratingData'][$field_name] = $value;
 82+ $userAnswers[] = $data;
 83+ $emailData['ratingData'][$field_name] = $value;
8484 }
8585 }
8686 if ( $error ) {
@@ -88,16 +88,17 @@
8989 }
9090
9191 // Save the response data
92 - $ratingIds = $this->saveUserRatings( $user_answers, $bucket, $params );
 92+ $ratingIds = $this->saveUserRatings( $userAnswers, $bucket, $params );
9393 $ctaId = $ratingIds['cta_id'];
9494 $feedbackId = $ratingIds['feedback_id'];
9595 $this->saveUserProperties( $feedbackId );
96 - $this->updateRollupTables( $pageId, $revisionId, $user_answers );
 96+ $this->updateRollupTables( $pageId, $revisionId, $userAnswers );
 97+ $this->updateFilterCounts( $pageId, $userAnswers );
9798
9899 // If we have an email address, capture it
99100 if ( $params['email'] ) {
100101 $this->captureEmail ( $params['email'], FormatJson::encode(
101 - $email_data
 102+ $emailData
102103 ) );
103104 }
104105
@@ -254,7 +255,66 @@
255256 return false;
256257 }
257258
 259+ public function updateFilterCounts( $pageId, $answers ) {
 260+ $has_comment = false;
 261+
 262+ # Does this record have a comment attached?
 263+ # Defined as an answer of type 'text'.
 264+ foreach( $answers as $a ) {
 265+ if( $a['aa_response_text'] !== null ) {
 266+ $has_comment = true;
 267+ }
 268+ }
 269+
 270+ # Update the overall number of records for this page.
 271+ $this->updateFilterCount( $pageId, 'all' );
 272+ # If the feedbackrecord had a comment, update that fitler count.
 273+ if( $has_comment ) {
 274+ $this->updateFilterCount( $pageId, 'comment' );
 275+ }
 276+ }
 277+
258278 /**
 279+ * Update the feedback count rollup table
 280+ *
 281+ * @param $pageId int the page id
 282+ * @param $filterName string the name of the filter to update
 283+ */
 284+ private function updateFilterCount( $pageId, $filterName ) {
 285+ $dbw = wfGetDB( DB_MASTER );
 286+
 287+ $dbw->begin();
 288+
 289+ # Try to insert the record, but ignore failures.
 290+ # Ensures the count row exists.
 291+ $dbw->insert(
 292+ 'aft_article_filter_counts',
 293+ array(
 294+ 'afc_page_id' => $pageId,
 295+ 'afc_filter_name' => $filterName,
 296+ 'afc_filter_count' => 0
 297+ ),
 298+ __METHOD__,
 299+ array( 'IGNORE' )
 300+ );
 301+
 302+ # Update the count row, incrementing the count.
 303+ $dbw->update(
 304+ 'aft_article_filter_counts',
 305+ array(
 306+ 'afc_filter_count = afc_filter_count + 1'
 307+ ),
 308+ array(
 309+ 'afc_page_id' => $pageId,
 310+ 'afc_filter_name' => $filterName
 311+ ),
 312+ __METHOD__
 313+ );
 314+
 315+ $dbw->commit();
 316+ }
 317+
 318+ /**
259319 * Update the rollup tables
260320 *
261321 * @param $page int the page id
Index: trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php
@@ -27,48 +27,52 @@
2828 */
2929 public function execute() {
3030 $params = $this->extractRequestParams();
31 - $html = '';
3231 $result = $this->getResult();
3332 $pageId = $params['pageid'];
 33+ $html = '';
3434 $length = 0;
35 - $count = $this->fetchFeedbackCount(
36 - $params['pageid'], $params['filter'] );
 35+ $count = $this->fetchFeedbackCount( $params['pageid'], $params['filter'] );
3736 $feedback = $this->fetchFeedback(
3837 $params['pageid'],
3938 $params['filter'],
4039 $params['sort'],
4140 $params['limit'],
42 - $params['offset']
 41+ ( $params['continue'] !== 'null' ? $params['continue'] : null )
4342 );
4443
4544 foreach ( $feedback as $record ) {
4645 $html .= $this->renderFeedback( $record );
4746 $length++;
4847 }
 48+ $tmp = end($feedback);
 49+ if( $tmp ) {
 50+ $continue = $tmp[0]->af_id;
 51+ }
4952
5053 $result->addValue( $this->getModuleName(), 'length', $length );
5154 $result->addValue( $this->getModuleName(), 'count', $count );
5255 $result->addValue( $this->getModuleName(), 'feedback', $html );
 56+ if ( $continue ) {
 57+ $result->addValue( $this->getModuleName(), 'continue', $continue );
 58+ }
5359 }
5460
5561 public function fetchFeedbackCount( $pageId, $filter ) {
56 - $dbr = wfGetDB( DB_SLAVE );
57 - $where = $this->getFilterCriteria( $filter );
 62+ $dbr = wfGetDB( DB_SLAVE );
5863
59 - $where['af_page_id'] = $pageId;
60 -
61 - # Until this is done properly, just don't do anything.
62 - return 0;
63 -
64 -# return $dbr->selectField(
65 -# array( 'aft_article_feedback' ),
66 -# array( 'COUNT(*) AS count' ),
67 -# $where
68 -# );
 64+ return $dbr->selectField(
 65+ array( 'aft_article_filter_count' ),
 66+ array( 'afc_filter_count' ),
 67+ array(
 68+ 'afc_page_id' => $pageId,
 69+ 'afc_filter_name' => $filter
 70+ ),
 71+ __METHOD__
 72+ );
6973 }
7074
7175 public function fetchFeedback( $pageId,
72 - $filter = 'visible', $order = 'newest', $limit = 25, $offset = 0 ) {
 76+ $filter = 'visible', $order = 'newest', $limit = 25, $continue = null ) {
7377 $dbr = wfGetDB( DB_SLAVE );
7478 $ids = array();
7579 $rows = array();
@@ -77,18 +81,25 @@
7882 $order;
7983
8084 # Newest first is the only option right now.
 85+ # TODO: The SQL needs to handle all sorts of weird cases.
8186 switch( $order ) {
8287 case 'oldest':
83 - $order = 'af_id ASC';
 88+ $order = 'af_id ASC';
 89+ $continueSql = 'af_id > ';
8490 break;
8591 case 'newest':
8692 default:
87 - $order = 'af_id DESC';
 93+ $order = 'af_id DESC';
 94+ $continueSql = 'af_id < ';
8895 break;
8996 }
9097
9198 $where['af_page_id'] = $pageId;
9299
 100+ if( $continue !== null ) {
 101+ $where[] = "$continueSql $continue";
 102+ }
 103+
93104 /* I'd really love to do this in one big query, but MySQL
94105 doesn't support LIMIT inside IN() subselects, and since
95106 we don't know the number of answers for each feedback
@@ -98,7 +109,6 @@
99110 'aft_article_feedback', 'af_id', $where, __METHOD__,
100111 array(
101112 'LIMIT' => $limit,
102 - 'OFFSET' => $offset,
103113 'ORDER BY' => $order
104114 )
105115 );
@@ -187,28 +197,32 @@
188198 $id = $record[0]->af_id;
189199
190200 # TODO: permalinks
191 - return Html::openElement( 'div', array( 'id' => 'aft5-feedback' ) )
 201+ return Html::openElement( 'div', array( 'class' => 'articleFeedbackv5-feedback' ) )
192202 . Html::openElement( 'p' )
193 - . Html::element( 'a', array( 'class' => 'aft5-comment-name', 'href' => 'profilepage or whatever' ), $id )
194 - . Html::element( 'span', array( 'class' => 'aft5-comment-timestamp' ), $record[0]->af_created )
 203+ . Html::element( 'a', array( 'class' => 'articleFeedbackv5-comment-name', 'href' => 'profilepage or whatever' ), $id )
 204+ . Html::element( 'span', array( 'class' => 'articleFeedbackv5-comment-timestamp' ), $record[0]->af_created )
195205 . Html::closeElement( 'p' )
196206 . wfMessage( 'articlefeedbackv5-form-optionid', $record[0]->af_bucket_id )->escaped()
197207 . $content
 208+
 209+ . Html::openElement( 'div', array( 'class' => 'articleFeedbackv5-feedback-rate' ) )
198210 . wfMessage( 'articlefeedbackv5-form-helpful-label' )->escaped()
199 - . Html::openElement( 'div', array( 'id' => 'aft5-feedback-tools' ) )
 211+ . Html::closeElement( 'div' )
 212+
 213+ . Html::openElement( 'div', array( 'class' => 'articleFeedbackv5-feedback-tools' ) )
200214 . Html::element( 'h3', array(), wfMessage( 'articlefeedbackv5-form-tools-label' )->text() )
201215 . Html::openElement( 'ul' )
202216 . ( $can_flag ? Html::rawElement( 'li', array(), Html::element( 'a', array(
203 - 'id' => "aft5-hide-link-$id",
204 - 'class' => 'aft5-hide-link'
 217+ 'id' => "articleFeedbackv5-hide-link-$id",
 218+ 'class' => 'articleFeedbackv5-hide-link'
205219 ), wfMessage( 'articlefeedbackv5-form-hide', $record[0]->af_hide_count )->text() ) ) : '' )
206220 . ( $can_hide ? Html::rawElement( 'li', array(), Html::element( 'a', array(
207 - 'id' => "aft5-abuse-link-$id",
208 - 'class' => 'aft5-abuse-link'
 221+ 'id' => "articleFeedbackv5-abuse-link-$id",
 222+ 'class' => 'articleFeedbackv5-abuse-link'
209223 ), wfMessage( 'articlefeedbackv5-form-abuse', $record[0]->af_abuse_count )->text() ) ) : '' )
210224 . ( $can_delete ? Html::rawElement( 'li', array(), Html::element( 'a', array(
211 - 'id' => "aft5-delete-link-$id",
212 - 'class' => 'aft5-delete-link'
 225+ 'id' => "articleFeedbackv5-delete-link-$id",
 226+ 'class' => 'articleFeedbackv5-delete-link'
213227 ), wfMessage( 'articlefeedbackv5-form-delete' )->text() ) ) : '' )
214228 . Html::closeElement( 'ul' )
215229 . Html::closeElement( 'div' )
@@ -312,17 +326,17 @@
313327 ApiBase::PARAM_REQUIRED => false,
314328 ApiBase::PARAM_ISMULTI => false,
315329 ApiBase::PARAM_TYPE => array(
316 - 'all', 'invisible', 'visible' )
 330+ 'all', 'invisible', 'visible', 'comment' )
317331 ),
318332 'limit' => array(
319333 ApiBase::PARAM_REQUIRED => false,
320334 ApiBase::PARAM_ISMULTI => false,
321335 ApiBase::PARAM_TYPE => 'integer'
322336 ),
323 - 'offset' => array(
 337+ 'continue' => array(
324338 ApiBase::PARAM_REQUIRED => false,
325339 ApiBase::PARAM_ISMULTI => false,
326 - ApiBase::PARAM_TYPE => 'integer'
 340+ ApiBase::PARAM_TYPE => 'string'
327341 ),
328342 );
329343 }
@@ -334,11 +348,11 @@
335349 */
336350 public function getParamDescription() {
337351 return array(
338 - 'pageid' => 'Page ID to get feedback ratings for',
339 - 'sort' => 'Key to sort records by',
340 - 'filter' => 'What filtering to apply to list',
341 - 'limit' => 'Number of records to show',
342 - 'offset' => 'How many to skip (for pagination)',
 352+ 'pageid' => 'Page ID to get feedback ratings for',
 353+ 'sort' => 'Key to sort records by',
 354+ 'filter' => 'What filtering to apply to list',
 355+ 'limit' => 'Number of records to show',
 356+ 'continue' => 'Offset from which to continue',
343357 );
344358 }
345359
Index: trunk/extensions/ArticleFeedbackv5/SpecialArticleFeedbackv5.php
@@ -15,6 +15,12 @@
1616 * @subpackage Special
1717 */
1818 class SpecialArticleFeedbackv5 extends SpecialPage {
 19+ private $filters = array(
 20+ 'visible',
 21+ 'invisible',
 22+ 'all',
 23+ 'comment'
 24+ );
1925
2026 /**
2127 * Constructor
@@ -29,8 +35,9 @@
3036 * @param $param string the parameter passed in the url
3137 */
3238 public function execute( $param ) {
33 - $out = $this->getOutput();
 39+ $out = $this->getOutput();
3440 $title = Title::newFromText( $param );
 41+
3542 if ( $title ) {
3643 $pageId = $title->getArticleID();
3744 } else {
@@ -39,8 +46,8 @@
4047 }
4148
4249 $ratings = $this->fetchOverallRating( $pageId );
43 - $found = isset( $ratings['found'] ) ? $ratings['found'] : null;
44 - $rating = isset( $ratings['rating'] ) ? $ratings['rating'] : null;
 50+ $found = isset( $ratings['found'] ) ? $ratings['found'] : null;
 51+ $rating = isset( $ratings['rating'] ) ? $ratings['rating'] : null;
4552
4653 $out->setPagetitle(
4754 $this->msg( 'articlefeedbackv5-special-pagetitle', $title )->escaped()
@@ -53,7 +60,7 @@
5461 $out->addHTML(
5562 Html::openElement(
5663 'div',
57 - array( 'id' => 'aft5-header-links' )
 64+ array( 'id' => 'articleFeedbackv5-header-links' )
5865 )
5966 . Linker::link(
6067 Title::newFromText( $param ),
@@ -76,11 +83,11 @@
7784 $out->addHTML(
7885 Html::openElement(
7986 'div',
80 - array( 'id' => 'aft5-showing-count-wrap' )
 87+ array( 'id' => 'articleFeedbackv5-showing-count-wrap' )
8188 )
8289 . $this->msg(
8390 'articlefeedbackv5-special-showing',
84 - Html::element( 'span', array( 'id' => 'aft-feedback-count-total' ), '0' )
 91+ Html::element( 'span', array( 'id' => 'articleFeedbackv5-feedback-count-total' ), '0' )
8592 )
8693 . Html::closeElement( 'div' )
8794 );
@@ -89,7 +96,7 @@
9097 $out->addHtml(
9198 Html::openElement(
9299 'div',
93 - array( 'id' => 'aft5-percent-found-wrap' )
 100+ array( 'id' => 'articleFeedbackv5-percent-found-wrap' )
94101 )
95102 . $this->msg( 'articlefeedbackv5-percent-found', $found )->escaped()
96103 . Html::closeElement( 'div' )
@@ -105,7 +112,6 @@
106113 $out->addJsConfigVars( 'afPageId', $pageId );
107114 $out->addModules( 'jquery.articleFeedbackv5.special' );
108115
109 -
110116 $sortLabels = array();
111117 $sortOpts = array( 'newest', 'oldest' );
112118 foreach ( $sortOpts as $sort ) {
@@ -113,24 +119,28 @@
114120 'a',
115121 array(
116122 'href' => '#',
117 - 'id' => 'articlefeedbackv5-special-sort-' . $sort,
118 - 'class' => 'aft5-sort-link'
 123+ 'id' => 'articleFeedbackv5-special-sort-' . $sort,
 124+ 'class' => 'articleFeedbackv5-sort-link'
119125 ),
120126 $this->msg( 'articlefeedbackv5-special-sort-' . $sort )->text()
121127 );
122128 }
123129
124 - $filterSelect = new XmlSelect( false, 'aft5-filter' );
125 - $filterSelect->addOptions( $this->selectMsg( array(
126 - 'articlefeedbackv5-special-filter-visible' => 'visible',
127 - 'articlefeedbackv5-special-filter-invisible' => 'invisible',
128 - 'articlefeedbackv5-special-filter-all' => 'all',
129 - ) ) );
 130+ $opts = array();
 131+ $counts = $this->getFilterCounts( $pageId );
 132+ foreach( $this->filters as $filter ) {
 133+ $count = isset($counts[$filter]) ? $counts[$filter] : 0;
 134+ $key = $this->msg( 'articlefeedbackv5-special-filter-'.$filter, $count )->escaped();
 135+ $opts[ (string) $key ] = $filter;
 136+ }
130137
 138+ $filterSelect = new XmlSelect( false, 'articleFeedbackv5-filter' );
 139+ $filterSelect->addOptions( $opts );
 140+
131141 $out->addHTML(
132142 Html::openElement(
133143 'div',
134 - array( 'id' => 'aft5-sort-filter-controls' )
 144+ array( 'id' => 'articleFeedbackv5-sort-filter-controls' )
135145 )
136146 . $this->msg( 'articlefeedbackv5-special-sort-label-before' )->escaped()
137147 . implode( $this->msg( 'pipe-separator' )->escaped(), $sortLabels )
@@ -143,7 +153,7 @@
144154 'a',
145155 array(
146156 'href' => '#',
147 - 'id' => 'articlefeedbackv5-special-add-feedback',
 157+ 'id' => 'articleFeedbackv5-special-add-feedback',
148158 ),
149159 $this->msg( 'articlefeedbackv5-special-add-feedback' )->text()
150160 )
@@ -154,15 +164,14 @@
155165 Html::element(
156166 'div',
157167 array(
158 - 'id' => 'aft5-show-feedback',
159 - 'style' => 'border:1px solid red;'
160 - ), ''
 168+ 'id' => 'articleFeedbackv5-show-feedback',
 169+ )
161170 )
162171 . Html::element(
163172 'a',
164173 array(
165174 'href' => '#',
166 - 'id' => 'aft5-show-more'
 175+ 'id' => 'articleFeedbackv5-show-more'
167176 ),
168177 $this->msg( 'articlefeedbackv5-special-more' )->text()
169178 )
@@ -220,5 +229,27 @@
221230 return $rv;
222231 }
223232
 233+ private function getFilterCounts( $pageId ) {
 234+ $rv = array();
 235+ $dbr = wfGetDB( DB_SLAVE );
 236+ $rows = $dbr->select(
 237+ 'aft_article_filter_count',
 238+ array(
 239+ 'afc_filter_name',
 240+ 'afc_filter_count'
 241+ ),
 242+ array(
 243+ 'afc_page_id' => $pageId
 244+ ),
 245+ array(),
 246+ __METHOD__
 247+ );
 248+
 249+ foreach( $rows as $row ) {
 250+ $rv[ $row->afc_filter_name ] = $row->afc_filter_count;
 251+ }
 252+
 253+ return $rv;
 254+ }
224255 }
225256

Follow-up revisions

RevisionCommit summaryAuthorDate
r110068AFT5:...gregchiasson19:23, 26 January 2012

Comments

#Comment by Siebrand (talk | contribs)   01:01, 14 January 2012

Please add message documentation for the newly added messages. Thanks.

#Comment by Catrope (talk | contribs)   19:26, 25 January 2012
-// $wgAPIListModules['articlefeedbackv5-view-ratings']  = 'ApiViewRatingsArticleFeedbackv5';
-// $wgAPIListModules['articlefeedbackv5-view-feedback'] = 'ApiViewFeedbackArticleFeedbackv5';
-// $wgAPIModules['articlefeedbackv5-flag-feedback']     = 'ApiFlagFeedbackArticleFeedbackv5';
+$wgAPIListModules['articlefeedbackv5-view-ratings']  = 'ApiViewRatingsArticleFeedbackv5';
+$wgAPIListModules['articlefeedbackv5-view-feedback'] = 'ApiViewFeedbackArticleFeedbackv5';
+$wgAPIModules['articlefeedbackv5-flag-feedback']     = 'ApiFlagFeedbackArticleFeedbackv5';
 $wgAPIModules['articlefeedbackv5']                   = 'ApiArticleFeedbackv5';
 
 // Special Page
-// $wgSpecialPages['ArticleFeedbackv5'] = 'SpecialArticleFeedbackv5';
-// $wgSpecialPageGroups['ArticleFeedbackv5'] = 'other';
+$wgSpecialPages['ArticleFeedbackv5'] = 'SpecialArticleFeedbackv5';
+$wgSpecialPageGroups['ArticleFeedbackv5'] = 'other';

This needs to be disabled as long as the special page is not ready.

+			$where[] = "$continueSql $continue";

Needs escaping of $continue .

OK otherwise.

Status & tagging log