Index: trunk/extensions/MoodBar/SpecialMoodBarFeedback.php |
— | — | @@ -10,11 +10,27 @@ |
11 | 11 | } |
12 | 12 | |
13 | 13 | public function execute( $par ) { |
14 | | - global $wgOut; |
| 14 | + global $wgOut, $wgRequest; |
| 15 | + |
| 16 | + // Determine filters from the query string |
| 17 | + $filters = array(); |
| 18 | + $type = $wgRequest->getArray( 'type' ); |
| 19 | + if ( $type ) { |
| 20 | + $filters['type'] = $type; |
| 21 | + } |
| 22 | + $username = strval( $wgRequest->getVal( 'username' ) ); |
| 23 | + if ( $username !== '' ) { |
| 24 | + $user = User::newFromName( $username ); |
| 25 | + if ( $user ) { |
| 26 | + $filters['user'] = $user; |
| 27 | + } |
| 28 | + } |
| 29 | + // Do the query |
| 30 | + $res = $this->doQuery( $filters ); |
15 | 31 | |
| 32 | + // Output HTML |
16 | 33 | $wgOut->setPageTitle( wfMsg( 'moodbar-feedback-title' ) ); |
17 | 34 | $wgOut->addHTML( $this->buildForm() ); |
18 | | - $res = $this->doQuery(); |
19 | 35 | $wgOut->addHTML( $this->buildList( $res ) ); |
20 | 36 | $wgOut->addModuleStyles( 'ext.moodBar.dashboard.styles' ); |
21 | 37 | } |
— | — | @@ -37,21 +53,21 @@ |
38 | 54 | <legend class="fbd-filters-label">$typeMsg</legend> |
39 | 55 | <ul> |
40 | 56 | <li> |
41 | | - <input type="checkbox" id="fbd-filters-type-praise"> |
| 57 | + <input type="checkbox" id="fbd-filters-type-praise" name="type[]" value="happy"> |
42 | 58 | <label for="fbd-filters-type-praise" id="fbd-filters-type-praise-label">$praiseMsg</label> |
43 | 59 | </li> |
44 | 60 | <li> |
45 | | - <input type="checkbox" id="fbd-filters-type-confusion"> |
| 61 | + <input type="checkbox" id="fbd-filters-type-confusion" name="type[]" value="confused"> |
46 | 62 | <label for="fbd-filters-type-confusion" id="fbd-filters-type-confusion-label">$confusionMsg</label> |
47 | 63 | </li> |
48 | 64 | <li> |
49 | | - <input type="checkbox" id="fbd-filters-type-issues"> |
| 65 | + <input type="checkbox" id="fbd-filters-type-issues" name="type[]" value="sad"> |
50 | 66 | <label for="fbd-filters-type-issues" id="fbd-filters-type-issues-label">$issuesMsg</label> |
51 | 67 | </li> |
52 | 68 | </ul> |
53 | 69 | </fieldset> |
54 | 70 | <label for="fbd-filters-username" class="fbd-filters-label">$usernameMsg</label> |
55 | | - <input type="text" id="fbd-filters-username" class="fbd-filters-input" /> |
| 71 | + <input type="text" id="fbd-filters-username" class="fbd-filters-input" name="username" /> |
56 | 72 | <button type="submit" id="fbd-filters-set">$setFiltersMsg</button> |
57 | 73 | </form> |
58 | 74 | <a href="#" id="fbd-about">$whatIsMsg</a> |
— | — | @@ -101,14 +117,28 @@ |
102 | 118 | return $html; |
103 | 119 | } |
104 | 120 | |
105 | | - public function doQuery() { |
| 121 | + public function doQuery( $filters ) { |
| 122 | + $conds = array(); |
| 123 | + if ( isset( $filters['type'] ) ) { |
| 124 | + $conds['mbf_type'] = $filters['type']; |
| 125 | + } |
| 126 | + if ( isset( $filters['user'] ) ) { |
| 127 | + if ( $filters['user']->isAnon() ) { |
| 128 | + $conds['mbf_user_id'] = 0; |
| 129 | + $conds['mbf_user_ip'] = $filters['user']->getName(); |
| 130 | + } else { |
| 131 | + $conds['mbf_user_id'] = $filters['user']->getID(); |
| 132 | + $conds[] = 'mbf_user_ip IS NULL'; |
| 133 | + } |
| 134 | + } |
| 135 | + |
106 | 136 | $dbr = wfGetDB( DB_SLAVE ); |
107 | 137 | return $dbr->select( array( 'moodbar_feedback', 'user' ), array( |
108 | 138 | 'user_name', 'mbf_id', 'mbf_type', |
109 | 139 | 'mbf_timestamp', 'mbf_user_id', 'mbf_user_ip', 'mbf_comment' |
110 | | - ), array( |
111 | | - '1=1', //TODO |
112 | | - ), __METHOD__, |
| 140 | + ), |
| 141 | + $conds, |
| 142 | + __METHOD__, |
113 | 143 | array( 'LIMIT' => 20 /*TODO*/, 'ORDER BY' => 'mbf_timestamp DESC' ), |
114 | 144 | array( 'user' => array( 'LEFT JOIN', 'user_id=mbf_user_id' ) ) |
115 | 145 | ); |