利用JSPWiki搭建簡易企業wiki平臺

開源的Wiki引擎Apache JSPWiki,基於標準 JEE 組件(Java、servlet、JSP)構建,支持模板、CSS樣式、插件、細粒度安全控制、autocomplete等功能,簡單易用、功能豐富,非常適合用來搭建簡易的企業wiki平臺。

安裝

推薦部署在Tomcat服務器,要求Tomcat 8.x或更高、JDK 1.8或更高版本。安裝步驟如下:

  1. 下載JSPWiki

選擇Apache mirror地址,進入binaries/webapp/目錄,下載JSPWiki.war。

  1. 可選,重命名war,比如修改爲wiki.war
  2. 將war放到$TOMCAT_HOME/webapps目錄,啓動tomcat
  3. 訪問 http://myhost/appname/Install.jsp, 進行初始配置

安裝程序將把設置寫到 $TOMCAT_HOME/temp/jspwiki-custom.properties,還會創建一個admin帳戶(密碼隨機生成)和一個 Admin 組,注意保存頁面提示的密碼。

  1. 停止tomcat,將jspwiki-custom.properties移動到$TOMCAT_HOME/lib目錄

您可以在系統屬性或web.xml的context-param內定義jspwiki.custom.config來指定jspwiki-custom.properties的位置。

也可以將jspwiki-custom.properties移動到$TOMCAT_HOME/webapp/appname/WEB-INF目錄,但這不利於升級。

默認,創建的用戶、組保存在WEB-INF目錄下的userdatabase.xml、groupdatabase.xml文件內。

jspwiki-custom.properties內容如下:

#Wed Feb 26 23:19:26 CST 2020
jspwiki.basicAttachmentProvider.storageDir=C\:\\\\Work\\\\wikipages
jspwiki.fileSystemProvider.pageDir=C\:\\\\Work\\\\wikipages
jspwiki.pageProvider=VersioningFileProvider
jspwiki.applicationName=iTRunnerWiki
jspwiki.workDir=C\:\\\\\\\\Work\\\\\\\\apache-tomcat-9.0.14\\\\\\\\temp

爲了便於升級,最好在jspwiki-custom.properties內指定用戶、組的保存位置:

jspwiki.xmlUserDatabaseFile
jspwiki.xmlGroupDatabaseFile

也可以使用數據庫:

jspwiki.userdatabase = org.apache.wiki.auth.user.JDBCUserDatabase
jspwiki.groupdatabase = org.apache.wiki.auth.authorize.JDBCGroupDatabase
  1. 安裝core pages

下載您選擇語言的wikipages,然後解壓將內容拷貝到前面指定的jspwiki.fileSystemProvider.pageDir目錄。啓動tomcat。

  1. 訪問wiki

您將進入Main頁面,可以學習JSPWiki知識,可以編輯這些頁面。
利用JSPWiki搭建簡易企業wiki平臺

JSPWiki Configuration

要查看jspwiki.properties支持的配置項,可以訪問官網,也可以解壓WEB-INF/lib/jspwiki-main.jar,ini目錄內含有此文件,其中包含所有屬性。

下面列出一些常用的屬性:

jspwiki.baseURL=http://www.itrunner.org/wiki

#  If this property is set to "true", then page titles are rendered
#  using an extra space between every capital letter.
jspwiki.breakTitleWithSpaces=true

# Set the default page
jspwiki.frontPage=Main

# Set the default template used by the Wiki engine
jspwiki.templateDir=default

# Set position of the favorites menu (aka left menu, sidebar)
# The value determines the css-class used to change the position of the #favorites block
# Possible values: fav-left or fav-right
# Default value is fav-left
jspwiki.defaultprefs.template.orientation=fav-right

#
#  By default JSPWiki accepts all types of attachments.  However, you
#  can allow some types only, or forbid some other types.  
# These allow/forbid statements are not enforced for users with AdminPermissions.
#
#  These both are space-separated lists of file suffixes
#
#  Example: Allow only PNG, JPG, ZIP and JAR file attachments
jspwiki.attachment.allowed=.png .jpg .zip .jar

#  Example: Forbid HTML, PHP, ASP and EXE
jspwiki.attachment.forbidden=.html .htm .php .asp .exe

# Example: Attachment links to HTML, HTM and MP3 files would force a download rather then opening the attachment
jspwiki.attachment.forceDownload= .html .htm

