PukiWiki1.4.7 WikiFarmEngine
HikiやFSWikiにはあるんだけどPukiWikiにはないので、どうにかならないかなぁと試行錯誤した結果。会社で社内Wiki用にまとめたけど、こっちにも書いておく。URLとかPathとかは適宜読み替えてください。ま、こんなもの参考にする人は何かあったときの未来の俺くらいだとは思うが。
http://www.aksum.jp/pukiwiki/index.php?%E3%83%8F%E3%83%83%E3%82%AF%2F04-WikiFarmEngine
こんなものがあるにはあるのだけども、残念ながらPukiWiki1.4.6ベースで、文字コードがEUC。今時EUCはねーだろう、ということでどうにか1.4.7UTF-8ベースにする
1.4.7ベースのFarm
1.4.7のソースを持ってきてフォルダわけ
tar zxf pukiwiki-1.4.7_notb_utf8.tar.gz -C /var/www/html/farm
cd /var/www/html/farm
mkdir {admin,common,datasource}
cp -a {attach,backup,cache,counter,diff,trackback,wiki,.ht*,index.php} {admin,datasource}
cp -a {config,image,lib,plugin,skin} common
mkdir common/doc
mkdir {admin,datasource}/config
延々とこんな感じでPukiFarmを参考に同じディレクトリ構成にする
patch
pukiwiki.ini.php
--- pukiwiki-1.4.7_notb_utf8/pukiwiki.ini.php 2006-10-22 05:40:24.000000000 +0900
+++ common/config/pukiwiki.ini.php 2008-10-09 14:02:09.000000000 +0900
@@ -8,6 +8,8 @@
//
// PukiWiki main setting file
+$adminpage = ':config/admin';
+
/////////////////////////////////////////////////
// Functionality settings
@@ -77,7 +79,7 @@
define('UPLOAD_DIR', DATA_HOME . 'attach/' ); // Attached files and logs
define('COUNTER_DIR', DATA_HOME . 'counter/' ); // Counter plugin's counts
define('TRACKBACK_DIR', DATA_HOME . 'trackback/'); // TrackBack logs
-define('PLUGIN_DIR', DATA_HOME . 'plugin/' ); // Plugin directory
+define('PLUGIN_DIR', COMMON_DIR . 'plugin/' ); // Plugin directory
/////////////////////////////////////////////////
// Directory settings II (ended with '/')
@@ -89,8 +91,10 @@
// CSSs(*.css) and JavaScripts(*.js) are needed at
// ./SKIN_DIR from index.php.
+require(CONFIG_DIR . 'skin.ini.php');
+
// Static image files
-define('IMAGE_DIR', 'image/');
+define('IMAGE_DIR', COMMON_DIR . 'image/');
// Keep this directory shown via web browsers like
// ./IMAGE_DIR from index.php.
@@ -190,7 +194,7 @@
// Admin password for this Wikisite
// Default: always fail
-$adminpass = '{x-php-md5}!';
+//$adminpass = '{x-php-md5}!';
// Sample:
//$adminpass = 'pass'; // Cleartext
@@ -230,42 +234,6 @@
$pagereading_config_dict = ':config/PageReading/dict';
/////////////////////////////////////////////////
-// User definition
-$auth_users = array(
- // Username => password
- 'foo' => 'foo_passwd', // Cleartext
- 'bar' => '{x-php-md5}f53ae779077e987718cc285b14dfbe86', // PHP md5() 'bar_passwd'
- 'hoge' => '{SMD5}OzJo/boHwM4q5R+g7LCOx2xGMkFKRVEx', // LDAP SMD5 'hoge_passwd'
-);
-
-/////////////////////////////////////////////////
-// Authentication method
-
-$auth_method_type = 'pagename'; // By Page name
-//$auth_method_type = 'contents'; // By Page contents
-
-/////////////////////////////////////////////////
-// Read auth (0:Disable, 1:Enable)
-$read_auth = 0;
-
-$read_auth_pages = array(
- // Regex Username
- '#HogeHoge#' => 'hoge',
- '#(NETABARE|NetaBare)#' => 'foo,bar,hoge',
-);
-
-/////////////////////////////////////////////////
-// Edit auth (0:Disable, 1:Enable)
-$edit_auth = 0;
-
-$edit_auth_pages = array(
- // Regex Username
- '#BarDiary#' => 'bar',
- '#HogeHoge#' => 'hoge',
- '#(NETABARE|NetaBare)#' => 'foo,bar,hoge',
-);
-
-/////////////////////////////////////////////////
// Search auth
// 0: Disabled (Search read-prohibited page contents)
// 1: Enabled (Search only permitted pages for the user)
@@ -530,4 +498,12 @@
array('pattern'=>'#^#', 'profile'=>'default'), // Sentinel
);
+
+require(DATA_HOME . 'userauth.php');
+$auth_users = $userauth->get_auth_users();
+$auth_method_type = $userauth->get_auth_method_type();
+$read_auth = $userauth->get_read_auth();
+$read_auth_pages = $userauth->get_read_auth_pages();
+$edit_auth = $userauth->get_edit_auth();
+$edit_auth_pages = $userauth->get_edit_auth_pages();
?>
ja.lng.php
--- pukiwiki-1.4.7_notb_utf8/ja.lng.php 2006-10-22 05:40:24.000000000 +0900
+++ common/config/ja.lng.php 2008-10-09 11:28:33.000000000 +0900
@@ -81,8 +81,8 @@
///////////////////////////////////////
// Page name
-$rule_page = 'FormattingRules'; // Formatting rules
-$help_page = 'Help'; // Help
+$rule_page = '整形ルール'; // Formatting rules
+$help_page = 'ヘルプ'; // Help
///////////////////////////////////////
// TrackBack (REMOVED)
@@ -442,4 +442,6 @@
// yetlist.inc.php
$_title_yetlist = '未作成のページ一覧';
$_err_notexist = '未作成のページはありません。';
+
+$_LANG['skin']['admin'] = '管理';
?>
lib/auth.php
--- pukiwiki-1.4.7_notb_utf8/lib/auth.php 2006-10-22 05:40:25.000000000 +0900
+++ common/lib/auth.php 2008-10-09 13:07:24.000000000 +0900
@@ -197,8 +197,8 @@
explode(':', base64_decode($matches[1]));
}
- if (PKWK_READONLY ||
- ! isset($_SERVER['PHP_AUTH_USER']) ||
+// if (PKWK_READONLY ||
+ if( ! isset($_SERVER['PHP_AUTH_USER']) ||
! in_array($_SERVER['PHP_AUTH_USER'], $user_list) ||
! isset($auth_users[$_SERVER['PHP_AUTH_USER']]) ||
pkwk_hash_compute(
lib/html.php
--- pukiwiki-1.4.7_notb_utf8/lib/html.php 2006-10-22 05:40:25.000000000 +0900
+++ common/lib/html.php 2008-10-09 16:34:57.000000000 +0900
@@ -37,6 +37,9 @@
$r_page = rawurlencode($_page);
// Set $_LINK for skin
+
+ $_LINK['admin'] = "$script?%3Aconfig%2Fadmin";
+
$_LINK['add'] = "$script?cmd=add&page=$r_page";
$_LINK['backup'] = "$script?cmd=backup&page=$r_page";
$_LINK['copy'] = "$script?plugin=template&refer=$r_page";
lib/pukiwiki.php
--- pukiwiki-1.4.7_notb_utf8/lib/pukiwiki.php 2006-10-22 05:40:25.000000000 +0900
+++ common/lib/pukiwiki.php 2008-10-08 11:17:07.000000000 +0900
@@ -68,6 +68,9 @@
require(LIB_DIR . 'trackback.php'); // TrackBack
}
+ include_once( COMMON_DIR . 'plugin/paraedit.inc.php');
+ $post["msg"] = _plugin_paraedit_parse_postmsg($post["msg_before"], $post["msg"], $post["msg_after"]);
+
/////////////////////////////////////////////////
// Main
skin/pukiwiki.skin.php
--- pukiwiki-1.4.7_notb_utf8/skin/pukiwiki.skin.php 2006-10-22 05:40:28.000000000 +0900
+++ common/skin/pukiwiki.skin.php 2008-10-08 19:31:22.000000000 +0900
@@ -76,8 +76,8 @@
<title><?php echo $title ?> - <?php echo $page_title ?></title>
<link rel="SHORTCUT ICON" href="<?php echo $image['favicon'] ?>" />
- <link rel="stylesheet" type="text/css" media="screen" href="skin/pukiwiki.css.php?charset=<?php echo $css_charset ?>" charset="<?php echo $css_charset ?>" />
- <link rel="stylesheet" type="text/css" media="print" href="skin/pukiwiki.css.php?charset=<?php echo $css_charset ?>&media=print" charset="<?php echo $css_charset ?>" />
+ <link rel="stylesheet" href="<?php echo CSS_FILE ?>?charset=<?php echo $css_charset ?>" type="text/css" media="screen" charset="<?php echo $css_charset ?>" />
+ <link rel="stylesheet" href="<?php echo CSS_FILE ?>?charset=<?php echo $css_charset ?>&media=print" type="text/css" media="print" charset="<?php echo $css_charset ?>" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="<?php echo $link['rss'] ?>" /><?php // RSS auto-discovery ?>
<?php if (PKWK_ALLOW_JAVASCRIPT && $trackback_javascript) { ?> <script type="text/javascript" src="skin/trackback.js"></script><?php } ?>
@@ -154,6 +154,8 @@
| <?php _navigator('help') ?>
]
+ [ <?php _navigator('admin') ?> ]
+
<?php if ($trackback) { ?>
[ <?php _navigator('trackback', $lang['trackback'] . '(' . tb_count($_page) . ')',
($trackback_javascript == 1) ? 'onclick="OpenTrackback(this.href); return false"' : '') ?> ]
skin/pukiwiki.css.php
--- pukiwiki-1.4.7_notb_utf8/skin/pukiwiki.css.php 2006-10-22 05:40:27.000000000 +0900
+++ common/skin/pukiwiki.css.php 2008-10-09 11:16:58.000000000 +0900
@@ -170,7 +170,6 @@
.style_table {
padding:0px;
border:0px;
- margin:auto;
text-align:left;
color:inherit;
background-color:#ccd5dd;
@@ -196,7 +195,7 @@
ol.list2 { list-style-type:lower-roman; }
ol.list3 { list-style-type:lower-alpha; }
-div.ie5 { text-align:center; }
+div.ie5 { text-align:left; }
span.noexists {
color:inherit;
1.4.7からじゃなくてPukiFarmからの差分
PukiFarmのソースはEUC-JPなので、単純にコピーするだけでなく
nkf –overwrite -w0 コピーしたソース
とか必ずやる
```diff
common/plugin/add_site.inc.php [#v644fe5c]
--- ~/pukifarm/common/plugin/add_site.inc.php 2008-10-09 18:44:16.137051769 +0900
+++ common/plugin/add_site.inc.php 2008-10-09 16:05:55.000000000 +0900
@@ -14,7 +14,7 @@
// サイトの元データ
define('INIT_DIR', '../datasource/' );
// PukiFarm の URL (編集必須)
-define('FARM_URL', 'http://aksum.jp/pukifarm/admin/');
+define('FARM_URL', 'http://wiki/farm/');
function plugin_add_site_convert()
{
@@ -73,8 +73,8 @@
closedir($dir);
plugin_add_site_create_site($id);
-
- $retval['msg'] = $_registed;
+
+ $retval['msg'] = $_registed;
$retval['body'] = convert_html('登録完了しました。'.FARM_URL.$id.'/ からアクセスして下さい。');
return $retval;
@@ -120,9 +120,7 @@
\$site_id = '{$id}';
require(CONFIG_DIR . 'password.ini.php');
require(CONFIG_DIR . 'baseconf.ini.php');
-require(CONFIG_DIR . 'amazon_id.ini.php');
/////////////////////////////////////////////////
require(LIB_DIR . 'pukiwiki.php');
追加
あとは足りないファイルをPukiFarmからコピって、同様にnkfする
新規
adminで既存Wikiの一覧を出したいので、プラグインを作る
common/plugin/farmlist.inc.php
<?php
// PukiWiki - Yet another WikiWikiWeb clone
// $Id: farmlist.inc.php,v 1.0 2008/10/08 nobu Exp $
// Copyright (C)
// 2002-2005 PukiWiki Developers Team
// 2001-2002 Originally written by yu-ji
// License: GPL v2 or (at your option) any later version
//
// WikiFarm List plugin
function plugin_farmlist_convert()
{
$path = '/var/www/html/farm/';
$count = 0;
foreach (glob($path . "*", GLOB_ONLYDIR) as $dirname) {
//最初からある3つのディレクトリは除外
if (ereg("admin$", $dirname));
elseif (ereg("datasource$", $dirname));
elseif (ereg("common$", $dirname));
else {
$list[] = array('name' => basename($dirname), 'time' => get_mtime($dirname));
$count++;
}
}
usort($list, "cmp");
$liststr = '';
foreach ($list as $key => $value) {
$liststr = $liststr . "<tr>\n";
$liststr = $liststr . " <td class=\"style_td\"><a href=\"http://wiki/farm/" . $value['name'] . "/\">" . $value['name'] . "</td>\n";
$liststr = $liststr . " <td class=\"style_td\">" . $value['time'] . "</td>\n";
$liststr = $liststr . "</tr>\n";
}
$string = <<<EOD
<div class="ie5">
<table class="style_table" cellspacing="1" border="0">
<tbody>
<tr>
<th class="style_th">wikiの名前</td>
<th class="style_th">最終更新日時</td>
</tr>
$liststr
</tbody>
</table>
</div>
EOD;
return $string;
}
function cmp($a, $b)
{
if ($a['time'] == $b['time']) {
return 0;
}
$datea = strptime($a['time'], "%Y/%m/%d %H:%M:%S");
$dateb = strptime($b['time'], "%Y/%m/%d %H:%M:%S");
return ($datea > $dateb) ? -1 : 1;
}
function get_mtime($path)
{
$mtime = filemtime($path);
return date("Y/m/d H:i:s", $mtime);
}
?>
datasource/wikiとadmin/wikiのファイル名変換
PukiFarmから持ってくるとEUC-JPなので、UTF-8ではうまく日本語が読めない。http://d.hatena.ne.jp/kohiro2/20080711/p1 からスクリプトを拝借、*/wikiのところだけ。
#!/usr/bin/perl -w
use strict;
use warnings;
use Encode;
use File::Basename;
use File::Copy;
use IO::File;
use Path::Class::Dir;
use Path::Class::File;
use constant REGEX_SUFFIX => qw(\..+$);> # 【最初】の . 以降を拡張子とする
#use constant REGEX_SUFFIX => qw(\.[^\.]+$); # 【最後】の . 以降を拡張子とする
&main();
sub main {
if ( $#ARGV != 1 ){
print "error: $0 [source_dir] [target_dir]\n";
exit 1;
}
(my $src_dir_root, my $trg_dir_root) = @ARGV;
my $subdir_name;
my @suffixes;
my $src_dir;
my $trg_dir;
####### */wiki #######
$subdir_name = "wiki";
@suffixes = (".txt");
($src_dir, $trg_dir) = &set_dir($src_dir_root, $trg_dir_root, $subdir_name);
foreach my $src_file ($src_dir->children) {
if ($src_file->is_dir) { next; }
(my $hexname, undef, my $suffix) = fileparse($src_file->basename, REGEX_SUFFIX);
next if ( grep( /$suffix/, @suffixes) == 0 );
my $trg_file = Path::Class::File->new($trg_dir, &hexEUCtoUTF8($hexname) . $suffix);
&fileEUCtoUTF8($src_file->open('r'), $trg_file->open('w'));
utime $src_file->stat->atime, $src_file->stat->mtime, $trg_file;
}
}
### 元先ディレクトリを設定
sub set_dir {
my $src_rootdir = shift;
my $trg_rootdir = shift;
my $subdir = shift;
my $src_dir = Path::Class::Dir->new($src_rootdir, $subdir);
my $trg_dir = Path::Class::Dir->new($trg_rootdir, $subdir);
# 元ディレクトリ確認
if ( ! -e $src_dir ) {
print "ERROR: Can't locate source directory.\n";
exit 1;
}
# 先ディレクトリ確認
$trg_dir->mkpath if ( ! -e $trg_dir );
return ($src_dir, $trg_dir);
}
### File EUC-JP => UTF-8
sub fileEUCtoUTF8 {
my $src_fh = shift;
my $trg_fh = shift;
while (<$src_fh>) {
chomp;
my $tmp = encode('utf-8', decode("euc-jp", $_));
$trg_fh->print("$tmp\n");
}
$trg_fh->close;
$src_fh->close;
}
### HEX => EUC-JP => UTF-8 => HEX => UPPER CASE
sub hexEUCtoUTF8 {
my $string = shift;
# 変換: 16進 → バイナリ
$string =~ s/([0-9A-Fa-f][0-9A-Fa-f])/pack("C", hex($1) )/eg;
# 変換: EUC-JP → UTF-8
$string = encode('utf-8', decode("euc-jp", $string));
# 変換: バイナリ → 16進
$string = unpack("H*", $string);
# 変換: 小文字 → 大文字
$string =~ tr/a-z/A-Z/;
return $string;
}
1;
認証まわり
- http://that.s41.xrea.com/?%BC%AB%BA%EE%A5%D7%A5%E9%A5%B0%A5%A4%A5%F3%2Fuserauth.php 基本これをつかう
- {datasource,admin}直下にuserauth.phpとuserauth_admin.php
- {datasource,admin}/configにuserauth.txt
- やっぱEUCなのでnkfで変換
userauth.php
--- - 2008-10-09 19:06:09.129869766 +0900
+++ datasource/userauth.php 2008-10-09 14:05:37.000000000 +0900
@@ -65,7 +65,7 @@
// なら他の対策を考える必要があります。)
//
// なお、この値と userauth_admin.php 内の設定は同じにして下さい。
- 'file' => 'userauth.txt'
+ 'file' => 'config/userauth.txt'
//////////////////// ここまで ///////////////////
// データ区切り記号(変える必要はありません)
userauth_admin.php
--- - 2008-10-09 19:07:01.886083742 +0900
+++ datasource/userauth_admin.php 2008-10-09 17:16:53.000000000 +0900
@@ -26,10 +26,11 @@
// md5('0123') ←0123の部分がパスワード
// のような記述でも使用できます。
// $adminpass = 'eb62f6b9306db575c2d596b1279627a4'; //例
-$adminpass = md5('0123');
+require('config/password.ini.php');
// * 戻るボタンの行き先
-$backurl = 'http://';
+$backurl = 'index.php';
// * 認証データのファイル名指定
//
@@ -49,7 +50,7 @@
// なら他の対策を考える必要があります。)
//
// なお、この値と userauth.php 内の設定は同じにして下さい。
-$file = 'userauth.txt';
+$file = 'config/userauth.txt';
// * userauth.phpのファイル名(保存後のチェックで使用)
$checkscript = 'userauth.php';
@@ -523,19 +524,13 @@
function admin_auth( &$mes, $logout = FALSE ){
global $adminpass;
-
- // adminpassがデフォルトのままなら認証失敗
$dmes = '';
- if($adminpass == 'eb62f6b9306db575c2d596b1279627a4'){
- $mes = '<b>$adminpass</b>の設定を変更して下さい'."\n";
- $logout = TRUE;
- }
if(!$logout && !isset($_GET['logout']) && isset($_SESSION['login'])){
$mes = 'login';
return TRUE;
} elseif(!$logout && !isset($_GET['logout']) && isset($_POST['lpassword'])){
- $in_passwd = md5(rtrim($_POST['lpassword']));
+ $in_passwd = '{x-php-md5}' . md5(rtrim($_POST['lpassword']));
if($in_passwd == $adminpass){
$_SESSION['login'] = 1;
$mes = 'login';
これで管理者パスワードと共通化できる。あとは :config/admin から呼び出したいので、リンクを張るだけのpluginを書く。
<?php
// PukiWiki - Yet another WikiWikiWeb clone
// $Id: comment.inc.php,v 1.0 2008/10/08 ogata.nobutoshi Exp $
// Copyright (C)
// 2002-2005 PukiWiki Developers Team
// 2001-2002 Originally written by yu-ji
// License: GPL v2 or (at your option) any later version
//
// WikiFarm List plugin
function plugin_userauth_admin_convert()
{
global $site_id;
return "<a href=\"http://wiki/farm/" . $site_id . "/userauth_admin.php\">ユーザー認証管理室</a>";
}
?>
:config/adminに余計なものがついてるので編集
*管理画面 [#u0e4cc19]
**管理者パスワードの変更 [#zfee523b]
#ch_password
**その他のユーザー認証管理 [#v31ac382]
#userauth_admin
httpd
httpd.conf
適当に追加
<Directory />
AllowOverride All
</Directory>
<Directory "/var/www/html/farm">
Options +ExecCGI +FollowSymLinks
AddHandler cgi-script .cgi
DirectoryIndex index.php
</Directory>
comments powered by Disqus