1# See bottom of file for license and copyright information 2package Foswiki; 3 4use strict; 5use warnings; 6 7BEGIN { 8 if ( $Foswiki::cfg{UseLocale} ) { 9 require locale; 10 import locale(); 11 } 12} 13 14sub GROUPINFO { 15 my ( $this, $params ) = @_; 16 17 my $group = $params->{_DEFAULT}; 18 my $format = $params->{format}; 19 my $sep = $params->{separator}; 20 $sep = ', ' unless defined $sep; 21 my $limit = $params->{limit} || 100000000; 22 my $limited = $params->{limited}; 23 $limited = '' unless defined $limited; 24 my $header = $params->{header}; 25 $header = '' unless defined $header; 26 my $footer = $params->{footer}; 27 $footer = '' unless defined $footer; 28 my $show = $params->{show}; 29 $show = 'all' unless defined $show; 30 my $zeroresults = $params->{zeroresults}; 31 my $expand = $params->{expand}; 32 $expand = '1' unless defined $expand; 33 34 $expand = Foswiki::Func::isTrue($expand); 35 36 my $it; #erator 37 my @rows; 38 39 if ($group) { 40 if ( $group =~ m/[\.\/]/ ) { # Contains a web/topic separator 41 ( my $web, $group ) = 42 Foswiki::Func::normalizeWebTopicName( $Foswiki::cfg{UsersWebName}, 43 $group ); 44 return '' unless ( $web eq $Foswiki::cfg{UsersWebName} ); 45 } 46 47 $it = $this->{users}->eachGroupMember( $group, { expand => $expand } ); 48 $format = '$wikiusername' unless defined $format; 49 } 50 else { 51 $it = $this->{users}->eachGroup(); 52 $format = '$name' unless defined $format; 53 } 54 while ( $it->hasNext() ) { 55 my $cUID = $it->next(); 56 my $row = $format; 57 if ($group) { 58 next unless ( $this->{users}->groupAllowsView($cUID) ); 59 my $change = $this->{users}->groupAllowsChange($cUID); 60 61 #filter by show="" param 62 next if ( ( $show eq 'allowchange' ) and ( not $change ) ); 63 next if ( ( $show eq 'denychange' ) and ($change) ); 64 if ( $show =~ m/allowchange\((.*)\)/ ) { 65 next 66 if ( 67 not $this->{users}->groupAllowsChange( 68 $group, $this->{users}->getCanonicalUserID($1) 69 ) 70 ); 71 } 72 if ( $show =~ m/denychange\((.*)\)/ ) { 73 next 74 if ( 75 $this->{users}->groupAllowsChange( 76 $group, $this->{users}->getCanonicalUserID($1) 77 ) 78 ); 79 } 80 81 my $wname = $this->{users}->getWikiName($cUID); 82 my $uname = $this->{users}->getLoginName($cUID) || $wname; 83 my $wuname = $this->{users}->webDotWikiName($cUID); 84 85 $row =~ s/\$wikiname/$wname/ge; 86 $row =~ s/\$username/$uname/ge; 87 $row =~ s/\$wikiusername/$wuname/ge; 88 $row =~ s/\$name/$group/g; 89 90 #TODO: should return 0 if $1 is not a valid user? 91 $row =~ 92s/\$allowschange\((.*?)\)/$this->{users}->groupAllowsChange( $group , $this->{users}->getCanonicalUserID($1))/ges; 93 $row =~ s/\$allowschange/$change/ge; 94 } 95 else { 96 97 # all groups 98 next unless ( $this->{users}->groupAllowsView($cUID) ); 99 my $change = $this->{users}->groupAllowsChange($cUID); 100 101 #filter by show="" param 102 next if ( ( $show eq 'allowchange' ) and ( not $change ) ); 103 next if ( ( $show eq 'denychange' ) and ($change) ); 104 if ( $show =~ m/allowchange\((.*)\)/ ) { 105 next 106 if ( 107 not $this->{users}->groupAllowsChange( 108 $cUID, $this->{users}->getCanonicalUserID($1) 109 ) 110 ); 111 } 112 if ( $show =~ m/denychange\((.*)\)/ ) { 113 next 114 if ( 115 $this->{users}->groupAllowsChange( 116 $cUID, $this->{users}->getCanonicalUserID($1) 117 ) 118 ); 119 } 120 121 $row =~ s/\$name/$cUID/g; 122 123 #TODO: should return 0 if $1 is not a valid user? 124 $row =~ 125s/\$allowschange\((.*?)\)/$this->{users}->groupAllowsChange( $cUID , $this->{users}->getCanonicalUserID($1))/ges; 126 $row =~ s/\$allowschange/$change/ge; 127 } 128 push( @rows, $row ); 129 last if ( --$limit == 0 ); 130 } 131 $footer = $limited . $footer if $limit == 0; 132 133 my $result; 134 if ( defined($zeroresults) and ( scalar(@rows) <= 0 ) ) { 135 $result = $zeroresults; 136 } 137 else { 138 $result = $header . join( $sep, @rows ) . $footer; 139 } 140 return expandStandardEscapes($result); 141} 142 1431; 144__END__ 145Foswiki - The Free and Open Source Wiki, http://foswiki.org/ 146 147Copyright (C) 2008-2009 Foswiki Contributors. Foswiki Contributors 148are listed in the AUTHORS file in the root of this distribution. 149NOTE: Please extend that file, not this notice. 150 151This program is free software; you can redistribute it and/or 152modify it under the terms of the GNU General Public License 153as published by the Free Software Foundation; either version 2 154of the License, or (at your option) any later version. For 155more details read LICENSE in the root of this distribution. 156 157This program is distributed in the hope that it will be useful, 158but WITHOUT ANY WARRANTY; without even the implied warranty of 159MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 160 161As per the GPL, removal of this notice is prohibited. 162