#!/home/ricjorge/tcl/tclkit # #!/bin/sh # #\ # exec /usr/local/bin/tclkit $0 source utils.tcl # source format.tcl # source worddiff.tcl package require http # ScriptURL defines the URL of this script # set ScriptURL http://mini.net/revhist.cgi set ScriptURL http://www.ricardo-jorge.eti.br/cgi-bin/revhist # TclhistURL defines the URL of the tclhist page # set TclhistURL http://mini.net/tclhist set TclhistURL http://www.ricardo-jorge.eti.br/wikihist # WikiURL defines the URL of the Wiki whose history is being displayed set WikiURL http://www.ricardo-jorge.eti.br/wiki/ # StyleURL defines the URL of the stylesheet used to display this page set StyleURL /wikihist.css # WikiName is the name of the Wiki to be displayed set WikiName "Tcl Wiki em Português" # This proc determines whether the specified page exists. # It does this by looking for the revision history from Tclhist. # If the returned page doesn't match the expected format, there is # no revision history for this page. # Note that this proc uses the revision history rather than the # actual page -- this is done because I'm guessing that the # revision history is a less taxing operation on the server. proc pageExists {PageNumber} { global TclhistURL set URL $TclhistURL/$PageNumber* set Token [::http::geturl $URL] set PageContents [::http::data $Token] ::http::cleanup $Token # The page contents returned should start with a revision number and date. # The call to regexp returns an indication of whether it does. regexp {^\d+ \d+} $PageContents - } # This proc returns the contents of the specified revision number # of the specified Wiki page. If no revision number is specified, # the latest revision is obtained. # As coded, this obtains it from the CVS repository. If desired, # this could be recoded to get it from a tclhist archive. proc getPageContents {PageNumber {RevNumber Latest}} { global TclhistURL if {[string equal $RevNumber "Latest"]} { set URL $TclhistURL/$PageNumber } else { set URL $TclhistURL/$PageNumber.$RevNumber } set Token [::http::geturl $URL] set PageContents [::http::data $Token] ::http::cleanup $Token return $PageContents } # This proc determines the title of the specified Wiki page. proc getPageTitle {PageNumber} { # Grab a copy of the latest version of the page from CVS. # The title is found on the first line of this page. set PageContents [getPageContents $PageNumber] set TitleLine [lindex [split $PageContents \n] 0] # Now, extract the title from the title line regexp {^Title:\s*(.*)$} $TitleLine junk Title return $Title } # This procedure splits long lines into lines no longer than 80 characters proc splitlongline { line } { set maxlen 80 set thisline "" set lines [list] set opentag 0 foreach word [split $line " "] { if { $opentag || [string first "<" $word] > -1 } { set opentag 1 append thisline " $word" if { [string last ">" $word] > [string last "<" $word] } { set opentag 0 } } else { if { [string equal $thisline ""] } { append thisline $word } else { if { [string length "$thisline $word"] > $maxlen } { if { [llength $lines] > 0 } { set thisline "... $thisline" } lappend lines $thisline set thisline $word } else { append thisline " $word" } } } } if { [llength $lines] > 0 } { set thisline "... $thisline" } lappend lines $thisline return [join $lines \n] } # This proc substitutes any special characters with their HTML equivalents. proc quoteHtml {s} { string map { & & < < > > } $s } # For the given Wiki page number, this proc examines Tclhist to determine # the revision number and check-in time of all revisions. The list # returned is ordered from latest revision to earliest revision. # Every revision results in two items in the list, the first being # the minor revision number, and the second being the time that # this revision was checked in, given as the number of # seconds since the Tcl epoch. proc getRevisionList {PageNumber} { global TclhistURL set RevisionList {} set URL $TclhistURL/$PageNumber* set Token [::http::geturl $URL] set AllRevs [::http::data $Token] ::http::cleanup $Token foreach RevisionEntry [split $AllRevs \n] { # Look for all lines with revision numbers. They start with the # revision number and the date in seconds since the Tcl epoch. if {[regexp {^(\d+) (\d+)} $RevisionEntry - RevNumber RevTime]} { lappend RevisionList $RevNumber $RevTime } } return $RevisionList } # This procedure generates the revision history HTML page # for the specified Wiki page number proc genRevisionHistory {PageNumber} { global WikiURL global ScriptURL global StyleURL # Generate the content type for the page (HTML) puts "Content-type: text/html" puts "Pragma: no-cache" puts "" # Determine the title of this page set PageTitle [quoteHtml [getPageTitle $PageNumber]] # Now, generate the page header. puts "" puts "" puts "" puts " Histórico de Revisões de $PageTitle" puts " " puts " " puts " " puts "" puts "" puts "" puts "

" puts " $PageTitle" puts "

" puts " Histórico de Revisões" puts "" puts "

" puts " Legend: (current) = diferença relativa a versão atual," puts " (last) = diferença relativa a versão anterior," puts " date = versão deste dia" puts "

