r71531 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71530‎ | r71531 | r71532 >
Date:00:19, 24 August 2010
Author:reedy
Status:deferred (Comments)
Tags:
Comment:
Fleshed out ApiListArticleAssessment module

Not quite finished, got a "quirk" that I can't think of a better way to do it (yay, tiredness) - Need to poke Roan
Modified paths:
  • /trunk/extensions/ArticleAssessmentPilot/api/ApiListArticleAssessment.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleAssessmentPilot/api/ApiListArticleAssessment.php
@@ -5,7 +5,7 @@
66 * @file
77 * @ingroup API
88 */
9 -class ApiListArticleAssessment extends ApiBase {
 9+class ApiListArticleAssessment extends ApiQueryBase {
1010 public function __construct( $query, $moduleName ) {
1111 parent::__construct( $query, $moduleName, 'aa' );
1212 }
@@ -16,7 +16,41 @@
1717 */
1818 public function execute() {
1919 $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__ );
2036
 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' );
2155 }
2256
2357 public function getAllowedParams() {
@@ -43,6 +77,12 @@
4478 return array_merge( parent::getPossibleErrors(), array(
4579 ) );
4680 }
 81+
 82+ protected function getExamples() {
 83+ return array(
 84+ 'api.php?action=query&list=articleassessment'
 85+ );
 86+ }
4787
4888 public function getVersion() {
4989 return __CLASS__ . ': $Id$';

Follow-up revisions

RevisionCommit summaryAuthorDate
r71777prefix of columns should match table name...reedy00:56, 27 August 2010

Comments

#Comment by Reedy (talk | contribs)   00:39, 24 August 2010

But

<?xml version="1.0"?>
<api>
  <query>
    <articleassessment>
      <aa pageid="1" revisionid="33">
        <dimensions>
          <d1 dimension="1" total="10" count="2" />
          <d2 dimension="2" total="10" count="2" />
          <d3 dimension="3" total="10" count="2" />
          <d4 dimension="4" total="10" count="2" />
        </dimensions>
      </aa>
    </articleassessment>
  </query>
</api>

is valid xml...

#Comment by Catrope (talk | contribs)   01:54, 24 August 2010

Why not just use:

        <dimensions>
          <d dimension="1" total="10" count="2" />
          <d dimension="2" total="10" count="2" />
          <d dimension="3" total="10" count="2" />
          <d dimension="4" total="10" count="2" />
        </dimensions>
#Comment by Reedy (talk | contribs)   02:06, 24 August 2010

Something to look at when I've slept.

I got the point I couldn't be bothered, so commited it as is..

Status & tagging log