Fossil

Check-in [37409e7d]
Login

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

Overview
Comment:Allow /wikiedit's page-list-fetch operation to silently skip over mysteriously missing (shunned but not yet rebuilt?) wiki pages, to resolve an issue on the core fossil site where such a missing/invisible page named 'Security Desk Technician' is causing /wikiedit to fail to load.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 37409e7dbeddf00cca9ba8c1640b635c4d01d549df95ddae7ccf66237aee71a7
User & Date: stephan 2020-08-20 20:05:25
References
2020-08-24
04:33
Reverted [37409e7dbe] in favor of [5244a548], which is cleaner, smaller, and works. ... (check-in: a7d8c58d user: stephan tags: trunk)
Context
2020-08-20
20:25
Added a "window." reference to a global variable in fossil.dom.js to make explicit where the variable is coming from. All the surrounding code does this, and the fix quiets a complaint from GCC. ... (check-in: 31af8053 user: wyoung tags: trunk)
20:05
Allow /wikiedit's page-list-fetch operation to silently skip over mysteriously missing (shunned but not yet rebuilt?) wiki pages, to resolve an issue on the core fossil site where such a missing/invisible page named 'Security Desk Technician' is causing /wikiedit to fail to load. ... (check-in: 37409e7d user: stephan tags: trunk)
19:52
Removed a pair of bogus "delete" calls in fossil.popupwidget.js, flagged by Google Closure Compiler. You can't delete the result of a function call, only object properties. ... (check-in: 0d7d54e8 user: wyoung tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/wiki.c.

723
724
725
726
727
728
729





730

731






732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748


749
750
751
752
753
754
755



756
757
758
759
760
761
762
763
764
765
766
767

768
769

770
771



772
773
774
775
776
777
778

