Skip to content

Commit

Permalink
Item14414: Add USERLIST macro, convert forms searches to use it.
Browse files Browse the repository at this point in the history
Still needs documentation.
  • Loading branch information
gac410 committed Jun 7, 2017
1 parent d717ab5 commit b0c5fa0
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 20 deletions.
13 changes: 3 additions & 10 deletions JQueryPlugin/data/System/JQueryAjaxHelper.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" date="1452096476" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" date="1496855187" format="1.1" version="1"}%
%META:TOPICPARENT{name="JQueryPlugin"}%
---+!! %TOPIC%
%JQREQUIRE{"chili, ui, ui::autocomplete" warn="off"}%
Expand Down Expand Up @@ -239,18 +239,11 @@ jQuery(function($){
* =limit=: number of search results to return, defaults to 10
<verbatim class="tml">
%STARTSECTION{"user"}%<literal>%FORMAT{
"%SEARCH{
"%USERLIST{
".*%URLPARAM{"term" default="does not exist"}%.*"
type="regex"
scope="topic"
format="$percntIF{\"'$percntGROUPINFO{\"$topic\" format=\"$dollarname, \" limit=\"1\"}$percnt'=''\"
then=\"$percntUSERINFO{\"$topic\" format=\"$dollarwikiname, \"}$percnt\"
else=\"$percntGROUPINFO{\"$topic\" format=\"$dollarname, \" limit=\"1\"}$percnt\"
}$percnt"
format="$percntUSERINFO{\"$wikiname\" format=\"$dollarwikiname, \"}$percnt"
separator=""
limit="%URLPARAM{"limit" default="10"}%"
nonoise="on"
web="%USERSWEB%"
}%"
type="string"
header="[$n"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" date="1426281104" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" date="1496855187" format="1.1" version="1"}%
%META:TOPICPARENT{name="FrequentlyAskedQuestions"}%
<div class="foswikiHelp">%X% Under normal circumstances, there should be no need to rebuild your %USERSWEB%.%WIKIUSERSTOPIC% topic.</div>

Expand All @@ -18,7 +18,8 @@ Usage Notes:
<!--%JQREQUIRE{"chili"}%-->
<verbatim class="tml">
%STARTSECTION{"WIKIUSERS"}%
%FORMAT{"A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z"
%FORMAT{
"%CALCULATE{"$LISTUNIQUE($LISTSORT(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,%USERLIST{".*" format="$percntCALCULATE{\"$SUBSTRING($wikiname,1,1)\"}$percnt" separator=","}%))"}%"
type="string"
format=" * $item - &lt;a name='$item'&gt;- - - -&lt;/a&gt; $percentINCLUDE{
\"%TOPIC%\"
Expand All @@ -28,17 +29,15 @@ Usage Notes:
}%
%ENDSECTION{"WIKIUSERS"}%

%STARTSECTION{"USERS"}%%SEARCH{
"name=~'^%letter%.*' AND (form.name~'*UserForm')"
type="query"
web="%USERSWEB%"
nonoise="on"
%STARTSECTION{"USERS"}%%USERLIST{
"^%letter%.*"
separator="$n"
casesensitive="on"
header="$n"
format=" * $topic - $percentUSERINFO{
\"$topic\"
format=" * $wikiname - $percentUSERINFO{
\"$wikiname\"
format=\"$dollarusername\"
}$percent - $createdate"
}$percent - $percntREVINFO{topic=\"%USERSWEB%.$wikiname\" format=\"$date\"}$percnt"
}%%ENDSECTION{"USERS"}%
</verbatim>

Expand Down
1 change: 1 addition & 0 deletions core/lib/Foswiki.pm
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ BEGIN {
URLENCODE => undef,
URLPARAM => undef,
USERINFO => undef,
USERLIST => undef,
USERNAME => undef,
VAR => undef,
WEBLIST => undef,
Expand Down
1 change: 1 addition & 0 deletions core/lib/Foswiki/Contrib/core/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ data/System/VarTOPICLIST.txt 0644
data/System/VarTWIKIWEB.txt 0644
data/System/VarURLPARAM.txt 0644
data/System/VarUSERINFO.txt 0644
data/System/VarUSERLIST.txt 0644
data/System/VarUSERNAME.txt 0644
data/System/VarUSERSWEB.txt 0644
data/System/VarVAR.txt 0644
Expand Down
87 changes: 87 additions & 0 deletions core/lib/Foswiki/Macros/USERLIST.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# See bottom of file for license and copyright information
package Foswiki;

use strict;
use warnings;

use Unicode::Normalize;

BEGIN {
if ( $Foswiki::cfg{UseLocale} ) {
require locale;
import locale();
}
}

sub USERLIST {
my ( $this, $params ) = @_;
my $format = $params->{format} || '$wikiname';
my $limit = $params->{limit} || 0;
my $filter = $params->{_DEFAULT};
my $separator = $params->{separator} || '';
my $casesensitive =
( Foswiki::isTrue( $params->{casesensitive} ) ) ? '' : '(?i)';

my $results = $params->{header} || '';

my $it = $Foswiki::Plugins::SESSION->{users}->eachUser();
$it->{process} = sub {
return $Foswiki::Plugins::SESSION->{users}->getWikiName( $_[0] );
};

my @users;

while ( $it->hasNext() ) {
my $user = $it->next();
if ( length($filter) ) {
next unless ( $user =~ m/$casesensitive$filter/ );
}
push @users, $user;
}

my $count = 0;
foreach my $user ( sort { NFKD($a) cmp NFKD($b) } @users ) {
$count++;
last if ( $limit && $count > $limit );

my $temp = $format;
$temp =~ s/\$wikiname/$user/g;
$results .= $temp;
$results .= $separator if ($separator);
}
$results = substr( $results, 0, -length($separator) ) if length($separator);
$results .= $params->{footer} || '';
$results = Foswiki::expandStandardEscapes($results);

return $results;
}

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2017 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Additional copyrights apply to some or all of the code in this
file as follows:
Copyright (C) 1999-2007 Peter Thoeny, peter@thoeny.org
and TWiki Contributors. All Rights Reserved. TWiki Contributors
are listed in the AUTHORS file in the root of this distribution.
Based on parts of Ward Cunninghams original Wiki and JosWiki.
Copyright (C) 1998 Markus Peter - SPiN GmbH (warpi@spin.de)
Some changes by Dave Harris (drh@bhresearch.co.uk) incorporated
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. For
more details read LICENSE in the root of this distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
As per the GPL, removal of this notice is prohibited.

0 comments on commit b0c5fa0

Please sign in to comment.