changeset 2879:cfdec0c11e3d

fix #88 add editor help based upon the content type of the target item
author RogerHaase <haaserd@gmail.com>
date Wed, 14 Jan 2015 21:32:03 -0700
parents 41f12b86b046
children 4eae4434fdfa
files MoinMoin/constants/contenttypes.py MoinMoin/items/__init__.py MoinMoin/items/content.py MoinMoin/templates/modify.html MoinMoin/templates/utils.html MoinMoin/themes/basic/templates/modify.html MoinMoin/themes/modernized/static/css/stylus/theme.styl MoinMoin/themes/modernized/static/css/theme.css
diffstat 8 files changed, 78 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/constants/contenttypes.py	Wed Jan 14 08:22:13 2015 -0700
+++ b/MoinMoin/constants/contenttypes.py	Wed Jan 14 21:32:03 2015 -0700
@@ -5,6 +5,10 @@
 MoinMoin - contenttype related constants
 """
 
+from collections import defaultdict
+from MoinMoin.i18n import _, L_, N_
+
+
 # Charset - we support only 'utf-8'. While older encodings might work,
 # we don't have the resources to test them, and there is no real
 # benefit for the user. IMPORTANT: use only lowercase 'utf-8'!
@@ -116,3 +120,54 @@
 GROUP_OTHER = 'Other Items'
 
 DRAWING_EXTENSIONS = ['.tdraw', '.adraw', '.svg', '.png', '.jpg', '.jpeg', '.gif', ]
+
+
+# help for wiki editors based on content type
+def ext_link(href, link_text=None):
+    return '<a class="moin-http" href="%s">%s</a>' % (href, link_text or href)
+
+
+help_on_plain_text = _("This is a plain text item, there is no markup.")
+help_on_binary = _("This item can not be edited, upload a revised file.")
+help_on_csv = ' '.join((
+    _("Use a semicolon or comma to separate cells."),
+    _("If the first row is recognized as a header, the table will be sortable."),
+    ext_link("https://en.wikipedia.org/wiki/Comma-separated_values"),
+))
+
+CONTENTTYPES_HELP_DOCS = {
+    # content type: tuple - must defer forming url until wiki root is known
+    u'text/x.moin.wiki;charset=utf-8': (('user/moinwiki.html', _("Click for help on Moin Wiki markup."))),
+    u'text/x-mediawiki;charset=utf-8': (('user/mediawiki.html', _("Click for help on Media Wiki markup."))),
+    u'text/x.moin.creole;charset=utf-8': (('user/creolewiki.html', _("Click for help on Creole Wiki markup."))),
+    u'text/x-markdown;charset=utf-8': (('user/markdown.html', _("Click for help on Markdown Wiki markup."))),
+    u'text/x-rst;charset=utf-8': (('user/rest.html', _("Click for help on ReST Wiki markup."))),
+    u'application/docbook+xml;charset=utf-8': (('user/docbook.html', _("Click for help on Docbook Wiki markup."))),
+    # content type: help string
+    u'text/html;charset=utf-8': ext_link('http://ckeditor.com/'),
+    u'text/plain;charset=utf-8': help_on_plain_text,
+    u'text/x-diff;charset=utf-8': help_on_plain_text,
+    u'text/x-python;charset=utf-8': help_on_plain_text,
+    u'text/csv;charset=utf-8': help_on_csv,
+    u'text/x-irclog;charset=utf-8': help_on_plain_text,
+    u'image/svg+xml': help_on_binary,
+    u'image/png': help_on_binary,
+    u'image/jpeg': help_on_binary,
+    u'image/gif': help_on_binary,
+    u'audio/wave': help_on_binary,
+    u'audio/ogg': help_on_binary,
+    u'audio/mpeg': help_on_binary,
+    u'audio/webm': help_on_binary,
+    u'video/ogg': help_on_binary,
+    u'video/webm': help_on_binary,
+    u'video/mp4': help_on_binary,
+    u'application/x-twikidraw': ext_link('http://twiki.org/cgi-bin/view/Plugins/TWikiDrawPlugin'),
+    u'application/x-anywikidraw': ext_link('http://anywikidraw.sourceforge.net/'),
+    u'application/x-svgdraw': ext_link('http://code.google.com/p/svg-edit/'),
+    u'application/octet-stream': help_on_binary,
+    u'application/x-tar': help_on_binary,
+    u'application/x-gtar': help_on_binary,
+    u'application/zip': help_on_binary,
+    u'application/pdf': help_on_binary,
+}
+CONTENTTYPES_HELP_DOCS = defaultdict(lambda: _('No help for unknown content type.'), CONTENTTYPES_HELP_DOCS)
--- a/MoinMoin/items/__init__.py	Wed Jan 14 08:22:13 2015 -0700
+++ b/MoinMoin/items/__init__.py	Wed Jan 14 21:32:03 2015 -0700
@@ -24,7 +24,7 @@
 
 from flask import current_app as app
 from flask import g as flaskg
-from flask import request, Response, redirect, abort, escape
+from flask import request, Response, redirect, abort, escape, url_for
 
 from flatland import Form
 from flatland.validation import Validator
@@ -33,6 +33,8 @@
 
 from whoosh.query import Term, Prefix, And, Or, Not
 
+from MoinMoin.constants.contenttypes import CONTENTTYPES_HELP_DOCS
+
 from MoinMoin import log
 logging = log.getLogger(__name__)
 
@@ -835,6 +837,11 @@
                                show_navigation=show_navigation,
                               )
 
+    def doc_link(self, filename, link_text):
+        """create a link to serve local doc files as help for wiki editors"""
+        filename = url_for('serve.files', name='docs', filename=filename)
+        return u'<a href="%s">%s</a>' % (filename, link_text)
+
     def do_modify(self):
         method = request.method
         if method in ['GET', 'HEAD']:
@@ -876,6 +883,9 @@
                     abort(403)
                 else:
                     return redirect(url_for_item(**self.fqname.split))
+        help = CONTENTTYPES_HELP_DOCS[self.contenttype]
+        if isinstance(help, tuple):
+            help = self.doc_link(*help)
         return render_template(self.modify_template,
                                fqname=self.fqname,
                                item_name=self.name,
@@ -883,6 +893,7 @@
                                rows_meta=str(ROWS_META), cols=str(COLS),
                                form=form,
                                search_form=None,
+                               help=help,
                               )
 
     show_template = 'show.html'
--- a/MoinMoin/items/content.py	Wed Jan 14 08:22:13 2015 -0700
+++ b/MoinMoin/items/content.py	Wed Jan 14 21:32:03 2015 -0700
@@ -326,9 +326,6 @@
         doc of Item._ModifyForm.
         """
         template = 'modify_binary.html'
