# HG changeset patch # User Paul Boddie # Date 1407692076 -7200 # Node ID 484cacbd943664328bd34bdf698a3ff66ce850e3 # Parent debb4b2401fbcb2eebf2b83efa59e9d0cc24f6f9 Added support for attachment downloads via the /download/attachment URL syntax. diff -r debb4b2401fb -r 484cacbd9436 README.txt --- a/README.txt Sun Aug 10 18:44:07 2014 +0200 +++ b/README.txt Sun Aug 10 19:34:36 2014 +0200 @@ -264,11 +264,12 @@ information. The redirect.py script, apart from supporting identifier-to-page redirects, -also supports PDF page exports since the "doexportpage" action uses -identifiers to indicate which page is to be exported. In an environment that -uses .htaccess and mod_rewrite, the redirect.py script should also be deployed -under separate names (such as export.py and exportpdf.py) so that it can -discover whether it should be exporting a page instead of just showing it. +also supports attachment downloads and PDF page exports, since both kinds of +resource employ identifiers to indicate which page is involved. In an +environment that uses .htaccess and mod_rewrite, the redirect.py script should +also be deployed under separate names (such as export.py and exportpdf.py) so +that it can discover whether it should be exporting a page instead of just +showing it. The search.py script redirects search requests in a suitable form to the MoinMoin "fullsearch" action. diff -r debb4b2401fb -r 484cacbd9436 config/mailmanwiki-redirect --- a/config/mailmanwiki-redirect Sun Aug 10 18:44:07 2014 +0200 +++ b/config/mailmanwiki-redirect Sun Aug 10 19:34:36 2014 +0200 @@ -4,3 +4,4 @@ ScriptAlias /spaces/flyingpdf/pdfpageexport.action "/var/www/mmwiki-scripts/redirect.py" ScriptAlias /dosearchsite.action "/var/www/mmwiki-scripts/search.py" ScriptAlias /dashboard.action "/var/www/mmwiki-scripts/dashboard.py" +ScriptAlias /download/attachment "/var/www/mmwiki-scripts/redirect.py" diff -r debb4b2401fb -r 484cacbd9436 config/mailmanwiki-redirect-htaccess --- a/config/mailmanwiki-redirect-htaccess Sun Aug 10 18:44:07 2014 +0200 +++ b/config/mailmanwiki-redirect-htaccess Sun Aug 10 19:34:36 2014 +0200 @@ -21,3 +21,7 @@ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^dashboard.action /dashboard.py [PT,L,QSA] + +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^/download/attachment/(.*) /redirect.py/$1 [PT,L,QSA] diff -r debb4b2401fb -r 484cacbd9436 scripts/redirect.py --- a/scripts/redirect.py Sun Aug 10 18:44:07 2014 +0200 +++ b/scripts/redirect.py Sun Aug 10 19:34:36 2014 +0200 @@ -16,17 +16,32 @@ # An empty string means that the wiki is anchored at the site root. URL_PREFIX = "" +DOWNLOAD_SCRIPT = "/download.py" EXPORT_SCRIPT = "/export.py" EXPORT_PDF_SCRIPT = "/exportpdf.py" -# See the scripts/tiny.py program for similar code in a stand-alone program. +# Conversion of tiny identifiers to verbose identifiers. from base64 import b64decode from struct import unpack def identifier(s): + + "Extract an identifier from the given string 's'." + + # Isolate numeric identifiers for things like downloads: + # /download/attachment//? + + if s.split("/")[0].isdigit(): + return s.split("/")[0] + + # Reject strings that are too long for tiny identifiers. + if len(s) > 6: return None + + # Attempt to unpack tiny identifiers. + bytes = b64decode(s.replace("-", "/").replace("_", "+") + "=" * (6 - len(s))) return str(unpack("