Fossil SCM

Updated the wiki CLI command to account for the sandbox pseudo-page and removed an obsolete TODO.

stephan 2020-08-01 18:47 trunk
Commit 7bc942704d2c9356db444bb910dcd67b1c43121d86a22024d2a0d99588fb0fb4
2 files changed +39 -33 +2 -1
+39 -33
--- src/wiki.c
+++ src/wiki.c
@@ -1917,13 +1917,18 @@
19171917
** year-month-day form, it may be truncated, the "T" may be replaced by
19181918
** a space, and it may also name a timezone offset from UTC as "-HH:MM"
19191919
** (westward) or "+HH:MM" (eastward). Either no timezone suffix or "Z"
19201920
** means UTC.
19211921
**
1922
+** The "Sandbox" wiki pseudo-page is a special case. Its name is
1923
+** checked case-insensitively and either "create" or "commit" may be
1924
+** used to update its contents.
19221925
*/
19231926
void wiki_cmd(void){
19241927
int n;
1928
+ int isSandbox = 0; /* true if dealing with sandbox pseudo-page */
1929
+
19251930
db_find_and_open_repository(0, 0);
19261931
if( g.argc<3 ){
19271932
goto wiki_cmd_usage;
19281933
}
19291934
n = strlen(g.argv[2]);
@@ -1930,14 +1935,14 @@
19301935
if( n==0 ){
19311936
goto wiki_cmd_usage;
19321937
}
19331938
19341939
if( strncmp(g.argv[2],"export",n)==0 ){
1935
- const char *zPageName; /* Name of the wiki page to export */
1940
+ const char *zPageName = 0; /* Name of the wiki page to export */
19361941
const char *zFile; /* Name of the output file (0=stdout) */
19371942
const char *zETime; /* The name of the technote to export */
1938
- int rid; /* Artifact ID of the wiki page */
1943
+ int rid = 0; /* Artifact ID of the wiki page */
19391944
int i; /* Loop counter */
19401945
char *zBody = 0; /* Wiki page content */
19411946
Blob body = empty_blob; /* Wiki page content */
19421947
Manifest *pWiki = 0; /* Parsed wiki page content */
19431948
int fHtml = 0; /* Export in HTML form */
@@ -1955,17 +1960,18 @@
19551960
if( !zETime ){
19561961
if( (g.argc!=4) && (g.argc!=5) ){
19571962
usage("export ?-html? PAGENAME ?FILE?");
19581963
}
19591964
zPageName = g.argv[3];
1960
- rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
1961
- " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
1962
- " ORDER BY x.mtime DESC LIMIT 1",
1963
- zPageName
1964
- );
1965
- if( (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0 ){
1966
- zBody = pWiki->zWiki;
1965
+ isSandbox = is_sandbox(zPageName);
1966
+ if(isSandbox){
1967
+ zBody = db_get("sandbox", 0);
1968
+ }else{
1969
+ wiki_fetch_by_name(zPageName, 0, &rid, &pWiki);
1970
+ if(pWiki){
1971
+ zBody = pWiki->zWiki;
1972
+ }
19671973
}
19681974
if( zBody==0 ){
19691975
fossil_fatal("wiki page [%s] not found",zPageName);
19701976
}
19711977
zFile = (g.argc==4) ? "-" : g.argv[4];
@@ -1991,30 +1997,24 @@
19911997
blob_init(&body, zBody, -1);
19921998
if(fHtml==0){
19931999
blob_append(&body, "\n", 1);
19942000
}else{
19952001
Blob html = empty_blob; /* HTML-ized content */
1996
- const char * zMimetype = wiki_filter_mimetypes(pWiki->zMimetype);
2002
+ const char * zMimetype = isSandbox
2003
+ ? db_get("sandbox-mimetype", "text/x-fossil-wiki")
2004
+ : wiki_filter_mimetypes(pWiki->zMimetype);
19972005
if( fossil_strcmp(zMimetype, "text/x-fossil-wiki")==0 ){
19982006
wiki_convert(&body,&html,0);
19992007
}else if( fossil_strcmp(zMimetype, "text/x-markdown")==0 ){
2000
- markdown_to_html(&body,0,&html)
2001
- /* TODO: add -HTML|-H flag to work like -html|-h but also
2002
- ** add <html><body> tag wrappers around the output. The
2003
- ** hurdle here is that the markdown converter resets its
2004
- ** input blob before appending the output, which is
2005
- ** different from wiki_convert() and htmlize_to_blob(), and
2006
- ** precludes us simply appending the opening <html><body>
2007
- ** part to the body
2008
- */;
2008
+ markdown_to_html(&body,0,&html);
20092009
safe_html_context(DOCSRC_WIKI);
20102010
safe_html(&html);
20112011
}else if( fossil_strcmp(zMimetype, "text/plain")==0 ){
20122012
htmlize_to_blob(&html,zBody,i);
20132013
}else{
20142014
fossil_fatal("Unsupported MIME type '%s' for wiki page '%s'.",
2015
- zMimetype, pWiki->zWikiTitle );
2015
+ zMimetype, pWiki ? pWiki->zWikiTitle : zPageName );
20162016
}
20172017
blob_reset(&body);
20182018
body = html /* transfer memory */;
20192019
}
20202020
pFile = fossil_fopen_for_output(zFile);
@@ -2056,28 +2056,28 @@
20562056
if( g.argc==4 ){
20572057
blob_read_from_channel(&content, stdin, -1);
20582058
}else{
20592059
blob_read_from_file(&content, g.argv[4], ExtFILE);
20602060
}
2061
+ isSandbox = is_sandbox(zPageName);
20612062
if ( !zETime ){
2062
- rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
2063
- " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
2064
- " ORDER BY x.mtime DESC LIMIT 1",
2065
- zPageName
2066
- );
2067
- if( rid>0 ){
2068
- pWiki = manifest_get(rid, CFTYPE_WIKI, 0);
2063
+ if( !isSandbox ){
2064
+ wiki_fetch_by_name(zPageName, 0, &rid, &pWiki);
20692065
}
20702066
}else{
20712067
rid = wiki_technote_to_rid(zETime);
20722068
if( rid>0 ){
20732069
pWiki = manifest_get(rid, CFTYPE_EVENT, 0);
20742070
}
20752071
}
20762072
if( !zMimeType || !*zMimeType ){
20772073
/* Try to deduce the mime type based on the prior version. */
2078
- if( pWiki!=0 && (pWiki->zMimetype && *pWiki->zMimetype) ){
2074
+ if(isSandbox){
2075
+ zMimeType =
2076
+ wiki_filter_mimetypes(db_get("sandbox-mimetype",
2077
+ "text/x-fossil-wiki"));
2078
+ }else if( pWiki!=0 && (pWiki->zMimetype && *pWiki->zMimetype) ){
20792079
zMimeType = pWiki->zMimetype;
20802080
}
20812081
}else{
20822082
zMimeType = wiki_filter_mimetypes(zMimeType);
20832083
}
@@ -2087,24 +2087,30 @@
20872087
}else{
20882088
/* Creating a tech note with same timestamp is permitted
20892089
and should create a new tech note */
20902090
rid = 0;
20912091
}
2092
- }else if( !isCreate && rid == 0 ){
2092
+ }else if( !isCreate && rid==0 && isSandbox==0 ){
20932093
if ( !zETime ){
20942094
fossil_fatal("no such wiki page: %s", zPageName);
20952095
}else{
20962096
fossil_fatal("no such tech note: %s", zETime);
20972097
}
20982098
}
20992099
21002100
if( !zETime ){
2101
- wiki_cmd_commit(zPageName, rid, &content, zMimeType, 1);
2102
- if( g.argv[2][1]=='r' ){
2103
- fossil_print("Created new wiki page %s.\n", zPageName);
2101
+ if(isSandbox){
2102
+ db_set("sandbox",blob_str(&content),0);
2103
+ db_set("sandbox-mimetype",zMimeType,0);
2104
+ fossil_print("Updated sandbox pseudo-page.\n");
21042105
}else{
2105
- fossil_print("Updated wiki page %s.\n", zPageName);
2106
+ wiki_cmd_commit(zPageName, rid, &content, zMimeType, 1);
2107
+ if( g.argv[2][1]=='r' ){
2108
+ fossil_print("Created new wiki page %s.\n", zPageName);
2109
+ }else{
2110
+ fossil_print("Updated wiki page %s.\n", zPageName);
2111
+ }
21062112
}
21072113
}else{
21082114
if( rid != -1 ){
21092115
char *zMETime; /* Normalized, mutable version of zETime */
21102116
zMETime = db_text(0, "SELECT coalesce(datetime(%Q),datetime('now'))",
21112117
--- src/wiki.c
+++ src/wiki.c
@@ -1917,13 +1917,18 @@
1917 ** year-month-day form, it may be truncated, the "T" may be replaced by
1918 ** a space, and it may also name a timezone offset from UTC as "-HH:MM"
1919 ** (westward) or "+HH:MM" (eastward). Either no timezone suffix or "Z"
1920 ** means UTC.
1921 **
 
 
 
1922 */
1923 void wiki_cmd(void){
1924 int n;
 
 
1925 db_find_and_open_repository(0, 0);
1926 if( g.argc<3 ){
1927 goto wiki_cmd_usage;
1928 }
1929 n = strlen(g.argv[2]);
@@ -1930,14 +1935,14 @@
1930 if( n==0 ){
1931 goto wiki_cmd_usage;
1932 }
1933
1934 if( strncmp(g.argv[2],"export",n)==0 ){
1935 const char *zPageName; /* Name of the wiki page to export */
1936 const char *zFile; /* Name of the output file (0=stdout) */
1937 const char *zETime; /* The name of the technote to export */
1938 int rid; /* Artifact ID of the wiki page */
1939 int i; /* Loop counter */
1940 char *zBody = 0; /* Wiki page content */
1941 Blob body = empty_blob; /* Wiki page content */
1942 Manifest *pWiki = 0; /* Parsed wiki page content */
1943 int fHtml = 0; /* Export in HTML form */
@@ -1955,17 +1960,18 @@
1955 if( !zETime ){
1956 if( (g.argc!=4) && (g.argc!=5) ){
1957 usage("export ?-html? PAGENAME ?FILE?");
1958 }
1959 zPageName = g.argv[3];
1960 rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
1961 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
1962 " ORDER BY x.mtime DESC LIMIT 1",
1963 zPageName
1964 );
1965 if( (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0 ){
1966 zBody = pWiki->zWiki;
 
1967 }
1968 if( zBody==0 ){
1969 fossil_fatal("wiki page [%s] not found",zPageName);
1970 }
1971 zFile = (g.argc==4) ? "-" : g.argv[4];
@@ -1991,30 +1997,24 @@
1991 blob_init(&body, zBody, -1);
1992 if(fHtml==0){
1993 blob_append(&body, "\n", 1);
1994 }else{
1995 Blob html = empty_blob; /* HTML-ized content */
1996 const char * zMimetype = wiki_filter_mimetypes(pWiki->zMimetype);
 
 
1997 if( fossil_strcmp(zMimetype, "text/x-fossil-wiki")==0 ){
1998 wiki_convert(&body,&html,0);
1999 }else if( fossil_strcmp(zMimetype, "text/x-markdown")==0 ){
2000 markdown_to_html(&body,0,&html)
2001 /* TODO: add -HTML|-H flag to work like -html|-h but also
2002 ** add <html><body> tag wrappers around the output. The
2003 ** hurdle here is that the markdown converter resets its
2004 ** input blob before appending the output, which is
2005 ** different from wiki_convert() and htmlize_to_blob(), and
2006 ** precludes us simply appending the opening <html><body>
2007 ** part to the body
2008 */;
2009 safe_html_context(DOCSRC_WIKI);
2010 safe_html(&html);
2011 }else if( fossil_strcmp(zMimetype, "text/plain")==0 ){
2012 htmlize_to_blob(&html,zBody,i);
2013 }else{
2014 fossil_fatal("Unsupported MIME type '%s' for wiki page '%s'.",
2015 zMimetype, pWiki->zWikiTitle );
2016 }
2017 blob_reset(&body);
2018 body = html /* transfer memory */;
2019 }
2020 pFile = fossil_fopen_for_output(zFile);
@@ -2056,28 +2056,28 @@
2056 if( g.argc==4 ){
2057 blob_read_from_channel(&content, stdin, -1);
2058 }else{
2059 blob_read_from_file(&content, g.argv[4], ExtFILE);
2060 }
 
2061 if ( !zETime ){
2062 rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
2063 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
2064 " ORDER BY x.mtime DESC LIMIT 1",
2065 zPageName
2066 );
2067 if( rid>0 ){
2068 pWiki = manifest_get(rid, CFTYPE_WIKI, 0);
2069 }
2070 }else{
2071 rid = wiki_technote_to_rid(zETime);
2072 if( rid>0 ){
2073 pWiki = manifest_get(rid, CFTYPE_EVENT, 0);
2074 }
2075 }
2076 if( !zMimeType || !*zMimeType ){
2077 /* Try to deduce the mime type based on the prior version. */
2078 if( pWiki!=0 && (pWiki->zMimetype && *pWiki->zMimetype) ){
 
 
 
 
2079 zMimeType = pWiki->zMimetype;
2080 }
2081 }else{
2082 zMimeType = wiki_filter_mimetypes(zMimeType);
2083 }
@@ -2087,24 +2087,30 @@
2087 }else{
2088 /* Creating a tech note with same timestamp is permitted
2089 and should create a new tech note */
2090 rid = 0;
2091 }
2092 }else if( !isCreate && rid == 0 ){
2093 if ( !zETime ){
2094 fossil_fatal("no such wiki page: %s", zPageName);
2095 }else{
2096 fossil_fatal("no such tech note: %s", zETime);
2097 }
2098 }
2099
2100 if( !zETime ){
2101 wiki_cmd_commit(zPageName, rid, &content, zMimeType, 1);
2102 if( g.argv[2][1]=='r' ){
2103 fossil_print("Created new wiki page %s.\n", zPageName);
 
2104 }else{
2105 fossil_print("Updated wiki page %s.\n", zPageName);
 
 
 
 
 
2106 }
2107 }else{
2108 if( rid != -1 ){
2109 char *zMETime; /* Normalized, mutable version of zETime */
2110 zMETime = db_text(0, "SELECT coalesce(datetime(%Q),datetime('now'))",
2111
--- src/wiki.c
+++ src/wiki.c
@@ -1917,13 +1917,18 @@
1917 ** year-month-day form, it may be truncated, the "T" may be replaced by
1918 ** a space, and it may also name a timezone offset from UTC as "-HH:MM"
1919 ** (westward) or "+HH:MM" (eastward). Either no timezone suffix or "Z"
1920 ** means UTC.
1921 **
1922 ** The "Sandbox" wiki pseudo-page is a special case. Its name is
1923 ** checked case-insensitively and either "create" or "commit" may be
1924 ** used to update its contents.
1925 */
1926 void wiki_cmd(void){
1927 int n;
1928 int isSandbox = 0; /* true if dealing with sandbox pseudo-page */
1929
1930 db_find_and_open_repository(0, 0);
1931 if( g.argc<3 ){
1932 goto wiki_cmd_usage;
1933 }
1934 n = strlen(g.argv[2]);
@@ -1930,14 +1935,14 @@
1935 if( n==0 ){
1936 goto wiki_cmd_usage;
1937 }
1938
1939 if( strncmp(g.argv[2],"export",n)==0 ){
1940 const char *zPageName = 0; /* Name of the wiki page to export */
1941 const char *zFile; /* Name of the output file (0=stdout) */
1942 const char *zETime; /* The name of the technote to export */
1943 int rid = 0; /* Artifact ID of the wiki page */
1944 int i; /* Loop counter */
1945 char *zBody = 0; /* Wiki page content */
1946 Blob body = empty_blob; /* Wiki page content */
1947 Manifest *pWiki = 0; /* Parsed wiki page content */
1948 int fHtml = 0; /* Export in HTML form */
@@ -1955,17 +1960,18 @@
1960 if( !zETime ){
1961 if( (g.argc!=4) && (g.argc!=5) ){
1962 usage("export ?-html? PAGENAME ?FILE?");
1963 }
1964 zPageName = g.argv[3];
1965 isSandbox = is_sandbox(zPageName);
1966 if(isSandbox){
1967 zBody = db_get("sandbox", 0);
1968 }else{
1969 wiki_fetch_by_name(zPageName, 0, &rid, &pWiki);
1970 if(pWiki){
1971 zBody = pWiki->zWiki;
1972 }
1973 }
1974 if( zBody==0 ){
1975 fossil_fatal("wiki page [%s] not found",zPageName);
1976 }
1977 zFile = (g.argc==4) ? "-" : g.argv[4];
@@ -1991,30 +1997,24 @@
1997 blob_init(&body, zBody, -1);
1998 if(fHtml==0){
1999 blob_append(&body, "\n", 1);
2000 }else{
2001 Blob html = empty_blob; /* HTML-ized content */
2002 const char * zMimetype = isSandbox
2003 ? db_get("sandbox-mimetype", "text/x-fossil-wiki")
2004 : wiki_filter_mimetypes(pWiki->zMimetype);
2005 if( fossil_strcmp(zMimetype, "text/x-fossil-wiki")==0 ){
2006 wiki_convert(&body,&html,0);
2007 }else if( fossil_strcmp(zMimetype, "text/x-markdown")==0 ){
2008 markdown_to_html(&body,0,&html);
 
 
 
 
 
 
 
 
2009 safe_html_context(DOCSRC_WIKI);
2010 safe_html(&html);
2011 }else if( fossil_strcmp(zMimetype, "text/plain")==0 ){
2012 htmlize_to_blob(&html,zBody,i);
2013 }else{
2014 fossil_fatal("Unsupported MIME type '%s' for wiki page '%s'.",
2015 zMimetype, pWiki ? pWiki->zWikiTitle : zPageName );
2016 }
2017 blob_reset(&body);
2018 body = html /* transfer memory */;
2019 }
2020 pFile = fossil_fopen_for_output(zFile);
@@ -2056,28 +2056,28 @@
2056 if( g.argc==4 ){
2057 blob_read_from_channel(&content, stdin, -1);
2058 }else{
2059 blob_read_from_file(&content, g.argv[4], ExtFILE);
2060 }
2061 isSandbox = is_sandbox(zPageName);
2062 if ( !zETime ){
2063 if( !isSandbox ){
2064 wiki_fetch_by_name(zPageName, 0, &rid, &pWiki);
 
 
 
 
 
2065 }
2066 }else{
2067 rid = wiki_technote_to_rid(zETime);
2068 if( rid>0 ){
2069 pWiki = manifest_get(rid, CFTYPE_EVENT, 0);
2070 }
2071 }
2072 if( !zMimeType || !*zMimeType ){
2073 /* Try to deduce the mime type based on the prior version. */
2074 if(isSandbox){
2075 zMimeType =
2076 wiki_filter_mimetypes(db_get("sandbox-mimetype",
2077 "text/x-fossil-wiki"));
2078 }else if( pWiki!=0 && (pWiki->zMimetype && *pWiki->zMimetype) ){
2079 zMimeType = pWiki->zMimetype;
2080 }
2081 }else{
2082 zMimeType = wiki_filter_mimetypes(zMimeType);
2083 }
@@ -2087,24 +2087,30 @@
2087 }else{
2088 /* Creating a tech note with same timestamp is permitted
2089 and should create a new tech note */
2090 rid = 0;
2091 }
2092 }else if( !isCreate && rid==0 && isSandbox==0 ){
2093 if ( !zETime ){
2094 fossil_fatal("no such wiki page: %s", zPageName);
2095 }else{
2096 fossil_fatal("no such tech note: %s", zETime);
2097 }
2098 }
2099
2100 if( !zETime ){
2101 if(isSandbox){
2102 db_set("sandbox",blob_str(&content),0);
2103 db_set("sandbox-mimetype",zMimeType,0);
2104 fossil_print("Updated sandbox pseudo-page.\n");
2105 }else{
2106 wiki_cmd_commit(zPageName, rid, &content, zMimeType, 1);
2107 if( g.argv[2][1]=='r' ){
2108 fossil_print("Created new wiki page %s.\n", zPageName);
2109 }else{
2110 fossil_print("Updated wiki page %s.\n", zPageName);
2111 }
2112 }
2113 }else{
2114 if( rid != -1 ){
2115 char *zMETime; /* Normalized, mutable version of zETime */
2116 zMETime = db_text(0, "SELECT coalesce(datetime(%Q),datetime('now'))",
2117
--- www/changes.wiki
+++ www/changes.wiki
@@ -63,11 +63,12 @@
6363
* The [/help?cmd=/wikiedit|wiki editor] has been modernized and is
6464
now Ajax-based. The WYSIWYG editing option for Fossil-format wiki
6565
pages was removed. (Please let us know, via the site's Support menu,
6666
if that removal unduly impacts you.) This also changes the semantics
6767
of the wiki "Sandbox": that pseudo-page may be freely edited but
68
- no longer saved via the UI.
68
+ no longer saved via the UI (the [/help?cmd=wiki|wiki CLI command]
69
+ can, though).
6970
* Countless documentation enhancements.
7071
7172
<a name='v2_11'></a>
7273
<h2>Changes for Version 2.11 (2020-05-25)</h2>
7374
7475
--- www/changes.wiki
+++ www/changes.wiki
@@ -63,11 +63,12 @@
63 * The [/help?cmd=/wikiedit|wiki editor] has been modernized and is
64 now Ajax-based. The WYSIWYG editing option for Fossil-format wiki
65 pages was removed. (Please let us know, via the site's Support menu,
66 if that removal unduly impacts you.) This also changes the semantics
67 of the wiki "Sandbox": that pseudo-page may be freely edited but
68 no longer saved via the UI.
 
69 * Countless documentation enhancements.
70
71 <a name='v2_11'></a>
72 <h2>Changes for Version 2.11 (2020-05-25)</h2>
73
74
--- www/changes.wiki
+++ www/changes.wiki
@@ -63,11 +63,12 @@
63 * The [/help?cmd=/wikiedit|wiki editor] has been modernized and is
64 now Ajax-based. The WYSIWYG editing option for Fossil-format wiki
65 pages was removed. (Please let us know, via the site's Support menu,
66 if that removal unduly impacts you.) This also changes the semantics
67 of the wiki "Sandbox": that pseudo-page may be freely edited but
68 no longer saved via the UI (the [/help?cmd=wiki|wiki CLI command]
69 can, though).
70 * Countless documentation enhancements.
71
72 <a name='v2_11'></a>
73 <h2>Changes for Version 2.11 (2020-05-25)</h2>
74
75

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button