Commits

Bruno Martin committed c0890c4

initial idea to avoid getting the item from wrong namespace. Tests missing

Comments (0)

Files changed (2)

MoinMoin/items/__init__.py

 from MoinMoin.util.iri import Iri
 from MoinMoin.util.crypto import cache_key
 from MoinMoin.storage.middleware.protecting import AccessDenied
+from MoinMoin.util.interwiki import split_interwiki
 
 try:
     import PIL
 
 class DummyRev(dict):
     """ if we have no stored Revision, we use this dummy """
-    def __init__(self, item, contenttype):
+    def __init__(self, item, contenttype, namespace=u''):
         self.item = item
         self.meta = {CONTENTTYPE: contenttype}
         self.data = StringIO('')
         self.revid = None
+        self.namespace = namespace
 
 
 class DummyItem(object):
     def create(cls, name=u'', contenttype=None, rev_id=CURRENT, item=None):
         if contenttype is None:
             contenttype = u'application/x-nonexistent'
-
+        wikiname, namespace, local_name = split_interwiki(name)
+        # TODO Decide how to handle external wikis. Maybe redirect using url generated by url_for_items?
+        if wikiname != u'Self':
+            return
+#        import ipdb; ipdb.set_trace()
         if 1: # try:
             if item is None:
                 item = flaskg.storage[name]
                 name = item.name
         if not item: # except NoSuchItemError:
             logging.debug("No such item: {0!r}".format(name))
-            item = DummyItem(name)
-            rev = DummyRev(item, contenttype)
+            item = DummyItem(local_name)
+            rev = DummyRev(item, contenttype, namespace)
             logging.debug("Item {0!r}, created dummy revision with contenttype {1!r}".format(name, contenttype))
         else:
             logging.debug("Got item: {0!r}".format(name))
                     # XXX add some message about invalid revision
                 except KeyError: # NoSuchRevisionError:
                     logging.debug("Item {0!r} has no revisions.".format(name))
-                    rev = DummyRev(item, contenttype)
+                    rev = DummyRev(item, contenttype, namespace)
                     logging.debug("Item {0!r}, created dummy revision with contenttype {1!r}".format(name, contenttype))
             logging.debug("Got item {0!r}, revision: {1!r}".format(name, rev_id))
         contenttype = rev.meta.get(CONTENTTYPE) or contenttype # use contenttype in case our metadata does not provide CONTENTTYPE

MoinMoin/storage/middleware/indexing.py

                             LANGUAGE, USERID, ADDRESS, HOSTNAME, SIZE, ACTION, COMMENT, \
                             CONTENT, ITEMLINKS, ITEMTRANSCLUSIONS, ACL, EMAIL, OPENID, \
                             ITEMID, REVID, CURRENT, PARENTID, \
-                            LATEST_REVS, ALL_REVS, BACKENDNAME
+                            LATEST_REVS, ALL_REVS, BACKENDNAME, NAMESPACE
 from MoinMoin import user
 from MoinMoin.search.analyzers import item_name_analyzer, MimeTokenizer, AclTokenizer
 from MoinMoin.themes import utctimestamp
 from MoinMoin.util.crypto import make_uuid
+from MoinMoin.util.interwiki import split_interwiki
 
 INDEXES = [LATEST_REVS, ALL_REVS, ]
 
             PARENTID: ID(stored=True),
             # backend name (which backend is this rev stored in?)
             BACKENDNAME: ID(stored=True),
+            # namespace off this item
+            NAMESPACE: ID(stored=True),
             # MTIME from revision metadata (converted to UTC datetime)
             MTIME: DATETIME(stored=True),
             # tokenized CONTENTTYPE from metadata
         """
         self.indexer = indexer
         self.backend = self.indexer.backend
+        self._name = query.get('name_exact')
+        if self._name:
+            _, namespace, name = split_interwiki(self._name)
+            self._name = name
         if latest_doc is None:
+#            if namespace:
+#                import ipdb;ipdb.set_trace()
+            if self._name:
+                query[NAMESPACE] = namespace
+#                query[NAME_EXACT] = name
             # we need to call the method without acl check to avoid endless recursion:
             latest_doc = self.indexer._document(**query) or {}
         self._current = latest_doc
-        self._name = query.get('name_exact')
+#        self._name = query.get('name_exact')
 
     def _get_itemid(self):
         return self._current.get(ITEMID)