# Inline all JPG files, PNG files, GIF files
jspwiki.translatorReader.inlinePattern.1 = *.jpg
jspwiki.translatorReader.inlinePattern.2 = *.png
jspwiki.translatorReader.inlinePattern.3 = *.gif

Security

JSPWiki 包含一套豐富、靈活的安全功能。

JSPWiki Policy

默認策略文件jspwiki.policy位於WEB-INF目錄下,可以使用配置屬性指定自定義策略文件位置:

jspwiki.policy.file=jspwiki-custom.policy

JSPWiki Security支持Role、Group,其中Role包含以下五種:

  • All 任何人
  • Anonymous 匿名用戶
  • Asserted 無需登錄,只要編輯過User Preferences即可
  • Authenticated 已登錄用戶
  • Admin 管理員

最初創建的admin用戶屬於Admin角色、Admin組,擁有全部權限。

初始策略很寬鬆,匿名用戶可以註冊、登錄,可以查看、修改、創建頁面。默認策略如下表:

Permission Anonymous users Asserted users (with cookie) Authenticated users Admin group
View all pages x x x x
Edit all pages x x x x
Upload attachments to all pages x x
Modify all pages (edit + upload) x x
Comment on all existing pages x x x x
Create new pages x x x x
Rename all pages x x
Delete all pages x
View all groups x x x
Edit all groups x x
Rename all groups x x
Delete all groups x
Create new groups x x
Create profile x x x x
Edit user preferences x x
Edit user profile x x

策略分爲四種主要權限類型:

  • PagePermission: view, edit, modify, comment, rename, upload, delete
  • GroupPermission: view, edit, delete
  • WikiPermission: createGroups, createPages, login, editPreferences, editProfile
  • AllPermission 授予全部權限

某些權限意味着其他權限:

  • The "rename" PagePermission implies "modify"
  • The "modify" PagePermission implies "edit" and "upload"
  • The "edit" PagePermission implies "view" and "comment"
  • The "upload" PagePermission implies "view"
  • The "delete" PagePermission implies "edit"
  • The "createGroups" WikiPermission implies "createPages"
  • The "edit" GroupPermission implies "view"
  • The "delete" GroupPermission" implies "edit" and "view"

ACL

除在policy文件統一配置權限外,還可以在每個頁面內單獨設置權限,如:

[{ALLOW edit Admin}]
[{ALLOW view All}]

可將權限授予角色、組或用戶。

AdminPages

安全原因,AdminPages默認是未啓用的。要啓用添加以下配置:

jspwiki-x.adminui.enable=true
jspwiki-x.securityconfig.enable=true

有兩個管理頁面,路徑分別爲:

  • /admin/Admin.jsp
  • /admin/SecurityConfig.jsp

Admin.jsp可以創建、編輯用戶和組:
利用JSPWiki搭建簡易企業wiki平臺
SecurityConfig.jsp檢查 JSPWiki 的安全配置,允許查看當前 Wiki 中的用戶、組和 ACL 配置:
利用JSPWiki搭建簡易企業wiki平臺

編輯Wiki

JSPWiki提供了友好的編輯界面:
利用JSPWiki搭建簡易企業wiki平臺
支持兩種模式:plain和wysiwyg,默認爲plain。點擊水滴按鈕彈出工具欄:
利用JSPWiki搭建簡易企業wiki平臺
選中某一工具會輸出相應的wiki語句,plugin、style、font、special character、ACL等工具還會顯示支持的選項,在您熟悉wiki語法後,可以脫離工具欄,直接輸入時同樣如此,非常方便。

Wiki Syntax

編輯wiki時點擊Help會顯示如下信息:

----             水平分隔線
\\               強制斷行
[link]           創建 "link" 的超鏈接,其中 "link" 可以是內部 Wiki 名稱(Wiki 頁面名稱)或者外部鏈接(http://)
[text|link]      創建一個顯示文本和實際超鏈接不同的超鏈接,其中“text”爲要 顯示的文本;“link”爲實際的超鏈接。
[text|wiki:link] 創建一個顯示文本和實際超鏈接不同的超鏈接,並且超鏈接指向指定的 Wiki(比如 JSPWiki、MediaWiki 等等)。
                 這種鏈接支持 Wiki 之間的鏈接。

*                創建一個項目列表('*' 必需爲所在行第一個字符)。用連續多個星號(**)表示次級項目符號。
#                創建一個編號列表('#' 必需爲所在行第一個字符)。用連續多個#號(##,###)表示縮進/次級編號。

!, !!, !!!       在行首加上感嘆號(!)生成標題。感嘆號越多表示標題越大。
__text__         文本加粗。
''text''         給文本斜體效果(注意是單引號 ')
{{text}}         使文本變爲等款字體。
;term:def        用 'def' 定義 'term'。用空的 'term' 可以表示簡短註釋(如,;:Created on 2008/02/28)。

|text|more text 生成表格。兩條豎線“||”表示表格標題。

更多的Wiki Syntax請查看官網。

Wiki Style

CSS styles
Following styles are supported by the standard jspwiki.css file:

  • %%small -- Smaller then normal font
  • %%sub -- Subscript
  • %%sup -- Superscript
  • %%strike -- Strike through text
  • %%ltr -- left-to-right text formatting
  • %%rtl -- right-to-left text formatting
  • %%commentbox -- comment box floating at the right margin

Dynamic styles

  • %%collapse -- Turn ordinary lists into collapsible trees.
  • %%collapsebox -- Creates a collapsible box which slides in/out vertically.
  • %%category -- Generates pop up with pages referenced by the category page.
  • %%tip -- Generates a transparent fly-over tip with additional info.
  • %%graphbar -- Add horizontal or vertical graph bars to your wikipages.
  • %%sortable -- Turn ordinary wiki tables into sortable tables.
  • %%table-filter -- Turn ordinary wiki tables into Excel-like filtered tables.
  • %%zebra-table -- Add alternate row colors to your tables.
  • %%columns -- Format text in multi-column news-paper format.
  • %%tabbedSection, %%tab -- Create pages with tabular sections.
  • %%tabbedAccordion -- Generates a tabbed section, with smooth transition effects based on accordion.
  • %%accordion -- Generates vertical accordion.
  • %%prettify -- Add code-coloring to a preformatted block of text.
  • %%slimbox -- Generates a fancy picture viewer for all enclosed links, similar to the attachment viewer.
  • %%reflection -- Generates a reflection at the bottom of the image.

例如:

JSPWiki官方頁面的LeftMenu,組合使用了%%list-unstyled-hover,%%accordion:

%%list-unstyled-hover

%%accordion
!General
* [News]
* [Getting Started]
* [Wiki Syntax]
* [Downloads]
* [ReleaseNotes|NewIn]
* [FAQ]
* [License|http://www.apache.org/licenses/]

!Community
* [Getting Started]
* [Getting Involved]
* [Documentation]
* [Legacy site|http://www.ecyrd.com/JSPWiki/]
* [Mailing lists|Mailing Lists]
* [Social media|Social Media]
* [People]
!Development
* [Browse sources|https://github.com/apache/jspwiki]
* [JavaDoc|http://jspwiki.apache.org/apidocs/index.html]
* [Binary compatibility reports|http://jspwiki.apache.org/japicmp/index.html]
* [Get and build source|Building from source code]
* [Issue tracker|https://issues.apache.org/jira/browse/JSPWIKI]
* [Jenkins build|https://builds.apache.org/job/JSPWiki/]
* [Sonar Analysis|https://sonarcloud.io/dashboard?id=jspwiki-builder]
* [ChangeLog|https://jspwiki.apache.org/development/changelog.html]
* [Other stuff]

!PMC
* [How to release]
* [Board Reports]

!Special Pages
* [Recent Changes]
* [Search]
* [Page Index|PageIndex]
* [SystemInfo]

!Referenced by
[{ReferringPagesPlugin max=20, maxwidth=50}]
/%
/%

無邊框表格:

%%table-noborder
|| Column 1 || Column 2 || Column 3 
| Text     | Text     | Text 
/%

JSPWiki支持自定義樣式,比如:
%%add-css
table {
margin: 20px;
width: 100%;
text-align: center;
}

table td {
text-align: center;
}
/%

還可以添加屬性, 如:

[{Image src='Main/tool.JPG' style='text-align: center; width: 800px;'}]

Wiki Plugin

JSPWiki提供很多的插件,在此不一一列舉,比如常用的目錄插件 [{TableOfContents}]、ACL插件 [{ALLOW plugin principal }]、Image插件 [{Image src='image.jpg'}]。

Reserved Pages

預留頁面是一些特殊用途的固定名稱頁面,比如CopyrightNotice、LeftMenu、LeftMenuFooter,在Wiki Template中會用到。

WikiTemplate

當前JSPWiki提供了default、210、raw、reader四套模板,位於war的templates目錄下,用戶可自定義模板。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章