Index: trunk/extensions/ArticleAssessmentPilot/api/ApiListArticleAssessment.php |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | * @file |
7 | 7 | * @ingroup API |
8 | 8 | */ |
9 | | -class ApiListArticleAssessment extends ApiBase { |
| 9 | +class ApiListArticleAssessment extends ApiQueryBase { |
10 | 10 | public function __construct( $query, $moduleName ) { |
11 | 11 | parent::__construct( $query, $moduleName, 'aa' ); |
12 | 12 | } |
— | — | @@ -16,7 +16,41 @@ |
17 | 17 | */ |
18 | 18 | public function execute() { |
19 | 19 | $params = $this->extractRequestParams(); |
| 20 | + |
| 21 | + $result = $this->getResult(); |
| 22 | + |
| 23 | + $this->addTables( 'article_assessment_pages' ); |
| 24 | + |
| 25 | + $this->addFields( array( 'aa_page_id', 'aa_revision', 'aa_total', 'aa_count', 'aa_dimension' ) ); |
| 26 | + |
| 27 | + if ( isset( $params['pageid'] ) ) { |
| 28 | + $this->addWhereFld( 'aa_page_id', $params['pageid'] ); |
| 29 | + } |
| 30 | + |
| 31 | + if ( isset( $params['revid'] ) ) { |
| 32 | + $this->addWhereFld( 'aa_revision', $params['revid'] ); |
| 33 | + } |
| 34 | + |
| 35 | + $res = $this->select( __METHOD__ ); |
20 | 36 | |
| 37 | + $assessments = array(); |
| 38 | + |
| 39 | + foreach( $res as $row ) { |
| 40 | + if ( !isset( $assessments[$row->aa_revision] ) ) { |
| 41 | + $assessments[$row->aa_revision] = array( |
| 42 | + 'pageid' => $row->aa_page_id, |
| 43 | + 'revisionid' => $row->aa_revision, |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + $assessments[$row->aa_revision]['dimensions']['d' . $row->aa_dimension] = array( 'dimension' => $row->aa_dimension, 'total' => $row->aa_total, 'count' => $row->aa_count ); |
| 48 | + } |
| 49 | + |
| 50 | + foreach( $assessments as $ass ) { |
| 51 | + $result->addValue( array( 'query', $this->getModuleName() ), null, $ass ); |
| 52 | + } |
| 53 | + |
| 54 | + $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'aa' ); |
21 | 55 | } |
22 | 56 | |
23 | 57 | public function getAllowedParams() { |
— | — | @@ -43,6 +77,12 @@ |
44 | 78 | return array_merge( parent::getPossibleErrors(), array( |
45 | 79 | ) ); |
46 | 80 | } |
| 81 | + |
| 82 | + protected function getExamples() { |
| 83 | + return array( |
| 84 | + 'api.php?action=query&list=articleassessment' |
| 85 | + ); |
| 86 | + } |
47 | 87 | |
48 | 88 | public function getVersion() { |
49 | 89 | return __CLASS__ . ': $Id$'; |