12/31/2006

架设 wiki -- MoinMoin server

简介

*
MoinMoin 是用 Python 语言写的一个开源的 WiKi 引擎,基于 GNU GPL 协议发布。MoinMoin 的软件架构很灵活,通过 Python 能很容易进行功能扩展,现在已开发出大量的 Extensions。MoinMoin 不使用后台数据库存放数据,而是以文本的形式存放在服务器目录中。
*
MoinMoin 不带 Web 服务器,需与 Web 服务器配合才能进行 WiKi 页面的发布。MoinMoin 支持的 Web 服务器有Apache + CGI、Apache + FastCgi、Apache + Mod_Python、IIS 等。dot1 上面 MoinMoin 采用 Apache + CGI 方式。

准备工作

* 1.保证 Apache、python 已安装并能正常工作;
*

2.下载最新版 moin-1.5.6, http://moinmoin.wikiwikiweb.de/MoinMoinDownload

安装配置

*

安装 MoinMoin
* tar zxvf moin-1.5.6.tar.gz
* cd moin-1.5.6
* python -v setup.py install
*

默认安装在 /usr/share/moin 目录下面,该目录存放 MoinMoin 系统的模板,内容大致有以下几类:
o

/usr/share/moin/data 目录存放 WiKi pages,users,plugin,cache 等
o

/usr/share/moin/underlay 目录存放默认的 WiKi pages,有多种语言版本的帮助文档、默认页面文档等
o /usr/share/moin/htdocs 目录存放网页元素,如图片、主题风格等
o /usr/share/moin/server 目录存放服务器启动脚本示例
o /usr/share/moin/config目录存放配置文件示例
*

通过拷贝模板目录中的文件,就可生成不同的 WiKi 实例。MoinMoin 的软件升级也很简单,只需用新版的模板文件下覆盖旧文就可以了。
*

创建 MoinMoin 实例
* 在服务器上创建一个目录用于存放实例,目录名不能是 wiki,它已被系统保留使用,这里我们使用 ccosswiki ,并从模板目录拷贝实例所需文件,如下:
o cd /var/www
o mkdir ccosswiki
o cp -rf /usr/share/moin/data ccosswiki
o cp -rf /usr/share/moin/underlay ccosswiki
o cp /usr/share/moin/config/wikiconfig.py ccosswiki
* 设置实例目录权限
* chown -R apache.apache ccosswiki
* chmod -R ug+rw ccosswiki
* chmod -R o-rwx ccosswiki
* 配置 Apache + CGI 方式
* 1.cp /usr/share/moin/server/moin.cgi /var/www/ccosswiki
* 2.修改 moin.cgi 中 sys.path.insert() 路径,如下:
o sys.path.insert(0, '/var/www/ccosswiki/')
* 3.配置 wikiconfig.py

# -*- coding: utf-8 -*- #使用UTF-8编码
# IMPORTANT! This encoding (charset) setting MUST be correct! If you live in a
# western country and you don't know that you use utf-8, you probably want to
# use iso-8859-1 (or some other iso charset). If you use utf-8 (a Unicode
# encoding) you MUST use: coding: utf-8
# That setting must match the encoding your editor uses when you modify the
# settings below. If it does not, special non-ASCII chars will be wrong.

"""
MoinMoin - Configuration for a single wiki

If you run a single wiki only, you can omit the farmconfig.py config
file and just use wikiconfig.py - it will be used for every request
we get in that case.

Note that there are more config options than you'll find in
the version of this file that is installed by default; see
the module MoinMoin.multiconfig for a full list of names and their
default values.

Also, the URL http://moinmoin.wikiwikiweb.de/HelpOnConfiguration has
a list of config options.

** Please do not use this file for a wiki farm. Use the sample file
from the wikifarm directory instead! **

@copyright: 2000-2005 by Juergen Hermann
@license: GNU GPL, see COPYING for details.
"""

from MoinMoin.multiconfig import DefaultConfig


class Config(DefaultConfig):

# Wiki identity ----------------------------------------------------

# Site name, used by default for wiki name-logo [Unicode]
sitename = u'CCOSS Wiki' #你的WiKi网站的名称

# Wiki logo. You can use an image, text or both. [Unicode]
# For no logo or text, use '' - the default is to show the sitename.
# See also url_prefix setting below!
logo_string = u'MoinMoin Logo' #网站Logo

