r62890 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62889‎ | r62890 | r62891 >
Date:20:37, 23 February 2010
Author:demon
Status:ok
Tags:
Comment:
Reduce code duplication by adding conditions to $conds directly, rather than adding them to a temporary variable and then later adding them
Modified paths:
  • /trunk/phase3/includes/specials/SpecialWatchlist.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialWatchlist.php
@@ -155,10 +155,13 @@
156156 return;
157157 }
158158
 159+ # Possible where conditions
 160+ $conds = array();
 161+
159162 if( $days <= 0 ) {
160163 $andcutoff = '';
161164 } else {
162 - $andcutoff = "rc_timestamp > '".$dbr->timestamp( time() - intval( $days * 86400 ) )."'";
 165+ $conds[] = "rc_timestamp > '".$dbr->timestamp( time() - intval( $days * 86400 ) )."'";
163166 }
164167
165168 # If the watchlist is relatively short, it's simplest to zip
@@ -170,21 +173,32 @@
171174 # Up estimate of watched items by 15% to compensate for talk pages...
172175
173176 # Toggles
174 - $andHideOwn = $hideOwn ? "rc_user != $uid" : '';
175 - $andHideBots = $hideBots ? "rc_bot = 0" : '';
176 - $andHideMinor = $hideMinor ? "rc_minor = 0" : '';
177 - $andHideLiu = $hideLiu ? "rc_user = 0" : '';
178 - $andHideAnons = $hideAnons ? "rc_user != 0" : '';
179 - $andHidePatrolled = $wgUser->useRCPatrol() && $hidePatrolled ? "rc_patrolled != 1" : '';
 177+ if( $hideOwn ) {
 178+ $conds[] = "rc_user != $uid";
 179+ }
 180+ if( $hideBots ) {
 181+ $conds[] = 'rc_bot = 0';
 182+ }
 183+ if( $hideMinor ) {
 184+ $conds[] = 'rc_minor = 0';
 185+ }
 186+ if( $hideLiu ) {
 187+ $conds[] = 'rc_user = 0';
 188+ }
 189+ if( $hideAnons ) {
 190+ $conds[] = 'rc_user != 0';
 191+ }
 192+ if ( $wgUser->useRCPatrol() && $hidePatrolled ) {
 193+ $conds[] = 'rc_patrolled != 1';
 194+ }
180195
181196 # Toggle watchlist content (all recent edits or just the latest)
182197 if( $wgUser->getOption( 'extendwatchlist' )) {
183 - $andLatest='';
184198 $limitWatchlist = intval( $wgUser->getOption( 'wllimit' ) );
185199 $usePage = false;
186200 } else {
187201 # Top log Ids for a page are not stored
188 - $andLatest = 'rc_this_oldid=page_latest OR rc_type=' . RC_LOG;
 202+ $conds[] = 'rc_this_oldid=page_latest OR rc_type=' . RC_LOG;
189203 $limitWatchlist = 0;
190204 $usePage = true;
191205 }
@@ -215,7 +229,6 @@
216230
217231 $tables = array( 'recentchanges', 'watchlist' );
218232 $fields = array( "{$recentchanges}.*" );
219 - $conds = array();
220233 $join_conds = array(
221234 'watchlist' => array('INNER JOIN',"wl_user='{$uid}' AND wl_namespace=rc_namespace AND wl_title=rc_title"),
222235 );
@@ -226,15 +239,6 @@
227240 if( $limitWatchlist ) {
228241 $options['LIMIT'] = $limitWatchlist;
229242 }
230 - if( $andcutoff ) $conds[] = $andcutoff;
231 - if( $andLatest ) $conds[] = $andLatest;
232 - if( $andHideOwn ) $conds[] = $andHideOwn;
233 - if( $andHideBots ) $conds[] = $andHideBots;
234 - if( $andHideMinor ) $conds[] = $andHideMinor;
235 - if( $andHideLiu ) $conds[] = $andHideLiu;
236 - if( $andHideAnons ) $conds[] = $andHideAnons;
237 - if( $andHidePatrolled ) $conds[] = $andHidePatrolled;
238 - if( $nameSpaceClause ) $conds[] = $nameSpaceClause;
239243
240244 $rollbacker = $wgUser->isAllowed('rollback');
241245 if ( $usePage || $rollbacker ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r65421* (bug 23286) Fix for r62890: namespace selector no longer has effectialex09:36, 22 April 2010

Status & tagging log