Fossil

Diff
Login

Differences From Artifact [243d90be0c]:

To Artifact [2eb22e15f9]:


568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
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( 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 ){
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
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
** WEBPAGE: /search
** show search results.
**
** Search for check-in comments, documents, tickets, or wiki that
** match a user-supplied pattern.
** 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_page(void){
  const char *zPattern = PD("s","");
  unsigned srchFlags = 0;
void search_screen(unsigned srchFlags, const char *zAction){
  const char *zType = 0;
  const char *zClass = 0;
  const char *zDisable;
  const char *zOnly = P("only");
  const char *zPattern;

  login_check_credentials();
  srchFlags = search_restrict(SRCH_ALL);
  switch( srchFlags ){
  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;
    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","");
  }
  style_header("Search");
  @ <form method="GET" action="search"><center>
  @ <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(zDisable)>
  @ <input type="submit" value="Search%s(zType)"%s(zDisable)>
  if( srchFlags==0 ){
    @ <p class="generalError">Search is disabled</p>
  }
  @ </center></form>
  @ </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>
  }
}
      @ <p><i>No matches for: "%h(zPattern)"</i></p>
    }

/*
** 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.