Implemented: Topic Create Date and User in Formatted Search

Add new variables to the FormattedSearch:

$createdate Time stamp of topic revision 1.1
$createusername Login name of topic revision 1.1, e.g. jsmith
$createwikiname Wiki user name of topic revision 1.1, e.g. JohnSmith
$createwikiusername Wiki user name of topic revision 1.1, e.g. Main.JohnSmith

Contributors:
-- CoreyFruitman - 01 May 2002
-- SvenDowideit - 22 Feb 2004
-- PeterThoeny - 05 Mar 2004

Adding this code lets users use $createdate in a Formatted Search to indicate when version 1.1 was created.

A few important notes:

  • This code supports the changes in SettingCorrectTimeZone. Its output is in local (server) time
  • It can easily be changed to GMT
  • It works well -- but there is, no doubt, a more efficient way to do this
  • Any widespread implementation should probably be coupled with the addition of $createauthor to get the creator of r1.1. That could be written in a very similar manner.

$createdate queries RCS for r1.1 information, then filters out the date and formats it.

Here's the code:

============= Search.pm
...
 # build the hashes for date and author
 foreach( @topicList ) {
 my $tempVal = $_;
 # FIXME should be able to get data from topic
 my( $meta, $text ) = &TWiki::Store::readTopic( $thisWebName, $tempVal );
 my ( $revdate, $revuser, $revnum ) = &TWiki::Store::getRevisionInfoFromMeta( $thisWebName, $tempVal, $meta, "isoLocalTimeFormat" ); # CFFLAG -- Changed: last arg was 1. Show $date revision in local time format; Corey Fruitman 30 Apr 2002
 $topicRevUser{ $tempVal } = &TWiki::userToWikiName( $revuser );
 $topicRevDate{ $tempVal } = $revdate;
 $topicRevNum{ $tempVal } = $revnum;
 $topicAllowView{ $tempVal } = &TWiki::Access::checkAccessPermission( "view", $TWiki::WikiUserName, $text, $tempVal, $thisWebName );
 }
 
 # sort by date (second time if exercise), Schwartzian Transform
 if( $revSort ) {
...
 
 $tempVal =~ s/\$date/$revDate/gos;
 $tempVal =~ s/\$isodate/&TWiki::revDate2ISO($revDate)/geos;
 $tempVal =~ s/\$rev/1.$revNum/gos;
 $tempVal =~ s/\$Wikiusername/$revUser/gos;
 $tempVal =~ s/\$username/&TWiki::WikiToUserName($revUser)/geos;
 
#CFFLAG -- allow date of topic creation to be shown in formatted search; Added 30 Apr 2002, Corey Fruitman
 
 $tempVal =~ s/\$createdate/&topicCreateDate($thisWebName, $topic)/geos;
 
 } else {
 $tempVal = $repeatText;
 }
 $tempVal =~ s/%WEB%/$thisWebName/go;
 $tempVal =~ s/%TOPICNAME%/$topic/go;
 $tempVal =~ s/%LOCKED%/$locked/o;
 $tempVal =~ s/%TIME%/$revDate/o;
...
 
#===========================
#CFFLAG -- 30 Apr 2002, Corey Fruitman
# This sub gets the date from revision 1.1 (in GM time) of the given topic, translates it into LOCAL time and formats it into dd Mon yyyy - hh:m
m
sub topicCreateDate
{
 my( $theWebName, $theTopic ) = @_;
 if( ! $theWebName ) {
 $theWebName = $TWiki::webName;
 }
 my $tmp= $TWiki::revHistCmd;
 
 my $attachment = "";
 
 my $fileName = TWiki::Store::getFileName( $theWebName, $theTopic, $attachment);
 
 my $rcsfilename = TWiki::Store::getFileName( $theWebName, $theTopic, $attachment, ",v" );
 if( ! -e $rcsfilename ) {
 return "";
 }
 # Narrow RCS log to revision 1.1 only and...
 $tmp =~ s/rlog/rlog -r1.1/;
 # ... remove the -h flag.
 $tmp =~ s/-h//;
 
 $tmp =~ s/%FILENAME%/$rcsfilename/;
 $tmp =~ /(.*)/;
 my $cmd = 1ドル; # now safe, so untaint variable
 $tmp = `$cmd`;
 _traceExec( $cmd, $tmp );
 $tmp =~ /date: (.*?);/;
 if( ( $tmp ) && ( 1ドル ) ) {
 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(TWiki::revDate2EpSecs(1ドル));
 $year += 1900;
 my @monthTranslation=("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
 $mon = $monthTranslation[$mon];
 return sprintf ("%02d %s %04d - %02d:%02d", $mday, $mon, $year, $hour, $min);
 } else {
 return "";
 }
 
}
 

-- CoreyFruitman - 01 May 2002

If there are no objections, I will merge this into Cairo (with appropriate changes for DISPLAYTIME, and $createauthor)

-- SvenDowideit - 22 Feb 2004

The actual cairo implementation is much simpler, both $createdate and $createauthor are commited into Cairo cvs

-- SvenDowideit - 01 Mar 2004

I made some performance improvements:

  • Topic info of rev 1.1 only gets pulled when needed
  • Topic info of rev 1.1 gets cached

I also changed the syntax to make it consistent with the existing $date, $username, $wikiname, $wikiusername. Sven, I hope this is OK.

Change is in TWikiAlphaRelease.

-- PeterThoeny - 05 Mar 2004

you beat me to it wink I was going to look at exactly that tomorrow smile

-- SvenDowideit - 05 Mar 2004

Edit | Attach | (削除) Watch (削除ここまで) | Print version | History : r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r6 - 2006年01月03日 - PeterThoeny
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-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.

AltStyle によって変換されたページ (->オリジナル) /