Merge "Pass database connection to SpecialWatchlist::countItems"
[lhc/web/wiklou.git] / includes / specials / SpecialWatchlist.php
index 5dfc113..afa9c78 100644 (file)
@@ -91,7 +91,9 @@ class SpecialWatchlist extends SpecialPage {
                        return;
                }
 
-               $nitems = $this->countItems();
+               $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
+
+               $nitems = $this->countItems( $dbr );
                if ( $nitems == 0 ) {
                        $output->addWikiMsg( 'nowatchlist' );
                        return;
@@ -190,13 +192,11 @@ class SpecialWatchlist extends SpecialPage {
                        return;
                }
 
-               $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
-
                # Possible where conditions
                $conds = array();
 
                if( $values['days'] > 0 ) {
-                       $conds[] = "rc_timestamp > '".$dbr->timestamp( time() - intval( $values['days'] * 86400 ) )."'";
+                       $conds[] = 'rc_timestamp > ' . $dbr->addQuotes( $dbr->timestamp( time() - intval( $values['days'] * 86400 ) ) );
                }
 
                # If the watchlist is relatively short, it's simplest to zip
@@ -272,7 +272,7 @@ class SpecialWatchlist extends SpecialPage {
                $form .= '<hr />';
 
                $tables = array( 'recentchanges', 'watchlist' );
-               $fields = array( $dbr->tableName( 'recentchanges' ) . '.*' );
+               $fields = RecentChange::selectFields();
                $join_conds = array(
                        'watchlist' => array(
                                'INNER JOIN',
@@ -432,7 +432,10 @@ class SpecialWatchlist extends SpecialPage {
                                $rc->numberofWatchingusers = 0;
                        }
 
-                       $s .= $list->recentChangesLine( $rc, $updated, $counter );
+                       $changeLine = $list->recentChangesLine( $rc, $updated, $counter );
+                       if ( $changeLine !== false ) {
+                               $s .= $changeLine;
+                       }
                }
                $s .= $list->endRecentChangesList();
 
@@ -494,11 +497,10 @@ class SpecialWatchlist extends SpecialPage {
        /**
         * Count the number of items on a user's watchlist
         *
+        * @param $dbr A database connection
         * @return Integer
         */
-       protected function countItems() {
-               $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
-
+       protected function countItems( $dbr ) {
                # Fetch the raw count
                $res = $dbr->select( 'watchlist', array( 'count' => 'COUNT(*)' ),
                        array( 'wl_user' => $this->getUser()->getId() ), __METHOD__ );