r71989 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71988‎ | r71989 | r71990 >
Date:22:17, 30 August 2010
Author:reedy
Status:deferred
Tags:
Comment:
Add a way to get the current users rating
Modified paths:
  • /trunk/extensions/ArticleAssessmentPilot/api/ApiListArticleAssessment.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleAssessmentPilot/api/ApiListArticleAssessment.php
@@ -19,12 +19,36 @@
2020
2121 $this->addFields( array( 'aap_page_id', 'aap_total', 'aap_count', 'aap_rating_id', 'aar_rating' ) );
2222
23 - $this->addWhere( 'aap_rating_id = aar_id' );
 23+ $this->addJoinConds( array(
 24+ 'article_assessment_ratings' => array( 'LEFT JOIN', array(
 25+ 'aar_id=aap_rating_id',
 26+ ) ),
 27+ )
 28+ );
2429
2530 if ( isset( $params['pageid'] ) ) {
2631 $this->addWhereFld( 'aap_page_id', $params['pageid'] );
2732 }
2833
 34+ if ( $params['userrating'] ) {
 35+ global $wgUser;
 36+
 37+ $this->addWhereFld( 'aa_user_id', $wgUser->getId() );
 38+ $this->addTables( 'article_assessment' );
 39+ $this->addJoinConds( array(
 40+ 'article_assessment' => array( 'LEFT JOIN', array(
 41+ 'aa_page_id=aap_page_id',
 42+ 'aa_rating_id=aap_rating_id' ) ),
 43+ )
 44+ );
 45+
 46+ $this->addFields( 'aa_rating_value' );
 47+
 48+ if ( isset( $params['revid'] ) ){
 49+ $this->addWhereFld( 'aa_revision', $params['revid'] );
 50+ }
 51+ }
 52+
2953 $res = $this->select( __METHOD__ );
3054
3155 $ratings = array();
@@ -33,17 +57,29 @@
3458 $pageId = $row->aap_page_id;
3559
3660 if ( !isset( $ratings[$pageId] ) ) {
37 - $ratings[$pageId] = array(
 61+ $page = array(
3862 'pageid' => $pageId,
3963 );
 64+
 65+ if ( isset( $params['revid'] ) ){
 66+ $page['revid'] = $row->aa_revision ;
 67+ }
 68+
 69+ $ratings[$pageId] = $page;
4070 }
4171
42 - $ratings[$pageId]['ratings'][] = array(
 72+ $thisRow = array(
4373 'ratingid' => $row->aap_rating_id,
4474 'ratingdesc' => $row->aar_rating,
4575 'total' => $row->aap_total,
46 - 'count' => $row->aap_count
 76+ 'count' => $row->aap_count,
4777 );
 78+
 79+ if ( $params['userrating'] && !is_null( $row->aa_rating_value ) ) {
 80+ $thisRow['userrating'] = $row->aa_rating_value;
 81+ }
 82+
 83+ $ratings[$pageId]['ratings'][] = $thisRow;
4884 }
4985
5086 foreach ( $ratings as $rat ) {
@@ -57,12 +93,16 @@
5894 public function getAllowedParams() {
5995 return array(
6096 'pageid' => null,
 97+ 'revid' => null,
 98+ 'userrating' => false,
6199 );
62100 }
63101
64102 public function getParamDescription() {
65103 return array(
66 - 'pageid' => '',
 104+ 'pageid' => 'Page ID to get assessments for',
 105+ 'revid' => 'Specific revision to get (used in conjunction with user param, otherwise ignored)',
 106+ 'userrating' => 'Whether to get the current users ratings for the specific rev/article',
67107 );
68108 }
69109
@@ -80,7 +120,8 @@
81121 protected function getExamples() {
82122 return array(
83123 'api.php?action=query&list=articleassessment',
84 - 'api.php?action=query&list=articleassessment&aapageid=1'
 124+ 'api.php?action=query&list=articleassessment&aapageid=1',
 125+ 'api.php?action=query&list=articleassessment&aapageid=1&userrating',
85126 );
86127 }
87128

Status & tagging log