Tags:
create new tag
view all tags

Implemented: New $wikiname variable in format parameter of formatted search

Summary: FormattedSearch understands now $username, $wikiname (NEW) 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:

WebStatistics
2024-02-07 - 08:00
TWikiAdminGroup
TWikiOrgStatistics
2024-02-01 - 08:36
PeterThoeny
PrinceXML
2023-09-09 - 00:35
JamesPaden

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 (NEW) 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

Topic attachments
I Attachment History Action Size Date Who Comment
Unknown file formatdiff simpleUserNameFromSearch.diff r1 manage 0.7 K 2003-09-05 - 22:26 UnknownUser Patch file to get a short name from a search
Unknown file formatdiff simpleUserNameFromSearch_wikiname.diff r1 manage 0.7 K 2003-09-06 - 19:26 UnknownUser same patch but uses $wikiname
Edit | Attach | Watch | Print version | History: r13 < r12 < r11 < r10 < r9 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r13 - 2004-01-03 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.