Index: trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php |
— | — | @@ -51,33 +51,6 @@ |
52 | 52 | $result->addValue( 'data', 'feedback', $html ); |
53 | 53 | } |
54 | 54 | |
55 | | - public function fetchOverallRating( $pageId ) { |
56 | | - $rv = array(); |
57 | | - $dbr = wfGetDB( DB_SLAVE ); |
58 | | - $rows = $dbr->select( |
59 | | - array( 'aft_article_feedback_ratings_rollup', |
60 | | - 'aft_article_field' ), |
61 | | - array( 'arr_total / arr_count AS rating', |
62 | | - 'afi_name' |
63 | | - ), |
64 | | - array( 'arr_page_id' => $pageId, |
65 | | - 'arr_rating_id = afi_id', |
66 | | - "afi_name IN ('found', 'rating')" |
67 | | - ) |
68 | | - ); |
69 | | - |
70 | | - foreach( $rows as $row ) { |
71 | | - if( $row->afi_name == 'found' ) { |
72 | | - $rv['found'] = ( int ) ( 100 * $row->rating ); |
73 | | - } elseif( $row->afi_name == 'rating' ) { |
74 | | - # Or should this be round/ceil/floor/float? |
75 | | - $rv['rating'] = ( int ) $row->rating; |
76 | | - } |
77 | | - } |
78 | | - |
79 | | - return $rv; |
80 | | - } |
81 | | - |
82 | 55 | public function fetchFeedbackCount( $pageId, $filter ) { |
83 | 56 | $dbr = wfGetDB( DB_SLAVE ); |
84 | 57 | $where = $this->getFilterCriteria( $filter ); |
Index: trunk/extensions/ArticleFeedbackv5/SpecialArticleFeedbackv5.php |
— | — | @@ -1,47 +1,44 @@ |
2 | 2 | <?php |
3 | 3 | class SpecialArticleFeedbackv5 extends SpecialPage { |
4 | | - private $api; |
5 | | - |
6 | 4 | public function __construct() { |
7 | 5 | parent::__construct( 'ArticleFeedbackv5' ); |
8 | 6 | } |
9 | 7 | |
10 | | - public function execute( $title ) { |
| 8 | + public function execute( $param ) { |
11 | 9 | global $wgOut; |
12 | | - $pageId = $this->pageIdFromTitle( $title ); |
13 | 10 | |
| 11 | + $title = Title::newFromText( $param ); |
| 12 | + if ( $title ) { |
| 13 | + $pageId = $title->getArticleID(); |
| 14 | + } else { |
| 15 | + $wgOut->addWikiMsg( 'articlefeedbackv5-invalid-page-id' ); |
| 16 | + return; |
| 17 | + } |
14 | 18 | |
15 | | -# private function getApi() { |
16 | | -# $q = new ApiQuery( |
17 | | -# 'ApiQuery', 'articlefeedbackv5-view-feedback' ); |
18 | | -# $api = new ApiViewFeedbackArticleFeedbackv5( |
19 | | -# $q, 'articlefeedbackv5-view-feedback' ); |
20 | | -# return $api; |
21 | | -# } |
22 | | - $rating_params = new FauxRequest( array( |
23 | | - 'action' => 'articlefeedbackv5-view-ratings', |
24 | | - 'format' => 'json', |
25 | | - 'pageId' => $pageId, |
26 | | - ) ); |
27 | | - $api = new ApiMain( $rating_params, true ); |
28 | | -# $ratings = $api->fetchOverallRating( $pageId ); |
| 19 | + $ratings = $this->fetchOverallRating( $pageId ); |
| 20 | + $found = isset( $ratings['found'] ) ? $ratings['found'] : null; |
| 21 | + $rating = isset( $ratings['rating'] ) ? $ratings['rating'] : null; |
29 | 22 | |
30 | | - |
31 | | - $found = isset( $ratings['found'] ) ? $ratings['found'] : null; |
32 | | - $rating = isset( $ratings['rating'] ) ? $ratings['rating'] : null; |
33 | | - |
34 | 23 | $wgOut->setPagetitle( "Feedback for $title" ); |
35 | 24 | |
36 | | - if( !$pageId ) { |
| 25 | + if( !$pageId ) { |
37 | 26 | $wgOut->addWikiMsg( 'articlefeedbackv5-invalid-page-id' ); |
38 | 27 | } else { |
39 | | - $wgOut->addWikiText( |
40 | | - "[[Wikipedia:$title|" |
41 | | - .wfMsg('articlefeedbackv5-go-to-article')."]] |
42 | | - | [[Wikipedia:$title|" |
43 | | - .wfMsg('articlefeedbackv5-discussion-page')."]] |
44 | | - | [[Wikipedia:$title|" |
45 | | - .wfMsg('articlefeedbackv5-whats-this')."]]" |
| 28 | + $wgOut->addHTML( |
| 29 | + Linker::link( |
| 30 | + Title::newFromText( $param ), |
| 31 | + wfMessage( 'articlefeedbackv5-go-to-article' )->escaped() |
| 32 | + ) |
| 33 | + .' | '. |
| 34 | + Linker::link( |
| 35 | + Title::newFromText( $param ), |
| 36 | + wfMessage( 'articlefeedbackv5-discussion-page' )->escaped() |
| 37 | + ) |
| 38 | + .' | '. |
| 39 | + Linker::link( |
| 40 | + Title::newFromText( $param ), |
| 41 | + wfMessage( 'articlefeedbackv5-whats-this' )->escaped() |
| 42 | + ) |
46 | 43 | ); |
47 | 44 | } |
48 | 45 | |
— | — | @@ -56,8 +53,6 @@ |
57 | 54 | $wgOut->addWikiMsg( 'articlefeedbackv5-special-title' ); |
58 | 55 | |
59 | 56 | $wgOut->addHTML(<<<EOH |
60 | | -<!-- This is a terrible, terrible hack. I'm taking it out as soon as I stop |
61 | | - being an idiot and sort this ResourceLoader thing out --> |
62 | 57 | <script> var hackPageId = $pageId; </script> |
63 | 58 | <script src="/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js"></script> |
64 | 59 | <!-- |
— | — | @@ -83,17 +78,39 @@ |
84 | 79 | ); |
85 | 80 | } |
86 | 81 | |
| 82 | + private function fetchOverallRating( $pageId ) { |
| 83 | + $rv = array(); |
| 84 | + $dbr = wfGetDB( DB_SLAVE ); |
| 85 | + $rows = $dbr->select( |
| 86 | + array( |
| 87 | + 'aft_article_feedback_ratings_rollup', |
| 88 | + 'aft_article_field' |
| 89 | + ), |
| 90 | + array( |
| 91 | + 'arr_total / arr_count AS rating', |
| 92 | + 'afi_name' |
| 93 | + ), |
| 94 | + array( |
| 95 | + 'arr_page_id' => $pageId, |
| 96 | + 'arr_field_id = afi_id', |
| 97 | + "afi_name IN ('found', 'rating')" |
| 98 | + ) |
| 99 | + ); |
| 100 | + |
| 101 | + foreach( $rows as $row ) { |
| 102 | + if( $row->afi_name == 'found' ) { |
| 103 | + $rv['found'] = ( int ) ( 100 * $row->rating ); |
| 104 | + } elseif( $row->afi_name == 'rating' ) { |
| 105 | + $rv['rating'] = ( int ) $row->rating; |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + return $rv; |
| 110 | + } |
| 111 | + |
| 112 | + |
87 | 113 | protected static function formatNumber( $number ) { |
88 | 114 | global $wgLang; |
89 | 115 | return $wgLang->formatNum( number_format( $number, 2 ) ); |
90 | 116 | } |
91 | | - |
92 | | - protected function pageIdFromTitle( $title ) { |
93 | | - $dbr = wfGetDB( DB_SLAVE ); |
94 | | - return $dbr->selectField( |
95 | | - 'page', |
96 | | - 'page_id', |
97 | | - array( 'page_title' => $title ) |
98 | | - ); |
99 | | - } |
100 | 117 | } |