Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1893)

Issue 5572047: meta entry externallinks for all non wiki links

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 years, 3 months ago by Reimar Bauer
Modified:
12 years, 3 months ago
Reviewers:
Visibility:
Public.

Description

diff -r 942d27d8fdf3 MoinMoin/constants/keys.py --- a/MoinMoin/constants/keys.py Tue Jan 17 21:08:30 2012 +0100 +++ b/MoinMoin/constants/keys.py Mon Jan 23 13:10:15 2012 +0100 @@ -29,6 +29,7 @@ CONTENTTYPE = "contenttype" SIZE = "size" LANGUAGE = "language" +EXTERNALLINKS = "externallinks" ITEMLINKS = "itemlinks" ITEMTRANSCLUSIONS = "itemtransclusions" TAGS = "tags" diff -r 942d27d8fdf3 MoinMoin/converter/_tests/test_link.py --- a/MoinMoin/converter/_tests/test_link.py Tue Jan 17 21:08:30 2012 +0100 +++ b/MoinMoin/converter/_tests/test_link.py Mon Jan 23 13:10:15 2012 +0100 @@ -65,6 +65,19 @@ for i in pairs: yield (self._do_wikilocal, ) + i + def test_wikiexternal(self): + pairs = [ + # note: result URLs assume test wiki running at / + ('wiki.external:http:moinmo.in', + 'Test', + 'http:moinmo.in'), + ('wiki.external:foo.bar_baz@bar.baz', + 'Test', + 'foo.bar_baz@bar.baz'), + ] + for i in pairs: + yield (self._do_wikiexternal, ) + i + def _do_wiki(self, input, output, skip=None): if skip: pytest.skip(skip) @@ -79,6 +92,15 @@ self.conv.handle_wikilocal_links(elem, Iri(input), Iri(page)) assert elem.get(xlink.href) == output + def _do_wikiexternal(self, input, page, output, skip=None): + if skip: + pytest.skip(skip) + elem = ET.Element(None) + self.conv.handle_external_links(elem, Iri(input), Iri(page)) + path = elem.get(xlink.href).path + # path starts with a / in that case + assert path[1:] == output + class TestConverterRefs(object): def setup_class(self): diff -r 942d27d8fdf3 MoinMoin/converter/_tests/test_moinwiki_in.py --- a/MoinMoin/converter/_tests/test_moinwiki_in.py Tue Jan 17 21:08:30 2012 +0100 +++ b/MoinMoin/converter/_tests/test_moinwiki_in.py Mon Jan 23 13:10:15 2012 +0100 @@ -35,15 +35,15 @@ (u'Text\n\nTest', '<page><body><p>Text</p><p>Test</p></body></page>'), (u'[[http://moinmo.in/]]', - '<page><body><p><a xlink:href="http://moinmo.in/">http://moinmo.in/</a></p></body></page>'), + '<page><body><p><a xlink:href="wiki.external:http://moinmo.in/">http://moinmo.in/</a></p></body></page>'), (u'[[javascript:alert("xss")]]', '<page><body><p><a xlink:href="wiki.local:javascript:alert%28%22xss%22%29">javascript:alert("xss")</a></p></body></page>'), (u'[[http://moinmo.in/|MoinMoin]]', - '<page><body><p><a xlink:href="http://moinmo.in/">MoinMoin</a></p></body></page>'), + '<page><body><p><a xlink:href="wiki.external:http://moinmo.in/">MoinMoin</a></p></body></page>'), (u'[[MoinMoin]]', '<page><body><p><a xlink:href="wiki.local:MoinMoin">MoinMoin</a></p></body></page>'), (u'{{http://moinmo.in/}}', - '<page><body><p><object xlink:href="http://moinmo.in/" /></p></body></page>', None, 'unknown'), + '<page><body><p><object xlink:href="wiki.external:http://moinmo.in/" /></p></body></page>', None, 'unknown'), (u'{{http://moinmo.in/|MoinMoin}}', '<page><body><p><object alt="MoinMoin" xlink:href="http://moinmo.in/" /></p></body></page>', None, 'unknown'), (u'----', @@ -295,13 +295,13 @@ def test_email(self): data = [ (u'[[mailto:root]]', - '<page><body><p><a xlink:href="mailto:root">mailto:root</a></p></body></page>'), + '<page><body><p><a xlink:href="wiki.external:mailto:root">mailto:root</a></p></body></page>'), (u'[[mailto:foo@bar.baz]]', - '<page><body><p><a xlink:href="mailto:foo@bar.baz">mailto:foo@bar.baz</a></p></body></page>'), + '<page><body><p><a xlink:href="wiki.external:mailto:foo@bar.baz">mailto:foo@bar.baz</a></p></body></page>'), (u'[[mailto:foo@bar.baz|write me]]', - '<page><body><p><a xlink:href="mailto:foo@bar.baz">write me</a></p></body></page>'), + '<page><body><p><a xlink:href="wiki.external:mailto:foo@bar.baz">write me</a></p></body></page>'), (u'[[mailto:foo.bar_baz@bar.baz]]', # . and _ are special characters commonly allowed by email systems - '<page><body><p><a xlink:href="mailto:foo.bar_baz@bar.baz">mailto:foo.bar_baz@bar.baz</a></p></body></page>'), + '<page><body><p><a xlink:href="wiki.external:mailto:foo.bar_baz@bar.baz">mailto:foo.bar_baz@bar.baz</a></p></body></page>'), ] for i in data: yield (self.do, ) + i diff -r 942d27d8fdf3 MoinMoin/converter/link.py --- a/MoinMoin/converter/link.py Tue Jan 17 21:08:30 2012 +0100 +++ b/MoinMoin/converter/link.py Mon Jan 23 13:10:15 2012 +0100 @@ -36,6 +36,9 @@ def handle_wikilocal_transclusions(self, elem, link, page_name): pass + def handle_external_links(self, elem, link, page_name): + pass + def __call__(self, *args, **kw): """ Calls the self.traverse_tree method @@ -62,8 +65,8 @@ self.handle_wikilocal_links(elem, xlink_href, page) elif xlink_href.scheme == 'wiki': self.handle_wiki_links(elem, xlink_href) - elif xlink_href.scheme: - elem.set(html.class_, 'moin-' + xlink_href.scheme) + elif xlink_href.scheme == 'wiki.external': + self.handle_external_links(elem, xlink_href, page) elif xinclude_href: xinclude_href = Iri(xinclude_href) @@ -175,6 +178,16 @@ link = Iri(url, query=query, fragment=input.fragment) elem.set(self._tag_xlink_href, link) + def handle_external_links(self, elem, input, page): + wiki_name = 'Self' + item_name = unicode(input.path) + endpoint, rev, query = self._get_do_rev(input.query) + url = url_for_item(item_name, wiki_name=wiki_name, rev=rev, endpoint=endpoint) + link = Iri(url, query=query, fragment=input.fragment) + elem.set(self._tag_xlink_href, link) + # TODO check if and where we need html.class + # elem.set(html.class_, 'moin-' + self._tag_xlink_href.scheme) + class ConverterItemRefs(ConverterBase): """ @@ -189,6 +202,7 @@ super(ConverterItemRefs, self).__init__(**kw) self.links = set() self.transclusions = set() + self.external_links = set() def __call__(self, *args, **kw): """ @@ -198,6 +212,7 @@ # in the handle methods self.links = set() self.transclusions = set() + self.external_links = set() super(ConverterItemRefs, self).__call__(*args, **kw) @@ -229,6 +244,16 @@ path = self.absolute_path(path, page.path) self.transclusions.add(unicode(path)) + def handle_external_links(self, elem, input, page): + """ + Adds the link item from the input param to self.external_links + :param elem: the element of the link + :param input: the iri of the link + :param page: the iri of the page where the link is + """ + path = input.path + self.external_links.add(unicode(path)) + def get_links(self): """ return a list of unicode link target item names @@ -241,6 +266,11 @@ """ return list(self.transclusions) + def get_external_links(self): + """ + return a list of unicode external links target item names + """ + return list(self.external_links) from . import default_registry default_registry.register(ConverterExternOutput._factory, type_moin_document, type_moin_document) diff -r 942d27d8fdf3 MoinMoin/converter/moinwiki_in.py --- a/MoinMoin/converter/moinwiki_in.py Tue Jan 17 21:08:30 2012 +0100 +++ b/MoinMoin/converter/moinwiki_in.py Mon Jan 23 13:10:15 2012 +0100 @@ -817,7 +817,7 @@ target = Iri(scheme='wiki.local', path=path, query=query, fragment=fragment) text = link_item else: - target = Iri(link_url) + target = Iri(scheme='wiki.external', path=link_url, query=None, fragment=None) text = link_url element = moin_page.a(attrib={xlink.href: target}) stack.push(element) @@ -929,7 +929,7 @@ element = xinclude.include(attrib=attrib) stack.top_append(element) else: - target = Iri(object_url) + target = Iri(scheme='wiki.external', path=object_url, query=None, fragment=None)#target = Iri(object_url) text = object_url attrib = {xlink.href: target} diff -r 942d27d8fdf3 MoinMoin/storage/middleware/indexing.py --- a/MoinMoin/storage/middleware/indexing.py Tue Jan 17 21:08:30 2012 +0100 +++ b/MoinMoin/storage/middleware/indexing.py Mon Jan 23 13:10:15 2012 +0100 @@ -72,7 +72,7 @@ from MoinMoin.config import WIKINAME, NAME, NAME_EXACT, MTIME, CONTENTTYPE, TAGS, \ LANGUAGE, USERID, ADDRESS, HOSTNAME, SIZE, ACTION, COMMENT, \ - CONTENT, ITEMLINKS, ITEMTRANSCLUSIONS, ACL, EMAIL, OPENID, \ + CONTENT, EXTERNALLINKS, ITEMLINKS, ITEMTRANSCLUSIONS, ACL, EMAIL, OPENID, \ ITEMID, REVID, CURRENT, PARENTID, \ LATEST_REVS, ALL_REVS from MoinMoin import user @@ -176,6 +176,7 @@ # side effect: we update some metadata: meta[ITEMLINKS] = refs_conv.get_links() meta[ITEMTRANSCLUSIONS] = refs_conv.get_transclusions() + meta[EXTERNALLINKS] = refs_conv.get_external_links() doc = output_conv(doc) return doc # no way

Patch Set 1 #

Unified diffs Side-by-side diffs Delta from patch set Stats (+66 lines, -12 lines) Patch
M MoinMoin/constants/keys.py View 1 chunk +1 line, -0 lines 0 comments Download
M MoinMoin/converter/_tests/test_link.py View 2 chunks +22 lines, -0 lines 0 comments Download
M MoinMoin/converter/_tests/test_moinwiki_in.py View 2 chunks +7 lines, -7 lines 0 comments Download
M MoinMoin/converter/link.py View 7 chunks +32 lines, -2 lines 0 comments Download
M MoinMoin/converter/moinwiki_in.py View 2 chunks +2 lines, -2 lines 0 comments Download
M MoinMoin/storage/middleware/indexing.py View 2 chunks +2 lines, -1 line 0 comments Download

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b