Index: trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.php |
— | — | @@ -2,8 +2,8 @@ |
3 | 3 | |
4 | 4 | // settings |
5 | 5 | |
6 | | -// number of reviews |
7 | | -$wgArticleAssessmentRevisionCutoff = 5; |
| 6 | +// number of new revisions to mark the last rating as old |
| 7 | +$wgArticleAssessmentStaleCount = 5; |
8 | 8 | |
9 | 9 | // Number of "ratings" to store. Allows it to be a bit more dynamic |
10 | 10 | $wgArticleAssessmentRatingCount = 4; |
Index: trunk/extensions/ArticleAssessmentPilot/api/ApiListArticleAssessment.php |
— | — | @@ -56,6 +56,8 @@ |
57 | 57 | |
58 | 58 | $ratings = array(); |
59 | 59 | |
| 60 | + $userRatedArticle = false; |
| 61 | + |
60 | 62 | foreach ( $res as $row ) { |
61 | 63 | $pageId = $row->aap_page_id; |
62 | 64 | |
— | — | @@ -80,11 +82,33 @@ |
81 | 83 | |
82 | 84 | if ( $params['userrating'] && !is_null( $row->aa_rating_value ) ) { |
83 | 85 | $thisRow['userrating'] = $row->aa_rating_value; |
| 86 | + |
| 87 | + $userRatedArticle = true; |
84 | 88 | } |
85 | 89 | |
86 | 90 | $ratings[$pageId]['ratings'][] = $thisRow; |
87 | 91 | } |
88 | 92 | |
| 93 | + //Only can actually be "stale" if the user has rated the article before |
| 94 | + if ( $params['userrating'] && $userRatedArticle ) { |
| 95 | + $this->resetQueryParams(); |
| 96 | + |
| 97 | + $this->addTables( 'revision' ); |
| 98 | + $this->addFields( array( 'COUNT(rev_id) AS norevs', 'rev_page' ) ); |
| 99 | + |
| 100 | + $this->addWhereFld( 'rev_page', $params['pageid'] ); |
| 101 | + $this->addWhere( 'rev_id > ' . $params['revid'] ); |
| 102 | + |
| 103 | + $res = $this->select( __METHOD__ ); |
| 104 | + |
| 105 | + global $wgArticleAssessmentStaleCount; |
| 106 | + |
| 107 | + if ( $res && $res[0]->norevs > $wgArticleAssessmentStaleCount ){ |
| 108 | + //it's stale! |
| 109 | + $ratings[$params['pageid']]['stale'] = ''; |
| 110 | + } |
| 111 | + } |
| 112 | + |
89 | 113 | $count = 0; |
90 | 114 | foreach ( $ratings as $rat ) { |
91 | 115 | if ( ++ $count > $limit ) { |
— | — | @@ -101,7 +125,10 @@ |
102 | 126 | |
103 | 127 | public function getAllowedParams() { |
104 | 128 | return array( |
105 | | - 'pageid' => null, |
| 129 | + 'pageid' => array( |
| 130 | + ApiBase::PARAM_ISMULTI => false, |
| 131 | + ApiBase::PARAM_TYPE => 'integer', |
| 132 | + ), |
106 | 133 | 'revid' => null, |
107 | 134 | 'userrating' => false, |
108 | 135 | 'limit' => array( |