Commits

Anonymous committed 8f73b05

Add subitems sidebar and link/transclude actions to modify_text.html

Comments (0)

Files changed (4)

MoinMoin/static/js/common.js

 jQuery(document).ready(function() {
     new QuicklinksExpander();
 })
+
+function guessContentType() {
+    /* Used in the modify_text template to guess the data content type client-side 
+     * This approach has the advantage of reacting to content type changes for the 
+     * link/transclude code without having to re-fetch the page */
+    var meta_text = $("#f_meta_text").val();
+    var ctype_regex = /["']contenttype["']\s*:\s*["']([\w-_+.]+\/[\w-_+.]+)(;|["'])/;
+    if (meta_text) {
+        var match = ctype_regex.exec(meta_text);
+        if (match) return match[1];
+    }
+    return null;
+}
+
+function transcludeSubitem(subitem_name) {
+    var input_element = $("#f_data_text");
+    input_element.val(input_element.val() + " {{/" + subitem_name + "}}");
+}
+
+function linkSubitem(subitem_name) {
+    var input_element = $("#f_data_text");
+    input_element.val(input_element.val() + "[[/" + subitem_name + "]]");
+}

MoinMoin/templates/modify_text.html

 {% extends "modify_binary.html" %}
+{% import "utils.html" as utils %}
+
+{% set subitems = theme_supp.subitem_index(item_name) %}
+{% if subitems %}
+    {% block subitem_navigation %}
+        {% call(fullname, shortname, contenttype, has_children) utils.render_subitem_navigation(subitems) %}
+            {# XXX: The replace filter is used to prevent XSS attacks
+                This needs security review, it could still be vulnerable #}
+            <a href="#" onclick="linkSubitem('{{ shortname|replace("\\", "\\\\")|replace("'", "\\'") }}')" title="{{ _('Link to Subitem') }}">
+                {{ _('Link') }}
+            </a>
+            <a href="#" onclick="transcludeSubitem('{{ shortname|replace("\\", "\\\\")|replace("'", "\\'") }}')" title="{{ _('Transclude Subitem') }}">
+                {{ _('Transclude') }}
+            </a>
+        {% endcall %}
+    {% endblock %}
+{% endif %}
+
 {% block data_editor %}
 {{ gen.textarea(form['data_text'], lang=lang, dir=direction, rows=rows_data, cols=cols) }}
 <br />

MoinMoin/templates/show.html

 {% block subitem_navigation %}
     {% set subitems = theme_supp.subitem_index(item_name) %}
     {% if subitems %}
-        <div class="moin-subitem-navigation">
-            <div class="list-header">
-                {{ _('Subitems') }} 
-            </div>
-            <ul>
-                {% for fullname, shortname, contenttype, has_children in subitems %}
-                    <li>
-                        <a href="{{ url_for('frontend.show_item', item_name=fullname) }}"
-                            title="{{ shortname }}">{{ shortname }}</a>
-                        {% if has_children %}<span class="sep">/</span>{% endif %}
-                    </li>
-                {% endfor %}
-            </ul>
-        </div>
+        {{ utils.render_subitem_navigation(subitems) }}
     {% endif %}
 {% endblock %}
 

MoinMoin/templates/utils.html

 </table>
 {% endmacro %}
 
+{% macro render_subitem_navigation(subitems) %}
+    <div class="moin-subitem-navigation">
+        <div class="list-header">
+            {{ _('Subitems') }} 
+        </div>
+        <ul>
+            {% for fullname, shortname, contenttype, has_children in subitems %}
+                <li>
+                    {# call our caller with all the data we have if they exist, used to implement
+                        transclude/link actions in the modify view #}
+                    {% if caller %}
+                        {{ caller(fullname, shortname, contenttype, has_children) }}
+                    {% endif %}
+                    <a href="{{ url_for('frontend.show_item', item_name=fullname) }}"
+                        title="{{ shortname }}" class="subitem-link">{{ shortname }}</a>
+                    {% if has_children %}<span class="sep">/</span>{% endif %}
+                </li>
+            {% endfor %}
+        </ul>
+    </div>
+{% endmacro %}