Hex Artifact Content
Not logged in

Artifact 5d26252ad0d720d9ec02e9ec44c4fabf94472d02:

File src/tagview.c part of check-in [9c01af2d22] - refactored some /tagview code into more generic bits. Added string_xform.c. by stephan on 2008-02-03 21:56:52.

0000: 2f 2a 0a 2a 2a 20 43 6f 70 79 72 69 67 68 74 20  /*.** Copyright 
0010: 28 63 29 20 32 30 30 37 20 44 2e 20 52 69 63 68  (c) 2007 D. Rich
0020: 61 72 64 20 48 69 70 70 0a 2a 2a 20 43 6f 70 79  ard Hipp.** Copy
0030: 72 69 67 68 74 20 28 63 29 20 32 30 30 38 20 53  right (c) 2008 S
0040: 74 65 70 68 61 6e 20 42 65 61 6c 0a 2a 2a 0a 2a  tephan Beal.**.*
0050: 2a 20 54 68 69 73 20 70 72 6f 67 72 61 6d 20 69  * This program i
0060: 73 20 66 72 65 65 20 73 6f 66 74 77 61 72 65 3b  s free software;
0070: 20 79 6f 75 20 63 61 6e 20 72 65 64 69 73 74 72   you can redistr
0080: 69 62 75 74 65 20 69 74 20 61 6e 64 2f 6f 72 0a  ibute it and/or.
0090: 2a 2a 20 6d 6f 64 69 66 79 20 69 74 20 75 6e 64  ** modify it und
00a0: 65 72 20 74 68 65 20 74 65 72 6d 73 20 6f 66 20  er the terms of 
00b0: 74 68 65 20 47 4e 55 20 47 65 6e 65 72 61 6c 20  the GNU General 
00c0: 50 75 62 6c 69 63 0a 2a 2a 20 4c 69 63 65 6e 73  Public.** Licens
00d0: 65 20 61 73 20 70 75 62 6c 69 73 68 65 64 20 62  e as published b
00e0: 79 20 74 68 65 20 46 72 65 65 20 53 6f 66 74 77  y the Free Softw
00f0: 61 72 65 20 46 6f 75 6e 64 61 74 69 6f 6e 3b 20  are Foundation; 
0100: 65 69 74 68 65 72 0a 2a 2a 20 76 65 72 73 69 6f  either.** versio
0110: 6e 20 32 20 6f 66 20 74 68 65 20 4c 69 63 65 6e  n 2 of the Licen
0120: 73 65 2c 20 6f 72 20 28 61 74 20 79 6f 75 72 20  se, or (at your 
0130: 6f 70 74 69 6f 6e 29 20 61 6e 79 20 6c 61 74 65  option) any late
0140: 72 20 76 65 72 73 69 6f 6e 2e 0a 2a 2a 0a 2a 2a  r version..**.**
0150: 20 54 68 69 73 20 70 72 6f 67 72 61 6d 20 69 73   This program is
0160: 20 64 69 73 74 72 69 62 75 74 65 64 20 69 6e 20   distributed in 
0170: 74 68 65 20 68 6f 70 65 20 74 68 61 74 20 69 74  the hope that it
0180: 20 77 69 6c 6c 20 62 65 20 75 73 65 66 75 6c 2c   will be useful,
0190: 0a 2a 2a 20 62 75 74 20 57 49 54 48 4f 55 54 20  .** but WITHOUT 
01a0: 41 4e 59 20 57 41 52 52 41 4e 54 59 3b 20 77 69  ANY WARRANTY; wi
01b0: 74 68 6f 75 74 20 65 76 65 6e 20 74 68 65 20 69  thout even the i
01c0: 6d 70 6c 69 65 64 20 77 61 72 72 61 6e 74 79 20  mplied warranty 
01d0: 6f 66 0a 2a 2a 20 4d 45 52 43 48 41 4e 54 41 42  of.** MERCHANTAB
01e0: 49 4c 49 54 59 20 6f 72 20 46 49 54 4e 45 53 53  ILITY or FITNESS
01f0: 20 46 4f 52 20 41 20 50 41 52 54 49 43 55 4c 41   FOR A PARTICULA
0200: 52 20 50 55 52 50 4f 53 45 2e 20 20 53 65 65 20  R PURPOSE.  See 
0210: 74 68 65 20 47 4e 55 0a 2a 2a 20 47 65 6e 65 72  the GNU.** Gener
0220: 61 6c 20 50 75 62 6c 69 63 20 4c 69 63 65 6e 73  al Public Licens
0230: 65 20 66 6f 72 20 6d 6f 72 65 20 64 65 74 61 69  e for more detai
0240: 6c 73 2e 0a 2a 2a 0a 2a 2a 20 59 6f 75 20 73 68  ls..**.** You sh
0250: 6f 75 6c 64 20 68 61 76 65 20 72 65 63 65 69 76  ould have receiv
0260: 65 64 20 61 20 63 6f 70 79 20 6f 66 20 74 68 65  ed a copy of the
0270: 20 47 4e 55 20 47 65 6e 65 72 61 6c 20 50 75 62   GNU General Pub
0280: 6c 69 63 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 61  lic.** License a
0290: 6c 6f 6e 67 20 77 69 74 68 20 74 68 69 73 20 6c  long with this l
02a0: 69 62 72 61 72 79 3b 20 69 66 20 6e 6f 74 2c 20  ibrary; if not, 
02b0: 77 72 69 74 65 20 74 6f 20 74 68 65 0a 2a 2a 20  write to the.** 
02c0: 46 72 65 65 20 53 6f 66 74 77 61 72 65 20 46 6f  Free Software Fo
02d0: 75 6e 64 61 74 69 6f 6e 2c 20 49 6e 63 2e 2c 20  undation, Inc., 
02e0: 35 39 20 54 65 6d 70 6c 65 20 50 6c 61 63 65 20  59 Temple Place 
02f0: 2d 20 53 75 69 74 65 20 33 33 30 2c 0a 2a 2a 20  - Suite 330,.** 
0300: 42 6f 73 74 6f 6e 2c 20 4d 41 20 20 30 32 31 31  Boston, MA  0211
0310: 31 2d 31 33 30 37 2c 20 55 53 41 2e 0a 2a 2a 0a  1-1307, USA..**.
0320: 2a 2a 20 41 75 74 68 6f 72 20 63 6f 6e 74 61 63  ** Author contac
0330: 74 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 3a 0a 2a  t information:.*
0340: 2a 20 20 20 64 72 68 40 68 77 61 63 69 2e 63 6f  *   drh@hwaci.co
0350: 6d 0a 2a 2a 20 20 20 68 74 74 70 3a 2f 2f 77 77  m.**   http://ww
0360: 77 2e 68 77 61 63 69 2e 63 6f 6d 2f 64 72 68 2f  w.hwaci.com/drh/
0370: 0a 2a 2a 0a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  .**.************
0380: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0390: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
03a0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
03b0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
03c0: 2a 2a 2a 0a 2a 2a 0a 2a 2a 20 49 6d 70 6c 65 6d  ***.**.** Implem
03d0: 65 6e 74 61 74 69 6f 6e 20 6f 66 20 74 68 65 20  entation of the 
03e0: 54 61 67 20 56 69 65 77 20 70 61 67 65 0a 2a 2f  Tag View page.*/
03f0: 0a 23 69 6e 63 6c 75 64 65 20 3c 61 73 73 65 72  .#include <asser
0400: 74 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 22 63  t.h>.#include "c
0410: 6f 6e 66 69 67 2e 68 22 0a 23 69 6e 63 6c 75 64  onfig.h".#includ
0420: 65 20 22 74 61 67 76 69 65 77 2e 68 22 0a 0a 0a  e "tagview.h"...
0430: 23 69 66 20 31 0a 23 20 20 64 65 66 69 6e 65 20  #if 1.#  define 
0440: 54 41 47 56 49 45 57 5f 44 45 46 41 55 4c 54 5f  TAGVIEW_DEFAULT_
0450: 46 49 4c 54 45 52 20 22 41 4e 44 20 74 2e 74 61  FILTER "AND t.ta
0460: 67 6e 61 6d 65 20 4e 4f 54 20 47 4c 4f 42 20 27  gname NOT GLOB '
0470: 77 69 6b 69 2d 2a 27 20 22 0a 23 65 6c 73 65 0a  wiki-*' ".#else.
0480: 23 20 20 64 65 66 69 6e 65 20 54 41 47 56 49 45  #  define TAGVIE
0490: 57 5f 44 45 46 41 55 4c 54 5f 46 49 4c 54 45 52  W_DEFAULT_FILTER
04a0: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 2a 0a 20 20 4c  .#endif../**.  L
04b0: 69 73 74 73 20 61 6c 6c 20 74 61 67 73 20 6d 61  ists all tags ma
04c0: 74 63 68 69 6e 67 20 74 68 65 20 67 69 76 65 6e  tching the given
04d0: 20 4c 49 4b 45 20 63 6c 61 75 73 65 20 28 77 68   LIKE clause (wh
04e0: 69 63 68 0a 6d 61 79 20 62 65 20 30 29 2e 0a 2a  ich.may be 0)..*
04f0: 2f 0a 73 74 61 74 69 63 20 76 6f 69 64 20 74 61  /.static void ta
0500: 67 76 69 65 77 5f 70 61 67 65 5f 6c 69 73 74 5f  gview_page_list_
0510: 74 61 67 73 28 20 63 68 61 72 20 63 6f 6e 73 74  tags( char const
0520: 20 2a 20 6c 69 6b 65 20 29 0a 7b 0a 20 20 63 68   * like ).{.  ch
0530: 61 72 20 2a 20 6c 69 6b 65 63 6c 61 75 73 65 20  ar * likeclause 
0540: 3d 20 30 3b 0a 20 20 63 6f 6e 73 74 20 69 6e 74  = 0;.  const int
0550: 20 6c 69 6d 69 74 20 3d 20 31 30 3b 0a 20 20 63   limit = 10;.  c
0560: 68 61 72 20 2a 20 6c 69 6d 69 74 73 74 72 20 3d  har * limitstr =
0570: 20 30 3b 0a 20 20 69 66 28 20 6c 69 6b 65 20 26   0;.  if( like &
0580: 26 20 73 74 72 6c 65 6e 28 6c 69 6b 65 29 20 29  & strlen(like) )
0590: 0a 20 20 7b 0a 20 20 20 20 6c 69 6b 65 63 6c 61  .  {.    likecla
05a0: 75 73 65 20 3d 20 6d 70 72 69 6e 74 66 28 20 22  use = mprintf( "
05b0: 41 4e 44 20 74 2e 74 61 67 6e 61 6d 65 20 4c 49  AND t.tagname LI
05c0: 4b 45 20 27 25 25 25 25 25 71 25 25 25 25 27 22  KE '%%%%%q%%%%'"
05d0: 2c 20 6c 69 6b 65 20 29 3b 0a 20 20 20 20 40 20  , like );.    @ 
05e0: 3c 68 32 3e 54 61 67 73 20 6d 61 74 63 68 69 6e  <h2>Tags matchin
05f0: 67 20 5b 25 73 28 6c 69 6b 65 63 6c 61 75 73 65  g [%s(likeclause
0600: 29 5d 3a 3c 2f 68 32 3e 0a 20 20 7d 0a 20 20 65  )]:</h2>.  }.  e
0610: 6c 73 65 0a 20 20 7b 0a 20 20 20 20 6c 69 6d 69  lse.  {.    limi
0620: 74 73 74 72 20 3d 20 6d 70 72 69 6e 74 66 28 20  tstr = mprintf( 
0630: 22 4c 49 4d 49 54 20 25 64 22 2c 20 6c 69 6d 69  "LIMIT %d", limi
0640: 74 20 29 3b 0a 20 20 20 20 40 20 3c 68 32 3e 25  t );.    @ <h2>%
0650: 64 28 6c 69 6d 69 74 29 20 6d 6f 73 74 20 72 65  d(limit) most re
0660: 63 65 6e 74 20 74 61 67 73 3a 3c 2f 68 32 3e 0a  cent tags:</h2>.
0670: 20 20 7d 0a 20 20 63 68 61 72 20 2a 20 73 71 6c    }.  char * sql
0680: 20 3d 20 6d 70 72 69 6e 74 66 28 20 0a 20 20 20   = mprintf( .   
0690: 20 22 53 45 4c 45 43 54 20 74 2e 74 61 67 69 64   "SELECT t.tagid
06a0: 2c 20 74 2e 74 61 67 6e 61 6d 65 2c 20 44 41 54  , t.tagname, DAT
06b0: 45 54 49 4d 45 28 74 78 2e 6d 74 69 6d 65 29 2c  ETIME(tx.mtime),
06c0: 20 62 2e 75 75 69 64 20 22 0a 20 20 20 20 22 46   b.uuid ".    "F
06d0: 52 4f 4d 20 74 61 67 20 74 2c 20 74 61 67 78 72  ROM tag t, tagxr
06e0: 65 66 20 74 78 2c 20 62 6c 6f 62 20 62 20 22 0a  ef tx, blob b ".
06f0: 20 20 20 20 22 57 48 45 52 45 20 28 74 2e 74 61      "WHERE (t.ta
0700: 67 69 64 3d 74 78 2e 74 61 67 69 64 29 20 61 6e  gid=tx.tagid) an
0710: 64 20 28 74 78 2e 73 72 63 69 64 3d 62 2e 72 69  d (tx.srcid=b.ri
0720: 64 29 20 22 0a 20 20 20 20 22 41 4e 44 20 28 74  d) ".    "AND (t
0730: 78 2e 74 61 67 74 79 70 65 20 21 3d 20 30 29 20  x.tagtype != 0) 
0740: 25 73 20 22 0a 20 20 20 20 54 41 47 56 49 45 57  %s ".    TAGVIEW
0750: 5f 44 45 46 41 55 4c 54 5f 46 49 4c 54 45 52 0a  _DEFAULT_FILTER.
0760: 20 20 20 20 22 4f 52 44 45 52 20 42 59 20 74 78      "ORDER BY tx
0770: 2e 6d 74 69 6d 65 20 44 45 53 43 20 25 73 22 2c  .mtime DESC %s",
0780: 0a 20 20 20 20 6c 69 6b 65 63 6c 61 75 73 65 20  .    likeclause 
0790: 3f 20 6c 69 6b 65 63 6c 61 75 73 65 20 3a 20 22  ? likeclause : "
07a0: 20 22 2c 0a 20 20 20 20 6c 69 6d 69 74 73 74 72   ",.    limitstr
07b0: 20 3f 20 6c 69 6d 69 74 73 74 72 20 3a 20 22 20   ? limitstr : " 
07c0: 22 0a 20 20 20 20 29 3b 0a 20 20 69 66 28 20 6c  ".    );.  if( l
07d0: 69 6d 69 74 73 74 72 20 29 20 66 72 65 65 28 6c  imitstr ) free(l
07e0: 69 6d 69 74 73 74 72 29 3b 0a 20 20 69 66 28 20  imitstr);.  if( 
07f0: 6c 69 6b 65 63 6c 61 75 73 65 20 29 20 66 72 65  likeclause ) fre
0800: 65 28 6c 69 6b 65 63 6c 61 75 73 65 29 3b 0a 20  e(likeclause);. 
0810: 20 63 68 61 72 20 63 6f 6e 73 74 20 2a 20 63 6f   char const * co
0820: 6e 73 74 20 63 6f 6c 6e 61 6d 65 73 5b 5d 20 3d  nst colnames[] =
0830: 20 7b 0a 20 20 20 20 22 54 61 67 20 49 44 22 2c   {.    "Tag ID",
0840: 20 22 4e 61 6d 65 22 2c 20 22 54 69 6d 65 73 74   "Name", "Timest
0850: 61 6d 70 22 2c 20 22 56 65 72 73 69 6f 6e 22 0a  amp", "Version".
0860: 20 20 7d 3b 0a 20 20 73 74 72 69 6e 67 5f 75 6e    };.  string_un
0870: 61 72 79 5f 78 66 6f 72 6d 5f 66 20 78 66 5b 5d  ary_xform_f xf[]
0880: 20 3d 20 7b 0a 20 20 20 20 73 74 72 78 66 6f 72   = {.    strxfor
0890: 6d 5f 6c 69 6e 6b 5f 74 6f 5f 74 61 67 69 64 2c  m_link_to_tagid,
08a0: 0a 20 20 20 20 73 74 72 78 66 6f 72 6d 5f 6c 69  .    strxform_li
08b0: 6e 6b 5f 74 6f 5f 74 61 67 6e 61 6d 65 2c 0a 20  nk_to_tagname,. 
08c0: 20 20 20 30 2c 0a 20 20 20 20 73 74 72 78 66 6f     0,.    strxfo
08d0: 72 6d 5f 6c 69 6e 6b 5f 74 6f 5f 75 75 69 64 0a  rm_link_to_uuid.
08e0: 20 20 7d 3b 0a 20 20 64 62 5f 67 65 6e 65 72 69    };.  db_generi
08f0: 63 5f 71 75 65 72 79 5f 76 69 65 77 28 20 73 71  c_query_view( sq
0900: 6c 2c 20 63 6f 6c 6e 61 6d 65 73 2c 20 78 66 20  l, colnames, xf 
0910: 29 3b 0a 20 20 66 72 65 65 28 20 73 71 6c 20 29  );.  free( sql )
0920: 3b 0a 7d 0a 0a 2f 2a 2a 0a 41 20 73 6d 61 6c 6c  ;.}../**.A small
0930: 20 73 65 61 72 63 68 20 66 6f 72 6d 20 77 68 69   search form whi
0940: 63 68 20 66 6f 72 77 61 72 64 73 20 74 6f 20 3f  ch forwards to ?
0950: 6c 69 6b 65 3d 53 45 41 52 43 48 5f 53 54 52 49  like=SEARCH_STRI
0960: 4e 47 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69  NG.*/.static voi
0970: 64 20 74 61 67 76 69 65 77 5f 70 61 67 65 5f 73  d tagview_page_s
0980: 65 61 72 63 68 5f 6d 69 6e 69 66 6f 72 6d 28 76  earch_miniform(v
0990: 6f 69 64 29 7b 0a 20 20 63 68 61 72 20 63 6f 6e  oid){.  char con
09a0: 73 74 20 2a 20 6c 69 6b 65 20 3d 20 50 28 22 6c  st * like = P("l
09b0: 69 6b 65 22 29 3b 0a 20 20 40 20 3c 64 69 76 20  ike");.  @ <div 
09c0: 73 74 79 6c 65 3d 27 66 6f 6e 74 2d 73 69 7a 65  style='font-size
09d0: 3a 73 6d 61 6c 6c 65 72 27 3e 0a 20 20 40 20 3c  :smaller'>.  @ <
09e0: 66 6f 72 6d 20 61 63 74 69 6f 6e 3d 27 2f 74 61  form action='/ta
09f0: 67 76 69 65 77 27 20 6d 65 74 68 6f 64 3d 27 70  gview' method='p
0a00: 6f 73 74 27 3e 0a 20 20 40 20 53 65 61 72 63 68  ost'>.  @ Search
0a10: 20 66 6f 72 20 74 61 67 73 3a 20 0a 20 20 40 20   for tags: .  @ 
0a20: 3c 69 6e 70 75 74 20 74 79 70 65 3d 27 74 65 78  <input type='tex
0a30: 74 27 20 6e 61 6d 65 3d 27 6c 69 6b 65 27 20 76  t' name='like' v
0a40: 61 6c 75 65 3d 27 25 73 28 28 6c 69 6b 65 3f 6c  alue='%s((like?l
0a50: 69 6b 65 3a 22 22 29 29 27 20 73 69 7a 65 3d 27  ike:""))' size='
0a60: 31 30 27 2f 3e 0a 20 20 40 20 3c 69 6e 70 75 74  10'/>.  @ <input
0a70: 20 74 79 70 65 3d 27 73 75 62 6d 69 74 27 2f 3e   type='submit'/>
0a80: 0a 20 20 40 20 3c 2f 66 6f 72 6d 3e 0a 20 20 40  .  @ </form>.  @
0a90: 20 3c 2f 64 69 76 3e 0a 7d 0a 0a 2f 2a 2a 0a 20   </div>.}../**. 
0aa0: 74 61 67 76 69 65 77 5f 70 61 67 65 5f 64 65 66  tagview_page_def
0ab0: 61 75 6c 74 28 29 20 72 65 6e 64 65 72 73 20 74  ault() renders t
0ac0: 68 65 20 64 65 66 61 75 6c 74 20 70 61 67 65 20  he default page 
0ad0: 66 6f 72 20 74 61 67 76 69 65 77 5f 70 61 67 65  for tagview_page
0ae0: 28 29 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f  ()..*/.static vo
0af0: 69 64 20 74 61 67 76 69 65 77 5f 70 61 67 65 5f  id tagview_page_
0b00: 64 65 66 61 75 6c 74 28 76 6f 69 64 29 7b 0a 20  default(void){. 
0b10: 20 74 61 67 76 69 65 77 5f 70 61 67 65 5f 6c 69   tagview_page_li
0b20: 73 74 5f 74 61 67 73 28 20 30 20 29 3b 0a 7d 0a  st_tags( 0 );.}.
0b30: 0a 2f 2a 2a 0a 20 20 4c 69 73 74 73 20 61 6c 6c  ./**.  Lists all
0b40: 20 74 61 67 73 20 6d 61 74 63 68 69 6e 67 20 74   tags matching t
0b50: 68 65 20 67 69 76 65 6e 20 74 61 67 69 64 2e 0a  he given tagid..
0b60: 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 64 20 74  */.static void t
0b70: 61 67 76 69 65 77 5f 70 61 67 65 5f 74 61 67 5f  agview_page_tag_
0b80: 62 79 5f 69 64 28 20 69 6e 74 20 74 61 67 69 64  by_id( int tagid
0b90: 20 29 0a 7b 0a 20 20 40 20 3c 68 32 3e 54 61 67   ).{.  @ <h2>Tag
0ba0: 20 23 25 64 28 74 61 67 69 64 29 3a 3c 2f 68 32   #%d(tagid):</h2
0bb0: 3e 0a 20 20 63 68 61 72 20 2a 20 73 71 6c 20 3d  >.  char * sql =
0bc0: 20 6d 70 72 69 6e 74 66 28 20 0a 20 20 20 20 22   mprintf( .    "
0bd0: 53 45 4c 45 43 54 20 44 49 53 54 49 4e 43 54 20  SELECT DISTINCT 
0be0: 28 74 2e 74 61 67 6e 61 6d 65 29 2c 20 44 41 54  (t.tagname), DAT
0bf0: 45 54 49 4d 45 28 74 78 2e 6d 74 69 6d 65 29 2c  ETIME(tx.mtime),
0c00: 20 62 2e 75 75 69 64 20 22 0a 20 20 20 20 22 46   b.uuid ".    "F
0c10: 52 4f 4d 20 74 61 67 20 74 2c 20 74 61 67 78 72  ROM tag t, tagxr
0c20: 65 66 20 74 78 2c 20 62 6c 6f 62 20 62 20 22 0a  ef tx, blob b ".
0c30: 20 20 20 20 22 57 48 45 52 45 20 28 74 2e 74 61      "WHERE (t.ta
0c40: 67 69 64 3d 25 64 29 20 41 4e 44 20 28 74 2e 74  gid=%d) AND (t.t
0c50: 61 67 69 64 3d 74 78 2e 74 61 67 69 64 29 20 41  agid=tx.tagid) A
0c60: 4e 44 20 28 74 78 2e 73 72 63 69 64 3d 62 2e 72  ND (tx.srcid=b.r
0c70: 69 64 29 20 22 0a 20 20 20 20 54 41 47 56 49 45  id) ".    TAGVIE
0c80: 57 5f 44 45 46 41 55 4c 54 5f 46 49 4c 54 45 52  W_DEFAULT_FILTER
0c90: 0a 20 20 20 20 22 4f 52 44 45 52 20 42 59 20 74  .    "ORDER BY t
0ca0: 78 2e 6d 74 69 6d 65 20 44 45 53 43 22 2c 0a 20  x.mtime DESC",. 
0cb0: 20 74 61 67 69 64 29 3b 0a 20 20 63 68 61 72 20   tagid);.  char 
0cc0: 63 6f 6e 73 74 20 2a 20 63 6f 6e 73 74 20 63 6f  const * const co
0cd0: 6c 6e 61 6d 65 73 5b 5d 20 3d 20 7b 0a 20 20 20  lnames[] = {.   
0ce0: 20 20 20 22 54 61 67 20 4e 61 6d 65 22 2c 20 22     "Tag Name", "
0cf0: 54 69 6d 65 73 74 61 6d 70 22 2c 20 22 56 65 72  Timestamp", "Ver
0d00: 73 69 6f 6e 22 0a 20 20 7d 3b 0a 20 20 73 74 72  sion".  };.  str
0d10: 69 6e 67 5f 75 6e 61 72 79 5f 78 66 6f 72 6d 5f  ing_unary_xform_
0d20: 66 20 78 66 5b 5d 20 3d 20 7b 0a 20 20 20 20 20  f xf[] = {.     
0d30: 20 73 74 72 78 66 6f 72 6d 5f 6c 69 6e 6b 5f 74   strxform_link_t
0d40: 6f 5f 74 61 67 6e 61 6d 65 2c 0a 20 20 20 20 20  o_tagname,.     
0d50: 20 30 2c 0a 20 20 20 20 20 20 73 74 72 78 66 6f   0,.      strxfo
0d60: 72 6d 5f 6c 69 6e 6b 5f 74 6f 5f 75 75 69 64 0a  rm_link_to_uuid.
0d70: 20 20 7d 3b 0a 20 20 64 62 5f 67 65 6e 65 72 69    };.  db_generi
0d80: 63 5f 71 75 65 72 79 5f 76 69 65 77 28 20 73 71  c_query_view( sq
0d90: 6c 2c 20 63 6f 6c 6e 61 6d 65 73 2c 20 78 66 20  l, colnames, xf 
0da0: 29 3b 0a 20 20 66 72 65 65 28 73 71 6c 29 3b 0a  );.  free(sql);.
0db0: 7d 0a 0a 2f 2a 2a 0a 20 20 4c 69 73 74 73 20 61  }../**.  Lists a
0dc0: 6c 6c 20 74 61 67 73 20 6d 61 74 63 68 69 6e 67  ll tags matching
0dd0: 20 74 68 65 20 67 69 76 65 6e 20 74 61 67 20 6e   the given tag n
0de0: 61 6d 65 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76  ame..*/.static v
0df0: 6f 69 64 20 74 61 67 76 69 65 77 5f 70 61 67 65  oid tagview_page
0e00: 5f 74 61 67 5f 62 79 5f 6e 61 6d 65 28 20 63 68  _tag_by_name( ch
0e10: 61 72 20 63 6f 6e 73 74 20 2a 20 74 61 67 6e 61  ar const * tagna
0e20: 6d 65 20 29 0a 7b 0a 20 20 40 20 3c 68 32 3e 54  me ).{.  @ <h2>T
0e30: 61 67 20 27 25 73 28 74 61 67 6e 61 6d 65 29 27  ag '%s(tagname)'
0e40: 3a 3c 2f 68 32 3e 0a 20 20 63 68 61 72 20 2a 20  :</h2>.  char * 
0e50: 73 71 6c 20 3d 20 6d 70 72 69 6e 74 66 28 20 0a  sql = mprintf( .
0e60: 20 20 20 20 22 53 45 4c 45 43 54 20 44 49 53 54      "SELECT DIST
0e70: 49 4e 43 54 20 74 2e 74 61 67 69 64 2c 20 44 41  INCT t.tagid, DA
0e80: 54 45 54 49 4d 45 28 74 78 2e 6d 74 69 6d 65 29  TETIME(tx.mtime)
0e90: 2c 20 62 2e 75 75 69 64 20 22 0a 20 20 20 20 22  , b.uuid ".    "
0ea0: 46 52 4f 4d 20 74 61 67 20 74 2c 20 74 61 67 78  FROM tag t, tagx
0eb0: 72 65 66 20 74 78 2c 20 62 6c 6f 62 20 62 20 22  ref tx, blob b "
0ec0: 0a 20 20 20 20 22 57 48 45 52 45 20 28 74 2e 74  .    "WHERE (t.t
0ed0: 61 67 6e 61 6d 65 3d 27 25 71 27 29 20 41 4e 44  agname='%q') AND
0ee0: 20 28 74 2e 74 61 67 69 64 3d 74 78 2e 74 61 67   (t.tagid=tx.tag
0ef0: 69 64 29 20 41 4e 44 20 28 74 78 2e 73 72 63 69  id) AND (tx.srci
0f00: 64 3d 62 2e 72 69 64 29 20 22 0a 20 20 20 20 54  d=b.rid) ".    T
0f10: 41 47 56 49 45 57 5f 44 45 46 41 55 4c 54 5f 46  AGVIEW_DEFAULT_F
0f20: 49 4c 54 45 52 0a 20 20 20 20 22 4f 52 44 45 52  ILTER.    "ORDER
0f30: 20 42 59 20 74 78 2e 6d 74 69 6d 65 20 44 45 53   BY tx.mtime DES
0f40: 43 22 2c 0a 20 20 20 20 74 61 67 6e 61 6d 65 29  C",.    tagname)
0f50: 3b 0a 20 20 63 68 61 72 20 63 6f 6e 73 74 20 2a  ;.  char const *
0f60: 20 63 6f 6e 73 74 20 63 6f 6c 6e 61 6d 65 73 5b   const colnames[
0f70: 5d 20 3d 20 7b 0a 20 20 20 20 20 20 22 54 61 67  ] = {.      "Tag
0f80: 20 49 44 22 2c 20 22 54 69 6d 65 73 74 61 6d 70   ID", "Timestamp
0f90: 22 2c 20 22 56 65 72 73 69 6f 6e 22 0a 20 20 7d  ", "Version".  }
0fa0: 3b 0a 20 20 73 74 72 69 6e 67 5f 75 6e 61 72 79  ;.  string_unary
0fb0: 5f 78 66 6f 72 6d 5f 66 20 78 66 5b 5d 20 3d 20  _xform_f xf[] = 
0fc0: 7b 0a 20 20 20 20 20 20 73 74 72 78 66 6f 72 6d  {.      strxform
0fd0: 5f 6c 69 6e 6b 5f 74 6f 5f 74 61 67 69 64 2c 0a  _link_to_tagid,.
0fe0: 20 20 20 20 20 20 30 2c 0a 20 20 20 20 20 20 73        0,.      s
0ff0: 74 72 78 66 6f 72 6d 5f 6c 69 6e 6b 5f 74 6f 5f  trxform_link_to_
1000: 75 75 69 64 0a 20 20 7d 3b 0a 20 20 64 62 5f 67  uuid.  };.  db_g
1010: 65 6e 65 72 69 63 5f 71 75 65 72 79 5f 76 69 65  eneric_query_vie
1020: 77 28 20 73 71 6c 2c 20 63 6f 6c 6e 61 6d 65 73  w( sql, colnames
1030: 2c 20 78 66 20 29 3b 0a 20 20 66 72 65 65 28 20  , xf );.  free( 
1040: 73 71 6c 20 29 3b 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a  sql );.}.../*.**
1050: 20 57 45 42 50 41 47 45 3a 20 2f 74 61 67 76 69   WEBPAGE: /tagvi
1060: 65 77 0a 2a 2f 0a 76 6f 69 64 20 74 61 67 76 69  ew.*/.void tagvi
1070: 65 77 5f 70 61 67 65 28 76 6f 69 64 29 7b 0a 20  ew_page(void){. 
1080: 20 6c 6f 67 69 6e 5f 63 68 65 63 6b 5f 63 72 65   login_check_cre
1090: 64 65 6e 74 69 61 6c 73 28 29 3b 0a 20 20 69 66  dentials();.  if
10a0: 28 20 21 67 2e 6f 6b 52 64 57 69 6b 69 20 29 7b  ( !g.okRdWiki ){
10b0: 0a 20 20 20 20 6c 6f 67 69 6e 5f 6e 65 65 64 65  .    login_neede
10c0: 64 28 29 3b 0a 20 20 7d 0a 20 20 73 74 79 6c 65  d();.  }.  style
10d0: 5f 68 65 61 64 65 72 28 22 54 61 67 73 22 29 3b  _header("Tags");
10e0: 0a 20 20 74 61 67 76 69 65 77 5f 70 61 67 65 5f  .  tagview_page_
10f0: 73 65 61 72 63 68 5f 6d 69 6e 69 66 6f 72 6d 28  search_miniform(
1100: 29 3b 0a 20 20 40 20 3c 68 72 2f 3e 0a 20 20 63  );.  @ <hr/>.  c
1110: 68 61 72 20 63 6f 6e 73 74 20 2a 20 63 68 65 63  har const * chec
1120: 6b 20 3d 20 30 3b 0a 20 20 69 66 28 20 30 20 21  k = 0;.  if( 0 !
1130: 3d 20 28 63 68 65 63 6b 20 3d 20 50 28 22 74 61  = (check = P("ta
1140: 67 69 64 22 29 29 20 29 0a 20 20 7b 0a 20 20 20  gid")) ).  {.   
1150: 20 74 61 67 76 69 65 77 5f 70 61 67 65 5f 74 61   tagview_page_ta
1160: 67 5f 62 79 5f 69 64 28 20 61 74 6f 69 28 63 68  g_by_id( atoi(ch
1170: 65 63 6b 29 20 29 3b 0a 20 20 7d 0a 20 20 65 6c  eck) );.  }.  el
1180: 73 65 20 69 66 28 20 30 20 21 3d 20 28 63 68 65  se if( 0 != (che
1190: 63 6b 20 3d 20 50 28 22 6c 69 6b 65 22 29 29 20  ck = P("like")) 
11a0: 29 0a 20 20 7b 0a 20 20 20 20 74 61 67 76 69 65  ).  {.    tagvie
11b0: 77 5f 70 61 67 65 5f 6c 69 73 74 5f 74 61 67 73  w_page_list_tags
11c0: 28 20 63 68 65 63 6b 20 29 3b 0a 20 20 7d 0a 20  ( check );.  }. 
11d0: 20 65 6c 73 65 20 69 66 28 20 30 20 21 3d 20 28   else if( 0 != (
11e0: 63 68 65 63 6b 20 3d 20 50 28 22 6e 61 6d 65 22  check = P("name"
11f0: 29 29 20 29 0a 20 20 7b 0a 20 20 20 20 74 61 67  )) ).  {.    tag
1200: 76 69 65 77 5f 70 61 67 65 5f 74 61 67 5f 62 79  view_page_tag_by
1210: 5f 6e 61 6d 65 28 20 63 68 65 63 6b 20 29 3b 0a  _name( check );.
1220: 20 20 7d 0a 20 20 65 6c 73 65 0a 20 20 7b 0a 20    }.  else.  {. 
1230: 20 20 20 74 61 67 76 69 65 77 5f 70 61 67 65 5f     tagview_page_
1240: 64 65 66 61 75 6c 74 28 29 3b 0a 20 20 7d 0a 20  default();.  }. 
1250: 20 73 74 79 6c 65 5f 66 6f 6f 74 65 72 28 29 3b   style_footer();
1260: 0a 7d 0a 0a 23 75 6e 64 65 66 20 54 41 47 56 49  .}..#undef TAGVI
1270: 45 57 5f 44 45 46 41 55 4c 54 5f 46 49 4c 54 45  EW_DEFAULT_FILTE
1280: 52 0a                                            R.