From 6f32e27ac3ca31134401b7ce8c260a7d611bb26c Mon Sep 17 00:00:00 2001 From: Erik Moeller Date: Sun, 21 Aug 2005 01:17:46 +0000 Subject: [PATCH] Bug #1956: Hide bot uploads in Special:Newimages This should work with any user/group setup. It should also interact cleanly with the other Special:Newimages functions (paging, searching, most recent uploads). --- includes/Database.php | 7 ++- includes/SpecialNewimages.php | 92 +++++++++++++++++++++++++++-------- languages/Language.php | 3 +- 3 files changed, 78 insertions(+), 24 deletions(-) diff --git a/includes/Database.php b/includes/Database.php index c974d138c5..719e63c445 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -15,6 +15,7 @@ define( 'LIST_COMMA', 0 ); define( 'LIST_AND', 1 ); define( 'LIST_SET', 2 ); define( 'LIST_NAMES', 3); +define( 'LIST_OR', 4); /** Number of times to re-try an operation in case of deadlock */ define( 'DEADLOCK_TRIES', 4 ); @@ -1033,18 +1034,20 @@ class Database { if ( !$first ) { if ( $mode == LIST_AND ) { $list .= ' AND '; + } elseif($mode == LIST_OR) { + $list .= ' OR '; } else { $list .= ','; } } else { $first = false; } - if ( $mode == LIST_AND && is_numeric( $field ) ) { + if ( ($mode == LIST_AND || $mode == LIST_OR) && is_numeric( $field ) ) { $list .= "($value)"; } elseif ( $mode == LIST_AND && is_array ($value) ) { $list .= $field." IN (".$this->makeList($value).") "; } else { - if ( $mode == LIST_AND || $mode == LIST_SET ) { + if ( $mode == LIST_AND || $mode == LIST_OR || $mode == LIST_SET ) { $list .= "$field = "; } $list .= $mode == LIST_NAMES ? $value : $this->addQuotes( $value ); diff --git a/includes/SpecialNewimages.php b/includes/SpecialNewimages.php index 744eb0ea70..37a487b0b0 100644 --- a/includes/SpecialNewimages.php +++ b/includes/SpecialNewimages.php @@ -12,19 +12,53 @@ require_once( 'ImageGallery.php' ); * */ function wfSpecialNewimages() { - global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest; + global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest, + $wgGroupPermissions; $wpIlMatch = $wgRequest->getText( 'wpIlMatch' ); $dbr =& wfGetDB( DB_SLAVE ); $sk = $wgUser->getSkin(); + $hidebots = $wgRequest->getBool('hidebots',1); + + if($hidebots) { + + /** Make a list of group names which have the 'bot' flag + set. + */ + $botconds=array(); + foreach ($wgGroupPermissions as $groupname=>$perms) { + if(array_key_exists('bot',$perms) && $perms['bot']) { + $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. + */ + $joinsql=' LEFT OUTER JOIN user_groups ON img_user=ug_user AND (' + . $isbotmember.')'; + } + $sql='SELECT img_timestamp from image'; + if($hidebots) { + $sql.=$joinsql.' WHERE ug_group IS NULL'; + } + $sql.=' ORDER BY img_timestamp DESC LIMIT 1'; + $res = $dbr->query($sql, 'wfSpecialNewImages'); + $row = $dbr->fetchRow($res); + if($row!==false) { + $ts=$row[0]; + } else { + $ts=false; + } + $dbr->freeResult($res); + $sql=''; /** If we were clever, we'd use this to cache. */ - $latestTimestamp = wfTimestamp( TS_MW, $dbr->selectField( - 'image', 'img_timestamp', - '', 'wfSpecialNewimages', - array( 'ORDER BY' => 'img_timestamp DESC', - 'LIMIT' => 1 ) ) ); - + $latestTimestamp = wfTimestamp( TS_MW, $ts); + /** Hardcode this for now. */ $limit = 48; @@ -47,16 +81,20 @@ function wfSpecialNewimages() { $where[] = 'img_timestamp >= ' . $dbr->timestamp( $from ); $invertSort = true; } - - $res = $dbr->select( 'image', - array( 'img_size', 'img_name', 'img_user', 'img_user_text', - 'img_description', 'img_timestamp' ), - $where, - 'wfSpecialNewimages', - array( 'LIMIT' => $limit + 1, - 'ORDER BY' => 'img_timestamp' . ( $invertSort ? '' : ' DESC' ) ) - ); + $sql='SELECT img_size, img_name, img_user, img_user_text,'. + 'img_description,img_timestamp FROM image'; + if($hidebots) { + $sql.=$joinsql; + $where[]='ug_group IS NULL'; + } + if(count($where)) { + $sql.=' WHERE '.$dbr->makeList($where, LIST_AND); + } + $sql.=' ORDER BY img_timestamp '. ( $invertSort ? '' : ' DESC' ); + $sql.=' LIMIT '.($limit+1); + $res = $dbr->query($sql, 'wfSpecialNewImages'); + /** * We have to flip things around to get the last N after a certain date */ @@ -106,7 +144,9 @@ function wfSpecialNewimages() { $sub = wfMsg( 'ilsubmit' ); $titleObj = Title::makeTitle( NS_SPECIAL, 'Newimages' ); $action = $titleObj->escapeLocalURL( "limit={$limit}" ); - + if(!$hidebots) { + $action.='&hidebots=0'; + } $wgOut->addHTML( "
" . "timeanddate( $now ); - $dateLink = $sk->makeKnownLinkObj( $titleObj, wfMsg( 'rclistfrom', $date ), 'from=' . $now ); + $dateLink = $sk->makeKnownLinkObj( $titleObj, wfMsg( 'rclistfrom', $date ), 'from='.$now.$botpar ); + + $botLink = $sk->makeKnownLinkObj($titleObj, wfMsg( 'showhidebots', ($hidebots ? wfMsg('show') : wfMsg('hide'))),'hidebots='.($hidebots ? '0' : '1')); $prevLink = wfMsg( 'prevn', $wgLang->formatNum( $limit ) ); if( $firstTimestamp && $firstTimestamp != $latestTimestamp ) { - $prevLink = $sk->makeKnownLinkObj( $titleObj, $prevLink, 'from=' . $firstTimestamp ); + $prevLink = $sk->makeKnownLinkObj( $titleObj, $prevLink, 'from=' . $firstTimestamp . $botpar ); } $nextLink = wfMsg( 'nextn', $wgLang->formatNum( $limit ) ); if( $shownImages > $limit && $lastTimestamp ) { - $nextLink = $sk->makeKnownLinkObj( $titleObj, $nextLink, 'until=' . $lastTimestamp ); + $nextLink = $sk->makeKnownLinkObj( $titleObj, $nextLink, 'until=' . $lastTimestamp.$botpar ); } - $prevnext = '

' . wfMsg( 'viewprevnext', $prevLink, $nextLink, $dateLink ) . '

'; + $prevnext = '

' . $botLink . ' '. wfMsg( 'viewprevnext', $prevLink, $nextLink, $dateLink ) .'

'; + $wgOut->addHTML( $prevnext ); if( count( $images ) ) { diff --git a/languages/Language.php b/languages/Language.php index bff57b136c..c88d0225d6 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -968,7 +968,7 @@ Unselected groups will not be changed. You can deselect a group with CTRL + Left 'diff' => 'diff', 'hist' => 'hist', 'hide' => 'Hide', -'show' => 'show', +'show' => 'Show', 'tableform' => 'table', 'listform' => 'list', 'nchanges' => "$1 changes", @@ -1770,6 +1770,7 @@ ta[\'ca-nstab-category\'] = new Array(\'c\',\'View the category page\'); 'showbigimage' => 'Download high resolution version ($1x$2, $3 KB)', 'newimages' => 'Gallery of new files', +'showhidebots' => '($1 bots)', 'noimages' => 'Nothing to see.', # short names for language variants used for language conversion links. -- 2.20.1