# name of entry page / front page [Unicode], choose one of those:

# a) if most wiki content is in a single language
#page_front_page = u"MyStartingPage"

# b) if wiki content is maintained in many languages
page_front_page = u"FrontPage" #启用首页

# The interwiki name used in interwiki links
#interwikiname = 'UntitledWiki'
# Show the interwiki name (and link it to page_front_page) in the Theme,
# nice for farm setups or when your logo does not show the wiki's name.
#show_interwiki = 1



# Critical setup ---------------------------------------------------

# Misconfiguration here will render your wiki unusable. Check that
# all directories are accessible by the web server or moin server.

# If you encounter problems, try to set data_dir and data_underlay_dir
# to absolute paths.

# Where your mutable wiki pages are. You want to make regular
# backups of this directory.
data_dir = '/root/mywiki/data/' #设置data目录路径,要用绝对路径

# Where read-only system and help page are. You might want to share
# this directory between several wikis. When you update MoinMoin,
# you can safely replace the underlay directory with a new one. This
# directory is part of MoinMoin distribution, you don't have to
# backup it.
data_underlay_dir = '/root/mywiki/underlay/' #设置underlay目录路径,要用绝对路径

# This must be '/wiki' for twisted and standalone. For CGI, it should
# match your Apache Alias setting.
url_prefix = '/wiki'


# Security ----------------------------------------------------------

# This is checked by some rather critical and potentially harmful actions,
# like despam or PackageInstaller action:
superuser = [u"root", ] #设置超级用户

# IMPORTANT: grant yourself admin rights! replace YourName with
# your user name. See HelpOnAccessControlLists for more help.
# All acl_rights_xxx options must use unicode [Unicode]
acl_rights_before = u"YourName:read,write,delete,revert,admin" #设置管理权限

# Link spam protection for public wikis (Uncomment to enable)
# Needs a reliable internet connection.
#from MoinMoin.util.antispam import SecurityPolicy


# Mail --------------------------------------------------------------

# Configure to enable subscribing to pages (disabled by default)
# or sending forgotten passwords.

# SMTP server, e.g. "mail.provider.com" (None to disable mail)
mail_smarthost = "192.168.28.200" #使用21cn的smtp服务器发送邮件

# The return address, e.g u"Jürgen Wiki " [Unicode]
mail_from = u"hongzhiyi" #发送者

# "user pwd" if you need to use SMTP AUTH
mail_login = "hongzhiyi 123456" #SMTP服务器验证,以"user password"格式填写


# User interface ----------------------------------------------------

# Add your wikis important pages at the end. It is not recommended to
# remove the default links. Leave room for user links - don't use
# more than 6 short items.
# You MUST use Unicode strings here, but you need not use localized
# page names for system and help pages, those will be used automatically
# according to the user selected language. [Unicode]
navi_bar = [ #设置导航栏
# If you want to show your page_front_page here:
u'%(page_front_page)s',
u'RecentChanges',
u'FindPage',
u'HelpContents',
]

# The default theme anonymous or new users get
theme_default = 'modern' #设置网页主题峁


# Language options --------------------------------------------------

# See http://moinmoin.wikiwikiweb.de/ConfigMarket for configuration in
# YOUR language that other people contributed.

# The main wiki language, set the direction of the wiki pages
language_default = 'zh' #设置默认语言

# You must use Unicode strings here [Unicode]
page_category_regex = u'^Category[A-Z]'
page_dict_regex = u'[a-z]Dict$'
page_form_regex = u'[a-z]Form$'
page_group_regex = u'[a-z]Group$'
page_template_regex = u'[a-z]Template$'

# Content options ---------------------------------------------------

# Show users hostnames in RecentChanges
show_hosts = 1

# Enable graphical charts, requires gdchart.
#chart_options = {'width': 600, 'height': 300}

* 4.配置 Apache2
* 在 /etc/httpd/conf.d/ 下新增 moinmoin.conf,添加如下内容:

Alias /wiki/ "/usr/share/moin/htdocs/"

Order deny,allow
Allow from all


ScriptAlias /ccosswiki "/var/www/ccosswiki/moin.cgi"

Order deny,allow
Allow from all


* 重启 Apache 并测试 Wiki
* 1./etc/init.d/httpd reload
*

2.在浏览器中输入 http://192.168.28.1/ccosswiki
* 安装中文语言包
* 测试成功后,添加新用户,输入 root 用户名(在 wikiconfig.py 设置的超级用户),然后以 root 身份登录,输入以下网址:
o

http://192.168.28.1/ccosswiki/SystemPagesSetup
o

如果你没有管理权限,访问该页面时在语言包前面是不会显示安装按钮的。

相关配置

* 设置时区
*

除了手动更改外,我没找到好的办法 :(
* 具体操作:在“用户设置”、“时区”中修改“您的当地时间是”为+8的时间,比如 2006-12-13 14:36:54 [+08:00]
*

PS.刚试了几个采用 MoinMoin 的中文 Wiki 也有这个问题。
* 其它设置

补充

* 采用 Apache + Mod_Python 方式
* 这种方式能获得更高的性能,配置也不复杂,至少在我自己的机器上面很轻松搞定
*

1.安装 Mod_Python,目前最新版本为3.2.10,下载地址:http://www.modpython.org,安装过程如下:
o tar zxvf mod_python-3.2.10.tgz
o cd mod_python-3.2.10
o

./configure --with-apxs=/opt/apache2/bin/apxs 由于我机器上的apache没有安装在默认路径,故需要指定 apxs 的路径
o

make && make install 默认安装在 apache/modules 目录下
*

2.配置 /etc/httpd/conf.d/python.conf,添加 LoadModule python_module modules/mod_python.so
*

这时可以重启 apache 看能否正确装载 Mod_Python
* 3.检查 wikiconfig.py 中 data_dir 和 data_underlay_dir 路径是否正确
*

4.修改 /etc/httpd/conf.d/moinmoin.conf,注释 ScriptAlias :

#ScriptAlias /mywiki "/var/www/moin/mywiki/moin.cgi"

* 并增加


SetHandler python-program
# Add the path of your wiki directory
PythonPath "['/var/www/moin/mywiki'] + sys.path"
PythonHandler MoinMoin.request::RequestModPy.run


* 5.重启 apache 测试

权限

1.成为管理员:
在配置文件wikiconfig.py中加入如下一行:

acl_rights_default = u'+admin:admin,delete Known:read,write,revert All:read'

这样非注册用户仅有阅读权限,注册用户(Known指已经注册的用户)可读写;admin拥有管理员权限并且可删除、重命名.简言之,拥有admin权限的就是管理员.
2.建立群组:
假设我们要建立一个名为TrustedGroup的可信赖的组(注意:一个组名应该就是一个WikiName(wiki名),即以首字母大写的两个(或以上)单词组成一个词(单词之间无空格),如TrustedGroup)
1)进入FindPage,建立一个名为TrustedGroup的wiki page
2)编辑TrustedGroup,所有的组员名单以列表方式给出,比如:

* hitgnu
* jeffrey

由于此页面会影响到访问权限的管理,应该设置其权限于仅允许管理员读写,其他的用户应该对其无任何权限,故而此页的最后内容应该类似如下的方式:

#acl +admin:write,read All:
* hitgnu
* jeffrey

3.关键页面授权特定用户组访问:
建立了用户组之后,我们可以指定某个页面授权特定组的特殊权限,只需在该页面添加类似如下的内容:

#acl +admin:read,write,revert,delete TrustedGroup:read,write,revert All:

这样,仅仅管理员和特定的组成员可以看到并可以编辑该页面的内容,有效地保护该页面包含的敏感内容.

1 条评论:

LinFengjun 说...

-----------
* 设置时区
*

除了手动更改外,我没找到好的办法 :(
* 具体操作:在“用户设置”、“时区”中修改“您的当地时间是”为+8的时间,比如 2006-12-13 14:36:54 [+08:00]
*
-------------


刚试了一下,在wikiconfig.py里加这个设置可以更改站点的默认时区:
tz_offset = 8.0 # default time zone offset in hours from UTC

参考:http://moinmo.in/HelpOnConfiguration

ps。在moinmoin的search bar里面搜“tz_offset”居然什么也搜不到。我是用timezone做关键字直接搜代码才搜到这个变量名。当前版本是1.8.2。 有点小失望。