Replace some manually-constructed single-field queries made via overlong function...
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 3 Dec 2007 16:34:16 +0000 (16:34 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 3 Dec 2007 16:34:16 +0000 (16:34 +0000)
includes/SpecialRecentchanges.php
includes/SpecialWatchlist.php

index 0e231af..3832346 100644 (file)
@@ -252,15 +252,14 @@ function wfSpecialRecentchanges( $par, $specialPage ) {
                                $rc->numberofWatchingusers = 0; // Default
                                if ($showWatcherCount && $obj->rc_namespace >= 0) {
                                        if (!isset($watcherCache[$obj->rc_namespace][$obj->rc_title])) {
-                                               $sql3 =
-                                                       'SELECT COUNT(*) AS n ' .
-                                                       "FROM $watchlist " .
-                                                       "WHERE wl_title='{$dbr->strencode($obj->rc_title)}' " .
-                                                       "AND wl_namespace=$obj->rc_namespace" ;
-                                               $res3 = $dbr->query( $sql3, __METHOD__ . '-watchers');
-                                               $x = $dbr->fetchObject( $res3 );
-                                               $watcherCache[$obj->rc_namespace][$obj->rc_title] = $x->n;
-                                               $dbr->freeResult( $res3 );
+                                               $watcherCache[$obj->rc_namespace][$obj->rc_title] =
+                                                       $dbr->selectField( 'watchlist',
+                                                               'COUNT(*)',
+                                                               array(
+                                                                       'wl_namespace' => $obj->rc_namespace,
+                                                                       'wl_title' => $obj->rc_title,
+                                                               ),
+                                                               __METHOD__ . '-watchers' );
                                        }
                                        $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
                                }
index 102a4b9..12137ad 100644 (file)
@@ -87,14 +87,11 @@ function wfSpecialWatchlist( $par ) {
        $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
        list( $page, $watchlist, $recentchanges ) = $dbr->tableNamesN( 'page', 'watchlist', 'recentchanges' );
 
-       $sql = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_user=$uid";
-       $res = $dbr->query( $sql, $fname );
-       $s = $dbr->fetchObject( $res );
-
-#      Patch *** A1 *** (see A2 below)
-#      adjust for page X, talk:page X, which are both stored separately, but treated together
-       $nitems = floor($s->n / 2);
-#      $nitems = $s->n;
+       $watchlistCount = $dbr->selectField( 'watchlist', 'COUNT(*)',
+               array( 'wl_user' => $uid ), __METHOD__ );
+       // Adjust for page X, talk:page X, which are both stored separately,
+       // but treated together
+       $nitems = floor($watchlistCount / 2);
 
        if( is_null($days) || !is_numeric($days) ) {
                $big = 1000; /* The magical big */
@@ -294,10 +291,13 @@ function wfSpecialWatchlist( $par ) {
                }
 
                if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
-                       $sql3 = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" .$dbr->strencode($obj->rc_title). "' AND wl_namespace='{$obj->rc_namespace}'" ;
-                       $res3 = $dbr->query( $sql3, $fname );
-                       $x = $dbr->fetchObject( $res3 );
-                       $rc->numberofWatchingusers = $x->n;
+                       $rc->numberofWatchingusers = $dbr->selectField( 'watchlist',
+                               'COUNT(*)',
+                               array(
+                                       'wl_namespace' => $obj->rc_namespace,
+                                       'wl_title' => $obj->rc_title,
+                               ),
+                               __METHOD__ );
                } else {
                        $rc->numberofWatchingusers = 0;
                }