Blame Extras/Mailman/2.1.9-4.el5/Mailman/Cgi/listinfo.py

4c79b5
# Copyright (C) 1998-2003 by the Free Software Foundation, Inc.
4c79b5
#
4c79b5
# This program is free software; you can redistribute it and/or
4c79b5
# modify it under the terms of the GNU General Public License
4c79b5
# as published by the Free Software Foundation; either version 2
4c79b5
# of the License, or (at your option) any later version.
4c79b5
#
4c79b5
# This program is distributed in the hope that it will be useful,
4c79b5
# but WITHOUT ANY WARRANTY; without even the implied warranty of
4c79b5
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4c79b5
# GNU General Public License for more details.
4c79b5
#
4c79b5
# You should have received a copy of the GNU General Public License
4c79b5
# along with this program; if not, write to the Free Software
4c79b5
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
4c79b5
4c79b5
"""Produce listinfo page, primary web entry-point to mailing lists.
4c79b5
"""
4c79b5
4c79b5
# No lock needed in this script, because we don't change data.
4c79b5
4c79b5
import os
4c79b5
import cgi
4c79b5
4c79b5
from Mailman import mm_cfg
4c79b5
from Mailman import Utils
4c79b5
from Mailman import MailList
4c79b5
from Mailman import Errors
4c79b5
from Mailman import i18n
4c79b5
from Mailman.htmlformat import *
4c79b5
from Mailman.Logging.Syslog import syslog
4c79b5
4c79b5
# Set up i18n
4c79b5
_ = i18n._
4c79b5
i18n.set_language(mm_cfg.DEFAULT_SERVER_LANGUAGE)
4c79b5
4c79b5
4c79b5

4c79b5
def main():
4c79b5
    parts = Utils.GetPathPieces()
4c79b5
    if not parts:
4c79b5
        listinfo_overview()
4c79b5
        return
4c79b5
4c79b5
    listname = parts[0].lower()
4c79b5
    try:
4c79b5
        mlist = MailList.MailList(listname, lock=0)
4c79b5
    except Errors.MMListError, e:
4c79b5
        # Avoid cross-site scripting attacks
4c79b5
        safelistname = Utils.websafe(listname)
4c79b5
        listinfo_overview(_('No such list %(safelistname)s'))
4c79b5
        syslog('error', 'No such list "%s": %s', listname, e)
4c79b5
        return
4c79b5
4c79b5
    # See if the user want to see this page in other language
4c79b5
    cgidata = cgi.FieldStorage()
4c79b5
    language = cgidata.getvalue('language')
4c79b5
    if not Utils.IsLanguage(language):
4c79b5
        language = mlist.preferred_language
4c79b5
    i18n.set_language(language)
4c79b5
    list_listinfo(mlist, language)
4c79b5
4c79b5

4c79b5
def listinfo_overview(msg=''):
4c79b5
    # Present the general listinfo overview
4c79b5
    hostname = Utils.get_domain()
4c79b5
    # Set up the document and assign it the correct language.  The only one we
4c79b5
    # know about at the moment is the server's default.
4c79b5
    doc = Document()
4c79b5
    doc.set_language(mm_cfg.DEFAULT_SERVER_LANGUAGE)
4c79b5
4c79b5
    legend = _('General Information') + ' - ' + _('Mailing Lists')
4c79b5
    doc.SetTitle(legend)
4c79b5
4c79b5
    table = Table()
4c79b5
    #table.AddRow([Center(Header(2, legend))])
4c79b5
    #table.AddCellInfo(table.GetCurrentRowIndex(), 0, colspan=2,
4c79b5
    #                  bgcolor=mm_cfg.WEB_HEADER_COLOR)
4c79b5
4c79b5
    # Skip any mailing lists that isn't advertised.
4c79b5
    advertised = []
4c79b5
    listnames = Utils.list_names()
4c79b5
    listnames.sort()
4c79b5
4c79b5
    for name in listnames:
4c79b5
        mlist = MailList.MailList(name, lock=0)
4c79b5
        if mlist.advertised:
4c79b5
            if mm_cfg.VIRTUAL_HOST_OVERVIEW and \
4c79b5
                   mlist.web_page_url.find(hostname) == -1:
4c79b5
                # List is for different identity of this host - skip it.
4c79b5
                continue
4c79b5
            else:
4c79b5
                advertised.append((mlist.GetScriptURL('listinfo'),
4c79b5
                                   mlist.real_name,
4c79b5
                                   mlist.description))
4c79b5
    welcome = Header(1, _('General Information')).Format()
4c79b5
    mailmanlink = Link(mm_cfg.MAILMAN_URL, _('Mailman')).Format()
4c79b5
    if not advertised:
4c79b5
        welcome += Paragraph(_('There currently are no publicly-advertised %(mailmanlink)s mailing lists on %(hostname)s.')).Format(css='class="strong"')
4c79b5
    else:
4c79b5
    	welcome += Paragraph(_('''Below is a listing of all the public mailing lists on %(hostname)s. Click on a list name to get more information about the list, or to subscribe, unsubscribe, and change the preferences on your subscription.''')).Format()
4c79b5
4c79b5
    # set up some local variables
4c79b5
    adj = msg and _('right') or ''
4c79b5
    siteowner = Utils.get_site_email()
4c79b5
    welcome += Paragraph( 
4c79b5
        _('''To visit the general information page for an unadvertised list, open a URL similar to this one, but with a '/' and the %(adj)s list name appended.''')).Format()
4c79b5
    
4c79b5
    welcome += Paragraph(_('''List administrators, you can visit ''') +
4c79b5
        Link(Utils.ScriptURL('admin'),
4c79b5
              _('the list admin overview page')).Format() + 
4c79b5
        _(''' to find the management interface for your list.''')).Format()
