changeset 1787:f4a941fe32f8

added SisterSites/SisterPages support
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 22 Feb 2007 13:45:23 +0100
parents 2c9853dc11f8
children 6277072e7add
files MoinMoin/action/pollsistersites.py MoinMoin/action/sisterpages.py MoinMoin/config/multiconfig.py MoinMoin/theme/__init__.py docs/CHANGES
diffstat 5 files changed, 162 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/action/pollsistersites.py	Thu Feb 22 13:45:23 2007 +0100
@@ -0,0 +1,56 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - "pollsistersites" action
+
+    This action fetches lists of page urls and page names from sister sites,
+    so we can implement SisterWiki functionality.
+    See: http://usemod.com/cgi-bin/mb.pl?SisterSitesImplementationGuide
+    
+    @copyright: 2007 by MoinMoin:ThomasWaldmann
+    @license: GNU GPL, see COPYING for details.
+"""
+
+import time, urllib
+
+from MoinMoin import caching
+from MoinMoin.util import timefuncs
+
+def execute(pagename, request):
+    status = []
+    for sistername, sisterurl in request.cfg.sistersites.items():
+        arena = 'sisters'
+        key = sistername
+        cache = caching.CacheEntry(request, arena, key, scope='farm', use_pickle=True)
+        if cache.exists():
+            data = cache.content()
+        else:
+            data = {'lastmod': ''}
+        uo = urllib.URLopener()
+        uo.version = 'MoinMoin SisterPage list fetcher 1.0'
+        lastmod = data['lastmod']
+        if lastmod:
+            uo.addheader('If-Modified-Since', lastmod)
+        try:
+            sisterpages = {}
+            f = uo.open(sisterurl)
+            for line in f:
+                line = line.strip()
+                try:
+                    page_url, page_name = line.split(' ', 1)
+                    sisterpages[page_name.decode('utf-8')] = page_url
+                except:
+                    pass # ignore invalid lines
+            try:
+                lastmod = f.info()["Last-Modified"]
+            except:
+                lastmod = timefuncs.formathttpdate(time.time())
+            f.close()
+            data['lastmod'] = lastmod
+            data['sisterpages'] = sisterpages
+            cache.update(data)
+            status.append(u"Site: %s Status: Updated. Pages: %d" % (sistername, len(sisterpages)))
+        except IOError, (title, code, msg, headers):
+            status.append(u"Site: %s Status: Not updated." % sistername)
+
+    request.emit_http_headers(["Content-Type: text/plain; charset=UTF-8"])
+    request.write("\r\n".join(status).encode("utf-8"))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/action/sisterpages.py	Thu Feb 22 13:45:23 2007 +0100
@@ -0,0 +1,66 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - "sisterpages" action
+
+    This action generates a list of page urls and page names, so that other wikis
+    can implement SisterWiki functionality easily.
+    See: http://usemod.com/cgi-bin/mb.pl?SisterSitesImplementationGuide
+    
+    @copyright: 2007 by MoinMoin:ThomasWaldmann
+    @license: GNU GPL, see COPYING for details.
+"""
+
+import time
+
+from MoinMoin import wikiutil
+from MoinMoin.Page import Page
+from MoinMoin.util import timefuncs
+from MoinMoin.logfile import editlog
+
+def execute(pagename, request):
+    log = editlog.EditLog(request)
+    try:
+        lastmod = wikiutil.version2timestamp(log.date())
+    except:
+        lastmod = 0
+
+    timestamp = timefuncs.formathttpdate(lastmod)
+    etag = "%d" % lastmod
+
+    # for 304, we look at if-modified-since and if-none-match headers,
+    # one of them must match and the other is either not there or must match.
+    if request.if_modified_since == timestamp:
+        if request.if_none_match:
+            if request.if_none_match == etag:
+                request.emit_http_headers(["Status: 304 Not modified"])
+        else:
+            request.emit_http_headers(["Status: 304 Not modified"])
+    elif request.if_none_match == etag:
+        if request.if_modified_since:
+            if request.if_modified_since == timestamp:
+                request.emit_http_headers(["Status: 304 Not modified"])
+        else:
+            request.emit_http_headers(["Status: 304 Not modified"])
+    else:
+        # generate an Expires header, using 1d cache lifetime of sisterpages list
+        expires = timefuncs.formathttpdate(time.time() + 24*3600)
+
+        httpheaders = ["Content-Type: text/plain; charset=UTF-8",
+                       "Expires: %s" % expires,
+                       "Last-Modified: %s" % timestamp,
+                       "Etag: %s" % etag, ]
+
+        # send the generated XML document
+        request.emit_http_headers(httpheaders)
+
+        baseurl = request.getBaseURL()
+        if not baseurl.endswith('/'):
+            baseurl += '/'
+
+        # Get list of user readable pages
+        pages = request.rootpage.getPageList()
+        pages.sort()
+        for pn in pages:
+            p = Page(request, pn)
+            entry = u"%s%s %s\r\n" % (baseurl, p.url(request, relative=False), p.page_name)
+            request.write(entry.encode('utf-8'))
--- a/MoinMoin/config/multiconfig.py	Thu Feb 22 12:04:46 2007 +0100
+++ b/MoinMoin/config/multiconfig.py	Thu Feb 22 13:45:23 2007 +0100
@@ -372,6 +372,11 @@
     quicklinks_default = [] # preload user quicklinks with this page list
     refresh = None # (minimum_delay, type), e.g.: (2, 'internal')
     rss_cache = 60 # suggested caching time for RecentChanges RSS, in seconds
