view MoinMoin/action/ @ 4109:e88baf535b48

fix backup action configuration (broke on windows due to backslashes in e.g. cache_dir), try 2. cfg.backup_exclude is now just a function of filename, telling whether the file should be excluded. By default, no file is excluded.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 19 Sep 2008 21:41:40 +0200
parents a739558ca3dc
children 25902b15fcce 85884c67228d
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
    MoinMoin - "sitemap" action

    Generate a URL list of all your pages (using google's sitemap XML format).

    @copyright: 2006 MoinMoin:ThomasWaldmann
    @license: GNU GPL, see COPYING for details.
import time
from MoinMoin import wikiutil

datetime_fmt = "%Y-%m-%dT%H:%M:%S+00:00"

def now():
    return time.strftime(datetime_fmt, time.gmtime())

def make_url_xml(vars):
    """ assemble a single <url> xml fragment """
    return """\
""" % vars

def sitemap_url(request, base, page):
    """ return a sitemap <url>..</url> fragment for page object <page> """
    url = page.url(request)
    pagename = page.page_name
    lastmod = page.mtime_printable(request)
    if lastmod == "0": # can happen in case of errors
        lastmod = now()

    # page's changefreq, priority and lastmod depends on page type / name
    if pagename in [u"RecentChanges", u"TitleIndex", ]:
        # important dynamic pages with macros
        changefreq = "hourly"
        priority = "0.9"
        lastmod = now() # the page text mtime never changes, but the macro output DOES

    elif pagename in [request.cfg.page_front_page, ]:
        # important user edited pages
        changefreq = "hourly"
        priority = "1.0"

    elif wikiutil.isSystemPage(request, pagename):
        # other system pages are rather boring
        changefreq = "yearly"
        priority = "0.1"

        # these are the content pages:
        changefreq = "daily"
        priority = "0.5"

    return make_url_xml(locals())

def execute(pagename, request):
    _ = request.getText
    form = request.form
    request.user.datetime_fmt = datetime_fmt
    base = request.getBaseURL()

    request.emit_http_headers(["Content-Type: text/xml; charset=UTF-8"])

    # we emit a piece of data so other side doesn't get bored:
    request.write("""<?xml version="1.0" encoding="UTF-8"?>\r\n""")

    result = []
    result.append("""<urlset xmlns="">\n""")

    # we include the / url as an important and often changed URL
        'base': base,
        'url': '/',
        'lastmod': now(), # fake
        'changefreq': 'hourly',
        'priority': '1.0',

    # Get page dict readable by current user
        underlay = int(form.get('underlay', [1])[0])
    except ValueError:
        underlay = 1
    pages = request.rootpage.getPageDict(include_underlay=underlay)
    pagelist = pages.keys()
    for name in pagelist:
        result.append(sitemap_url(request, base, pages[name]))


    result = "".join(result)
    result = result.replace("\n", "\r\n") # text/* requires CR/LF

    # emit all real data