Index: trunk/phase3/includes/specials/SpecialWatchlist.php |
— | — | @@ -13,7 +13,6 @@ |
14 | 14 | global $wgUser, $wgOut, $wgLang, $wgRequest; |
15 | 15 | global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker; |
16 | 16 | global $wgEnotifWatchlist; |
17 | | - $fname = 'wfSpecialWatchlist'; |
18 | 17 | |
19 | 18 | $skin = $wgUser->getSkin(); |
20 | 19 | $specialTitle = SpecialPage::getTitleFor( 'Watchlist' ); |
— | — | @@ -41,7 +40,9 @@ |
42 | 41 | } |
43 | 42 | |
44 | 43 | $uid = $wgUser->getId(); |
45 | | - if( ($wgEnotifWatchlist || $wgShowUpdatedMarker) && $wgRequest->getVal( 'reset' ) && $wgRequest->wasPosted() ) { |
| 44 | + if( ($wgEnotifWatchlist || $wgShowUpdatedMarker) && $wgRequest->getVal( 'reset' ) && |
| 45 | + $wgRequest->wasPosted() ) |
| 46 | + { |
46 | 47 | $wgUser->clearAllNotifications( $uid ); |
47 | 48 | $wgOut->redirect( $specialTitle->getFullUrl() ); |
48 | 49 | return; |
— | — | @@ -86,9 +87,9 @@ |
87 | 88 | if( !is_null( $nameSpace ) ) { |
88 | 89 | $nameSpace = intval( $nameSpace ); |
89 | 90 | if( $invert && $nameSpace !== 'all' ) |
90 | | - $nameSpaceClause = " AND rc_namespace != $nameSpace"; |
| 91 | + $nameSpaceClause = "rc_namespace != $nameSpace"; |
91 | 92 | else |
92 | | - $nameSpaceClause = " AND rc_namespace = $nameSpace"; |
| 93 | + $nameSpaceClause = "rc_namespace = $nameSpace"; |
93 | 94 | } else { |
94 | 95 | $nameSpace = ''; |
95 | 96 | $nameSpaceClause = ''; |
— | — | @@ -140,13 +141,7 @@ |
141 | 142 | if ( $days <= 0 ) { |
142 | 143 | $andcutoff = ''; |
143 | 144 | } 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 ) )."'"; |
151 | 146 | } |
152 | 147 | |
153 | 148 | # If the watchlist is relatively short, it's simplest to zip |
— | — | @@ -158,21 +153,21 @@ |
159 | 154 | # Up estimate of watched items by 15% to compensate for talk pages... |
160 | 155 | |
161 | 156 | # 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" : ''; |
168 | 163 | |
169 | 164 | # Toggle watchlist content (all recent edits or just the latest) |
170 | 165 | if( $wgUser->getOption( 'extendwatchlist' )) { |
171 | 166 | $andLatest=''; |
172 | | - $limitWatchlist = 'LIMIT ' . intval( $wgUser->getOption( 'wllimit' ) ); |
| 167 | + $limitWatchlist = intval( $wgUser->getOption( 'wllimit' ) ); |
173 | 168 | } else { |
174 | 169 | # 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; |
177 | 172 | } |
178 | 173 | |
179 | 174 | # Show a message about slave lag, if applicable |
— | — | @@ -188,7 +183,7 @@ |
189 | 184 | if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) { |
190 | 185 | $form .= wfMsgExt( 'wlheader-enotif', 'parse' ) . "\n"; |
191 | 186 | } |
192 | | - if ( $wgShowUpdatedMarker ) { |
| 187 | + if( $wgShowUpdatedMarker ) { |
193 | 188 | $form .= Xml::openElement( 'form', array( 'method' => 'post', |
194 | 189 | 'action' => $specialTitle->getLocalUrl(), |
195 | 190 | 'id' => 'mw-watchlist-resetbutton' ) ) . |
— | — | @@ -198,32 +193,33 @@ |
199 | 194 | Xml::closeElement( 'form' ); |
200 | 195 | } |
201 | 196 | $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'; |
207 | 208 | } |
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 ); |
228 | 224 | $numRows = $dbr->numRows( $res ); |
229 | 225 | |
230 | 226 | /* Start bottom header */ |
— | — | @@ -415,7 +411,8 @@ |
416 | 412 | $dbr = wfGetDB( DB_SLAVE, 'watchlist' ); |
417 | 413 | |
418 | 414 | # 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' ); |
420 | 417 | $row = $dbr->fetchObject( $res ); |
421 | 418 | $count = $row->count; |
422 | 419 | $dbr->freeResult( $res ); |