From 39feaba24da99fdb5db442cbd455277ef1c3bf73 Mon Sep 17 00:00:00 2001 From: Greg Sabino Mullane Date: Wed, 9 Aug 2006 16:13:07 +0000 Subject: [PATCH] Prevent a SQL error if no bot groups exist, by not doing the whole outer join. --- includes/SpecialNewimages.php | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/includes/SpecialNewimages.php b/includes/SpecialNewimages.php index 1bd3e4cb8a..95c90e42db 100644 --- a/includes/SpecialNewimages.php +++ b/includes/SpecialNewimages.php @@ -17,7 +17,8 @@ function wfSpecialNewimages( $par, $specialPage ) { $shownav = !$specialPage->including(); $hidebots = $wgRequest->getBool('hidebots',1); - if($hidebots) { + $hidebotsql = ''; + if ($hidebots) { /** Make a list of group names which have the 'bot' flag set. @@ -28,23 +29,26 @@ function wfSpecialNewimages( $par, $specialPage ) { $botconds[]="ug_group='$groupname'"; } } - $isbotmember=$dbr->makeList($botconds, LIST_OR); - /** This join, in conjunction with WHERE ug_group - IS NULL, returns only those rows from IMAGE - where the uploading user is not a member of - a group which has the 'bot' permission set. - */ - $ug = $dbr->tableName('user_groups'); - $joinsql=" LEFT OUTER JOIN $ug ON img_user=ug_user AND (" - . $isbotmember.')'; + /* If not bot groups, do not set $hidebotsql */ + if ($botconds) { + $isbotmember=$dbr->makeList($botconds, LIST_OR); + + /** This join, in conjunction with WHERE ug_group + IS NULL, returns only those rows from IMAGE + where the uploading user is not a member of + a group which has the 'bot' permission set. + */ + $ug = $dbr->tableName('user_groups'); + $hidebotsql = " LEFT OUTER JOIN $ug ON img_user=ug_user AND ($isbotmember)"; + } } $image = $dbr->tableName('image'); $sql="SELECT img_timestamp from $image"; - if($hidebots) { - $sql.=$joinsql.' WHERE ug_group IS NULL'; + if ($hidebotsql) { + $sql .= "$hidebotsql WHERE ug_group IS NULL"; } $sql.=' ORDER BY img_timestamp DESC LIMIT 1'; $res = $dbr->query($sql, 'wfSpecialNewImages'); @@ -91,8 +95,8 @@ function wfSpecialNewimages( $par, $specialPage ) { $sql='SELECT img_size, img_name, img_user, img_user_text,'. "img_description,img_timestamp FROM $image"; - if($hidebots) { - $sql.=$joinsql; + if($hidebotsql) { + $sql .= $hidebotsql; $where[]='ug_group IS NULL'; } if(count($where)) { -- 2.20.1