Fossil

Check-in [bb4a130121]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Unify the search screen generator code. Provide class marks to support CSS customization.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: bb4a13012143affd0d88412d5654f19fbacc2f59
User & Date: drh 2015-02-03 13:17:16.796
Context
2015-02-03
13:26
Adapt "makefile.wiki" to new requirement: availability of FTS4 ... (check-in: 0b3464cf72 user: jan.nijtmans tags: trunk)
13:17
Unify the search screen generator code. Provide class marks to support CSS customization. ... (check-in: bb4a130121 user: drh tags: trunk)
06:05
Fix to hyperlinks on search results. ... (check-in: 1c25812337 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/doc.c.
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816

/*
** WEBPAGE: /docsrch
**
** Search for documents that match a user-supplied pattern.
*/
void doc_search_page(void){
  const char *zPattern = PD("s","");
  unsigned srchFlags = 0;
  const char *zDisable;

  login_check_credentials();
  srchFlags = search_restrict(SRCH_DOC);
  if( srchFlags==0 ){
    zDisable = " disabled";
    zPattern = "";
  }else{
    zDisable = "";
    zPattern = PD("s","");
  }
  style_header("Document Search");
  @ <form method="GET" action="docsrch"><center>
  @ <input type="text" name="s" size="40" value="%h(zPattern)"%s(zDisable)>
  @ <input type="submit" value="Search Docs"%s(zDisable)>
  if( srchFlags==0 ){
    @ <p class="generalError">Document search is disabled</p>
  }
  @ </center></form>
  while( fossil_isspace(zPattern[0]) ) zPattern++;
  if( zPattern[0] ){
    if( search_run_and_output(zPattern, srchFlags)==0 ){
      @ <p><i>No matches for: "%h(zPattern)"</i></p>
    }
  }
  style_footer();
}







<
<
<
<

<
<
<
<
<
<
<
<

|
<
<
<
<
<
<
<
<
<
<
<
<


781
782
783
784
785
786
787




788








789
790












791
792

/*
** WEBPAGE: /docsrch
**
** Search for documents that match a user-supplied pattern.
*/
void doc_search_page(void){




  login_check_credentials();








  style_header("Document Search");
  search_screen(SRCH_DOC, "docsrch");












  style_footer();
}
Changes to src/search.c.
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
** Remove bits from srchFlags which are disallowed by either the
** current server configuration or by user permissions.
*/
unsigned int search_restrict(unsigned int srchFlags){
  if( g.perm.Read==0 )   srchFlags &= ~(SRCH_CKIN|SRCH_DOC);
  if( g.perm.RdTkt==0 )  srchFlags &= ~(SRCH_TKT);
  if( g.perm.RdWiki==0 ) srchFlags &= ~(SRCH_WIKI);
  if( search_index_exists() ) return srchFlags;
  if( (srchFlags & SRCH_CKIN)!=0 && db_get_boolean("search-ci",0)==0 ){
    srchFlags &= ~SRCH_CKIN;
  }
  if( (srchFlags & SRCH_DOC)!=0 && db_get_boolean("search-doc",0)==0 ){
    srchFlags &= ~SRCH_DOC;
  }
  if( (srchFlags & SRCH_TKT)!=0 && db_get_boolean("search-tkt",0)==0 ){







<







568
569
570
571
572
573
574

575
576
577
578
579
580
581
** Remove bits from srchFlags which are disallowed by either the
** current server configuration or by user permissions.
*/
unsigned int search_restrict(unsigned int srchFlags){
  if( g.perm.Read==0 )   srchFlags &= ~(SRCH_CKIN|SRCH_DOC);
  if( g.perm.RdTkt==0 )  srchFlags &= ~(SRCH_TKT);
  if( g.perm.RdWiki==0 ) srchFlags &= ~(SRCH_WIKI);

  if( (srchFlags & SRCH_CKIN)!=0 && db_get_boolean("search-ci",0)==0 ){
    srchFlags &= ~SRCH_CKIN;
  }
  if( (srchFlags & SRCH_DOC)!=0 && db_get_boolean("search-doc",0)==0 ){
    srchFlags &= ~SRCH_DOC;
  }
  if( (srchFlags & SRCH_TKT)!=0 && db_get_boolean("search-tkt",0)==0 ){
822
823
824
825
826
827
828


829
830
831




832

833
834
835
836
837
838
839
840
841
842
843
844
845
846
847

848
849
850
851
852
853
854
855
856





857
858
859
860
861
862
863
864





865





866









867






868


869
870
871
872
873
874
875
  if( nRow ){
    @ </ol>
  }
  return nRow;
}

/*


** WEBPAGE: /search
**
** Search for check-in comments, documents, tickets, or wiki that




** match a user-supplied pattern.

*/
void search_page(void){
  const char *zPattern = PD("s","");
  unsigned srchFlags = 0;
  const char *zDisable;
  const char *zOnly = P("only");

  login_check_credentials();
  srchFlags = search_restrict(SRCH_ALL);
  if( zOnly ){
    if( strchr(zOnly,'c') ) srchFlags &= SRCH_CKIN;
    if( strchr(zOnly,'d') ) srchFlags &= SRCH_DOC;
    if( strchr(zOnly,'t') ) srchFlags &= SRCH_TKT;
    if( strchr(zOnly,'w') ) srchFlags &= SRCH_WIKI;
  }

  if( srchFlags==0 ){
    zDisable = " disabled";
    zPattern = "";
  }else{
    zDisable = "";
    zPattern = PD("s","");
  }
  style_header("Search");
  @ <form method="GET" action="search"><center>





  @ <input type="text" name="s" size="40" value="%h(zPattern)"%s(zDisable)>
  @ <input type="submit" value="Search"%s(zDisable)>
  if( srchFlags==0 ){
    @ <p class="generalError">Search is disabled</p>
  }
  @ </center></form>
  while( fossil_isspace(zPattern[0]) ) zPattern++;
  if( zPattern[0] ){





    if( search_run_and_output(zPattern, srchFlags)==0 ){





      @ <p><i>No matches for: "%h(zPattern)"</i></p>









    }






  }


  style_footer();
}


/*
** This is a helper function for search_stext().  Writing into pOut
** the search text obtained from pIn according to zMimetype.







>
>
|

<
>
>
>
>
|
>

|
|
|

|
<
<
|
<
|
|
|
|

>







<
|
>
>
>
>
>

|



|


>
>
>
>
>

>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>

>
>







821
822
823
824
825
826
827
828
829
830
831

832
833
834
835
836
837
838
839
840
841
842
843


844

845
846
847
848
849
850
851
852
853
854
855
856
857

858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
  if( nRow ){
    @ </ol>
  }
  return nRow;
}

/*
** Generate some HTML for doing search.  At a minimum include the
** Search-Text entry form.  If the "s" query parameter is present, also
** show search results.
**

** The srchFlags parameter is used to customize some of the text of the
** form and the results.  srchFlags should be either a single search
** category or all categories.  Any srchFlags with two or more bits set
** is treated like SRCH_ALL for display purposes.
**
** The entry box is shown disabled if srchFlags is 0.
*/
void search_screen(unsigned srchFlags, const char *zAction){
  const char *zType = 0;
  const char *zClass = 0;
  const char *zDisable;
  const char *zPattern;


  switch( srchFlags ){

    case SRCH_CKIN:  zType = " Check-ins";  zClass = "Ckin";  break;
    case SRCH_DOC:   zType = " Docs";       zClass = "Doc";   break;
    case SRCH_TKT:   zType = " Tickets";    zClass = "Tkt";   break;
    case SRCH_WIKI:  zType = " Wiki";       zClass = "Wiki";  break;
  }
  srchFlags = search_restrict(srchFlags);
  if( srchFlags==0 ){
    zDisable = " disabled";
    zPattern = "";
  }else{
    zDisable = "";
    zPattern = PD("s","");
  }

  @ <form method='GET' action='%s(zAction)'>
  if( zClass ){
    @ <div class='searchForm searchForm%s(zClass)'>
  }else{
    @ <div class='searchForm'>
  }
  @ <input type="text" name="s" size="40" value="%h(zPattern)"%s(zDisable)>
  @ <input type="submit" value="Search%s(zType)"%s(zDisable)>
  if( srchFlags==0 ){
    @ <p class="generalError">Search is disabled</p>
  }
  @ </div></form>
  while( fossil_isspace(zPattern[0]) ) zPattern++;
  if( zPattern[0] ){
    if( zClass ){
      @ <div class='searchResult searchResult%s(zClass)'>
    }else{
      @ <div class='searchResult'>
    }
    if( search_run_and_output(zPattern, srchFlags)==0 ){
      @ <p class='searchEmpty'>No matches for: <span>%h(zPattern)</span></p>
    }
    @ </div>
  }
}

/*
** WEBPAGE: /search
**
** Search for check-in comments, documents, tickets, or wiki that
** match a user-supplied pattern.
*/
void search_page(void){
  unsigned srchFlags = SRCH_ALL;
  const char *zOnly = P("only");

  login_check_credentials();
  if( zOnly ){
    if( strchr(zOnly,'c') ) srchFlags &= SRCH_CKIN;
    if( strchr(zOnly,'d') ) srchFlags &= SRCH_DOC;
    if( strchr(zOnly,'t') ) srchFlags &= SRCH_TKT;
    if( strchr(zOnly,'w') ) srchFlags &= SRCH_WIKI;
  }
  style_header("Search");
  search_screen(srchFlags, "search");
  style_footer();
}


/*
** This is a helper function for search_stext().  Writing into pOut
** the search text obtained from pIn according to zMimetype.
Changes to src/style.c.
1128
1129
1130
1131
1132
1133
1134








1135
1136
1137
1138
1139
1140
1141
    @ content: '\2191';
  },
  { "span.snippet>mark",
    "Search markup",
    @ background-color: inherit;
    @ font-weight: bold;
  },








  { 0,
    0,
    0
  }
};

/*







>
>
>
>
>
>
>
>







1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
    @ content: '\2191';
  },
  { "span.snippet>mark",
    "Search markup",
    @ background-color: inherit;
    @ font-weight: bold;
  },
  { "div.searchForm",
    "Container for the search terms entry box",
    @ text-align: center;
  },
  { "p.searchEmpty",
    "Message explaining that there are no search results",
    @ font-style: italic;
  },
  { 0,
    0,
    0
  }
};

/*
Changes to src/tkt.c.
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
/*
** WEBPAGE: tktsrch
** Usage:  /tktsrch?s=PATTERN
**
** Full-text search of all current tickets
*/
void tkt_srchpage(void){
  const char *zPattern = PD("s","");
  unsigned srchFlags = 0;
  const char *zDisable;

  login_check_credentials();
  srchFlags = search_restrict(SRCH_TKT);
  if( srchFlags==0 ){
    zDisable = " disabled";
    zPattern = "";
  }else{
    zDisable = "";
    zPattern = PD("s","");
  }
  style_header("Ticket Search");
  ticket_standard_submenu(T_ALL_BUT(T_SRCH));
  @ <form method="GET" action="tktsrch"><center>
  @ <input type="text" name="s" size="40" value="%h(zPattern)"%s(zDisable)>
  @ <input type="submit" value="Search Tickets"%s(zDisable)>
  if( srchFlags==0 ){
    @ <p class="generalError">Ticket search is disabled</p>
  }
  @ </center></form>
  while( fossil_isspace(zPattern[0]) ) zPattern++;
  if( zPattern[0] ){
    if( search_run_and_output(zPattern, srchFlags)==0 ){
      @ <p><i>No matches for: "%h(zPattern)"</i></p>
    }
  }
  style_footer();
}







<
<
<
<

<
<
<
<
<
<
<
<


|
<
<
<
<
<
<
<
<
<
<
<
<


1429
1430
1431
1432
1433
1434
1435




1436








1437
1438
1439












1440
1441
/*
** WEBPAGE: tktsrch
** Usage:  /tktsrch?s=PATTERN
**
** Full-text search of all current tickets
*/
void tkt_srchpage(void){




  login_check_credentials();








  style_header("Ticket Search");
  ticket_standard_submenu(T_ALL_BUT(T_SRCH));
  search_screen(SRCH_TKT, "tktsrch");












  style_footer();
}
Changes to src/wiki.c.
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
/*
** WEBPAGE: wikisrch
** Usage:  /wikisrch?s=PATTERN
**
** Full-text search of all current wiki text
*/
void wiki_srchpage(void){
  const char *zPattern = PD("s","");
  unsigned srchFlags = 0;
  const char *zDisable;

  login_check_credentials();
  srchFlags = search_restrict(SRCH_WIKI);
  if( srchFlags==0 ){
    zDisable = " disabled";
    zPattern = "";
  }else{
    zDisable = "";
    zPattern = PD("s","");
  }
  style_header("Wiki Search");
  wiki_standard_submenu(W_HELP|W_LIST|W_SANDBOX);
  @ <form method="GET" action="wikisrch"><center>
  @ <input type="text" name="s" size="40" value="%h(zPattern)"%s(zDisable)>
  @ <input type="submit" value="Search Wiki"%s(zDisable)>
  if( srchFlags==0 ){
    @ <p class="generalError">Wiki search is disabled</p>
  }
  @ </center></form>
  while( fossil_isspace(zPattern[0]) ) zPattern++;
  if( zPattern[0] ){
    if( search_run_and_output(zPattern, srchFlags)==0 ){
      @ <p><i>No matches for: "%h(zPattern)"</i></p>
    }
  }
  style_footer();
}

/*
** WEBPAGE: wiki
** URL: /wiki?name=PAGENAME
*/







<
<
<
<

<
<
<
<
<
<
<
<


|
<
<
<
<
<
<
<
<
<
<
<
<







286
287
288
289
290
291
292




293








294
295
296












297
298
299
300
301
302
303
/*
** WEBPAGE: wikisrch
** Usage:  /wikisrch?s=PATTERN
**
** Full-text search of all current wiki text
*/
void wiki_srchpage(void){




  login_check_credentials();








  style_header("Wiki Search");
  wiki_standard_submenu(W_HELP|W_LIST|W_SANDBOX);
  search_screen(SRCH_WIKI, "wikisrch");












  style_footer();
}

/*
** WEBPAGE: wiki
** URL: /wiki?name=PAGENAME
*/