Implemented: New $wikiname variable in format parameter of formatted search
Summary: FormattedSearch understands now
$username,
$wikiname (

) and
$wikiusername. This small enhancement makes formatted search consistent with the
TWikiVariables USERNAME,
WIKINAME and
WIKIUSERNAME, respectively. Example:
jsmith,
JohnSmith,
Main.JohnSmith, respectively.
Problem: How to get the short user name from a Search
On my TWiki homepage I have a list of 10 most recent changed topics. It shows the topic (as link) and the revision date and time, as a result of a ==.
I thought it would be handy to have the latest author named as well.
I found I only have these options (from Search.pm):
$wikiusername shows me: Main.ArthurClemens. (somehow [ [$wikiusername] ] is rendered as
Main.ArthurClemens, unlike the signature )
$username shows me: arthurclemens
But I just want to have the Wiki name without Main. and without link, like: ArthurClemens
So I wrote this small patch that does that. It uses the variable
$name:
| *Most recent changes* |
%SEARCH{ ".*" regex="on" nosearch="on" nototal="on" order="modified" reverse="on" limit="10" format="| [[$topic]] <br />$date<br />$name |" }%
--
ArthurClemens - 05 Sep 2003
That's interesting. I can't think of a way to do what you've done within the confines of the current code; maybe it does require a patch.
If it does, why don't you use $wikiname instead of $name. This goes along better with the TWiki variables %USERNAME%, %WIKIUSERNAME%, and %WIKINAME%.
--
TedPavlic - 06 Sep 2003
Why not just write
$wikiusername without the
[[...]]? It's the square brackets that are causing the display of the web name.
--
RichardDonkin - 06 Sep 2003
The problem is the format is making the wikiword not link - no patch is required, per se.
format="| [[$topic]] <br />$date<br />$name |" }%
Should be:
format="| [[$topic]] <br />$date<br /> $wikiusername |" }%
TWikiGuest
Solution with user names as link
An extra space is needed after the linebreak. So a patch is not necessary in this case.
format="| [[$topic]] <br />$date<br /> $wikiusername |" }%
... will work fine:
Solution with user names without being a link
Use the provided patch. See
example page.
--
ArthurClemens - 06 Sep 2003
I think the above proposed solutions (without a patch) disregard key features of the problem Aurthur is trying to communicate. That is:
- The ability to produce a %WIKINAME% without a link
- Using $wikiusername produces things like Main.TedPavlic
- By putting a space in front of the Main.TedPavlic, a link is produced that links to TedPavlic's wiki page
- Aurthur would like to produce "TedPavlic" without a link
- Using $username does not have this functionality because $username returns the logon ID that the user might use, which might not be the same as the user's WikiName
- For example, $username may return "guest" for TWikiGuest and "tpavlic" for TedPavlic or aurthurclemens for AurthurClemens
There are already three TWiki variables that produce what Aurthur would want outside of the search:
- %USERNAME% - the login username (i.e. "guest" or "tpavlic" or "aurthurclemens"
- This is like $username in the search
- %WIKINAME% - The Wiki username (i.e. "TWikiGuest" or "TedPavlic" or "AurthurClemens")
- There is no equivalent for this without Aurthur's patch. This is why I suggest Aurthur change his patch to use $wikiname instead of $name
- %WIKIUSERNAME% - %WIKINAME% including the Main web name (i.e. "Main.TWikiGuest" or "Main.TedPavlic" or "Main.AurthurCLemens")
- This is like $wikiusername in search
So you can see, there is no equivalent for the simple %WIKINAME% in the search, which may be used by a user to produce a Wiki user name without a link. Because $username and $wikiusername track %USERNAME% and %WIKIUSERNAME% so well, I really think that $name should be called $wikiname to continue the correlation.
--
TedPavlic - 06 Sep 2003
Thanks for the explanation Ted. I've changed the patch so you can use $wikiname. Using simpleUserNameFromSearch_wikiname.diff:
| *Most recent changes* |
%SEARCH{ ".*" regex="on" nosearch="on" nototal="on" order="modified" reverse="on" limit="10" format="| [[$topic]] <br />$date<br />$wikiname |" }%
--
ArthurClemens - 06 Sep 2003
FormattedSearch understands now
$username,
$wikiname (

) and
$wikiusername. This small enhancement makes formatted search consistent with the
TWikiVariables USERNAME,
WIKINAME and
WIKIUSERNAME, respectively.
A slightly modified version (better performance) is now in
TWikiAlphaRelease and at TWiki.org, to be released in
CairoRelease. Documentation at
FormattedSearch is updated as well.
Use the
FormattedSearchFormTesting to test drive this feature. Note that
$username and
$wikiname are identical at TWiki.org.
Index: Search.pm
===================================================================
RCS file: /cvsroot/twiki/twiki/lib/TWiki/Search.pm,v
retrieving revision 1.49
diff -c -r1.49 Search.pm
*** Search.pm 10 Aug 2003 19:52:39 -0000 1.49
--- Search.pm 8 Sep 2003 05:09:30 -0000
***************
*** 519,524 ****
--- 519,525 ----
$tempVal =~ s/\$isodate/&TWiki::revDate2ISO($revDate)/geos;
$tempVal =~ s/\$rev/1.$revNum/gos;
$tempVal =~ s/\$wikiusername/$revUser/gos;
+ $tempVal =~ s/\$wikiname/wikiName($revUser)/geos;
$tempVal =~ s/\$username/&TWiki::wikiToUserName($revUser)/geos;
if( $tempVal =~ m/\$text/ ) {
# expand topic text
***************
*** 771,776 ****
--- 772,786 ----
$theText = "" unless( $theText =~ s/$thePattern/$1/is );
return $theText;
+ }
+
+ #=========================
+ sub wikiName
+ {
+ my( $theWikiUserName ) = @_;
+
+ $theWikiUserName =~ s/^.*\.//o;
+ return $theWikiUserName;
}
#=========================
--
PeterThoeny - 08 Sep 2003
Category:
TWikiPatches