Commits

Thomas Waldmann committed 93ae039

fixed indexable and diff views, use revids not revnos for diffs and urls

added revid attr and read/seek/tell methods to PseudoRevision

Comments (0)

Files changed (9)

MoinMoin/apps/frontend/views.py

 @frontend.route('/+indexable/<rev>/<itemname:item_name>')
 @frontend.route('/+indexable/<itemname:item_name>', defaults=dict(rev=CURRENT))
 def indexable(item_name, rev):
-    from MoinMoin.converter import convert_to_indexable
-    item = flaskg.storage.get_item(item_name)
-    rev = item.get_revision(rev)
-    content = convert_to_indexable(rev)
+    from MoinMoin.storage.middleware.indexing import convert_to_indexable
+    item = flaskg.storage[item_name]
+    rev = item[rev]
+    content = convert_to_indexable(rev.meta, rev.data)
     return Response(content, 200, mimetype='text/plain')
 
 
     except AccessDeniedError:
         abort(403)
     show_revision = show_navigation = rev != CURRENT
-    # Note: rev.revno of DummyRev is None
     first_rev = None
     last_rev = None
     if show_navigation:
     date = timestamp
     # this is how we get called from "recent changes"
     # try to find the latest rev1 before bookmark <date>
-    try:
-        item = flaskg.storage.get_item(item_name)
-    except AccessDeniedError:
-        abort(403)
-    revnos = item.list_revisions()
-    revnos.reverse()  # begin with latest rev
-    for revno in revnos:
-        revision = item.get_revision(revno)
-        if revision.timestamp <= date:
-            rev1 = revision.revno
+    item = flaskg.storage[item_name]
+    revs = sorted([(rev.meta[MTIME], rev.revid) for rev in item.iter_revs()], reverse=True)
+    for rev in revs:
+        if rev.meta[MTIME] <= date:
+            rev1 = rev.revid
             break
     else:
-        rev1 = revno  # if we didn't find a rev, we just take oldest rev we have
-    rev2 = -1  # and compare it with latest we have
+        rev1 = rev.revid  # if we didn't find a rev, we just take oldest rev we have
+    rev2 = CURRENT  # and compare it with latest we have
     return _diff(item, rev1, rev2)
 
 
     # TODO get_item and get_revision calls may raise an AccessDeniedError.
     #      If this happens for get_item, don't show the diff at all
     #      If it happens for get_revision, we may just want to skip that rev in the list
-    try:
-        item = flaskg.storage.get_item(item_name)
-    except AccessDeniedError:
-        abort(403)
+    item = flaskg.storage[item_name]
     rev1 = request.values.get('rev1')
     rev2 = request.values.get('rev2')
     return _diff(item, rev1, rev2)
 
 
-def _normalize_revnos(item, revno1, revno2):
-    try:
-        revno1 = int(revno1)
-    except (ValueError, TypeError):
-        revno1 = -2
-    try:
-        revno2 = int(revno2)
-    except (ValueError, TypeError):
-        revno2 = -1
-
-    # get (absolute) current revision number
-    current_revno = item.get_revision(-1).revno
-    # now we can calculate the absolute revnos if we don't have them yet
-    if revno1 < 0:
-        revno1 += current_revno + 1
-    if revno2 < 0:
-        revno2 += current_revno + 1
-
-    if revno1 > revno2:
-        oldrevno, newrevno = revno2, revno1
-    else:
-        oldrevno, newrevno = revno1, revno2
-    return oldrevno, newrevno
-
-
-def _common_type(rev1, rev2):
-    ct1 = rev1.get(CONTENTTYPE)
-    ct2 = rev2.get(CONTENTTYPE)
+def _common_type(ct1, ct2):
     if ct1 == ct2:
         # easy, exactly the same content type, call do_diff for it
         commonmt = ct1
 
 
 def _diff(item, revno1, revno2):
-    oldrevno, newrevno = _normalize_revnos(item, revno1, revno2)
-    oldrev = item.get_revision(oldrevno)
-    newrev = item.get_revision(newrevno)
-
-    commonmt = _common_type(oldrev, newrev)
+    oldrev = item[revno1]
+    newrev = item[revno2]
+    commonmt = _common_type(oldrev.meta[CONTENTTYPE], newrev.meta[CONTENTTYPE])
 
     try:
-        item = Item.create(item.name, contenttype=commonmt, rev_no=newrevno)
+        item = Item.create(item.name, contenttype=commonmt, rev_no=newrev.revid)
     except AccessDeniedError:
         abort(403)
