Back to index

moin  1.9.0~rc2
WikiConfig.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - Wiki Configuration
00004 """
00005 from MoinMoin.config import multiconfig
00006 
00007 Dependencies = ['user'] # table headings are translated to user language
00008 generates_headings = True
00009 
00010 def macro_WikiConfig(macro):
00011     request = macro.request
00012     _ = request.getText
00013     f = macro.request.formatter
00014     ret = []
00015 
00016     if not request.user or not request.user.isSuperUser():
00017         return ''
00018 
00019     settings = {}
00020     for groupname in multiconfig.options:
00021         heading, desc, opts = multiconfig.options[groupname]
00022         for name, default, description in opts:
00023             name = groupname + '_' + name
00024             if isinstance(default, multiconfig.DefaultExpression):
00025                 default = default.value
00026             settings[name] = default
00027     for groupname in multiconfig.options_no_group_name:
00028         heading, desc, opts = multiconfig.options_no_group_name[groupname]
00029         for name, default, description in opts:
00030             if isinstance(default, multiconfig.DefaultExpression):
00031                 default = default.value
00032             settings[name] = default
00033 
00034     ret.extend([
00035         f.heading(1, 1, id='current_config'),
00036         f.text(_("Wiki configuration")),
00037         f.heading(0, 1),
00038         f.paragraph(1),
00039         _("This table shows all settings in this wiki that do not have default values. "
00040           "Settings that the configuration system doesn't know about are shown in ''italic'', "
00041           "those may be due to third-party extensions needing configuration or settings that "
00042           "were removed from Moin.",
00043           wiki=True),
00044         f.paragraph(0),
00045     ])
00046     ret.extend([
00047         f.table(1),
00048         f.table_row(1),
00049         f.table_cell(1), f.strong(1), f.text(_('Variable name')), f.strong(0), f.table_cell(0),
00050         f.table_cell(1), f.strong(1), f.text(_('Setting')), f.strong(0), f.table_cell(0),
00051         f.table_row(0),
00052     ])
00053 
00054     def iter_vnames(cfg):
00055         dedup = {}
00056         for name in cfg.__dict__:
00057             dedup[name] = True
00058             yield name, cfg.__dict__[name]
00059         for cls in cfg.__class__.mro():
00060             if cls == multiconfig.ConfigFunctionality:
00061                 break
00062             for name in cls.__dict__:
00063                 if not name in dedup:
00064                     dedup[name] = True
00065                     yield name, cls.__dict__[name]
00066 
00067     found = []
00068     for vname, value in iter_vnames(request.cfg):
00069         if hasattr(multiconfig.ConfigFunctionality, vname):
00070             continue
00071         if vname in settings and settings[vname] == value:
00072             continue
00073         found.append((vname, value))
00074     found.sort()
00075     for vname, value in found:
00076         vname = f.text(vname)
00077         if not vname in settings:
00078             vname = f.emphasis(1) + vname + f.emphasis(0)
00079         vtxt = '%r' % (value, )
00080         ret.extend([
00081             f.table_row(1),
00082             f.table_cell(1), vname, f.table_cell(0),
00083             f.table_cell(1), f.code(1, css="backtick"), f.text(vtxt), f.code(0), f.table_cell(0),
00084             f.table_row(0),
00085         ])
00086     ret.append(f.table(0))
00087 
00088     return ''.join(ret)