-        help = """\
-There is no help, you're doomed!
-"""
         data_file = File.using(optional=True, label=L_('Upload file:'))
 
         def _load(self, item):
@@ -1149,7 +1146,6 @@
 
     class ModifyForm(Draw.ModifyForm):
         template = "modify_twikidraw.html"
-        help = ""
 
     def _transform_map(self, image_map, title):
         mapid = 'ImageMapOf' + self.name  # TODO: make it unique
@@ -1173,7 +1169,6 @@
 
     class ModifyForm(Draw.ModifyForm):
         template = "modify_anywikidraw.html"
-        help = ""
 
         def _load(self, item):
             super(AnyWikiDraw.ModifyForm, self)._load(item)
@@ -1201,7 +1196,6 @@
 
     class ModifyForm(Draw.ModifyForm):
         template = "modify_svg-edit.html"
-        help = ""
 
     def handle_post(self):
         # called from modify UI/POST
--- a/MoinMoin/templates/modify.html	Wed Jan 14 08:22:13 2015 -0700
+++ b/MoinMoin/templates/modify.html	Wed Jan 14 21:32:03 2015 -0700
@@ -46,9 +46,7 @@
                 </dl>
             {% endif %}
             {{ data_editor(form['content_form'], item_name) }}
-            {% if form['content_form'].help %}
-                <pre id="moin-editor-help">{{ form['content_form'].help }}</pre>
-            {% endif %}
+            {{ utils.help_on_editing(help) }}
             {% set may_admin = user.may.admin(fqname) %}
             {{ meta_editor(form['meta_form'], may_admin) }}
             <dl>
--- a/MoinMoin/templates/utils.html	Wed Jan 14 08:22:13 2015 -0700
+++ b/MoinMoin/templates/utils.html	Wed Jan 14 21:32:03 2015 -0700
@@ -102,6 +102,14 @@
     {{ gen.form.close() }}
 {% endmacro %}
 
+{% macro help_on_editing(help) %}
+    {% if help %}
+        <div class="tip">
+            <p> {{ help|safe }} </p>
+        </div>
+    {% endif %}
+{% endmacro %}
+
 {% macro meta_info(meta) %}
     <!-- Bootstrap classes list-group and list-group-item used to display the metadata info in an unordered list -->
     <ul class="list-group">
--- a/MoinMoin/themes/basic/templates/modify.html	Wed Jan 14 08:22:13 2015 -0700
+++ b/MoinMoin/themes/basic/templates/modify.html	Wed Jan 14 21:32:03 2015 -0700
@@ -76,10 +76,9 @@
                 {% else %}
                     {{ gen.input(field, type='hidden', class='form-control') }}
                 {% endif %}
+
                 <div class="tab-pane active" id="help">
-                    {% if form['content_form'].help %}
-                        <pre id="moin-editor-help">{{ form['content_form'].help }}</pre>
-                    {% endif %}
+                    {{ utils.help_on_editing(help) }}
                 </div>
             </div>
             {#
--- a/MoinMoin/themes/modernized/static/css/stylus/theme.styl	Wed Jan 14 08:22:13 2015 -0700
+++ b/MoinMoin/themes/modernized/static/css/stylus/theme.styl	Wed Jan 14 21:32:03 2015 -0700
@@ -325,10 +325,6 @@
     padding 3px
     width 99%
 
-#moin-editor-help
-    font-size small
-    background-color table_bg_color
-
 #preview
     border border_style
     padding 10px 30px 20px 30px
--- a/MoinMoin/themes/modernized/static/css/theme.css	Wed Jan 14 08:22:13 2015 -0700
+++ b/MoinMoin/themes/modernized/static/css/theme.css	Wed Jan 14 21:32:03 2015 -0700
@@ -355,7 +355,6 @@
 .searchpages td a,.searchpages td a:link{text-decoration:underline}
 #f_data_text{border:1px solid #4e7da9;font-family:monospace;margin:.33em 0;padding:3px;width:100%}
 #f_comment,#f_summary,#f_textcha{border:1px solid #4e7da9;display:inline;margin:.33em 0;padding:3px;width:99%}
-#moin-editor-help{font-size:small;background-color:#eef1f6}
 #preview{border:1px solid #4e7da9;padding:10px 30px 20px 30px;background:url("../img/draft.png");margin-top:.5em}
 .moin-hist-rev input{float:left}
 .moin-hist-rev{margin:0}