-    rev_nos = item.rev.item.list_revisions()
+    rev_nos = [CURRENT]  # XXX TODO we need a reverse sorted list
     return render_template(item.diff_template,
                            item=item, item_name=item.name,
                            rev=item.rev,
 
 
 def _diff_raw(item, revno1, revno2):
-    oldrevno, newrevno = _normalize_revnos(item, revno1, revno2)
-    oldrev = item.get_revision(oldrevno)
-    newrev = item.get_revision(newrevno)
-
+    oldrev = item[revno1]
+    newrev = item[revno2]
     commonmt = _common_type(oldrev, newrev)
 
     try:
-        item = Item.create(item.name, contenttype=commonmt, rev_no=newrevno)
+        item = Item.create(item.name, contenttype=commonmt, rev_no=newrev.revid)
     except AccessDeniedError:
         abort(403)
     return item._render_data_diff_raw(oldrev, newrev)

MoinMoin/converter/audio_video_in.py

         item_name = rev.item.name
         attrib = {
             moin_page.type_: unicode(self.input_type),
-            xlink.href: Iri(scheme='wiki', authority='', path='/'+item_name, query='do=get&rev=%d' % rev.revno),
+            xlink.href: Iri(scheme='wiki', authority='', path='/'+item_name, query='do=get&rev=%s' % rev.revid),
         }
         return moin_page.object_(attrib=attrib, children=[u'Your Browser does not support HTML5 audio/video element.', ])
 

MoinMoin/converter/everything.py

     def __call__(self, rev, contenttype=None, arguments=None):
         item_name = rev.item.name
         attrib = {
-            xlink.href: Iri(scheme='wiki', authority='', path='/'+item_name, query='do=get&rev=%d' % rev.revno),
+            xlink.href: Iri(scheme='wiki', authority='', path='/'+item_name, query='do=get&rev=%s' % rev.revid),
         }
         return moin_page.a(attrib=attrib, children=["Download %s." % item_name])
 

MoinMoin/converter/image_in.py

         item_name = rev.item.name
         attrib = {
             moin_page.type_: unicode(self.input_type),
-            xlink.href: Iri(scheme='wiki', authority='', path='/'+item_name, query='do=get&rev=%d' % rev.revno),
+            xlink.href: Iri(scheme='wiki', authority='', path='/'+item_name, query='do=get&rev=%s' % rev.revid),
         }
         return moin_page.object_(attrib=attrib, children=[item_name, ])
 

MoinMoin/converter/link.py

             query = separator.join(result)
         else:
             query = None
-        if revno is not None:
-            revno = int(revno)
         do_to_endpoint = dict(
             show='frontend.show_item',
             get='frontend.get_item',

MoinMoin/storage/middleware/indexing.py

         def __init__(self, meta, data):
             self.meta = meta
             self.data = data
-            self.revno = -1 # TODO: remove access to this in converters
+            self.revid = meta.get(REVID)
             class PseudoItem(object):
                 def __init__(self, name):
                     self.name = name
             self.item = PseudoItem(meta.get(NAME))
+        def read(self, *args, **kw):
+            return self.data.read(*args, **kw)
+        def seek(self, *args, **kw):
+            return self.data.seek(*args, **kw)
+        def tell(self, *args, **kw):
+            return self.data.tell(*args, **kw)
 
     rev = PseudoRev(meta, data)
     try:

MoinMoin/templates/diff.html

 {% extends theme("show.html") %}
 {% block content %}
 {% block headline %}
-<h1>{{ _("Item: %(item_name)s (Diff between revision %(oldrevno)s and %(newrevno)s)", item_name=newrev.item.name, oldrevno=oldrev.revno, newrevno=newrev.revno) }}</h1>
+<h1>{{ _("Item: %(item_name)s (Diff between revision %(oldrevno)s and %(newrevno)s)", item_name=newrev.item.name, oldrevno=oldrev.revid, newrevno=newrev.revid) }}</h1>
 {% endblock %}
 {{ item._render_data_diff(oldrev, newrev) }}
 {% endblock %}

MoinMoin/templates/show.html

 {% macro rev_navigation(view='frontend.show_item') %}
     <ul id="moin-rev-navigation">
         <li class="moin-rev-navigation-older">
-        {% if rev.revno > 0 -%}
+        {% if rev.revid != 'current' -%}
             <a href="{{ url_for(view, rev=rev.revno-1, item_name=item_name) }}">&lt;-- {{ _('older') }}</a>
         {%- else -%}
             <span class="moin-disabled">{{ _('no older revision') }}</span>

MoinMoin/util/interwiki.py

 
 import os.path
 
+from MoinMoin.config import CURRENT
+
 from MoinMoin import log
 logging = log.getLogger(__name__)
 
     return wiki_name in app.cfg.interwiki_map
 
 
-def url_for_item(item_name, wiki_name='', rev=-1, endpoint='frontend.show_item', _external=False):
+def url_for_item(item_name, wiki_name='', rev=CURRENT, endpoint='frontend.show_item', _external=False):
     """
     Compute URL for some local or remote/interwiki item.
 
     Computed URLs are always fully specified.
     """
     if is_local_wiki(wiki_name):
-        if rev is None or rev == -1:
+        if rev is None or rev == CURRENT:
             url = url_for(endpoint, item_name=item_name, _external=_external)
         else:
             url = url_for(endpoint, item_name=item_name, rev=rev, _external=_external)
             logging.warning("no interwiki_map entry for %r" % wiki_name)
             url = '' # can we find something useful?
         else:
-            if (rev is None or rev == -1) and endpoint == 'frontend.show_item':
+            if (rev is None or rev == CURRENT) and endpoint == 'frontend.show_item':
                 # we just want to show latest revision (no special revision given) -
                 # this is the generic interwiki url support, should work for any remote wiki
                 url = join_wiki(wiki_base_url, item_name)