Cf "virtual hosting leads to broken urls" on LinkProblems. I'm trying to get a handle on this situation now. Here is my guess-recollection of the key points:
- I needed a simple way to get the wiki & page url, that worked reliably
both on a page and one level deeper in the backlinks/editform. The first naive implementation worked out the path by walking up to the zodb root (1):
def wiki_page_url(self): """return the url path for the current wiki page""" o = self url = [] while hasattr(o,'id'): url.insert(0,absattr(o.id)) o = getattr(o,'aq_parent', None) return quote('/' + join(url[1:],'/')) def wiki_base_url(self): etc..
RonDagostino & others found that this broke when doing virtual hosting
EvanSimpson gave us (2):
def wiki_page_url(self): """return the url path for the current wiki page""" return '/' + self.absolute_url(relative=1) def wiki_base_url(self): """return the base url path for the current wiki""" return '/' + self.aq_inner.aq_parent.absolute_url(relative=1)
and it went into the codebase (around v0.7 ?). Since then, we've had
RobertoLupi (3):
I've had problems with your code on my server and changed it as follows:: def wiki_page_url(self): """return the url path for the current wiki page""" return self.REQUEST['BASE1'] + '/' + self.absolute_url(relative=1) def wiki_base_url(self): """return the base url path for the current wiki""" return self.REQUEST['BASE1'] + '/' + self.aq_inner.aq_parent.absolute_url(relative=1)
EricKidd (4):
Evan's code *almost* worked for me, but not quite. This is how I changed it:: def wiki_page_url(self): """return the url path for the current wiki page""" return self.absolute_url(relative=0) def wiki_base_url(self): """return the base url path for the current wiki""" return self.aq_inner.aq_parent.absolute_url(relative=0)
Christian Scholz had one slash too many and preferred (5):
def wiki_page_url(self): """return the url path for the current wiki page""" return self.absolute_url() def wiki_base_url(self): """return the base url path for the current wiki""" return self.aq_inner.aq_parent.absolute_url()
<!----> (5) went into the code after 0.8.1 and is still there (slightly modified) in 0.9.2. It works with zwiki.org's virtual hosting configuration and on non-virtual hosts. My impression is that so far it causes the least breakage - I don't have a sense of how much breakage that is though.
what might Ken be doing in WFN ? Something tricky which seems to address a different problem (6):
def wiki_page_url(self): """return the url path for the current wiki page""" return '/' + self.absolute_url(relative=1) def wiki_base_url(self): """return the base url path for the current wiki""" return '/' + self.aq_inner._my_folder().absolute_url(relative=1) def _my_folder(self): """Obtain parent folder, avoiding potential acquisition recursion.""" got = parent = self.aq_parent # Handle bizarred degenerate case - darnit, i've forgotten now where # i've seen this occur! while (got and hasattr(got, 'aq_parent') and got.aq_parent and (got is not got.aq_parent) and (aq_base(got) is aq_base(got.aq_parent))): parent = got got = got.aq_parent return parent
and here is my current favorite, in 0.9.2 - it's (5) slightly refactored (7):
def wiki_page_url(self): """return the url path for the current wiki page""" return self.wiki_base_url() + '/' + self.id() def wiki_base_url(self): """return the base url path for the current wiki""" return self.aq_inner.aq_parent.absolute_url()
<dtml-comment> |||||| result of alternatives in the present environment: || || || wiki_base_url: || wiki_page_url: || ||(1) ||&dtml-wiki_base_url1; ||&dtml-wiki_page_url1; || ||(2) ||&dtml-wiki_base_url2; ||&dtml-wiki_page_url2; || ||(3) ||&dtml-wiki_base_url3; ||&dtml-wiki_page_url3; || ||(4) ||&dtml-wiki_base_url4; ||&dtml-wiki_page_url4; || ||(5) ||&dtml-wiki_base_url5; ||&dtml-wiki_page_url5; || ||(6) ||&dtml-wiki_base_url6; ||&dtml-wiki_page_url6; || ||(7) ||&dtml-wiki_base_url7; ||&dtml-wiki_page_url7; || </dtml-comment>
So I'm ready to write unit tests, except I'm still too confused. Do we have a problem ? Would you post or contact me if you can produce a failure with 0.9.x code ([zwikidir/releases/ZWiki-0.9.3.tgz]?) or share some insight ? --SM
LaloMartins -- Fri, 4 May 2001 23:40:28 -0300
I think absolute links (with 'self.absolute_url()') are more robust anyway. In my own version (based on WFN), I'm using absolute links, altough for a completely different reason (I have a "wiki-tree" that spans trough folders). However, the testbed site for this version uses virtual hosting and it's working like a charm.
(Actually, I was wondering why the links were relative to begin with. I mean, why all that pain, when absolute links are more robust and almost guaranteed to work?)