+    sistersites = {
+        #'Self': 'http://localhost:8080/?action=sisterpages',
+        'EmacsWiki': 'http://www.emacswiki.org/cgi-bin/test?action=sisterpages',
+        'JspWiki': 'http://www.jspwiki.org/SisterSites.jsp',
+    } # dict {sistersitename: sisterpagelistfetchurl}
     shared_intermap = None # can be string or list of strings (filenames)
     show_hosts = True
     show_interwiki = False
--- a/MoinMoin/theme/__init__.py	Thu Feb 22 12:04:46 2007 +0100
+++ b/MoinMoin/theme/__init__.py	Thu Feb 22 13:45:23 2007 +0100
@@ -6,7 +6,7 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-from MoinMoin import i18n, wikiutil, config, version
+from MoinMoin import i18n, wikiutil, config, version, caching
 from MoinMoin.Page import Page
 from MoinMoin.util import pysupport
 
@@ -436,7 +436,7 @@
                 items.append(item % (cls, link))
                 found[pagename] = 1
 
-        # Add current page at end
+        # Add current page at end of local pages
         if not current in found:
             title = d['page'].split_title()
             title = self.shortenPagename(title)
@@ -444,6 +444,25 @@
             cls = 'current'
             items.append(item % (cls, link))
 
+        # Add sister pages.
+        for sistername in request.cfg.sistersites: # TODO: sort?
+            if sistername == request.cfg.interwikiname: # it is THIS wiki
+                cls = 'sisterwiki current'
+                items.append(item % (cls, sistername))
+            else:
+                # TODO optimize performance
+                cache = caching.CacheEntry(request, 'sisters', sistername, 'farm', use_pickle=True)
+                if cache.exists():
+                    data = cache.content()
+                    sisterpages = data['sisterpages']
+                    if current in sisterpages:
+                        cls = 'sisterwiki'
+                        url = sisterpages[current]
+                        link = request.formatter.url(1, url) + \
+                               request.formatter.text(sistername) +\
+                               request.formatter.url(0)
+                        items.append(item % (cls, link))
+
         # Assemble html
         items = u''.join(items)
         html = u'''
--- a/docs/CHANGES	Thu Feb 22 12:04:46 2007 +0100
+++ b/docs/CHANGES	Thu Feb 22 13:45:23 2007 +0100
@@ -313,6 +313,20 @@
     * There is a new item in the edit bar: "Comments". If you click it, the
       visibility of all class "comment" tags will be toggled. There is a user
       preferences item "show_comments" to set if the default view shows them or not.
+    * Added SisterPages support:
+      * action=sisterpages will generate a list of url pagename lines for all
+        pages in your moin wiki.
+      * action=pollsistersites will poll all sister sites listed in
+        cfg.sistersites = { 'OtherWiki': 'http://server/?action=sisterpages', ...}
+      * if the current page exists on some sister wiki, a link to it will be
+        added to the navibar.
+      You can use sister wikis for adding another dimension to your wiki UI: use
+      it for simple multi language support, or for comments, or anything else
+      "related" you need.
+      TODO: remove sample sistersites from multiconfig
+            add sistersites_force with sister sites we link to even if they do not
+            have the page yet (will work only for moin as we don't know
+            pagename>url transformation of other wikis)
 
   Bugfixes:
     * on action "info" page, "revert" link will not be displayed for empty page