Package: didiwiki
Version: 0.5-13
Severity: wishlist
Tags: patch
This is a proposed patch for 0.5-14.
As a side effect, it would also fix bug #864883.
Note that this is *not* related to "Amigo's 0.8 Didiwiki" from the
PuppyLinux project, but has been developed independently based on the
current Debian version.
The patch is intended to be applied atop of 0.5-13 and contains the
following parts:
001_fix_camelcase_in_help.patch
003_document_image_filetypes.patch
004_reduced_logging_opt.patch
005_https_support.patch
006_delete_empty_pages.patch
007_backwards_compatible_automigrate_away_nul.patch
The patches have been developed with Quilt, but have then been
reformatted so that they will also be accepted by "git am".
Here is an overview of what the patches do:
==============================
$ sed '/^Subject/,/^diff /!d; /^diff / s/./-/g' *.patch
Subject: Avoid incorrectly formatted word "camelcase"
The help text contains /camelcase/, but for some reason (read: most
likely a bug) the word does not get formatted as italic text.
Therefore changing the word to CamelCase, which will also serve as a
better example.
original-patch-name: fix_camelcase_in_help.patch
--------------------------------------------
Subject: Document which image files types are supported
The current help text mentions just a few examples of possible image
file types, but does not give an exhaustive list.
Fix that.
original-patch-name: document_image_filetypes.patch
--------------------------------------------
Subject: Add --log-less option to restrict logging
I did not like that didiwiki used to flood my syslog with messages what
pages were shown.
Firstly, those messages are mostly irrelevant except for debugging.
Secondly, I consider this to be a privacy issue. didiwiki is supposed to
be a private Wiki, so I cannot see why this private activity should be
logged at all.
When using the shipped /etc/default/didiwiki configuration file, logging
can be restricted via the LISTEN setting: Change
LISTEN=127.0.0.1
into
LISTEN="127.0.0.1 --log-less"
This should do the trick without needing to edit the existing service
script.
original-patch-name: reduced_logging_opt.patch
------------------------------------
Subject: Also support "https://"-URLs as external links
Plus add an exhaustive list of supported URL schemes to the help text.
original-patch-name: https_support.patch
------------------------------------
Subject: Add support for page deletions
This works really simple: If an existing page is edited and turns out to
be empty when saved, it is deleted instead.
original-patch-name: delete_empty_pages.patch
------------------------------------
Subject: Get rid of useless NUL terminator in Wiki pages
Until now, Wiki pages have been saved as Internet text files (i. e.
using CRLF newline sequences), plus a NUL byte at the end.
At first, I assumed this was the case becaus DidiWiki would mmap() the
whole file, therefore requiring the NUL byte as a buffer terminator.
However, this is not the case. The files are read with the usual
functions; not mmapped. IMHO, the NUL terminator is completely useless.
Therefore change the code so that a NUL terminator will do no harm when
it is read, but will be ignored and is not required at all.
Also change code for writing wiki pages so that no NUL terminator is
written.
This allows a seamless and transparent migration from old existing Wiki
pages which still contain NUL terminators to newly written or updated
Wiki pages without the NUL terminator.
This means it is not necessary to convert any existing Wiki Pages. They
will lose their NUL terminator if they should be updated, but will also
work fine with the terminator still present.
original-patch-name: backwards_compatible_automigrate_away_nul.patch
------------------------------------
==============================================================================
The patch can either be applied in a single operation with
$ patch -p1 < didiwiki_0.5-13_p1-2018.258.patch
or by unpacking it into individual patches first and then applying the
individual patches:
$ ar xov didiwiki_0.5-13_p1-2018.258.patch
$ cat 0*.patch | patch -p1
Finally, here is the patch itself.
$ cat << 'EOF' > didiwiki_0.5-13_p1-2018.258.patch
!<arch>
// 208 `
001_fix_camelcase_in_help.patch/
003_document_image_filetypes.patch/
004_reduced_logging_opt.patch/
005_https_support.patch/
006_delete_empty_pages.patch/
007_backwards_compatible_automigrate_away_nul.patch/
/0 0 0 0 644 1415 `
From b35d756add96aa2c69d7e43beae90cda58730cec Mon Sep 17 00:00:00 2001
From: Guenther Brunthaler <gb@xquad.emgenxx69lwyn5ctlr4nl64ul.local>
Date: Thu, 13 Sep 2018 22:40:31 +0200
Subject: Avoid incorrectly formatted word "camelcase"
The help text contains /camelcase/, but for some reason (read: most
likely a bug) the word does not get formatted as italic text.
Therefore changing the word to CamelCase, which will also serve as a
better example.
original-patch-name: fix_camelcase_in_help.patch
diff --git a/src/wikitext.h b/src/wikitext.h
index 50cabe5..1869120 100644
--- a/src/wikitext.h
+++ b/src/wikitext.h
@@ -122,8 +122,8 @@
" /*Combination of bold and italics*/\n" \
"----\n" \
"\n" \
-"WikiLinks are formed by two or more words in /camelcase/.\n" \
-" WikiLinks are formed by two or more words in /camelcase/.\n" \
+"WikiLinks are formed by two or more words in CamelCase.\n" \
+" WikiLinks are formed by two or more words in CamelCase.\n" \
"External links begin with http://, like http://www.freepan.org\n" \
" External links begin with http://, like http://www.freepan.org\n" \
"Forced wiki [links] are a alphanumeric string surrounded by square
brackets.\n" \
--
2.11.0
/33 0 0 0 644 1112 `
From 59e1d15cbf52b28bb05d204fe0fce3a4f73b1562 Mon Sep 17 00:00:00 2001
From: Guenther Brunthaler <gb@xquad.emgenxx69lwyn5ctlr4nl64ul.local>
Date: Thu, 13 Sep 2018 22:50:04 +0200
Subject: Document which image files types are supported
The current help text mentions just a few examples of possible image
file types, but does not give an exhaustive list.
Fix that.
original-patch-name: document_image_filetypes.patch
diff --git a/src/wikitext.h b/src/wikitext.h
index 1869120..41635b9 100644
--- a/src/wikitext.h
+++ b/src/wikitext.h
@@ -140,6 +140,7 @@
"\n" \
"http://www.google.com/images/logo.gif\n" \
" http://www.google.com/images/logo.gif\n" \
+"Supported image file extensions: .gif .png .jpg .jpeg\n" \
"----\n" \
"Unordered lists begin with a '* '. The number of asterisks determines
the level:\n" \
"* foo\n" \
--
2.11.0
/69 0 0 0 644 2492 `
From 7f8eb987429ea32b7aafc39107a22afd9bb0bde4 Mon Sep 17 00:00:00 2001
From: Guenther Brunthaler <gb@xquad.emgenxx69lwyn5ctlr4nl64ul.local>
Date: Fri, 14 Sep 2018 18:23:04 +0200
Subject: Add --log-less option to restrict logging
I did not like that didiwiki used to flood my syslog with messages what
pages were shown.
Firstly, those messages are mostly irrelevant except for debugging.
Secondly, I consider this to be a privacy issue. didiwiki is supposed to
be a private Wiki, so I cannot see why this private activity should be
logged at all.
When using the shipped /etc/default/didiwiki configuration file, logging
can be restricted via the LISTEN setting: Change
LISTEN=127.0.0.1
into
LISTEN="127.0.0.1 --log-less"
This should do the trick without needing to edit the existing service
script.
original-patch-name: reduced_logging_opt.patch
diff --git a/src/didi.c b/src/didi.c
index f2ce746..b141db6 100644
--- a/src/didi.c
+++ b/src/didi.c
@@ -1,11 +1,13 @@
#include "didi.h"
static int debug;
+int restrict_logging;
int
usage()
{
fprintf(stderr, "Usage: didiwiki [options]\n");
+ fprintf(stderr, " --log-less : suppress non-critical
syslog output\n");
fprintf(stderr, " -d, --debug : debug mode, listens to
requests from stdin\n");
fprintf(stderr, " -h, --home <path> : specify didiwiki's home
directory\n");
fprintf(stderr, " -l, --listen <ipaddr> : specify IP address\n");
@@ -33,6 +35,7 @@ main(int argc, char **argv)
{
static struct option long_options[] =
{
+ {"log-less", no_argument, 0, 12},
{"debug", no_argument, 0, 'd'},
{"listen", required_argument, 0, 'l'},
{"port", required_argument, 0, 'p'},
@@ -54,6 +57,10 @@ main(int argc, char **argv)
{
case 0:
break;
+
+ case 12: /* ^L restrict syslog output. */
+ restrict_logging = 1;
+ break;
case 'd':
debug = 1;
diff --git a/src/http.c b/src/http.c
index 13fd807..c0314fa 100644
--- a/src/http.c
+++ b/src/http.c
@@ -481,6 +481,8 @@ sigterm(int sig)
*/
#define MAX_PARALLEL 5
+extern int restrict_logging;
+
/*
** Implement an HTTP server daemon.
*/
@@ -539,6 +541,10 @@ http_server(struct in_addr address, int iPort)
/* log starting information */
openlog("didiwiki", 0, 0);
+ if (restrict_logging)
+ {
+ setlogmask(LOG_EMERG | LOG_ALERT | LOG_CRIT | LOG_ERR);
+ }
syslog(LOG_LOCAL0|LOG_INFO, "started with PID %d", getpid());
listen(listener,10);
--
2.11.0
/100 0 0 0 644 1675 `
From bc904cb25276c34440132f48a53e7289e81a3eec Mon Sep 17 00:00:00 2001
From: Guenther Brunthaler <gb@xquad.emgenxx69lwyn5ctlr4nl64ul.local>
Date: Thu, 13 Sep 2018 16:05:24 +0200
Subject: Also support "https://"-URLs as external links
Plus add an exhaustive list of supported URL schemes to the help text.
original-patch-name: https_support.patch
diff --git a/src/wiki.c b/src/wiki.c
index 4c64c95..10cc73c 100644
--- a/src/wiki.c
+++ b/src/wiki.c
@@ -81,6 +81,7 @@ check_for_link(char *line, int *skip_chars)
p++;
}
else if (!strncasecmp(p, "http://", 7)
+ || !strncasecmp(p, "https://", 8)
|| !strncasecmp(p, "mailto://", 9)
|| !strncasecmp(p, "file://", 7))
{
@@ -132,7 +133,7 @@ check_for_link(char *line, int *skip_chars)
{
char *extra_attr = "";
- if (!strncasecmp(url, "http://", 7))
+ if (!strncasecmp(url, "http://", 7) || !strncasecmp(url, "https://",
8))
extra_attr = " title='WWW link' ";
if (title)
diff --git a/src/wikitext.h b/src/wikitext.h
index 41635b9..0fb04c0 100644
--- a/src/wikitext.h
+++ b/src/wikitext.h
@@ -134,6 +134,7 @@
" Sometimes !WordsShouldNotMakeAWikiLink so put a '! ' beforehand.\n"
\
"Same thing with !http://foobar.com\n" \
" Same thing with !http://foobar.com\n" \
+"Supported types of external links: http:// https:// mailto:// file://\n" \
"----\n" \
"\n" \
"Links to images display the image:\n" \
--
2.11.0
/125 0 0 0 644 1824 `
From d83620c6c83819f3056c6d638e650d19e81cd53f Mon Sep 17 00:00:00 2001
From: Guenther Brunthaler <gb@xquad.emgenxx69lwyn5ctlr4nl64ul.local>
Date: Thu, 13 Sep 2018 17:06:03 +0200
Subject: Add support for page deletions
This works really simple: If an existing page is edited and turns out to
be empty when saved, it is deleted instead.
original-patch-name: delete_empty_pages.patch
diff --git a/src/wiki.c b/src/wiki.c
index 10cc73c..da02723 100644
--- a/src/wiki.c
+++ b/src/wiki.c
@@ -1027,6 +1027,13 @@ wiki_handle_http_request(HttpRequest *req)
/* TODO: dont blindly write wikitext data to disk */
if ( (wikitext = http_request_param_get(req, "wikitext")) != NULL)
{
+ if (*wikitext == '\0' && access(page, F_OK) == 0)
+ {
+ syslog(LOG_LOCAL0|LOG_INFO, "delete empty page %s", page);
+ unlink(page); /* remove() would also delete empty directories. */
+ wiki_redirect(res, "WikiHome");
+ return;
+ }
file_write(page, wikitext);
/* log modified page name and IP address */
diff --git a/src/wikitext.h b/src/wikitext.h
index 0fb04c0..9a07274 100644
--- a/src/wikitext.h
+++ b/src/wikitext.h
@@ -83,7 +83,7 @@
\
"=Quick Guide \n" \
"Top toolbar usage\n" \
-"* [?edit Edit] Allows you to edit pages ( see below for rules )\n" \
+"* [?edit Edit] Allows you to edit pages (see below for rules). Saving
an empty page will delete it.\n" \
"* [/WikiHome Home] Takes you to the wiki front page\n" \
"* [/Changes Changes] Lists the pages changed by date\n"
\
"* [/Create New] Creates a new wiki page by title\n"
\
--
2.11.0
/155 0 0 0 644 1957 `
From 7e71a001db765ba9b31429893137769e8661bcfc Mon Sep 17 00:00:00 2001
From: Guenther Brunthaler <gb@xquad.emgenxx69lwyn5ctlr4nl64ul.local>
Date: Fri, 14 Sep 2018 21:30:46 +0200
Subject: Get rid of useless NUL terminator in Wiki pages
Until now, Wiki pages have been saved as Internet text files (i. e.
using CRLF newline sequences), plus a NUL byte at the end.
At first, I assumed this was the case becaus DidiWiki would mmap() the
whole file, therefore requiring the NUL byte as a buffer terminator.
However, this is not the case. The files are read with the usual
functions; not mmapped. IMHO, the NUL terminator is completely useless.
Therefore change the code so that a NUL terminator will do no harm when
it is read, but will be ignored and is not required at all.
Also change code for writing wiki pages so that no NUL terminator is
written.
This allows a seamless and transparent migration from old existing Wiki
pages which still contain NUL terminators to newly written or updated
Wiki pages without the NUL terminator.
This means it is not necessary to convert any existing Wiki Pages. They
will lose their NUL terminator if they should be updated, but will also
work fine with the terminator still present.
original-patch-name: backwards_compatible_automigrate_away_nul.patch
diff --git a/src/wiki.c b/src/wiki.c
index da02723..bc627fb 100644
--- a/src/wiki.c
+++ b/src/wiki.c
@@ -168,8 +168,8 @@ file_read(char *filename)
str = (char *)malloc(sizeof(char)*(st.st_size + 1));
len = fread(str, 1, st.st_size, fp);
- if (len >= 0) str[len] = '\0';
-
+ if (len >= 0) str[len] = '\0'; else { free(str); str= NULL; }
+
fclose(fp);
return str;
@@ -181,7 +181,7 @@ file_write(char *filename, char *data)
{
FILE* fp;
int bytes_written = 0;
- int len = strlen(data)+1;
+ int len = strlen(data);
if (!(fp = fopen(filename, "wb")))
return -1;
--
2.11.0
EOF