Hex Artifact Content
Not logged in

Artifact 527b17089fed630f668a5a7de3fa226f61afea77:

File src/tagview.c part of check-in [007d1ce44f] - Rename admin_sql_page.c to admin.c. Refactor the strxform functions into SQL functions. Refactor the db_generic_query_view() routine. Fix multiple security vulnerabilities. Bring the code closer into compliance with style guidelines. by drh on 2008-02-07 15:08:02.

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 0a 2a 2a 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 2a 2a 20 6d 61 79 20 62 65 20 30 29  ich.** may be 0)
04f0: 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 64  ..*/.static void
0500: 20 74 61 67 76 69 65 77 5f 70 61 67 65 5f 6c 69   tagview_page_li
0510: 73 74 5f 74 61 67 73 28 63 6f 6e 73 74 20 63 68  st_tags(const ch
0520: 61 72 20 2a 7a 4c 69 6b 65 29 7b 0a 20 20 63 68  ar *zLike){.  ch
0530: 61 72 20 2a 7a 4c 69 6b 65 43 6c 61 75 73 65 20  ar *zLikeClause 
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 7a 4c 69 6d 69 74 20 3d 20 30 3b  har *zLimit = 0;
0570: 0a 20 20 63 68 61 72 20 2a 7a 53 71 6c 3b 0a 0a  .  char *zSql;..
0580: 20 20 69 66 28 20 7a 4c 69 6b 65 20 26 26 20 7a    if( zLike && z
0590: 4c 69 6b 65 5b 30 5d 20 29 7b 0a 20 20 20 20 7a  Like[0] ){.    z
05a0: 4c 69 6b 65 43 6c 61 75 73 65 20 3d 20 6d 70 72  LikeClause = mpr
05b0: 69 6e 74 66 28 20 22 41 4e 44 20 74 2e 74 61 67  intf( "AND t.tag
05c0: 6e 61 6d 65 20 4c 49 4b 45 20 27 25 25 25 71 25  name LIKE '%%%q%
05d0: 25 27 22 2c 20 7a 4c 69 6b 65 20 29 3b 0a 20 20  %'", zLike );.  
05e0: 20 20 7a 4c 69 6d 69 74 20 3d 20 22 22 3b 0a 20    zLimit = "";. 
05f0: 20 20 20 40 20 3c 68 32 3e 54 61 67 73 20 6d 61     @ <h2>Tags ma
0600: 74 63 68 69 6e 67 20 5b 25 68 28 7a 4c 69 6b 65  tching [%h(zLike
0610: 43 6c 61 75 73 65 29 5d 3a 3c 2f 68 32 3e 0a 20  Clause)]:</h2>. 
0620: 20 7d 65 6c 73 65 7b 0a 20 20 20 20 7a 4c 69 6d   }else{.    zLim
0630: 69 74 20 3d 20 6d 70 72 69 6e 74 66 28 20 22 4c  it = mprintf( "L
0640: 49 4d 49 54 20 25 64 22 2c 20 6c 69 6d 69 74 20  IMIT %d", limit 
0650: 29 3b 0a 20 20 20 20 7a 4c 69 6b 65 43 6c 61 75  );.    zLikeClau
0660: 73 65 20 3d 20 22 22 3b 0a 20 20 20 20 40 20 3c  se = "";.    @ <
0670: 68 32 3e 25 64 28 6c 69 6d 69 74 29 20 6d 6f 73  h2>%d(limit) mos
0680: 74 20 72 65 63 65 6e 74 20 74 61 67 73 3a 3c 2f  t recent tags:</
0690: 68 32 3e 0a 20 20 7d 0a 20 20 7a 53 71 6c 20 3d  h2>.  }.  zSql =
06a0: 20 6d 70 72 69 6e 74 66 28 20 0a 20 20 20 20 22   mprintf( .    "
06b0: 53 45 4c 45 43 54 20 22 0a 20 20 20 20 22 20 20  SELECT ".    "  
06c0: 20 6c 69 6e 6b 74 61 67 69 64 28 74 2e 74 61 67   linktagid(t.tag
06d0: 69 64 29 20 41 53 20 27 54 61 67 20 49 44 27 2c  id) AS 'Tag ID',
06e0: 22 0a 20 20 20 20 22 20 20 20 6c 69 6e 6b 74 61  ".    "   linkta
06f0: 67 6e 61 6d 65 28 74 2e 74 61 67 6e 61 6d 65 29  gname(t.tagname)
0700: 20 41 53 20 27 4e 61 6d 65 27 2c 22 0a 20 20 20   AS 'Name',".   
0710: 20 22 20 20 20 44 41 54 45 54 49 4d 45 28 74 78   "   DATETIME(tx
0720: 2e 6d 74 69 6d 65 29 20 41 53 20 27 54 69 6d 65  .mtime) AS 'Time
0730: 73 74 61 6d 70 27 2c 22 0a 20 20 20 20 22 20 20  stamp',".    "  
0740: 20 6c 69 6e 6b 75 75 69 64 28 62 2e 75 75 69 64   linkuuid(b.uuid
0750: 29 20 41 53 20 27 56 65 72 73 69 6f 6e 27 22 0a  ) AS 'Version'".
0760: 20 20 20 20 22 20 20 46 52 4f 4d 20 74 61 67 20      "  FROM tag 
0770: 74 2c 20 74 61 67 78 72 65 66 20 74 78 2c 20 62  t, tagxref tx, b
0780: 6c 6f 62 20 62 20 22 0a 20 20 20 20 22 20 57 48  lob b ".    " WH
0790: 45 52 45 20 74 2e 74 61 67 69 64 3d 74 78 2e 74  ERE t.tagid=tx.t
07a0: 61 67 69 64 20 41 4e 44 20 74 78 2e 73 72 63 69  agid AND tx.srci
07b0: 64 3d 62 2e 72 69 64 22 0a 20 20 20 20 22 20 20  d=b.rid".    "  
07c0: 20 41 4e 44 20 74 78 2e 74 61 67 74 79 70 65 21   AND tx.tagtype!
07d0: 3d 30 20 25 73 20 22 0a 20 20 20 20 54 41 47 56  =0 %s ".    TAGV
07e0: 49 45 57 5f 44 45 46 41 55 4c 54 5f 46 49 4c 54  IEW_DEFAULT_FILT
07f0: 45 52 0a 20 20 20 20 22 20 4f 52 44 45 52 20 42  ER.    " ORDER B
0800: 59 20 74 78 2e 6d 74 69 6d 65 20 44 45 53 43 20  Y tx.mtime DESC 
0810: 25 73 22 2c 0a 20 20 20 20 7a 4c 69 6b 65 43 6c  %s",.    zLikeCl
0820: 61 75 73 65 2c 20 7a 4c 69 6d 69 74 0a 20 20 29  ause, zLimit.  )
0830: 3b 0a 20 20 64 62 5f 67 65 6e 65 72 69 63 5f 71  ;.  db_generic_q
0840: 75 65 72 79 5f 76 69 65 77 28 7a 53 71 6c 2c 20  uery_view(zSql, 
0850: 31 29 3b 0a 20 20 66 72 65 65 28 7a 53 71 6c 29  1);.  free(zSql)
0860: 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 41 20 73 6d 61  ;.}../*.** A sma
0870: 6c 6c 20 73 65 61 72 63 68 20 66 6f 72 6d 20 77  ll search form w
0880: 68 69 63 68 20 66 6f 72 77 61 72 64 73 20 74 6f  hich forwards to
0890: 20 3f 6c 69 6b 65 3d 53 45 41 52 43 48 5f 53 54   ?like=SEARCH_ST
08a0: 52 49 4e 47 0a 2a 2f 0a 73 74 61 74 69 63 20 76  RING.*/.static v
08b0: 6f 69 64 20 74 61 67 76 69 65 77 5f 70 61 67 65  oid tagview_page
08c0: 5f 73 65 61 72 63 68 5f 6d 69 6e 69 66 6f 72 6d  _search_miniform
08d0: 28 76 6f 69 64 29 7b 0a 20 20 63 68 61 72 20 63  (void){.  char c
08e0: 6f 6e 73 74 20 2a 20 6c 69 6b 65 20 3d 20 50 28  onst * like = P(
08f0: 22 6c 69 6b 65 22 29 3b 0a 20 20 40 20 3c 64 69  "like");.  @ <di
0900: 76 20 73 74 79 6c 65 3d 27 66 6f 6e 74 2d 73 69  v style='font-si
0910: 7a 65 3a 73 6d 61 6c 6c 65 72 27 3e 0a 20 20 40  ze:smaller'>.  @
0920: 20 3c 66 6f 72 6d 20 61 63 74 69 6f 6e 3d 27 2f   <form action='/
0930: 74 61 67 76 69 65 77 27 20 6d 65 74 68 6f 64 3d  tagview' method=
0940: 27 70 6f 73 74 27 3e 0a 20 20 40 20 53 65 61 72  'post'>.  @ Sear
0950: 63 68 20 66 6f 72 20 74 61 67 73 3a 20 0a 20 20  ch for tags: .  
0960: 40 20 3c 69 6e 70 75 74 20 74 79 70 65 3d 27 74  @ <input type='t
0970: 65 78 74 27 20 6e 61 6d 65 3d 27 6c 69 6b 65 27  ext' name='like'
0980: 20 76 61 6c 75 65 3d 27 25 68 28 28 6c 69 6b 65   value='%h((like
0990: 3f 6c 69 6b 65 3a 22 22 29 29 27 20 73 69 7a 65  ?like:""))' size
09a0: 3d 27 31 30 27 2f 3e 0a 20 20 40 20 3c 69 6e 70  ='10'/>.  @ <inp
09b0: 75 74 20 74 79 70 65 3d 27 73 75 62 6d 69 74 27  ut type='submit'
09c0: 2f 3e 0a 20 20 40 20 3c 2f 66 6f 72 6d 3e 0a 20  />.  @ </form>. 
09d0: 20 40 20 3c 2f 64 69 76 3e 0a 7d 0a 0a 2f 2a 0a   @ </div>.}../*.
09e0: 2a 2a 20 74 61 67 76 69 65 77 5f 70 61 67 65 5f  ** tagview_page_
09f0: 64 65 66 61 75 6c 74 28 29 20 72 65 6e 64 65 72  default() render
0a00: 73 20 74 68 65 20 64 65 66 61 75 6c 74 20 70 61  s the default pa
0a10: 67 65 20 66 6f 72 20 74 61 67 76 69 65 77 5f 70  ge for tagview_p
0a20: 61 67 65 28 29 2e 0a 2a 2f 0a 73 74 61 74 69 63  age()..*/.static
0a30: 20 76 6f 69 64 20 74 61 67 76 69 65 77 5f 70 61   void tagview_pa
0a40: 67 65 5f 64 65 66 61 75 6c 74 28 76 6f 69 64 29  ge_default(void)
0a50: 7b 0a 20 20 74 61 67 76 69 65 77 5f 70 61 67 65  {.  tagview_page
0a60: 5f 6c 69 73 74 5f 74 61 67 73 28 20 30 20 29 3b  _list_tags( 0 );
0a70: 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 4c 69 73 74 73 20  .}../*.** Lists 
0a80: 61 6c 6c 20 74 61 67 73 20 6d 61 74 63 68 69 6e  all tags matchin
0a90: 67 20 74 68 65 20 67 69 76 65 6e 20 74 61 67 69  g the given tagi
0aa0: 64 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69  d..*/.static voi
0ab0: 64 20 74 61 67 76 69 65 77 5f 70 61 67 65 5f 74  d tagview_page_t
0ac0: 61 67 5f 62 79 5f 69 64 28 20 69 6e 74 20 74 61  ag_by_id( int ta
0ad0: 67 69 64 20 29 7b 0a 20 20 63 68 61 72 20 2a 7a  gid ){.  char *z
0ae0: 53 71 6c 3b 0a 20 20 40 20 3c 68 32 3e 54 61 67  Sql;.  @ <h2>Tag
0af0: 20 23 25 64 28 74 61 67 69 64 29 3a 3c 2f 68 32   #%d(tagid):</h2
0b00: 3e 0a 20 20 7a 53 71 6c 20 3d 20 6d 70 72 69 6e  >.  zSql = mprin
0b10: 74 66 28 20 0a 20 20 20 20 22 53 45 4c 45 43 54  tf( .    "SELECT
0b20: 20 44 49 53 54 49 4e 43 54 22 0a 20 20 20 20 22   DISTINCT".    "
0b30: 20 20 20 20 20 20 20 6c 69 6e 6b 74 61 67 6e 61         linktagna
0b40: 6d 65 28 74 2e 74 61 67 6e 61 6d 65 29 20 41 53  me(t.tagname) AS
0b50: 20 27 54 61 67 20 4e 61 6d 65 27 2c 22 0a 20 20   'Tag Name',".  
0b60: 20 20 22 20 20 20 20 20 20 20 44 41 54 45 54 49    "       DATETI
0b70: 4d 45 28 74 78 2e 6d 74 69 6d 65 29 20 41 53 20  ME(tx.mtime) AS 
0b80: 27 54 69 6d 65 73 74 61 6d 70 27 2c 22 0a 20 20  'Timestamp',".  
0b90: 20 20 22 20 20 20 20 20 20 20 6c 69 6e 6b 75 75    "       linkuu
0ba0: 69 64 28 62 2e 75 75 69 64 29 20 41 53 20 27 56  id(b.uuid) AS 'V
0bb0: 65 72 73 69 6f 6e 27 22 0a 20 20 20 20 22 20 20  ersion'".    "  
0bc0: 46 52 4f 4d 20 74 61 67 20 74 2c 20 74 61 67 78  FROM tag t, tagx
0bd0: 72 65 66 20 74 78 2c 20 62 6c 6f 62 20 62 22 0a  ref tx, blob b".
0be0: 20 20 20 20 22 20 57 48 45 52 45 20 74 2e 74 61      " WHERE t.ta
0bf0: 67 69 64 3d 25 64 20 41 4e 44 20 74 2e 74 61 67  gid=%d AND t.tag
0c00: 69 64 3d 74 78 2e 74 61 67 69 64 20 41 4e 44 20  id=tx.tagid AND 
0c10: 74 78 2e 73 72 63 69 64 3d 62 2e 72 69 64 20 22  tx.srcid=b.rid "
0c20: 0a 20 20 20 20 54 41 47 56 49 45 57 5f 44 45 46  .    TAGVIEW_DEF
0c30: 41 55 4c 54 5f 46 49 4c 54 45 52 0a 20 20 20 20  AULT_FILTER.    
0c40: 22 20 4f 52 44 45 52 20 42 59 20 74 78 2e 6d 74  " ORDER BY tx.mt
0c50: 69 6d 65 20 44 45 53 43 22 2c 0a 20 20 20 20 74  ime DESC",.    t
0c60: 61 67 69 64 0a 20 20 29 3b 0a 20 20 64 62 5f 67  agid.  );.  db_g
0c70: 65 6e 65 72 69 63 5f 71 75 65 72 79 5f 76 69 65  eneric_query_vie
0c80: 77 28 7a 53 71 6c 2c 20 31 29 3b 0a 20 20 66 72  w(zSql, 1);.  fr
0c90: 65 65 28 7a 53 71 6c 29 3b 0a 7d 0a 0a 2f 2a 0a  ee(zSql);.}../*.
0ca0: 2a 2a 20 4c 69 73 74 73 20 61 6c 6c 20 74 61 67  ** Lists all tag
0cb0: 73 20 6d 61 74 63 68 69 6e 67 20 74 68 65 20 67  s matching the g
0cc0: 69 76 65 6e 20 74 61 67 20 6e 61 6d 65 2e 0a 2a  iven tag name..*
0cd0: 2f 0a 73 74 61 74 69 63 20 76 6f 69 64 20 74 61  /.static void ta
0ce0: 67 76 69 65 77 5f 70 61 67 65 5f 74 61 67 5f 62  gview_page_tag_b
0cf0: 79 5f 6e 61 6d 65 28 20 63 68 61 72 20 63 6f 6e  y_name( char con
0d00: 73 74 20 2a 20 74 61 67 6e 61 6d 65 20 29 7b 0a  st * tagname ){.
0d10: 20 20 63 68 61 72 20 2a 7a 53 71 6c 3b 0a 20 20    char *zSql;.  
0d20: 40 20 3c 68 32 3e 54 61 67 20 27 25 73 28 74 61  @ <h2>Tag '%s(ta
0d30: 67 6e 61 6d 65 29 27 3a 3c 2f 68 32 3e 0a 20 20  gname)':</h2>.  
0d40: 7a 53 71 6c 20 3d 20 6d 70 72 69 6e 74 66 28 20  zSql = mprintf( 
0d50: 0a 20 20 20 20 22 53 45 4c 45 43 54 20 44 49 53  .    "SELECT DIS
0d60: 54 49 4e 43 54 22 0a 20 20 20 20 22 20 20 20 20  TINCT".    "    
0d70: 20 20 20 6c 69 6e 6b 74 61 67 69 64 28 74 2e 74     linktagid(t.t
0d80: 61 67 69 64 29 20 41 53 20 27 54 61 67 20 49 44  agid) AS 'Tag ID
0d90: 27 2c 22 0a 20 20 20 20 22 20 20 20 20 20 20 20  ',".    "       
0da0: 44 41 54 45 54 49 4d 45 28 74 78 2e 6d 74 69 6d  DATETIME(tx.mtim
0db0: 65 29 20 41 53 20 27 54 69 6d 65 73 74 61 6d 70  e) AS 'Timestamp
0dc0: 27 2c 22 0a 20 20 20 20 22 20 20 20 20 20 20 20  ',".    "       
0dd0: 6c 69 6e 6b 75 75 69 64 28 62 2e 75 75 69 64 29  linkuuid(b.uuid)
0de0: 20 41 53 20 27 56 65 72 73 69 6f 6e 27 22 0a 20   AS 'Version'". 
0df0: 20 20 20 22 20 20 46 52 4f 4d 20 74 61 67 20 74     "  FROM tag t
0e00: 2c 20 74 61 67 78 72 65 66 20 74 78 2c 20 62 6c  , tagxref tx, bl
0e10: 6f 62 20 62 20 22 0a 20 20 20 20 22 20 57 48 45  ob b ".    " WHE
0e20: 52 45 20 74 2e 74 61 67 6e 61 6d 65 3d 27 25 71  RE t.tagname='%q
0e30: 27 20 41 4e 44 20 74 2e 74 61 67 69 64 3d 74 78  ' AND t.tagid=tx
0e40: 2e 74 61 67 69 64 20 41 4e 44 20 74 78 2e 73 72  .tagid AND tx.sr
0e50: 63 69 64 3d 62 2e 72 69 64 20 22 0a 20 20 20 20  cid=b.rid ".    
0e60: 54 41 47 56 49 45 57 5f 44 45 46 41 55 4c 54 5f  TAGVIEW_DEFAULT_
0e70: 46 49 4c 54 45 52 0a 20 20 20 20 22 20 4f 52 44  FILTER.    " ORD
0e80: 45 52 20 42 59 20 74 78 2e 6d 74 69 6d 65 20 44  ER BY tx.mtime D
0e90: 45 53 43 22 2c 0a 20 20 20 20 74 61 67 6e 61 6d  ESC",.    tagnam
0ea0: 65 29 3b 0a 20 20 64 62 5f 67 65 6e 65 72 69 63  e);.  db_generic
0eb0: 5f 71 75 65 72 79 5f 76 69 65 77 28 7a 53 71 6c  _query_view(zSql
0ec0: 2c 20 31 29 3b 0a 20 20 66 72 65 65 28 7a 53 71  , 1);.  free(zSq
0ed0: 6c 29 3b 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 57 45  l);.}.../*.** WE
0ee0: 42 50 41 47 45 3a 20 2f 74 61 67 76 69 65 77 0a  BPAGE: /tagview.
0ef0: 2a 2f 0a 76 6f 69 64 20 74 61 67 76 69 65 77 5f  */.void tagview_
0f00: 70 61 67 65 28 76 6f 69 64 29 7b 0a 20 20 6c 6f  page(void){.  lo
0f10: 67 69 6e 5f 63 68 65 63 6b 5f 63 72 65 64 65 6e  gin_check_creden
0f20: 74 69 61 6c 73 28 29 3b 0a 20 20 69 66 28 20 21  tials();.  if( !
0f30: 67 2e 6f 6b 52 64 57 69 6b 69 20 29 7b 0a 20 20  g.okRdWiki ){.  
0f40: 20 20 6c 6f 67 69 6e 5f 6e 65 65 64 65 64 28 29    login_needed()
0f50: 3b 0a 20 20 7d 0a 20 20 73 74 79 6c 65 5f 68 65  ;.  }.  style_he
0f60: 61 64 65 72 28 22 54 61 67 73 22 29 3b 0a 20 20  ader("Tags");.  
0f70: 74 61 67 76 69 65 77 5f 70 61 67 65 5f 73 65 61  tagview_page_sea
0f80: 72 63 68 5f 6d 69 6e 69 66 6f 72 6d 28 29 3b 0a  rch_miniform();.
0f90: 20 20 40 20 3c 68 72 2f 3e 0a 20 20 63 68 61 72    @ <hr/>.  char
0fa0: 20 63 6f 6e 73 74 20 2a 20 63 68 65 63 6b 20 3d   const * check =
0fb0: 20 30 3b 0a 20 20 69 66 28 20 30 20 21 3d 20 28   0;.  if( 0 != (
0fc0: 63 68 65 63 6b 20 3d 20 50 28 22 74 61 67 69 64  check = P("tagid
0fd0: 22 29 29 20 29 7b 0a 20 20 20 20 74 61 67 76 69  ")) ){.    tagvi
0fe0: 65 77 5f 70 61 67 65 5f 74 61 67 5f 62 79 5f 69  ew_page_tag_by_i
0ff0: 64 28 20 61 74 6f 69 28 63 68 65 63 6b 29 20 29  d( atoi(check) )
1000: 3b 0a 20 20 7d 65 6c 73 65 20 69 66 28 20 30 20  ;.  }else if( 0 
1010: 21 3d 20 28 63 68 65 63 6b 20 3d 20 50 28 22 6c  != (check = P("l
1020: 69 6b 65 22 29 29 20 29 7b 0a 20 20 20 20 74 61  ike")) ){.    ta
1030: 67 76 69 65 77 5f 70 61 67 65 5f 6c 69 73 74 5f  gview_page_list_
1040: 74 61 67 73 28 20 63 68 65 63 6b 20 29 3b 0a 20  tags( check );. 
1050: 20 7d 65 6c 73 65 20 69 66 28 20 30 20 21 3d 20   }else if( 0 != 
1060: 28 63 68 65 63 6b 20 3d 20 50 28 22 6e 61 6d 65  (check = P("name
1070: 22 29 29 20 29 7b 0a 20 20 20 20 74 61 67 76 69  ")) ){.    tagvi
1080: 65 77 5f 70 61 67 65 5f 74 61 67 5f 62 79 5f 6e  ew_page_tag_by_n
1090: 61 6d 65 28 20 63 68 65 63 6b 20 29 3b 0a 20 20  ame( check );.  
10a0: 7d 65 6c 73 65 7b 0a 20 20 20 20 74 61 67 76 69  }else{.    tagvi
10b0: 65 77 5f 70 61 67 65 5f 64 65 66 61 75 6c 74 28  ew_page_default(
10c0: 29 3b 0a 20 20 7d 0a 20 20 73 74 79 6c 65 5f 66  );.  }.  style_f
10d0: 6f 6f 74 65 72 28 29 3b 0a 7d 0a 0a 23 75 6e 64  ooter();.}..#und
10e0: 65 66 20 54 41 47 56 49 45 57 5f 44 45 46 41 55  ef TAGVIEW_DEFAU
10f0: 4c 54 5f 46 49 4c 54 45 52 0a                    LT_FILTER.