changeset 2377:605b3327c016

Merged thomaswaldmann/moin-2.0 into default
author sharky93 <rishabhr123@gmail.com>
date Sun, 11 Aug 2013 12:16:36 +0530
parents 6485ee98ab0e (current diff) 762ca22a428c (diff)
children bff46cb932d1
files
diffstat 5 files changed, 79 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/_tests/test_frontend.py	Sat Aug 10 03:45:45 2013 +0530
+++ b/MoinMoin/apps/frontend/_tests/test_frontend.py	Sun Aug 11 12:16:36 2013 +0530
@@ -119,6 +119,12 @@
     def test_index(self):
         self._test_view('frontend.index', status='200 OK', viewopts=dict(item_name='DoesntExist'))
 
+    def test_refs(self):
+        self._test_view('frontend.refs', status='200 OK', viewopts=dict(item_name='DoesntExist'))
+
+    def test_forwardrefs(self):
+        self._test_view('frontend.forwardrefs', status='200 OK', viewopts=dict(item_name='DoesntExist'))
+
     def test_backrefs(self):
         self._test_view('frontend.backrefs', status='200 OK', viewopts=dict(item_name='DoesntExist'))
 
--- a/MoinMoin/apps/frontend/views.py	Sat Aug 10 03:45:45 2013 +0530
+++ b/MoinMoin/apps/frontend/views.py	Sun Aug 11 12:16:36 2013 +0530
@@ -102,6 +102,8 @@
 Disallow: /+similar_names/
 Disallow: /+quicklink/
 Disallow: /+subscribe/
+Disallow: /+refs/
+Disallow: /+forwardrefs/
 Disallow: /+backrefs/
 Disallow: /+wanteds/
 Disallow: /+orphans/
@@ -825,6 +827,60 @@
     return [rev.name for rev in revs]
 
 
+@frontend.route('/+refs/<itemname:item_name>')
+def refs(item_name):
+    """
+    Returns the list of all incoming/outgoing links or transclusions of item item_name
+
+    :param item_name: the name of the current item
+    :type item_name: unicode
+    :returns: a page with all incoming/outgoing item links of this item
+    """
+    refs = _forwardrefs(item_name)
+    backrefs = _backrefs(item_name)
+    return render_template('refs.html',
+                           item_name=item_name,
+                           refs=refs,
+                           backrefs=backrefs
+    )
+
+
+@frontend.route('/+forwardrefs/<itemname:item_name>')
+def forwardrefs(item_name):
+    """
+    Returns the list of all links or transclusions of item item_name
+
+    :param item_name: the name of the current item
+    :type item_name: unicode
+    :returns: a page with all the items linked from this item
+    """
+    refs = _forwardrefs(item_name)
+    return render_template('link_list_item_panel.html',
+                           item_name=item_name,
+                           headline=_(u"Items that are referred by '%(item_name)s'", item_name=item_name),
+                           item_names=refs
+    )
+
+
+def _forwardrefs(item_name):
+    """
+    Returns a list with all names of items that get referenced from item_name
+
+    :param item_name: the name of the current item
+    :type item_name: unicode
+    :returns: the list of all items which are referenced from this item
+    """
+    q = {WIKINAME: app.cfg.interwikiname,
+         NAME_EXACT: item_name,
+        }
+    rev = flaskg.storage.document(**q)
+    if rev is None:
+        refs = []
+    else:
+        refs = rev.meta.get(ITEMLINKS, []) + rev.meta.get(ITEMTRANSCLUSIONS, [])
+    return refs
+
+
 @frontend.route('/+backrefs/<itemname:item_name>')
 def backrefs(item_name):
     """
--- a/MoinMoin/config/default.py	Sat Aug 10 03:45:45 2013 +0530
+++ b/MoinMoin/config/default.py	Sun Aug 11 12:16:36 2013 +0530
@@ -407,7 +407,7 @@
             ('frontend.rename_item', L_('Rename'), L_('Rename this item'), True, ),
             ('frontend.delete_item', L_('Delete'), L_('Delete this item'), True, ),
             ('frontend.destroy_item', L_('Destroy'), L_('Completely destroy this item'), True, ),
-            ('frontend.backrefs', L_('Referrers'), L_('What refers here?'), False, ),
+            ('frontend.refs', L_('References'), L_('Show incoming and outgoing references'), False, ),
             ('frontend.sitemap', L_('Site Map'), L_('Local Site Map of this item'), True, ),
             ('frontend.similar_names', L_('Similar'), L_('Items with similar names'), False, ),
         ], 'list of edit bar entries (list of tuples (endpoint, label))'),
--- a/MoinMoin/templates/itemviews.html	Sat Aug 10 03:45:45 2013 +0530
+++ b/MoinMoin/templates/itemviews.html	Sun Aug 11 12:16:36 2013 +0530
@@ -5,7 +5,7 @@
             {%- if endpoint in [
                 'frontend.show_item', 'frontend.index', 'frontend.highlight_item',
                 'frontend.show_item_meta', 'frontend.download_item',
-                'frontend.history', 'frontend.backrefs', 'frontend.sitemap',
+                'frontend.history', 'frontend.refs', 'frontend.sitemap',
                 'frontend.similar_names', 'frontend.copy_item',
             ] %}
                 <li>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/templates/refs.html	Sun Aug 11 12:16:36 2013 +0530
@@ -0,0 +1,15 @@
+{% extends theme("show.html") %}
+{% block content %}
+<h1>{{ _('Outgoing Item References') }}</h1>
+<ul>
+    {% for item_name in refs|sort %}
+    <li><a href="{{ url_for('frontend.show_item', item_name=item_name) }}">{{ item_name }}</a></li>
+    {% endfor %}
+</ul>
+<h1>{{ _('Incoming Item References') }}</h1>
+<ul>
+    {% for item_name in backrefs|sort %}
+    <li><a href="{{ url_for('frontend.show_item', item_name=item_name) }}">{{ item_name }}</a></li>
+    {% endfor %}
+</ul>
+{% endblock %}