Merge "Pass database connection to SpecialWatchlist::countItems"
[lhc/web/wiklou.git] / includes / specials / SpecialWatchlist.php
index 3cfa31f..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
@@ -497,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__ );