Index: trunk/extensions/MoodBar/SpecialMoodBarFeedback.php |
— | — | @@ -12,11 +12,13 @@ |
13 | 13 | public function execute( $par ) { |
14 | 14 | global $wgOut, $wgRequest; |
15 | 15 | |
| 16 | + $limit = 20; |
| 17 | + $offset = false; |
16 | 18 | $id = intval( $par ); |
17 | 19 | if ( $id > 0 ) { |
18 | 20 | $filters = array( 'id' => $id ); |
19 | 21 | } else { |
20 | | - // Determine filters from the query string |
| 22 | + // Determine filters and offset from the query string |
21 | 23 | $filters = array(); |
22 | 24 | $type = $wgRequest->getArray( 'type' ); |
23 | 25 | if ( $type ) { |
— | — | @@ -26,14 +28,20 @@ |
27 | 29 | if ( $username !== '' ) { |
28 | 30 | $filters['username'] = $username; |
29 | 31 | } |
| 32 | + $offset = $wgRequest->getVal( 'offset', $offset ); |
30 | 33 | } |
31 | 34 | // Do the query |
32 | | - $res = $this->doQuery( $filters ); |
| 35 | + $res = $this->doQuery( $filters, $limit + 1, $offset ); |
| 36 | + $rows = iterator_to_array( $res ); |
| 37 | + $lastRow = null; |
| 38 | + if ( count( $rows ) == $limit + 1 ) { |
| 39 | + $lastRow = array_pop( $rows ); |
| 40 | + } |
33 | 41 | |
34 | 42 | // Output HTML |
35 | 43 | $wgOut->setPageTitle( wfMsg( 'moodbar-feedback-title' ) ); |
36 | 44 | $wgOut->addHTML( $this->buildForm() ); |
37 | | - $wgOut->addHTML( $this->buildList( $res ) ); |
| 45 | + $wgOut->addHTML( $this->buildList( $rows, $lastRow ) ); |
38 | 46 | $wgOut->addModuleStyles( 'ext.moodBar.dashboard.styles' ); |
39 | 47 | } |
40 | 48 | |
— | — | @@ -48,6 +56,7 @@ |
49 | 57 | $setFiltersMsg = wfMessage( 'moodbar-feedback-filters-button' )->escaped(); |
50 | 58 | $whatIsMsg = wfMessage( 'moodbar-feedback-whatis' )->escaped(); |
51 | 59 | $whatIsURL = htmlspecialchars( $wgMoodBarConfig['infoUrl'] ); |
| 60 | + $actionURL = htmlspecialchars( $this->getTitle()->getLinkURL() ); |
52 | 61 | |
53 | 62 | $types = $wgRequest->getArray( 'type', array() ); |
54 | 63 | $happyCheckbox = Xml::check( 'type[]', in_array( 'happy', $types ), |
— | — | @@ -61,7 +70,7 @@ |
62 | 71 | |
63 | 72 | return <<<HTML |
64 | 73 | <div id="fbd-filters"> |
65 | | - <form> |
| 74 | + <form action="$actionURL"> |
66 | 75 | <h3 id="fbd-filters-title">$filtersMsg</h3> |
67 | 76 | <fieldset id="fbd-filters-types"> |
68 | 77 | <legend class="fbd-filters-label">$typeMsg</legend> |
— | — | @@ -89,8 +98,8 @@ |
90 | 99 | HTML; |
91 | 100 | } |
92 | 101 | |
93 | | - public function buildList( $rows ) { |
94 | | - global $wgLang; |
| 102 | + public function buildList( $rows, $lastRow ) { |
| 103 | + global $wgLang, $wgRequest; |
95 | 104 | $now = wfTimestamp( TS_UNIX ); |
96 | 105 | $list = ''; |
97 | 106 | foreach ( $rows as $row ) { |
— | — | @@ -127,14 +136,20 @@ |
128 | 137 | if ( $list === '' ) { |
129 | 138 | return '<div id="fbd-list">' . wfMessage( 'moodbar-feedback-noresults' )->escaped() . '</div>'; |
130 | 139 | } else { |
131 | | - // Only show paging stuff if the result is not empty |
132 | | - $moreURL = '#'; //TODO |
133 | | - $moreText = wfMessage( 'moodbar-feedback-more' )->escaped(); |
134 | | - return "<ul id=\"fbd-list\">$list</ul>" . '<div id="fbd-list-more"><a href="#">More</a></div>'; |
| 140 | + // Only show paging stuff if the result is not empty and there are more results |
| 141 | + $html = "<ul id=\"fbd-list\">$list</ul>"; |
| 142 | + if ( $lastRow ) { |
| 143 | + $offset = wfTimestamp( TS_MW, $lastRow->mbf_timestamp ) . '|' . intval( $lastRow->mbf_id ); |
| 144 | + $moreURL = htmlspecialchars( $this->getTitle()->getLinkURL( $this->getQuery( $offset ) ) ); |
| 145 | + $moreText = wfMessage( 'moodbar-feedback-more' )->escaped(); |
| 146 | + $html .= "<div id=\"fbd-list-more\"><a href=\"$moreURL\">More</a></div>"; |
| 147 | + } |
| 148 | + return $html; |
135 | 149 | } |
136 | 150 | } |
137 | 151 | |
138 | | - public function doQuery( $filters ) { |
| 152 | + public function doQuery( $filters, $limit, $offset ) { |
| 153 | + $dbr = wfGetDB( DB_SLAVE ); |
139 | 154 | $conds = array(); |
140 | 155 | if ( isset( $filters['type'] ) ) { |
141 | 156 | $conds['mbf_type'] = $filters['type']; |
— | — | @@ -152,16 +167,30 @@ |
153 | 168 | if ( isset( $filters['id'] ) ) { |
154 | 169 | $conds['mbf_id'] = $filters['id']; |
155 | 170 | } |
| 171 | + if ( $offset !== false ) { |
| 172 | + $arr = explode( '|', $offset, 2 ); |
| 173 | + $ts = $dbr->addQuotes( $dbr->timestamp( $arr[0] ) ); |
| 174 | + $id = isset( $arr[1] ) ? intval( $arr[1] ) : 0; |
| 175 | + $conds[] = "mbf_timestamp < $ts OR (mbf_timestamp = $ts AND mbf_id <= $id)"; |
| 176 | + } |
156 | 177 | |
157 | | - $dbr = wfGetDB( DB_SLAVE ); |
158 | 178 | return $dbr->select( array( 'moodbar_feedback', 'user' ), array( |
159 | 179 | 'user_name', 'mbf_id', 'mbf_type', |
160 | 180 | 'mbf_timestamp', 'mbf_user_id', 'mbf_user_ip', 'mbf_comment' |
161 | 181 | ), |
162 | 182 | $conds, |
163 | 183 | __METHOD__, |
164 | | - array( 'LIMIT' => 20 /*TODO*/, 'ORDER BY' => 'mbf_timestamp DESC' ), |
| 184 | + array( 'LIMIT' => $limit, 'ORDER BY' => 'mbf_timestamp DESC' ), |
165 | 185 | array( 'user' => array( 'LEFT JOIN', 'user_id=mbf_user_id' ) ) |
166 | 186 | ); |
167 | 187 | } |
| 188 | + |
| 189 | + protected function getQuery( $offset ) { |
| 190 | + global $wgRequest; |
| 191 | + return array( |
| 192 | + 'type' => $wgRequest->getArray( 'type', array() ), |
| 193 | + 'username' => $wgRequest->getVal( 'username' ), |
| 194 | + 'offset' => $offset, |
| 195 | + ); |
| 196 | + } |
168 | 197 | } |