4c79b5
    welcome += Paragraph(_('''If you are having trouble using the lists, please contact ''') + 
4c79b5
         Link('mailto:' + siteowner, siteowner).Format()).Format()
4c79b5
4c79b5
    if advertised:
4c79b5
        highlight = 1
4c79b5
        for url, real_name, description in advertised:
4c79b5
            table.AddRow(
4c79b5
                [Link(url, real_name),
4c79b5
                      description or _('[no description available]')])
4c79b5
            if highlight:
4c79b5
                table.AddCellInfo(table.GetCurrentRowIndex(), 0, css='class="title strong"')
4c79b5
                table.AddCellInfo(table.GetCurrentRowIndex(), 1, css='class="title left"')
4c79b5
	    else:
4c79b5
                table.AddCellInfo(table.GetCurrentRowIndex(), 0, css='class="strong"')
4c79b5
            	table.AddCellInfo(table.GetCurrentRowIndex(), 1, css='class="left"')
4c79b5
            highlight = not highlight
4c79b5
4c79b5
    doc.AddItem(welcome)
4c79b5
    # When printing the mailing list table; avoid empty  tag to appear when
4c79b5
    # no mailing list / rows are present inside it. Empty  tags are a violation
4c79b5
    # in the "-//W3C//DTD XHTML 1.0 Transitional//EN" standard.
4c79b5
    if advertised:
4c79b5
    	doc.AddItem(table)
4c79b5
    doc.AddItem(MailmanLogo())
4c79b5
    print doc.Format()
4c79b5
4c79b5
4c79b5

4c79b5
def list_listinfo(mlist, lang):
4c79b5
    # Generate list specific listinfo
4c79b5
    doc = HeadlessDocument()
4c79b5
    doc.set_language(lang)
4c79b5
4c79b5
    replacements = mlist.GetStandardReplacements(lang)
4c79b5
4c79b5
    if not mlist.digestable or not mlist.nondigestable:
4c79b5
        replacements['<mm-digest-radio-button>'] = ""
4c79b5
        replacements['<mm-undigest-radio-button>'] = ""
4c79b5
        replacements['<mm-digest-question-start>'] = '
4c79b5
        replacements['<mm-digest-question-end>'] = ' -->'
4c79b5
    else:
4c79b5
        replacements['<mm-digest-radio-button>'] = mlist.FormatDigestButton()
4c79b5
        replacements['<mm-undigest-radio-button>'] = \
4c79b5
                                                   mlist.FormatUndigestButton()
4c79b5
        replacements['<mm-digest-question-start>'] = ''
4c79b5
        replacements['<mm-digest-question-end>'] = ''
4c79b5
    replacements['<mm-plain-digests-button>'] = \
4c79b5
                                              mlist.FormatPlainDigestsButton()
4c79b5
    replacements['<mm-mime-digests-button>'] = mlist.FormatMimeDigestsButton()
4c79b5
    replacements['<mm-subscribe-box>'] = mlist.FormatBox('email', size=30)
4c79b5
    replacements['<mm-subscribe-button>'] = mlist.FormatButton(
4c79b5
        'email-button', text=_('Subscribe'))
4c79b5
    replacements['<mm-new-password-box>'] = mlist.FormatSecureBox('pw')
4c79b5
    replacements['<mm-confirm-password>'] = mlist.FormatSecureBox('pw-conf')
4c79b5
    replacements['<mm-subscribe-form-start>'] = mlist.FormatFormStart(
4c79b5
        'subscribe')
4c79b5
    # Roster form substitutions
4c79b5
    replacements['<mm-roster-form-start>'] = mlist.FormatFormStart('roster')
4c79b5
    replacements['<mm-roster-option>'] = mlist.FormatRosterOptionForUser(lang)
4c79b5
    # Options form substitutions
4c79b5
    replacements['<mm-options-form-start>'] = mlist.FormatFormStart('options')
4c79b5
    replacements['<mm-editing-options>'] = mlist.FormatEditingOption(lang)
4c79b5
    replacements['<mm-info-button>'] = SubmitButton('UserOptions',
4c79b5
                                                    _('Edit Options')).Format()
4c79b5
    # If only one language is enabled for this mailing list, omit the choice
4c79b5
    # buttons.
4c79b5
    if len(mlist.GetAvailableLanguages()) == 1:
4c79b5
        displang = ''
4c79b5
    else:
4c79b5
        displang = mlist.FormatButton('displang-button',
4c79b5
                                      text = _('View this page in'))
4c79b5
    replacements['<mm-displang-box>'] = displang
4c79b5
    replacements['<mm-lang-form-start>'] = mlist.FormatFormStart('listinfo')
4c79b5
    replacements['<mm-fullname-box>'] = mlist.FormatBox('fullname', size=30)
4c79b5
4c79b5
    # Links on header section (errormsg)
4c79b5
    listadmin_link = Link(Utils.ScriptURL('admin'), _('Administration')).Format()
4c79b5
    listinfo_link = Link(Utils.ScriptURL('listinfo'), _('General Information')).Format()
4c79b5
    replacements['<mm-errormsg-listinfo>'] = listinfo_link
4c79b5
    replacements['<mm-errormsg-listadmin>'] = listadmin_link
4c79b5
    replacements['<mm-errormsg-header>'] = _('Mailing Lists')
4c79b5
4c79b5
    # Do the expansion.
4c79b5
    doc.AddItem(mlist.ParseTags('listinfo.html', replacements, lang))
4c79b5
    print doc.Format()
4c79b5
4c79b5
4c79b5

4c79b5
if __name__ == "__main__":
4c79b5
    main()