r71816 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71815‎ | r71816 | r71817 >
Date:22:25, 27 August 2010
Author:reedy
Status:deferred (Comments)
Tags:
Comment:
Tidy up sql, enable insert

Code tweaks, minor refactoring. 0 based index for ratings, looks better in JSON format

Followup to r71777
Modified paths:
  • /trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.sql (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/api/ApiListArticleAssessment.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.sql
@@ -4,8 +4,8 @@
55 aar_rating varchar(255) binary NOT NULL
66 ) /*$wgDBTableOptions*/;
77
 8+INSERT INTO /*$wgDBprefix*/article_assessment_ratings(aar_rating) VALUES('articleassessment-rating-wellsourced'),
 9+('articleassessment-rating-neutrality'), ('articleassessment-rating-completeness'), ('articleassessment-rating-readability');
810
911 -- Store article assessments
1012 CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/article_assessment (
Index: trunk/extensions/ArticleAssessmentPilot/api/ApiListArticleAssessment.php
@@ -15,8 +15,7 @@
1616
1717 $result = $this->getResult();
1818
19 - $this->addTables( 'article_assessment_pages' );
20 - $this->addTables( 'article_assessment_ratings' );
 19+ $this->addTables( array( 'article_assessment_pages', 'article_assessment_ratings' ) );
2120
2221 $this->addFields( array( 'aap_page_id', 'aap_total', 'aap_count', 'aap_rating_id', 'aar_rating' ) );
2322
@@ -28,16 +27,18 @@
2928
3029 $res = $this->select( __METHOD__ );
3130
32 - $assessments = array();
 31+ $ratings = array();
3332
3433 foreach ( $res as $row ) {
35 - if ( !isset( $assessments[$row->aap_page_id] ) ) {
36 - $assessments[$row->aap_page_id] = array(
37 - 'pageid' => $row->aap_page_id,
 34+ $pageId = $row->aap_page_id;
 35+
 36+ if ( !isset( $ratings[$pageId] ) ) {
 37+ $ratings[$pageId] = array(
 38+ 'pageid' => $pageId,
3839 );
3940 }
4041
41 - $assessments[$row->aap_page_id]['ratings'][$row->aap_rating_id] = array(
 42+ $ratings[$pageId]['ratings'][] = array(
4243 'ratingid' => $row->aap_rating_id,
4344 'ratingdesc' => $row->aar_rating,
4445 'total' => $row->aap_total,
@@ -45,9 +46,9 @@
4647 );
4748 }
4849
49 - foreach ( $assessments as $ass ) {
50 - $result->setIndexedTagName( $ass['ratings'], 'r' );
51 - $result->addValue( array( 'query', $this->getModuleName() ), null, $ass );
 50+ foreach ( $ratings as $rat ) {
 51+ $result->setIndexedTagName( $rat['ratings'], 'r' );
 52+ $result->addValue( array( 'query', $this->getModuleName() ), null, $rat );
5253 }
5354
5455 $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'aa' );

Past revisions this follows-up on

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

Comments

#Comment by Reedy (talk | contribs)   22:26, 27 August 2010
{
	"query": {
		"articleassessment": [
			{
				"pageid": "1",
				"ratings": [
					{
						"ratingid": "1",
						"ratingdesc": "articleassessment-rating-wellsourced",
						"total": "5",
						"count": "1"
					},
					{
						"ratingid": "2",
						"ratingdesc": "articleassessment-rating-neutrality",
						"total": "5",
						"count": "1"
					},
					{
						"ratingid": "3",
						"ratingdesc": "articleassessment-rating-completeness",
						"total": "5",
						"count": "1"
					},
					{
						"ratingid": "4",
						"ratingdesc": "articleassessment-rating-readability",
						"total": "5",
						"count": "1"
					}
				]
			}
		]
	}
}

Status & tagging log