From 0844fe8ce0bf3c86a5a9dbf0d921072c04bd00ab Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 3 Dec 2007 16:34:16 +0000 Subject: [PATCH] Replace some manually-constructed single-field queries made via overlong function sequences with nice easy selectField() calls. --- includes/SpecialRecentchanges.php | 17 ++++++++--------- includes/SpecialWatchlist.php | 24 ++++++++++++------------ 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/includes/SpecialRecentchanges.php b/includes/SpecialRecentchanges.php index 0e231af3a0..3832346937 100644 --- a/includes/SpecialRecentchanges.php +++ b/includes/SpecialRecentchanges.php @@ -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]; } diff --git a/includes/SpecialWatchlist.php b/includes/SpecialWatchlist.php index 102a4b940f..12137add5e 100644 --- a/includes/SpecialWatchlist.php +++ b/includes/SpecialWatchlist.php @@ -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; } -- 2.20.1