Index: trunk/extensions/ArticleAssessmentPilot/api/ApiArticleAssessment.php |
— | — | @@ -13,22 +13,22 @@ |
14 | 14 | public function execute() { |
15 | 15 | global $wgUser; |
16 | 16 | $params = $this->extractRequestParams(); |
17 | | - |
| 17 | + |
18 | 18 | $userName = $wgUser->getName(); |
19 | | - |
| 19 | + |
20 | 20 | //TODO:Refactor out...? |
21 | | - |
| 21 | + |
22 | 22 | $this->addTables( 'article_assessment' ); |
23 | | - |
| 23 | + |
24 | 24 | $this->addFields( array( 'aa_m1', 'aa_m2', 'aa_m3', 'aa_m3' ) ); |
25 | | - |
| 25 | + |
26 | 26 | //$this->addWhereFld( 'aa_page_id', $params['pageid'] ); |
27 | 27 | |
28 | 28 | $this->addWhereFld( 'aa_revision', $params['revid'] ); |
29 | 29 | $this->addWhereFld( 'aa_user_text', $userName ); |
30 | | - |
| 30 | + |
31 | 31 | $res = $this->select( __METHOD__ ); |
32 | | - |
| 32 | + |
33 | 33 | if ( $res ) { |
34 | 34 | $lastM1 = $res[0]->aa_m1; |
35 | 35 | $lastM2 = $res[0]->aa_m2; |
— | — | @@ -45,12 +45,12 @@ |
46 | 46 | $m2 = isset( $params['2'] ) ? $params['2'] : 0; |
47 | 47 | $m3 = isset( $params['3'] ) ? $params['3'] : 0; |
48 | 48 | $m4 = isset( $params['4'] ) ? $params['4'] : 0; |
49 | | - |
| 49 | + |
50 | 50 | //Do for each metric/dimension |
51 | | - |
| 51 | + |
52 | 52 | $pageId = $params['pageid']; |
53 | 53 | $revisionId = $params['revisionid']; |
54 | | - |
| 54 | + |
55 | 55 | $this->insertOrUpdatePages( $pageId, $revisionId, $userName, 1, $m1, ( $m1 - $lastM1 ) ); |
56 | 56 | $this->insertOrUpdatePages( $pageId, $revisionId, $userName, 2, $m1, ( $m2 - $lastM2 ) ); |
57 | 57 | $this->insertOrUpdatePages( $pageId, $revisionId, $userName, 3, $m1, ( $m3 - $lastM3 ) ); |
— | — | @@ -81,20 +81,20 @@ |
82 | 82 | 'aa_m4' => $m4, |
83 | 83 | ) |
84 | 84 | ); |
85 | | - |
| 85 | + |
86 | 86 | $r = array(); |
87 | 87 | $r['result'] = 'Success'; |
88 | 88 | $this->getResult()->addValue( null, $this->getModuleName(), $r ); |
89 | 89 | } |
90 | | - |
91 | | - private function insertOrUpdatePages( $pageId, $revisionId, $dimension, $insertAddition, $updateAddition ) { |
| 90 | + |
| 91 | + private function insertOrUpdatePages( $pageId, $revisionId, $dimension, $insert, $updateAddition ) { |
92 | 92 | $dbw = wfGetDB( DB_MASTER ); |
93 | 93 | |
94 | 94 | $dbw->insertOrUpdate( 'article_assessment_pages', |
95 | 95 | array( |
96 | 96 | 'aap_page_id' => $pageId, |
97 | 97 | 'aap_revision' => $revisionId, |
98 | | - 'aap_total', => 'aap_total + ' . $insertAddition, |
| 98 | + 'aap_total' => $insert, |
99 | 99 | 'aap_count' => 'aap_count + 1', |
100 | 100 | 'aap_dimension' => $dimension, |
101 | 101 | ), |
— | — | @@ -159,12 +159,12 @@ |
160 | 160 | 'Submit article assessments' |
161 | 161 | ); |
162 | 162 | } |
163 | | - |
| 163 | + |
164 | 164 | public function getPossibleErrors() { |
165 | 165 | return array_merge( parent::getPossibleErrors(), array( |
166 | 166 | ) ); |
167 | 167 | } |
168 | | - |
| 168 | + |
169 | 169 | protected function getExamples() { |
170 | 170 | return array( |
171 | 171 | 'api.php?action=articleassessment' |