r97968 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97967‎ | r97968 | r97969 >
Date:22:44, 23 September 2011
Author:catrope
Status:ok
Tags:
Comment:
MoodBar: Implement filtering in Special:MoodBarFeedback. Doesn't preserve form values yet, will add that
Modified paths:
  • /trunk/extensions/MoodBar/SpecialMoodBarFeedback.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MoodBar/SpecialMoodBarFeedback.php
@@ -10,11 +10,27 @@
1111 }
1212
1313 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 );
1531
 32+ // Output HTML
1633 $wgOut->setPageTitle( wfMsg( 'moodbar-feedback-title' ) );
1734 $wgOut->addHTML( $this->buildForm() );
18 - $res = $this->doQuery();
1935 $wgOut->addHTML( $this->buildList( $res ) );
2036 $wgOut->addModuleStyles( 'ext.moodBar.dashboard.styles' );
2137 }
@@ -37,21 +53,21 @@
3854 <legend class="fbd-filters-label">$typeMsg</legend>
3955 <ul>
4056 <li>
41 - <input type="checkbox" id="fbd-filters-type-praise">
 57+ <input type="checkbox" id="fbd-filters-type-praise" name="type[]" value="happy">
4258 <label for="fbd-filters-type-praise" id="fbd-filters-type-praise-label">$praiseMsg</label>
4359 </li>
4460 <li>
45 - <input type="checkbox" id="fbd-filters-type-confusion">
 61+ <input type="checkbox" id="fbd-filters-type-confusion" name="type[]" value="confused">
4662 <label for="fbd-filters-type-confusion" id="fbd-filters-type-confusion-label">$confusionMsg</label>
4763 </li>
4864 <li>
49 - <input type="checkbox" id="fbd-filters-type-issues">
 65+ <input type="checkbox" id="fbd-filters-type-issues" name="type[]" value="sad">
5066 <label for="fbd-filters-type-issues" id="fbd-filters-type-issues-label">$issuesMsg</label>
5167 </li>
5268 </ul>
5369 </fieldset>
5470 <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" />
5672 <button type="submit" id="fbd-filters-set">$setFiltersMsg</button>
5773 </form>
5874 <a href="#" id="fbd-about">$whatIsMsg</a>
@@ -101,14 +117,28 @@
102118 return $html;
103119 }
104120
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+
106136 $dbr = wfGetDB( DB_SLAVE );
107137 return $dbr->select( array( 'moodbar_feedback', 'user' ), array(
108138 'user_name', 'mbf_id', 'mbf_type',
109139 'mbf_timestamp', 'mbf_user_id', 'mbf_user_ip', 'mbf_comment'
110 - ), array(
111 - '1=1', //TODO
112 - ), __METHOD__,
 140+ ),
 141+ $conds,
 142+ __METHOD__,
113143 array( 'LIMIT' => 20 /*TODO*/, 'ORDER BY' => 'mbf_timestamp DESC' ),
114144 array( 'user' => array( 'LEFT JOIN', 'user_id=mbf_user_id' ) )
115145 );

Follow-up revisions

RevisionCommit summaryAuthorDate
r97972Followup r97968, preserve form valuescatrope23:02, 23 September 2011

Status & tagging log