Index: trunk/extensions/MoodBar/ApiQueryMoodBarComments.php |
— | — | @@ -13,17 +13,8 @@ |
14 | 14 | $this->addJoinConds( array( 'user' => array( 'LEFT JOIN', 'user_id=mbf_user_id' ) ) ); |
15 | 15 | $this->addFields( array( 'user_name', 'mbf_id', 'mbf_type', 'mbf_timestamp', 'mbf_user_id', 'mbf_user_ip', |
16 | 16 | 'mbf_comment' ) ); |
17 | | - |
18 | | - $sortDesc = $params['dir'] == 'older'; |
19 | | - $dir = $sortDesc ? ' DESC' : ''; |
20 | | - $orderFields = array(); |
21 | | - $useTypeFromContinue = false; |
22 | 17 | if ( count( $params['type'] ) ) { |
23 | 18 | $this->addWhereFld( 'mbf_type', $params['type'] ); |
24 | | - if ( count( $params['type'] ) > 1 ) { |
25 | | - $orderFields[] = 'mbf_type' . $dir; |
26 | | - $useTypeFromContinue = true; |
27 | | - } |
28 | 19 | } |
29 | 20 | if ( $params['user'] !== null ) { |
30 | 21 | $user = User::newFromName( $params['user'] ); // returns false for IPs |
— | — | @@ -37,11 +28,11 @@ |
38 | 29 | } |
39 | 30 | |
40 | 31 | if ( $params['continue'] !== null ) { |
41 | | - $this->applyContinue( $params['continue'], $sortDesc, $useTypeFromContinue ); |
| 32 | + $this->applyContinue( $params['continue'], $params['dir'] == 'older' ); |
42 | 33 | } |
43 | 34 | |
44 | | - $orderFields[] = 'mbf_timestamp' . $dir; |
45 | | - $this->addOption( 'ORDER BY', $orderFields ); |
| 35 | + // Add ORDER BY mbf_timestamp {ASC|DESC} |
| 36 | + $this->addWhereRange( 'mbf_timestamp', $params['dir'], null, null ); |
46 | 37 | $this->addOption( 'LIMIT', $params['limit'] + 1 ); |
47 | 38 | |
48 | 39 | $res = $this->select( __METHOD__ ); |
— | — | @@ -66,35 +57,25 @@ |
67 | 58 | |
68 | 59 | protected function getContinue( $row ) { |
69 | 60 | $ts = wfTimestamp( TS_MW, $row->mbf_timestamp ); |
70 | | - return "$ts|{$row->mbf_type}|{$row->mbf_id}"; |
| 61 | + return "$ts|{$row->mbf_id}"; |
71 | 62 | } |
72 | 63 | |
73 | | - protected function applyContinue( $continue, $sortDesc, $useType ) { |
74 | | - $vals = explode( '|', $continue, 4 ); |
75 | | - if ( count( $vals ) !== 3 ) { |
| 64 | + protected function applyContinue( $continue, $sortDesc ) { |
| 65 | + $vals = explode( '|', $continue, 3 ); |
| 66 | + if ( count( $vals ) !== 2 ) { |
76 | 67 | // TODO this should be a standard message in ApiBase |
77 | 68 | $this->dieUsage( 'Invalid continue param. You should pass the original value returned by the previous query', 'badcontinue' ); |
78 | 69 | } |
79 | 70 | |
80 | 71 | $db = $this->getDB(); |
81 | 72 | $ts = $db->addQuotes( $db->timestamp( $vals[0] ) ); |
82 | | - $type = $db->addQuotes( $vals[1] ); |
83 | | - $id = intval( $vals[2] ); |
| 73 | + $id = intval( $vals[1] ); |
84 | 74 | $op = $sortDesc ? '<' : '>'; |
85 | 75 | // TODO there should be a standard way to do this in DatabaseBase or ApiQueryBase something |
86 | | - if ( $useType ) { |
87 | | - $this->addWhere( "mbf_type $op $type OR " . |
88 | | - "(mbf_type = $type AND " . |
89 | | - "(mbf_timestamp $op $ts OR " . |
90 | | - "(mbf_timestamp = $ts AND " . |
91 | | - "mbf_id $op= $id)))" |
92 | | - ); |
93 | | - } else { |
94 | | - $this->addWhere( "mbf_timestamp $op $ts OR " . |
95 | | - "(mbf_timestamp = $ts AND " . |
96 | | - "mbf_id $op= $id)" |
97 | | - ); |
98 | | - } |
| 76 | + $this->addWhere( "mbf_timestamp $op $ts OR " . |
| 77 | + "(mbf_timestamp = $ts AND " . |
| 78 | + "mbf_id $op= $id)" |
| 79 | + ); |
99 | 80 | } |
100 | 81 | |
101 | 82 | protected function extractRowInfo( $row ) { |