We relaunched the TWiki.org project with an expanded TWiki charter, and we invite you to participate! The TWiki.org Code of Conduct agreement took effect on 27 Oct 2008. We ask existing twiki.org users to opt-in. You need to opt-in to participate in the Blog, Codev, Plugins and TWiki webs. -- PeterThoeny - 27 Oct 2008
Tags:
create new tag
, view all tags

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

Topic revision: r6 - 03 Jan 2006 - 08:41:45 - PeterThoeny
 
TWIKI.NET
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback