r97993 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97992‎ | r97993 | r97994 >
Date:11:57, 24 September 2011
Author:catrope
Status:ok
Tags:
Comment:
Remove ordering by type in list=moodbarcomments
Modified paths:
  • /trunk/extensions/MoodBar/ApiQueryMoodBarComments.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MoodBar/ApiQueryMoodBarComments.php
@@ -13,17 +13,8 @@
1414 $this->addJoinConds( array( 'user' => array( 'LEFT JOIN', 'user_id=mbf_user_id' ) ) );
1515 $this->addFields( array( 'user_name', 'mbf_id', 'mbf_type', 'mbf_timestamp', 'mbf_user_id', 'mbf_user_ip',
1616 'mbf_comment' ) );
17 -
18 - $sortDesc = $params['dir'] == 'older';
19 - $dir = $sortDesc ? ' DESC' : '';
20 - $orderFields = array();
21 - $useTypeFromContinue = false;
2217 if ( count( $params['type'] ) ) {
2318 $this->addWhereFld( 'mbf_type', $params['type'] );
24 - if ( count( $params['type'] ) > 1 ) {
25 - $orderFields[] = 'mbf_type' . $dir;
26 - $useTypeFromContinue = true;
27 - }
2819 }
2920 if ( $params['user'] !== null ) {
3021 $user = User::newFromName( $params['user'] ); // returns false for IPs
@@ -37,11 +28,11 @@
3829 }
3930
4031 if ( $params['continue'] !== null ) {
41 - $this->applyContinue( $params['continue'], $sortDesc, $useTypeFromContinue );
 32+ $this->applyContinue( $params['continue'], $params['dir'] == 'older' );
4233 }
4334
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 );
4637 $this->addOption( 'LIMIT', $params['limit'] + 1 );
4738
4839 $res = $this->select( __METHOD__ );
@@ -66,35 +57,25 @@
6758
6859 protected function getContinue( $row ) {
6960 $ts = wfTimestamp( TS_MW, $row->mbf_timestamp );
70 - return "$ts|{$row->mbf_type}|{$row->mbf_id}";
 61+ return "$ts|{$row->mbf_id}";
7162 }
7263
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 ) {
7667 // TODO this should be a standard message in ApiBase
7768 $this->dieUsage( 'Invalid continue param. You should pass the original value returned by the previous query', 'badcontinue' );
7869 }
7970
8071 $db = $this->getDB();
8172 $ts = $db->addQuotes( $db->timestamp( $vals[0] ) );
82 - $type = $db->addQuotes( $vals[1] );
83 - $id = intval( $vals[2] );
 73+ $id = intval( $vals[1] );
8474 $op = $sortDesc ? '<' : '>';
8575 // 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+ );
9980 }
10081
10182 protected function extractRowInfo( $row ) {

Status & tagging log