r44596 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44595‎ | r44596 | r44597 >
Date:21:47, 14 December 2008
Author:aaron
Status:ok
Tags:
Comment:
* Rewrite query the new way. Should make bug 16636 easier.
* Remove commented out code
* Break long lines
Modified paths:
  • /trunk/phase3/includes/specials/SpecialWatchlist.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialWatchlist.php
@@ -13,7 +13,6 @@
1414 global $wgUser, $wgOut, $wgLang, $wgRequest;
1515 global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker;
1616 global $wgEnotifWatchlist;
17 - $fname = 'wfSpecialWatchlist';
1817
1918 $skin = $wgUser->getSkin();
2019 $specialTitle = SpecialPage::getTitleFor( 'Watchlist' );
@@ -41,7 +40,9 @@
4241 }
4342
4443 $uid = $wgUser->getId();
45 - if( ($wgEnotifWatchlist || $wgShowUpdatedMarker) && $wgRequest->getVal( 'reset' ) && $wgRequest->wasPosted() ) {
 44+ if( ($wgEnotifWatchlist || $wgShowUpdatedMarker) && $wgRequest->getVal( 'reset' ) &&
 45+ $wgRequest->wasPosted() )
 46+ {
4647 $wgUser->clearAllNotifications( $uid );
4748 $wgOut->redirect( $specialTitle->getFullUrl() );
4849 return;
@@ -86,9 +87,9 @@
8788 if( !is_null( $nameSpace ) ) {
8889 $nameSpace = intval( $nameSpace );
8990 if( $invert && $nameSpace !== 'all' )
90 - $nameSpaceClause = " AND rc_namespace != $nameSpace";
 91+ $nameSpaceClause = "rc_namespace != $nameSpace";
9192 else
92 - $nameSpaceClause = " AND rc_namespace = $nameSpace";
 93+ $nameSpaceClause = "rc_namespace = $nameSpace";
9394 } else {
9495 $nameSpace = '';
9596 $nameSpaceClause = '';
@@ -140,13 +141,7 @@
141142 if ( $days <= 0 ) {
142143 $andcutoff = '';
143144 } else {
144 - $andcutoff = "AND rc_timestamp > '".$dbr->timestamp( time() - intval( $days * 86400 ) )."'";
145 - /*
146 - $sql = "SELECT COUNT(*) AS n FROM $page, $revision WHERE rev_timestamp>'$cutoff' AND page_id=rev_page";
147 - $res = $dbr->query( $sql, $fname );
148 - $s = $dbr->fetchObject( $res );
149 - $npages = $s->n;
150 - */
 145+ $andcutoff = "rc_timestamp > '".$dbr->timestamp( time() - intval( $days * 86400 ) )."'";
151146 }
152147
153148 # If the watchlist is relatively short, it's simplest to zip
@@ -158,21 +153,21 @@
159154 # Up estimate of watched items by 15% to compensate for talk pages...
160155
161156 # Toggles
162 - $andHideOwn = $hideOwn ? "AND (rc_user <> $uid)" : '';
163 - $andHideBots = $hideBots ? "AND (rc_bot = 0)" : '';
164 - $andHideMinor = $hideMinor ? "AND (rc_minor = 0)" : '';
165 - $andHideLiu = $hideLiu ? "AND (rc_user = 0)" : '';
166 - $andHideAnons = $hideAnons ? "AND (rc_user != 0)" : '';
167 - $andHidePatrolled = $wgUser->useRCPatrol() && $hidePatrolled ? "AND (rc_patrolled != 1)" : '';
 157+ $andHideOwn = $hideOwn ? "rc_user != $uid" : '';
 158+ $andHideBots = $hideBots ? "rc_bot = 0" : '';
 159+ $andHideMinor = $hideMinor ? "rc_minor = 0" : '';
 160+ $andHideLiu = $hideLiu ? "rc_user = 0" : '';
 161+ $andHideAnons = $hideAnons ? "rc_user != 0" : '';
 162+ $andHidePatrolled = $wgUser->useRCPatrol() && $hidePatrolled ? "rc_patrolled != 1" : '';
168163
169164 # Toggle watchlist content (all recent edits or just the latest)
170165 if( $wgUser->getOption( 'extendwatchlist' )) {
171166 $andLatest='';
172 - $limitWatchlist = 'LIMIT ' . intval( $wgUser->getOption( 'wllimit' ) );
 167+ $limitWatchlist = intval( $wgUser->getOption( 'wllimit' ) );
173168 } else {
174169 # Top log Ids for a page are not stored
175 - $andLatest = 'AND (rc_this_oldid=page_latest OR rc_type=' . RC_LOG . ') ';
176 - $limitWatchlist = '';
 170+ $andLatest = 'rc_this_oldid=page_latest OR rc_type=' . RC_LOG;
 171+ $limitWatchlist = 0;
177172 }
178173
179174 # Show a message about slave lag, if applicable
@@ -188,7 +183,7 @@
189184 if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
190185 $form .= wfMsgExt( 'wlheader-enotif', 'parse' ) . "\n";
191186 }
192 - if ( $wgShowUpdatedMarker ) {
 187+ if( $wgShowUpdatedMarker ) {
193188 $form .= Xml::openElement( 'form', array( 'method' => 'post',
194189 'action' => $specialTitle->getLocalUrl(),
195190 'id' => 'mw-watchlist-resetbutton' ) ) .
@@ -198,32 +193,33 @@
199194 Xml::closeElement( 'form' );
200195 }
201196 $form .= '<hr />';
202 -
203 - if ( $wgShowUpdatedMarker ) {
204 - $wltsfield = ", ${watchlist}.wl_notificationtimestamp ";
205 - } else {
206 - $wltsfield = '';
 197+
 198+ $tables = array( 'recentchanges', 'watchlist', 'page' );
 199+ $fields = array( "{$recentchanges}.*" );
 200+ $conds = array();
 201+ $join_conds = array(
 202+ 'watchlist' => array('INNER JOIN',"wl_user='{$uid}' AND wl_namespace=rc_namespace AND wl_title=rc_title"),
 203+ 'page' => array('LEFT JOIN','rc_cur_id=page_id')
 204+ );
 205+ $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
 206+ if( $wgShowUpdatedMarker ) {
 207+ $fields[] = 'wl_notificationtimestamp';
207208 }
208 - $sql = "SELECT ${recentchanges}.* ${wltsfield}
209 - FROM $watchlist,$recentchanges
210 - LEFT JOIN $page ON rc_cur_id=page_id
211 - WHERE wl_user=$uid
212 - AND wl_namespace=rc_namespace
213 - AND wl_title=rc_title
214 - $andcutoff
215 - $andLatest
216 - $andHideOwn
217 - $andHideBots
218 - $andHideMinor
219 - $andHideLiu
220 - $andHideAnons
221 - $andHidePatrolled
222 - $nameSpaceClause
223 - $hookSql
224 - ORDER BY rc_timestamp DESC
225 - $limitWatchlist";
226 -
227 - $res = $dbr->query( $sql, $fname );
 209+ if( $limitWatchlist ) {
 210+ $options['LIMIT'] = $limitWatchlist;
 211+ }
 212+ if( $andcutoff ) $conds[] = $andcutoff;
 213+ if( $andLatest ) $conds[] = $andLatest;
 214+ if( $andHideOwn ) $conds[] = $andHideOwn;
 215+ if( $andHideBots ) $conds[] = $andHideBots;
 216+ if( $andHideMinor ) $conds[] = $andHideMinor;
 217+ if( $andHideLiu ) $conds[] = $andHideLiu;
 218+ if( $andHideAnons ) $conds[] = $andHideAnons;
 219+ if( $andHidePatrolled ) $conds[] = $andHidePatrolled;
 220+ if( $nameSpaceClause ) $conds[] = $nameSpaceClause;
 221+ if( $hookSql ) $conds[] = $hookSql;
 222+
 223+ $res = $dbr->select( $tables, $fields, $conds, __METHOD__, $options, $join_conds );
228224 $numRows = $dbr->numRows( $res );
229225
230226 /* Start bottom header */
@@ -415,7 +411,8 @@
416412 $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
417413
418414 # Fetch the raw count
419 - $res = $dbr->select( 'watchlist', 'COUNT(*) AS count', array( 'wl_user' => $user->mId ), 'wlCountItems' );
 415+ $res = $dbr->select( 'watchlist', 'COUNT(*) AS count',
 416+ array( 'wl_user' => $user->mId ), 'wlCountItems' );
420417 $row = $dbr->fetchObject( $res );
421418 $count = $row->count;
422419 $dbr->freeResult( $res );

Follow-up revisions

RevisionCommit summaryAuthorDate
r44882* (Bug 16636) Add "diff to last sighted version" to watchlist...aaron21:39, 21 December 2008

Status & tagging log