To use the links with the current page the following can be done:
<a href="wiki.pl?action=browse&id=.Id&embed=1">Printer Friendly</a>The .Id is the magic bit. Note that HTMLLinks will have to be on, however it could still be done with a full path and http link to the wiki.pl.
To create this the variable $CurrentPageId was created and set when delivering the page you are looking at. This can then be used where ever the page rendering is done by subsituting the .Id with this page name. (I found out later that the variable $OpenPageName may have served just as well).
These links are more useful with the SideMenu patch, but they can be used in the content of normal pages as well.
.Sig feature is added as well. If you add this to your edits when they are saved it will be replaced with your -- <user name> <date and time>. I have thought that this would be better if it was .SignOff?, as I worry that this would be accidentally typed in. However I will leave it as the small and fast to type version until I get some complaints. (grin).
.User is added to return the current user name.
Also .Search has been added. This allows a search form to be added where you want it. I have also added the improved search output that can be found at WikiPatches/BetterSearchOutput, but I added a few changes of my own.
Given I add a number of special pages that begin with . they are not listed in the site listings.
--- wiki.1.0.0.pl Thu Sep 12 10:53:14 2002 +++ wikipatch.SpecialLinksOffTopBar.pl Thu Jan 22 10:39:30 2004 @@ -59,7 +59,7 @@ use vars qw(%Page %Section %Text %InterSite %SaveUrl %SaveNumUrl %KeptRevisions %UserCookie %SetCookie %UserData %IndexHash %Translate %LinkIndex $InterSiteInit $SaveUrlIndex $SaveNumUrlIndex $MainPage - $OpenPageName @KeptList @IndexList $IndexInit $TableMode + $OpenPageName @KeptList @IndexList $IndexInit $TableMode $CurrentPageId $q $Now $UserID $TimeZoneOffset $ScriptName $BrowseCode $OtherCode $AnchoredLinkPattern @HeadingNumbers $TableOfContents $QuotedFullUrl $ConfigError $UploadPattern ); @@ -422,6 +422,12 @@ return 0; } &InitCookie(); # Reads in user data + $CurrentPageId = $HomePage; + if (&GetParam('action', '')) { + $CurrentPageId = &GetParam('action', ''); + } elsif (&GetParam('keywords', '')) { + $CurrentPageId = &GetParam('keywords', ''); + } return 1; } @@ -1480,8 +1486,10 @@ $bartext .= " | " . &GetPageLink($main); } $bartext .= " | " . &GetPageLink($RCName); - $bartext .= " | " . &GetPrefsLink(); - if ($UseUpload && &UserCanUpload()) { + if (!$HtmlLinks) { + $bartext .= " | " . &GetPrefsLink(); + } + if (!$HtmlLinks && $UseUpload && &UserCanUpload()) { $bartext .= " | " . &GetUploadLink(); } if (&GetParam("linkrandom", 0)) { @@ -1629,6 +1637,8 @@ } s/\<tt\>(.*?)\<\/tt\>/<tt>$1<\/tt>/gis; # <tt> (MeatBall) s/\<br\>/<br>/gi; # Allow simple line break anywhere + s/\.Id/$CurrentPageId/g; # Allow link to use current page + s/\.User/&GetParam("username", "")/gie; # Allow link have the current UserName. if ($HtmlLinks) { s/\<A(\s[^<>]+?)\>(.*?)\<\/a\>/&StoreHref($1, $2)/gise; } @@ -1674,6 +1684,7 @@ } else { s/----+/<hr class=wikiline>/g; } + s/\.Search/&GetSearchForm()/ge; } if ($doLines) { # 0 = no line-oriented, 1 or 2 = do line-oriented # The quote markup patterns avoid overlapping tags (with 5 quotes) @@ -1960,7 +1971,7 @@ if ($BracketImg && $useImage && &ImageAllowed($text)) { $text = "<img src=\"$text\">"; } else { - $text = "[$text]"; + $text = "$text°"; # Allows for nicer display of external links in menus etc. } return &StoreRaw("<a href=\"$url\">$text</a>"); } @@ -3719,7 +3730,7 @@ } print &GetHeader('', &QuoteHtml(Ts('Search for: %s', $string)), ''); print '<br>'; - &PrintPageList(&SearchTitleAndBody($string)); + &PrintSearchResults($string,&SearchTitleAndBody($string)) ; print &GetCommonFooter(); } @@ -3740,10 +3751,16 @@ my $pagename; print "<h2>", Ts('%s pages found:', ($#_ + 1)), "</h2>\n"; + my $pagesSkipped = 0; foreach $pagename (@_) { + if ($pagename =~ /(^\.|\/\.)/) { # Dont do special pages, OR special subpages are OK. + $pagesSkipped++; + next; + } print ".... " if ($pagename =~ m|/|); print &GetPageLink($pagename), "<br>\n"; } + print "\n<h2>", Ts('%s special pages hidden:', $pagesSkipped), "</h2>"; } sub DoLinks { @@ -3885,6 +3902,62 @@ return @links; } +sub PrintSearchResults { + my ( $searchstring, @results ) = @_ ; # inputs + my $output; + my $name; + my $pageText; + my ($t, $j, $jsnippet, $start, $end); + my $snippetlen = 100; + my $maxsnippets = 4; + my $pagesFound = $#results + 1; + + foreach $name (@results) { + if ($name =~ /^\./) { # Dont do special pages, but special subpages are OK. + $pagesFound--; + next; + } + &OpenPage($name); + &OpenDefaultText(); + $pageText = &QuoteHtml($Text{'text'}); + $pageText =~ s/$FS//g; # Remove separators (paranoia) + $pageText =~ s/[\s]+/ /g; # Shrink whitespace + $pageText =~ s/([-_=\\*\\.]){10,}/$1$1$1$1$1/g ; # e.g. shrink "----------" + foreach $t (@HtmlPairs, "pre", "nowiki", "code" ) { + $pageText =~ s/\<$t(\s[^<>]+?)?\>(.*?)\<\/$t\>/$2/gis; + } + foreach $t (@HtmlSingle) { + $pageText =~ s/\<$t(\s[^<>]+?)?\>//gi; + } + $output .= "\n<div class='wikisearch'>\n" ; + $output .= "<p><b>" . &GetPageLink($name) . "</b><br>\n" ; + $j = index( $pageText, " ", $snippetlen ) ; # end on word boundary + $output .= substr( $pageText, 0, $j ) . " <b>...</b> " ; + $pageText = substr( $pageText, $j ) ; # to avoid rematching + $jsnippet = 0 ; + while ( $jsnippet < $maxsnippets + && $pageText =~ m/($searchstring)/i ) { # captures match as $1 + $jsnippet++ ; # paranoid about looping + if ( ($j = index( $pageText, $1 )) > -1 ) { # get index of match + $start = index( $pageText, " ", $j-($snippetlen/2) ) ; + $start = 0 if ( $start == -1 ) ; + $end = index( $pageText, " ", $j+($snippetlen/2) ) ; + $end = length( $pageText ) if ( $end == -1 ) ; + $t = substr( $pageText, $start, $end-$start ) ; + $output .= $t . " <b>...</b> " ; + $pageText = substr( $pageText, $end ) ; + } + } + $output .= "<br><i><font color=gray>" + . int((length($pageText)/1024)+1) . "K - " . T('Last edited') . " " + . &TimeToText($Section{ts}) . " " . T('by') . " " + . &GetAuthorLink( $Section{'host'}, $Section{'username'}, $Section{'id'} ) + . "</font></i><br></p></div>" ; + } + print "\n<h2>", Ts('%s pages found:', $pagesFound), "</h2>"; + print $output; +} + sub DoPost { my ($editDiff, $old, $newAuthor, $pgtime, $oldrev, $preview, $user); my $string = &GetParam("text", undef); @@ -3914,6 +3987,9 @@ if (length($summary) > 300) { # Too long (longer than form allows) $summary = substr($summary, 0, 300); } + my ($sec, $min, $hour, $mday, $mon, $year, $wday) = localtime(); + my $signoff = "--" . &GetParam("username", "") . " " . sprintf("%3s, %04d/%02d/%02d %02d:%02d", ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")[$wday], $year+1900, $mon+1, $mday, $hour, $min); + $string =~ s/\.Sig/$signoff/g; # Add a newline to the end of the string (if it doesn't have one) $string .= "\n" if (!($string =~ /\n$/)); # Lock before getting old page to prevent races