/*
** Loads the given wiki page, sets the response type to
** application/json, and emits it as a JSON object.  If zPageName is a
** sandbox page then a "fake" object is emitted, as the wikiajax API
** does not permit saving the sandbox.
**





** Returns true on success, false on error, and on error it

** queues up a JSON-format error response.






**
** Output JSON format:
**
** { name: "page name",
**   type: "normal" | "tag" | "checkin" | "branch" | "sandbox",
**   mimetype: "mime type",
**   version: UUID string or null for a sandbox page,
**   parent: "parent uuid" or null if no parent,
**   isDeleted: true if the page has no content (is "deleted")
**              else not set (making it "falsy" in JS),
**   content: "page content" (only if includeContent is true)
** }
**
** If includeContent is false then the content member is elided.
*/
static int wiki_ajax_emit_page_object(const char *zPageName,
                                      int includeContent){


  Manifest * pWiki = 0;
  char * zUuid;

  if( is_sandbox(zPageName) ){
    char * zMimetype =
      db_get("sandbox-mimetype","text/x-fossil-wiki");
    char * zBody = db_get("sandbox","");



    CX("{\"name\": %!j, \"type\": \"sandbox\", "
       "\"mimetype\": %!j, \"version\": null, \"parent\": null",
       zPageName, zMimetype);
    if(includeContent){
      CX(", \"content\": %!j",
       zBody);
    }
    CX("}");
    fossil_free(zMimetype);
    fossil_free(zBody);
    return 1;
  }else if( !wiki_fetch_by_name(zPageName, 0, 0, &pWiki) ){

    ajax_route_error(404, "Wiki page could not be loaded: %s",
                     zPageName);

    return 0;
  }else{



    zUuid = rid_to_uuid(pWiki->rid);
    CX("{\"name\": %!j, \"type\": %!j, "
       "\"version\": %!j, "
       "\"mimetype\": %!j, ",
       pWiki->zWikiTitle,
       wiki_page_type_name(pWiki->zWikiTitle),
       zUuid,







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
















|
>
>







>
>
>












>
|
|
>


>
>
>







723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800

/*
** Loads the given wiki page, sets the response type to
** application/json, and emits it as a JSON object.  If zPageName is a
** sandbox page then a "fake" object is emitted, as the wikiajax API
** does not permit saving the sandbox.
**
** If includeLeadingComma is true then a comma will be emitted
** preceeding the object. This parameter is a bit of a hack to allow
** wiki page list generation to recover from an unusual (so far unique
** to one repo) error mode.
**
** Returns true on success, false on error. Its behaviour on error
** depends on the 4th argument: if it's true, this function simply
** returns false, else it queues up a JSON response and returns false.
** The intention of this flag is to avoid a weird corner case seen, so
** far, only on the main fossil repo (not clones of it) in which
** loading fails for a page named "Security Desk Technician". The
** hypothesis is that that page was once shunned on the core repo, but
** a reference to it still exists in the tables from which we pull the
** wiki list.
**
** Output JSON format:
**
** { name: "page name",
**   type: "normal" | "tag" | "checkin" | "branch" | "sandbox",
**   mimetype: "mime type",
**   version: UUID string or null for a sandbox page,
**   parent: "parent uuid" or null if no parent,
**   isDeleted: true if the page has no content (is "deleted")
**              else not set (making it "falsy" in JS),
**   content: "page content" (only if includeContent is true)
** }
**
** If includeContent is false then the content member is elided.
*/
static int wiki_ajax_emit_page_object(const char *zPageName,
                                      int includeContent,
                                      int includeLeadingComma,
                                      int ignoreLoadError){
  Manifest * pWiki = 0;
  char * zUuid;

  if( is_sandbox(zPageName) ){
    char * zMimetype =
      db_get("sandbox-mimetype","text/x-fossil-wiki");
    char * zBody = db_get("sandbox","");
    if(includeLeadingComma){
      CX(",");
    }
    CX("{\"name\": %!j, \"type\": \"sandbox\", "
       "\"mimetype\": %!j, \"version\": null, \"parent\": null",
       zPageName, zMimetype);
    if(includeContent){
      CX(", \"content\": %!j",
       zBody);
    }
    CX("}");
    fossil_free(zMimetype);
    fossil_free(zBody);
    return 1;
  }else if( !wiki_fetch_by_name(zPageName, 0, 0, &pWiki) ){
    if(ignoreLoadError!=0){
      ajax_route_error(404, "Wiki page could not be loaded: %s",
                       zPageName);
    }
    return 0;
  }else{
    if(includeLeadingComma){
      CX(",");
    }
    zUuid = rid_to_uuid(pWiki->rid);
    CX("{\"name\": %!j, \"type\": %!j, "
       "\"version\": %!j, "
       "\"mimetype\": %!j, ",
       pWiki->zWikiTitle,
       wiki_page_type_name(pWiki->zWikiTitle),
       zUuid,
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
                     "isnew=1.", zPageName);
    return;
  }
  blob_init(&content, zContent ? zContent : "", -1);
  cgi_set_content_type("application/json");
  db_begin_transaction();
  wiki_cmd_commit(zPageName, parentRid, &content, zMimetype, 0);
  rollback = wiki_ajax_emit_page_object(zPageName, 1) ? 0 : 1;
  db_end_transaction(rollback);
}

/*
** Ajax route handler for /wikiajax/fetch.
**
** URL params:







|







873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
                     "isnew=1.", zPageName);
    return;
  }
  blob_init(&content, zContent ? zContent : "", -1);
  cgi_set_content_type("application/json");
  db_begin_transaction();
  wiki_cmd_commit(zPageName, parentRid, &content, zMimetype, 0);
  rollback = wiki_ajax_emit_page_object(zPageName, 1, 0, 0) ? 0 : 1;
  db_end_transaction(rollback);
}

/*
** Ajax route handler for /wikiajax/fetch.
**
** URL params:
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
  const char * zPageName = P("page");
  
  if( zPageName==0 || zPageName[0]==0 ){
    ajax_route_error(400,"Missing page name.");
    return;
  }
  cgi_set_content_type("application/json");
  wiki_ajax_emit_page_object(zPageName, 1);
}

/*
** Ajax route handler for /wikiajax/diff.
**
** URL params:
**







|







896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
  const char * zPageName = P("page");
  
  if( zPageName==0 || zPageName[0]==0 ){
    ajax_route_error(400,"Missing page name.");
    return;
  }
  cgi_set_content_type("application/json");
  wiki_ajax_emit_page_object(zPageName, 1, 0, 0);
}

/*
** Ajax route handler for /wikiajax/diff.
**
** URL params:
**
982
983
984
985
986
987
988

989
990
991
992
993
994
995

996
997
998
999
1000
1001
1002
             " substr(tagname,6) AS name"
             " FROM tag WHERE tagname GLOB 'wiki-*'"
             " UNION SELECT 'Sandbox' AS name"
             " ORDER BY name COLLATE NOCASE");
  CX("[");
  while( SQLITE_ROW==db_step(&q) ){
    char const * zName = db_column_text(&q,0);

    if(n++){
      CX(",");
    }
    if(verbose==0){
      CX("%!j", zName);
    }else{
      wiki_ajax_emit_page_object(zName, includeContent);

    }
  }
  CX("]");
  db_finalize(&q);
  db_end_transaction(0);
}








>
|
|
|
<


|
>







1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014

1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
             " substr(tagname,6) AS name"
             " FROM tag WHERE tagname GLOB 'wiki-*'"
             " UNION SELECT 'Sandbox' AS name"
             " ORDER BY name COLLATE NOCASE");
  CX("[");
  while( SQLITE_ROW==db_step(&q) ){
    char const * zName = db_column_text(&q,0);
    if(verbose==0){
      if(n++){
        CX(",");
      }

      CX("%!j", zName);
    }else{
      wiki_ajax_emit_page_object(zName, includeContent,
                                 n++>0, 1);
    }
  }
  CX("]");
  db_finalize(&q);
  db_end_transaction(0);
}