
# Outputs a textual /changelog
proc webpage_changelog {} {
  html "<!-- NEWS-style timeline --> <meta http-equiv=\"Content-Type\" content=\"text/plain\"> <pre>\n\n";
  set version "trunk"
  puts "$version (unreleased)\n";
  query {
     SELECT event.mtime, tag.tagname, MAX(tag.tagid), DATE(event.mtime) AS d,
            REPLACE(TRIM(REPLACE(event.comment, char(10,10), char(10)), char(8,10,13,32)), char(10), char(10,32,32,32)) AS comment
     FROM event
      LEFT JOIN tagxref ON event.objid=tagxref.rid
      LEFT JOIN tag ON tagxref.tagid=tag.tagid
     WHERE type='ci'
     GROUP BY objid
     ORDER BY event.mtime DESC
     LIMIT 750
  } {
     if {[regexp {^sym-.*\d+\.\d+} $tagname]} {
        for {} {[string length $tagname] >= 3 && [regexp {^\d+\.} $tagname] == 0} {} {
          set tagname [string range $tagname 1 100]
        }
        puts "\n$tagname ($d)\n";
     }
     puts " * $comment\n";
  }
  puts "\n\n";
}

# Alternative to /raw trunk file access without ?name=uuid,
# Doesn't work with CONTENT() yet.
proc webpage_cat {} {
  set name [getParameter name ""]
  if {![string length $name]} { puts "No filename given."; break; }
  query {
     SELECT uuid
     FROM blob LEFT JOIN mlink ON blob.rid=mlink.fid
               LEFT JOIN filename ON mlink.fnid=filename.fnid
     WHERE name = $name
     ORDER BY rid DESC LIMIT 1
  } { html [artifact "$uuid"]; }
}

# Generate a text/uri-list for available files
proc webpage_uri-list {} {
  html "# Fossil latest file references <pre>\r\n"
  query {
     SELECT filename.name, uuid
     FROM blob LEFT JOIN mlink ON blob.rid=mlink.fid LEFT JOIN filename ON mlink.fnid=filename.fnid
     GROUP BY filename.name  ORDER BY rid DESC
  } { html "$name?name=$uuid\r\n" }
}

# Invokes web request page procs
proc webpage_hook {} {
  #if {! [anycap ro]} { break }
  catch { "webpage_$::web_name"; return -code 2 found; } rc
  if {"$rc" eq "found"} { break continue }
}

