"""
    MoinMoin - WikiLicense action

    Allows users to specify a license for a MoinMoin wiki.

    @copyright: 2007 Nathan R. Yergler <nathan@yergler.net>
    @license: GNU GPL, see COPYING for details.
"""

import os
import urllib
import urllib2

from MoinMoin import wikiutil
from MoinMoin.Page import Page
from MoinMoin.PageEditor import PageEditor
from MoinMoin.action import ActionBase

from license import LicenseActionBase

class WikiLicense(LicenseActionBase):
    """ Wiki site license action
    """

    LICENSE_PAGE_TEXT="""Except where otherwise noted, this wiki is licensed under the [%(license_uri)s %(license_name)s] license."""
    
    def __init__(self, pagename, request):
        LicenseActionBase.__init__(self, pagename, request)

        self.form_trigger_label = self._('License Wiki')

        # see if an alternate template has been provided
        if hasattr(request.cfg, 'page_license_template'):
            self.LICENSE_PAGE_TEXT = request.cfg.page_license_template

    def get_license_pagename(self, pagename):
        """Return the page name where license information is stored.
        For single-page licensing, this is usually a sub-page of the
        page; for site-wide licensing, this is a page defined in the
        wikiconfig.py (page_license_page)."""

        return self.request.cfg.page_license_page
        
    def is_allowed(self):
        may = self.request.user.may
        return may.write(self.pagename)

def execute(pagename, request):
    """ Glue code for actions """
    WikiLicense(pagename, request).render()