" puts "" # Now, obtain a list of the revisions and the time that they were # checked in. set RevisionList [getRevisionList $PageNumber] # Now that we've got the list of revisions, we need to generate the # revision information to display on the page. puts " " puts "" puts "" puts "" puts "" } # This proc renders the specified revision of the specified page number proc renderPageRevision {PageNumber RevNumber} { global StyleURL global ScriptURL global WikiURL set PageContents [getPageContents $PageNumber $RevNumber] # Extract the page title and check-in date, # then strip off the title, date, and site # (first 4 lines of the contents). set TitleLine [lindex [split $PageContents \n] 0] regexp {^Title:\s*(.*)$} $TitleLine junk PageTitle set PageTitle [quoteHtml $PageTitle] set PageContents [join [lrange [split $PageContents \n] 3 end] \n] # Generate the content type for the page (HTML) puts "Content-type: text/html" puts "Pragma: no-cache" puts "" # Now, generate the page header. puts "" puts "" puts "" puts " Revisão $RevNumber de $PageTitle" puts " " puts " " puts " " puts "" puts "" puts "" puts "

" puts " Revisão $RevNumber de $PageTitle " puts "

" puts "" set HTMLContents\ [lindex [::Wikit::Format::StreamToHTML\ [::Wikit::Format::TextToStream $PageContents]\ "$WikiURL/"] 0] puts $HTMLContents puts "" puts "" puts "" puts "" } # This proc renders the page showing the difference between two revisions # of a page. If only one revision number is given, the difference between # the current page and the specified page is shown. proc renderPageDiff {PageNumber RevNumber {OldRevNumber "Unspecified"}} { global StyleURL global ScriptURL # If the old revision number isn't specified, we do a diff between # the current contents of the page and the specified revision. if { [string equal $OldRevNumber "Unspecified"] } { set PageContents [getPageContents $PageNumber] set OldContents [getPageContents $PageNumber $RevNumber] } else { set PageContents [getPageContents $PageNumber $RevNumber] set OldContents [getPageContents $PageNumber $OldRevNumber] } # Determine the title of the page set TitleLine [lindex [split $PageContents \n] 0] regexp {^Title:\s*(.*)$} $TitleLine junk PageTitle set PageTitle [quoteHtml $PageTitle] # Strip the page header information from the pages set PageContents [join [lrange [split $PageContents \n] 3 end] \n] set OldContents [join [lrange [split $OldContents \n] 3 end] \n] # Generate the HTML description of the differences set LongHtmlChanges [doHtmlDiff context $OldContents $PageContents] # Split long lines set HtmlChanges "" foreach line [split $LongHtmlChanges \n] { append HtmlChanges "[splitlongline $line]\n" } # Generate the content type for the page (HTML) puts "Content-type: text/html" puts "Pragma: no-cache" puts "" # Now, generate the page header. puts "" puts "" puts "" if { [string equal $OldRevNumber "Unspecified"] } { puts " Diferenças entre a última versão e a versão $RevNumber de $PageTitle" } else { puts " Diferenças entre a versão $RevNumber e a versão $OldRevNumber de $PageTitle" } puts " " puts " " puts " " puts "" puts "" puts "" puts "

" if { [string equal $OldRevNumber "Unspecified"] } { puts " Diferenças entre a última versão e a versão $RevNumber de $PageTitle " } else { puts " Diferenças entre a versão $RevNumber e a versão $OldRevNumber de $PageTitle " } puts "

" puts {

Legend:

gray text: context matter
 red text: old text, or that which has been removed.
 green text: new text, interesting new knowledge.
 yellow text: new text, brand new page, interestly fresh knowledge.
} puts "

" puts " Diferenças:" puts "

" puts "" # Display the differences if { [string length $HtmlChanges] == 0 } { puts "

" puts " Não existem diferenças entre as duas versões da página." puts "

" puts "" } else { puts "
$HtmlChanges
" puts "" } puts "" puts "" puts "" } set env(PATH_INFO) {revhist/15} catch { if { [info exists env(PATH_INFO)] } { set PathInfo [file tail $env(PATH_INFO)] } else { set PathInfo {} } set ShowInstructions false set NoSuchFile false if { [regexp {^(\d+)(\D)(\d*)$} $PathInfo - page sep rev] } { if { [pageExists $page] } { switch -- $sep { . { renderPageRevision $page $rev } - { renderPageDiff $page $rev } default { set ShowInstructions true } } } else { set NoSuchFile true } } elseif { [regexp {^(\d+)(\D)(\d*)(\D)(\d*)$} $PathInfo\ - page sep1 rev1 sep2 rev2] } { if { [pageExists $page] } { if { ( $sep1 == "-" ) && ( $sep2 == "-" ) } { renderPageDiff $page $rev1 $rev2 } else { set ShowInstructions true } } else { set NoSuchFile true } } elseif { [regexp {^(\d+)$} $PathInfo - page] } { if { [pageExists $page] } { genRevisionHistory $page } else { set NoSuchFile true } } else { set ShowInstructions true } if { $ShowInstructions } { puts "Content-type: text/plain" puts "Pragma: no-cache" puts " Este é o histórico de revisões de: $WikiName Exemplos: Ver o histórico de revisões da página 12: $ScriptURL/12 Recuperar a versão 5 da página 12: $ScriptURL/12.5 Comparar a versão 5 da página 12 com a última versão: $ScriptURL/12-5 Comparar a versão 5 da página 12 com a versão 2: $ScriptURL/12-5-2 " } elseif { $NoSuchFile } { puts "Content-type: text/plain" puts "Pragma: no-cache" puts "" puts "Não existe histórico de revisões, neste Wiki, para a página $page." } } err if 0 { puts #################### puts $err puts $errorInfo }