Fossil SCM
Reverted [37409e7dbe] in favor of [5244a548], which is cleaner, smaller, and works.
Commit
a7d8c58d48c0810219dcba440c3dbcdd95b7d91584bb135d7eac22eb0c74cde4
Parent
2df0e5c4288df7c…
1 file changed
+11
-34
+11
-34
| --- src/wiki.c | ||
| +++ src/wiki.c | ||
| @@ -729,24 +729,12 @@ | ||
| 729 | 729 | ** Loads the given wiki page, sets the response type to |
| 730 | 730 | ** application/json, and emits it as a JSON object. If zPageName is a |
| 731 | 731 | ** sandbox page then a "fake" object is emitted, as the wikiajax API |
| 732 | 732 | ** does not permit saving the sandbox. |
| 733 | 733 | ** |
| 734 | -** If includeLeadingComma is true then a comma will be emitted | |
| 735 | -** preceeding the object. This parameter is a bit of a hack to allow | |
| 736 | -** wiki page list generation to recover from an unusual (so far unique | |
| 737 | -** to one repo) error mode. | |
| 738 | -** | |
| 739 | -** Returns true on success, false on error. Its behaviour on error | |
| 740 | -** depends on the 4th argument: if it's true, this function simply | |
| 741 | -** returns false, else it queues up a JSON response and returns false. | |
| 742 | -** The intention of this flag is to avoid a weird corner case seen, so | |
| 743 | -** far, only on the main fossil repo (not clones of it) in which | |
| 744 | -** loading fails for a page named "Security Desk Technician". The | |
| 745 | -** hypothesis is that that page was once shunned on the core repo, but | |
| 746 | -** a reference to it still exists in the tables from which we pull the | |
| 747 | -** wiki list. | |
| 734 | +** Returns true on success, false on error, and on error it | |
| 735 | +** queues up a JSON-format error response. | |
| 748 | 736 | ** |
| 749 | 737 | ** Output JSON format: |
| 750 | 738 | ** |
| 751 | 739 | ** { name: "page name", |
| 752 | 740 | ** type: "normal" | "tag" | "checkin" | "branch" | "sandbox", |
| @@ -759,23 +747,18 @@ | ||
| 759 | 747 | ** } |
| 760 | 748 | ** |
| 761 | 749 | ** If includeContent is false then the content member is elided. |
| 762 | 750 | */ |
| 763 | 751 | static int wiki_ajax_emit_page_object(const char *zPageName, |
| 764 | - int includeContent, | |
| 765 | - int includeLeadingComma, | |
| 766 | - int ignoreLoadError){ | |
| 752 | + int includeContent){ | |
| 767 | 753 | Manifest * pWiki = 0; |
| 768 | 754 | char * zUuid; |
| 769 | 755 | |
| 770 | 756 | if( is_sandbox(zPageName) ){ |
| 771 | 757 | char * zMimetype = |
| 772 | 758 | db_get("sandbox-mimetype","text/x-fossil-wiki"); |
| 773 | 759 | char * zBody = db_get("sandbox",""); |
| 774 | - if(includeLeadingComma){ | |
| 775 | - CX(","); | |
| 776 | - } | |
| 777 | 760 | CX("{\"name\": %!j, \"type\": \"sandbox\", " |
| 778 | 761 | "\"mimetype\": %!j, \"version\": null, \"parent\": null", |
| 779 | 762 | zPageName, zMimetype); |
| 780 | 763 | if(includeContent){ |
| 781 | 764 | CX(", \"content\": %!j", |
| @@ -784,19 +767,14 @@ | ||
| 784 | 767 | CX("}"); |
| 785 | 768 | fossil_free(zMimetype); |
| 786 | 769 | fossil_free(zBody); |
| 787 | 770 | return 1; |
| 788 | 771 | }else if( !wiki_fetch_by_name(zPageName, 0, 0, &pWiki) ){ |
| 789 | - if(ignoreLoadError!=0){ | |
| 790 | - ajax_route_error(404, "Wiki page could not be loaded: %s", | |
| 791 | - zPageName); | |
| 792 | - } | |
| 772 | + ajax_route_error(404, "Wiki page could not be loaded: %s", | |
| 773 | + zPageName); | |
| 793 | 774 | return 0; |
| 794 | 775 | }else{ |
| 795 | - if(includeLeadingComma){ | |
| 796 | - CX(","); | |
| 797 | - } | |
| 798 | 776 | zUuid = rid_to_uuid(pWiki->rid); |
| 799 | 777 | CX("{\"name\": %!j, \"type\": %!j, " |
| 800 | 778 | "\"version\": %!j, " |
| 801 | 779 | "\"mimetype\": %!j, ", |
| 802 | 780 | pWiki->zWikiTitle, |
| @@ -879,11 +857,11 @@ | ||
| 879 | 857 | } |
| 880 | 858 | blob_init(&content, zContent ? zContent : "", -1); |
| 881 | 859 | cgi_set_content_type("application/json"); |
| 882 | 860 | db_begin_transaction(); |
| 883 | 861 | wiki_cmd_commit(zPageName, parentRid, &content, zMimetype, 0); |
| 884 | - rollback = wiki_ajax_emit_page_object(zPageName, 1, 0, 0) ? 0 : 1; | |
| 862 | + rollback = wiki_ajax_emit_page_object(zPageName, 1) ? 0 : 1; | |
| 885 | 863 | db_end_transaction(rollback); |
| 886 | 864 | } |
| 887 | 865 | |
| 888 | 866 | /* |
| 889 | 867 | ** Ajax route handler for /wikiajax/fetch. |
| @@ -902,11 +880,11 @@ | ||
| 902 | 880 | if( zPageName==0 || zPageName[0]==0 ){ |
| 903 | 881 | ajax_route_error(400,"Missing page name."); |
| 904 | 882 | return; |
| 905 | 883 | } |
| 906 | 884 | cgi_set_content_type("application/json"); |
| 907 | - wiki_ajax_emit_page_object(zPageName, 1, 0, 0); | |
| 885 | + wiki_ajax_emit_page_object(zPageName, 1); | |
| 908 | 886 | } |
| 909 | 887 | |
| 910 | 888 | /* |
| 911 | 889 | ** Ajax route handler for /wikiajax/diff. |
| 912 | 890 | ** |
| @@ -1011,18 +989,17 @@ | ||
| 1011 | 989 | " UNION SELECT 'Sandbox' AS name" |
| 1012 | 990 | " ORDER BY name COLLATE NOCASE"); |
| 1013 | 991 | CX("["); |
| 1014 | 992 | while( SQLITE_ROW==db_step(&q) ){ |
| 1015 | 993 | char const * zName = db_column_text(&q,0); |
| 994 | + if(n++){ | |
| 995 | + CX(","); | |
| 996 | + } | |
| 1016 | 997 | if(verbose==0){ |
| 1017 | - if(n++){ | |
| 1018 | - CX(","); | |
| 1019 | - } | |
| 1020 | 998 | CX("%!j", zName); |
| 1021 | 999 | }else{ |
| 1022 | - wiki_ajax_emit_page_object(zName, includeContent, | |
| 1023 | - n++>0, 1); | |
| 1000 | + wiki_ajax_emit_page_object(zName, includeContent); | |
| 1024 | 1001 | } |
| 1025 | 1002 | } |
| 1026 | 1003 | CX("]"); |
| 1027 | 1004 | db_finalize(&q); |
| 1028 | 1005 | db_end_transaction(0); |
| 1029 | 1006 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -729,24 +729,12 @@ | |
| 729 | ** Loads the given wiki page, sets the response type to |
| 730 | ** application/json, and emits it as a JSON object. If zPageName is a |
| 731 | ** sandbox page then a "fake" object is emitted, as the wikiajax API |
| 732 | ** does not permit saving the sandbox. |
| 733 | ** |
| 734 | ** If includeLeadingComma is true then a comma will be emitted |
| 735 | ** preceeding the object. This parameter is a bit of a hack to allow |
| 736 | ** wiki page list generation to recover from an unusual (so far unique |
| 737 | ** to one repo) error mode. |
| 738 | ** |
| 739 | ** Returns true on success, false on error. Its behaviour on error |
| 740 | ** depends on the 4th argument: if it's true, this function simply |
| 741 | ** returns false, else it queues up a JSON response and returns false. |
| 742 | ** The intention of this flag is to avoid a weird corner case seen, so |
| 743 | ** far, only on the main fossil repo (not clones of it) in which |
| 744 | ** loading fails for a page named "Security Desk Technician". The |
| 745 | ** hypothesis is that that page was once shunned on the core repo, but |
| 746 | ** a reference to it still exists in the tables from which we pull the |
| 747 | ** wiki list. |
| 748 | ** |
| 749 | ** Output JSON format: |
| 750 | ** |
| 751 | ** { name: "page name", |
| 752 | ** type: "normal" | "tag" | "checkin" | "branch" | "sandbox", |
| @@ -759,23 +747,18 @@ | |
| 759 | ** } |
| 760 | ** |
| 761 | ** If includeContent is false then the content member is elided. |
| 762 | */ |
| 763 | static int wiki_ajax_emit_page_object(const char *zPageName, |
| 764 | int includeContent, |
| 765 | int includeLeadingComma, |
| 766 | int ignoreLoadError){ |
| 767 | Manifest * pWiki = 0; |
| 768 | char * zUuid; |
| 769 | |
| 770 | if( is_sandbox(zPageName) ){ |
| 771 | char * zMimetype = |
| 772 | db_get("sandbox-mimetype","text/x-fossil-wiki"); |
| 773 | char * zBody = db_get("sandbox",""); |
| 774 | if(includeLeadingComma){ |
| 775 | CX(","); |
| 776 | } |
| 777 | CX("{\"name\": %!j, \"type\": \"sandbox\", " |
| 778 | "\"mimetype\": %!j, \"version\": null, \"parent\": null", |
| 779 | zPageName, zMimetype); |
| 780 | if(includeContent){ |
| 781 | CX(", \"content\": %!j", |
| @@ -784,19 +767,14 @@ | |
| 784 | CX("}"); |
| 785 | fossil_free(zMimetype); |
| 786 | fossil_free(zBody); |
| 787 | return 1; |
| 788 | }else if( !wiki_fetch_by_name(zPageName, 0, 0, &pWiki) ){ |
| 789 | if(ignoreLoadError!=0){ |
| 790 | ajax_route_error(404, "Wiki page could not be loaded: %s", |
| 791 | zPageName); |
| 792 | } |
| 793 | return 0; |
| 794 | }else{ |
| 795 | if(includeLeadingComma){ |
| 796 | CX(","); |
| 797 | } |
| 798 | zUuid = rid_to_uuid(pWiki->rid); |
| 799 | CX("{\"name\": %!j, \"type\": %!j, " |
| 800 | "\"version\": %!j, " |
| 801 | "\"mimetype\": %!j, ", |
| 802 | pWiki->zWikiTitle, |
| @@ -879,11 +857,11 @@ | |
| 879 | } |
| 880 | blob_init(&content, zContent ? zContent : "", -1); |
| 881 | cgi_set_content_type("application/json"); |
| 882 | db_begin_transaction(); |
| 883 | wiki_cmd_commit(zPageName, parentRid, &content, zMimetype, 0); |
| 884 | rollback = wiki_ajax_emit_page_object(zPageName, 1, 0, 0) ? 0 : 1; |
| 885 | db_end_transaction(rollback); |
| 886 | } |
| 887 | |
| 888 | /* |
| 889 | ** Ajax route handler for /wikiajax/fetch. |
| @@ -902,11 +880,11 @@ | |
| 902 | if( zPageName==0 || zPageName[0]==0 ){ |
| 903 | ajax_route_error(400,"Missing page name."); |
| 904 | return; |
| 905 | } |
| 906 | cgi_set_content_type("application/json"); |
| 907 | wiki_ajax_emit_page_object(zPageName, 1, 0, 0); |
| 908 | } |
| 909 | |
| 910 | /* |
| 911 | ** Ajax route handler for /wikiajax/diff. |
| 912 | ** |
| @@ -1011,18 +989,17 @@ | |
| 1011 | " UNION SELECT 'Sandbox' AS name" |
| 1012 | " ORDER BY name COLLATE NOCASE"); |
| 1013 | CX("["); |
| 1014 | while( SQLITE_ROW==db_step(&q) ){ |
| 1015 | char const * zName = db_column_text(&q,0); |
| 1016 | if(verbose==0){ |
| 1017 | if(n++){ |
| 1018 | CX(","); |
| 1019 | } |
| 1020 | CX("%!j", zName); |
| 1021 | }else{ |
| 1022 | wiki_ajax_emit_page_object(zName, includeContent, |
| 1023 | n++>0, 1); |
| 1024 | } |
| 1025 | } |
| 1026 | CX("]"); |
| 1027 | db_finalize(&q); |
| 1028 | db_end_transaction(0); |
| 1029 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -729,24 +729,12 @@ | |
| 729 | ** Loads the given wiki page, sets the response type to |
| 730 | ** application/json, and emits it as a JSON object. If zPageName is a |
| 731 | ** sandbox page then a "fake" object is emitted, as the wikiajax API |
| 732 | ** does not permit saving the sandbox. |
| 733 | ** |
| 734 | ** Returns true on success, false on error, and on error it |
| 735 | ** queues up a JSON-format error response. |
| 736 | ** |
| 737 | ** Output JSON format: |
| 738 | ** |
| 739 | ** { name: "page name", |
| 740 | ** type: "normal" | "tag" | "checkin" | "branch" | "sandbox", |
| @@ -759,23 +747,18 @@ | |
| 747 | ** } |
| 748 | ** |
| 749 | ** If includeContent is false then the content member is elided. |
| 750 | */ |
| 751 | static int wiki_ajax_emit_page_object(const char *zPageName, |
| 752 | int includeContent){ |
| 753 | Manifest * pWiki = 0; |
| 754 | char * zUuid; |
| 755 | |
| 756 | if( is_sandbox(zPageName) ){ |
| 757 | char * zMimetype = |
| 758 | db_get("sandbox-mimetype","text/x-fossil-wiki"); |
| 759 | char * zBody = db_get("sandbox",""); |
| 760 | CX("{\"name\": %!j, \"type\": \"sandbox\", " |
| 761 | "\"mimetype\": %!j, \"version\": null, \"parent\": null", |
| 762 | zPageName, zMimetype); |
| 763 | if(includeContent){ |
| 764 | CX(", \"content\": %!j", |
| @@ -784,19 +767,14 @@ | |
| 767 | CX("}"); |
| 768 | fossil_free(zMimetype); |
| 769 | fossil_free(zBody); |
| 770 | return 1; |
| 771 | }else if( !wiki_fetch_by_name(zPageName, 0, 0, &pWiki) ){ |
| 772 | ajax_route_error(404, "Wiki page could not be loaded: %s", |
| 773 | zPageName); |
| 774 | return 0; |
| 775 | }else{ |
| 776 | zUuid = rid_to_uuid(pWiki->rid); |
| 777 | CX("{\"name\": %!j, \"type\": %!j, " |
| 778 | "\"version\": %!j, " |
| 779 | "\"mimetype\": %!j, ", |
| 780 | pWiki->zWikiTitle, |
| @@ -879,11 +857,11 @@ | |
| 857 | } |
| 858 | blob_init(&content, zContent ? zContent : "", -1); |
| 859 | cgi_set_content_type("application/json"); |
| 860 | db_begin_transaction(); |
| 861 | wiki_cmd_commit(zPageName, parentRid, &content, zMimetype, 0); |
| 862 | rollback = wiki_ajax_emit_page_object(zPageName, 1) ? 0 : 1; |
| 863 | db_end_transaction(rollback); |
| 864 | } |
| 865 | |
| 866 | /* |
| 867 | ** Ajax route handler for /wikiajax/fetch. |
| @@ -902,11 +880,11 @@ | |
| 880 | if( zPageName==0 || zPageName[0]==0 ){ |
| 881 | ajax_route_error(400,"Missing page name."); |
| 882 | return; |
| 883 | } |
| 884 | cgi_set_content_type("application/json"); |
| 885 | wiki_ajax_emit_page_object(zPageName, 1); |
| 886 | } |
| 887 | |
| 888 | /* |
| 889 | ** Ajax route handler for /wikiajax/diff. |
| 890 | ** |
| @@ -1011,18 +989,17 @@ | |
| 989 | " UNION SELECT 'Sandbox' AS name" |
| 990 | " ORDER BY name COLLATE NOCASE"); |
| 991 | CX("["); |
| 992 | while( SQLITE_ROW==db_step(&q) ){ |
| 993 | char const * zName = db_column_text(&q,0); |
| 994 | if(n++){ |
| 995 | CX(","); |
| 996 | } |
| 997 | if(verbose==0){ |
| 998 | CX("%!j", zName); |
| 999 | }else{ |
| 1000 | wiki_ajax_emit_page_object(zName, includeContent); |
| 1001 | } |
| 1002 | } |
| 1003 | CX("]"); |
| 1004 | db_finalize(&q); |
| 1005 | db_end_transaction(0); |
| 1006 |