r71618 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71617‎ | r71618 | r71619 >
Date:02:26, 25 August 2010
Author:reedy
Status:deferred
Tags:
Comment:
Fleshed out module, completely untested

Not sure about naming of parameters, needs discussion
Modified paths:
  • /trunk/extensions/ArticleAssessmentPilot/api/ApiArticleAssessment.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleAssessmentPilot/api/ApiArticleAssessment.php
@@ -11,12 +11,135 @@
1212 }
1313
1414 public function execute() {
 15+ global $wgUser;
 16+ $params = $this->extractRequestParams();
 17+
 18+ $userName = $wgUser->getName();
 19+
 20+ //TODO:Refactor out...?
 21+
 22+ $this->addTables( 'article_assessment' );
 23+
 24+ $this->addFields( array( 'aa_m1', 'aa_m2', 'aa_m3', 'aa_m3' ) );
 25+
 26+ //$this->addWhereFld( 'aa_page_id', $params['pageid'] );
 27+
 28+ $this->addWhereFld( 'aa_revision', $params['revid'] );
 29+ $this->addWhereFld( 'aa_user_text', $userName );
 30+
 31+ $res = $this->select( __METHOD__ );
 32+
 33+ if ( $res ) {
 34+ $lastM1 = $res[0]->aa_m1;
 35+ $lastM2 = $res[0]->aa_m2;
 36+ $lastM3 = $res[0]->aa_m3;
 37+ $lastM4 = $res[0]->aa_m4;
 38+ } else {
 39+ $lastM1 = 0;
 40+ $lastM2 = 0;
 41+ $lastM3 = 0;
 42+ $lastM4 = 0;
 43+ }
 44+
 45+ $m1 = isset( $params['1'] ) ? $params['1'] : 0;
 46+ $m2 = isset( $params['2'] ) ? $params['2'] : 0;
 47+ $m3 = isset( $params['3'] ) ? $params['3'] : 0;
 48+ $m4 = isset( $params['4'] ) ? $params['4'] : 0;
 49+
 50+ //Do for each metric/dimension
 51+
 52+ $pageId = $params['pageid'];
 53+ $revisionId = $params['revisionid'];
 54+
 55+ $this->insertOnDupeUpdatePages( $pageId, $revisionId, $userName, 1, $m1, ( $m1 - $lastM1 ) );
 56+ $this->insertOnDupeUpdatePages( $pageId, $revisionId, $userName, 2, $m1, ( $m2 - $lastM2 ) );
 57+ $this->insertOnDupeUpdatePages( $pageId, $revisionId, $userName, 3, $m1, ( $m3 - $lastM3 ) );
 58+ $this->insertOnDupeUpdatePages( $pageId, $revisionId, $userName, 4, $m1, ( $m4 - $lastM4 ) );
 59+
 60+ //Insert (or update) a users rating for a revision
 61+ $dbw = wfGetDB( DB_MASTER );
 62+
 63+ $dbw->insertOnDupeUpdate( 'article_assessment',
 64+ array(
 65+ 'aa_page_id' => $pageId,
 66+ 'aa_user_text' => $userName,
 67+ 'aa_revision' => $revisionId,
 68+ 'aa_user' => $userName,
 69+ 'aa_timestamp' => wfTimestampNow(),
 70+ 'aa_m1' => $m1,
 71+ 'aa_m2' => $m2,
 72+ 'aa_m3' => $m3,
 73+ 'aa_m4' => $m4,
 74+ ),
 75+ __METHOD__,
 76+ array(),
 77+ array(
 78+ 'aa_timestamp' => wfTimestampNow(),
 79+ 'aa_m1' => $m1,
 80+ 'aa_m2' => $m2,
 81+ 'aa_m3' => $m3,
 82+ 'aa_m4' => $m4,
 83+ )
 84+ );
 85+
 86+ $r = array();
 87+ $r['result'] = 'Success';
 88+ $this->getResult()->addValue( null, $this->getModuleName(), $r );
1589 }
 90+
 91+ private function insertOnDupeUpdatePages( $pageId, $revisionId, $dimension, $insertAddition, $updateAddition ) {
 92+ $dbw = wfGetDB( DB_MASTER );
1693
 94+ $dbw->insertOnDupeUpdate( 'article_assessment_pages',
 95+ array(
 96+ 'aap_page_id' => $pageId,
 97+ 'aap_revision' => $revisionId,
 98+ 'aap_total', => 'aap_total + ' . $insertAddition,
 99+ 'aap_count' => 'aap_count + 1',
 100+ 'aap_dimension' => $dimension,
 101+ ),
 102+ __METHOD__,
 103+ array(),
 104+ array(
 105+ 'aap_total' => 'aap_total + ' . $updateAddition,
 106+ )
 107+ );
 108+ }
 109+
17110 public function getAllowedParams() {
18111 return array(
19 - 'pageid' => null,
20 - 'revid' => null,
 112+ 'pageid' => array(
 113+ ApiBase::PARAM_TYPE => 'integer',
 114+ ApiBase::PARAM_REQUIRED => true,
 115+ ),
 116+ 'revid' => array(
 117+ ApiBase::PARAM_TYPE => 'integer',
 118+ ApiBase::PARAM_REQUIRED => true,
 119+ ),
 120+ '1' => array(
 121+ ApiBase::PARAM_TYPE => 'integer',
 122+ ApiBase::PARAM_DFLT => 0,
 123+ ApiBase::PARAM_MIN => 0,
 124+ ApiBase::PARAM_MAX => 5,
 125+ ),
 126+ '2' => array(
 127+ ApiBase::PARAM_TYPE => 'integer',
 128+ ApiBase::PARAM_DFLT => 0,
 129+ ApiBase::PARAM_MIN => 0,
 130+ ApiBase::PARAM_MAX => 5,
 131+ ),
 132+ '3' => array(
 133+ ApiBase::PARAM_TYPE => 'integer',
 134+ ApiBase::PARAM_DFLT => 0,
 135+ ApiBase::PARAM_MIN => 0,
 136+ ApiBase::PARAM_MAX => 5,
 137+ ),
 138+ '4' => array(
 139+ ApiBase::PARAM_TYPE => 'integer',
 140+ ApiBase::PARAM_DFLT => 0,
 141+ ApiBase::PARAM_MIN => 0,
 142+ ApiBase::PARAM_MAX => 5,
 143+ ),
21144 );
22145 }
23146
@@ -24,6 +147,10 @@
25148 return array(
26149 'pageid' => '',
27150 'revid' => '',
 151+ '1' => 'Metric 1',
 152+ '2' => 'Metric 2',
 153+ '3' => 'Metric 3',
 154+ '4' => 'Metric 4',
28155 );
29156 }
30157

Status & tagging log