ChangeLog - *YukiWiki本体/プラグインの改造/新機能追加についての記録 (最終更新 2006/03/10)

目次

YukiWiki本体/プラグインの改造/新機能追加についての記録 (最終更新 2006/03/10)

  • このサイトでは YukiWiki 2.1.2 をベースに新機能を追加してく予定です。

基本方針

  • YukiWikiの基本仕様(YukiWiki本体/プラグインの実装ではなく、ユーザの入力インターフェースの仕様)を損なわないこと。

TODO

オリジナルのYukiWikiに追加した機能のリスト

Wiki Spam 対策

http://www.hyuki.com/diary/20050125080555 に従って、対策をほどこす。

ページの作成/修正/削除の通知メイルのサブジェクトにページ名とモードを追加する

  • sub send_mail_to_admin の
Subject: [Wiki] 
Subject: [Wiki] $page $mode
に変更。

アクセスログをとる

  • wiki.cgiの冒頭に
my $access_data_log = 'log保存ディレクトリ名/ログファイル名';
を加える。
  • sub accesslog を作成
sub accesslog {
#Accesslog by T.Tsukamoto
my ( $a_sec,$a_min,$a_hour,$a_day,$a_mon,$a_year,$a_wday ) = localtime(time);
$a_mon++;
$a_year=$a_year+1900;
open(LOG, ">>$access_data_log");
print LOG "$a_mon/$a_day/$a_year, $a_hour:$a_min:$a_sec, $ENV{'REMOTE_ADDR'}, $ENV{'HTTP_USER_AGENT'}, $ENV{'HTTP_REFERER'}, $form{mypage}\n";
close(LOG);
}
  • sub mainを呼んだ後に sub accesslog を呼ぶようにする。
# &test_convert;
&main;
&accesslog;
exit(0);
  • ログファイルを touch し、パーミッションを適切に設定しておく。

YukiWiki 凍結ページでもコメントを書けるようにする(2004年10月7日実施)

http://hpcgi2.nifty.com/tokd/index.cgi?YukiWikiModifiedVersion

*** 1112,1117 ****
--- 1112,1122 ----
      my ($willbefrozen) = $form{myfrozen};
      if (not $isfrozen and not $willbefrozen) {
          # You need no check.
+         return 0;
+     } elsif ($isfrozen and $form{mycmd} eq 'comment') {
+         # keep frozen
+         $form{myfrozen} = 1;
+         # Comment is always allowed.
          return 0;
      } elsif (valid_password($form{mypassword})) {
          # You are admin.
に基づき、sub frozen_reject を修正。

サイドメニューバーを付ける

nekyoさんのPyukiWikiを参考にして、
  • wiki.cgi の冒頭部分で
my $use_SideBar = 1;
my $SideBar = 'SideBar';
を追加。
  • wiki.cgi の sub do_read で
sub do_read {
    &print_header($form{mypage});
    &print_content($database{$form{mypage}});
    &print_footer($form{mypage});
}
sub do_read {
    &print_header($form{mypage});
    if ($use_SideBar){
    my $MypageBK = $form{mypage}; 
    print <<"EOD";
<table width="100%" border="0">
  <tr>
      <td class="sidebar" valign="top">
      <div id="sidebar">
EOD
    $form{mypage} = $SideBar;
    &print_content($database{$form{mypage}});
    print <<"EOD";
      </div>
      </td>
      <td class="pbody" valign="top">
EOD
    $form{mypage} = $MypageBK; 
    &print_content($database{$form{mypage}});
    print <<"EOD";
      </td>
  </tr>
</table>
EOD
    }else{
    &print_content($database{$form{mypage}});
    }
    &print_footer($form{mypage});
}
に変更。
  • wiki.css を適宜修正

ここの wiki.css です。...適当にいじっただけなので、変なところはご指摘ください。

/*
 * wiki.css for http://www.ps23.org/tamio/YukiWiki/
 * 2004/11/25
 */

body.normal {
    margin: .1em 1% .1em 1%;
    background-color: white;
    color: black;
    /* font-family: monospace; */
    font-size: 12px;
}

body.frozen {
    color: black;
    background: #eee;
    font-size: 12px;
}

.preview {
    color: black;
    background: #fcc;
    font-size: 12px;
}

p {
    margin: 1em 0 1em 1em;
    line-height: 120%;
    font-size: 12px;
}

pre, ul, li {
    line-height: 120%;
    font-size: 12px;
}

a {
}

a:hover {
    color: red;
    background-color: white;
    text-decoration: underline;
}

a img {
    border: none;
}

.tools {
    text-align: left;
    padding: 0 .1em 0 .1em;
    font-size: 12px;
    margin: 0 0 0 0;
}

.header {
    text-align: left;
    border: #999 1px solid;
    color: black;
    background: #fdd;
    padding: .1em .5em .1em .5em;
    margin: .2em 0 0 0;
    font-size: 160%;
    /* font-family: "Courier New", monospace; */
}

.footer {
    font-style: normal; /* italic */
    text-align: right;
    font-size: 80%;
}


.InterWiki {
    color: black;
    background: #eee;
}

h2 {
    text-align: left;
    border: #999 1px solid;
    color: black;
    background: #cfc;
    padding: .1em .5em .1em .5em;
    font-size: 140%;
    /* margin: .2em 0 0 0;*/ 
}

h3 {
    text-align: left;
    border-bottom: #999 1px solid;
    color: black;
    background: #cef;
    padding: .1em .5em .1em .5em;
    /* font-size: 110%;*/
    /* margin: .2em 0 0 0; */
}

h4 {
    text-align: left;
    border-bottom: #999 1px solid;
    color: black;
    background: #def;
    padding: .1em .5em .1em .5em;
    /* font-size: 100%;*/
    /* margin: .2em 0 0 0; */
}

.date {
    font-family: monospace;
}

/* verbatim */
pre.verbatim-hard {
    background-color: #eef;
    border: #ccf 1px solid;
    padding: 1em 1em 1em 1em;
    margin-left: 1em;
    margin-right: 1em;
}

pre.verbatim-soft {
    background-color: #eef;
    border: #ccf 1px solid;
    padding: 1em 1em 1em 1em;
    margin-left: 1em;
    margin-right: 1em;
}

/*  SideBar */

td.sidebar
{
    background: #fff;
}
td.pbody
{
    background: #fff;
}
div#sidebar
{
	width:10em;
    font-size: 100%;
	padding:0px;
	margin:0px;
	word-break:break-all;
	overflow:hidden;
}

div#sidebar ul
{
	margin:0px 0px 0px .5em;
	padding:0px 0px 0px .5em;
}

div#sidebar ul li
{
	line-height:110%;
}

div#sidebar h3
{
	font-size:100%;
}

div#sidebar h4
{
	font-size:100%;
}

/*  SideBar  End */


/* diff */
.added {
    color: blue;
}

.deleted {
    color: red;
}

.same {
    color: #666;
}

.diff {
    color: black;
    background: #eee;
}

/* table */
table {
    background: #ccf;
}

td {
    margin: 1px;
    padding: 5px;
    background: #eef;
}

.error {
}

/*
 * Styles for printer.
 */

@media print {
    form {
        display: none;
    }

    .header {
        color: black;
        border: none;
        text-align: center;
        /* font-size: large; */
        margin-bottom: 1em;
    }

    h2 {
        border: none;
        border-bottom: #ccc 1px solid;
        border-left: #ccc .5em solid;
    }

    h3 {
        border: none;
        border-bottom: #ccc 1px solid;
    }

    h4 {
        border: none;
    }

    a:hover {
        color: black;
        text-decoration: none;
    }

    a {
        text-decoration: none;
    }

    a.editlink {
        display: none;
    }

    .footer {
        display: none;
    }

    body {
    }

    .tools {
        display: none;
    }

    p {
        font-family: Serif;
    }
   td.sidebar
   {
        display: none;
   }
}

  • SideBar」というページを新規作成し、サイドメニューを書き込む

リンクをクリックした時に新しいWindowを開く

wiki.cgiを変更する方法(パラメータで選択)

1)wiki.cgi の冒頭部分で
  my $use_popupwindow = 1;  # Pop up new window when link is clicked. 
と設定。
2)sub make_link の
        } else {
              return qq(<a href="$chunk">$chunk</a>);
となっているところを、
        } else {
	  if ($use_popupwindow){
              return qq(<a href="$chunk" target="_blank">$chunk</a>);
	  }else{
              return qq(<a href="$chunk">$chunk</a>);
	  }
に変更

pluginによる方法 (YukiWikiのlink.plを元にwlink.plを作成)

#### wlink ####
use strict;

package wlink;

sub plugin_inline {
    my ($escaped_argument) = @_;
    my ($caption, $url) = split(/,/, $escaped_argument);
    if ($url =~ /^(mailto|http|https|ftp):/) {
        return qq(<a href="$url" target="_blank">$caption</a>);
    } else {
        return qq(&link($escaped_argument));
    }
}

sub plugin_usage {
    return {
        name => 'wlink',
        version => '1.1t',
        author => 'based on link:Hiroshi Yuki <hyuki@hyuki.com>/modified by Tamio Tsukamoto',
        syntax => '&wlink(caption,url)',
        description => 'Create link with given caption.. and open new window',
        example => "Please visit &wlink(Hiroshi Yuki,http://www.hyuki.com/).",
    };
}

1;

番号付きリスト(行の先頭に「+」を書く)

+起床
+洗顔
+朝食
  1. 起床
  2. 洗顔
  3. 朝食
wiki.cgi の sub text_to_htmlの 番号無しのリストの後に
        } elsif (/^(\+{1,3})(.+)/) {
            &back_push('ol', length($1), \@saved, \@result);
            push(@result, '<li>' . &inline($2) . '</li>');
を追加

強制改行(行末にチルダ「~」を付ける)

このように~
強制改行~
できます。~
このように
強制改行
できます。
wiki.cgi の sub inline に
    $line =~ s|~$|<br>|g;                                   # ~\n -> <br>
を追加

コメント行(行の先頭に「//」を付ける)

//コメントです
wiki.cgi の sub inline に
## Imported from PyukiWiki
    $line =~ s|^//.*$||g;				        # Comment
を追加

左よせ、センタリング、右よせ

wiki.cgiを修正する方法

LEFT:左よせ
CENTER:センタリング
RIGHT:右寄せ
左よせ
センタリング
右寄せ
wiki.cgi の sub inline に
## Imported from PyukiWiki
    $line =~ s!^(LEFT|CENTER|RIGHT):(.*)$!<div style="text-align:$1">$2</div>!g;
を追加

pluginによる方法(left.pl,center.pl,right.plを新規作成)

#### left.pl ####
use strict;

package left;

sub plugin_inline {
    my ($escaped_argument) = @_;
    return qq(<div align="left">$escaped_argument</div>);
}

sub plugin_usage {
    return {
        name => 'left',
        version => '1.0',
        author => 'Tamio Tsukamoto<tamio@mb.infoweb.ne.jp>',
        syntax => '&left(STRING)',
        description => 'Align Left',
        example => '&left(String)',
    };
}

1;
#### center.pl ####
use strict;

package center;

sub plugin_inline {
    my ($escaped_argument) = @_;
    return qq(<center>$escaped_argument</center>);
}

sub plugin_usage {
    return {
        name => 'center',
        version => '1.0',
        author => 'Tamio Tsukamoto<tamio@mb.infoweb.ne.jp>',
        syntax => '&center(STRING)',
        description => 'center',
        example => '&center(String)',
    };
}

1;
#### right.pl ####
use strict;

package right;

sub plugin_inline {
    my ($escaped_argument) = @_;
    return qq(<div align="right">$escaped_argument</div>);
}

sub plugin_usage {
    return {
        name => 'right',
        version => '1.0',
        author => 'Tamio Tsukamoto<tamio@mb.infoweb.ne.jp>',
        syntax => '&right(STRING)',
        description => 'Align Right',
        example => '&right(String)',
    };
}

1;

アンダーライン、取消線

wiki.cgiを変更する方法

%%%アンダーライン%%%、%%取消線%%
アンダーライン取消線
wiki.cgi の sub inline に
    $line =~ s|%%%([^%]*)%%%|<U>$1</U>|g;                   # Under Line
    $line =~ s|%%([^%]*)%%|<S>$1</S>|g;                     # Delete Line
を追加

plugin による方法

取消線は結城浩さんの del.plを入手、 アンダーラインは、新たにunder.plを作成。
#### under.pl ####
use strict;

package under;

sub plugin_inline {
    my ($escaped_argument) = @_;
    return qq(<U>$escaped_argument</U>);
}

sub plugin_usage {
    return {
        name => 'under',
        version => '1.0',
        author => 'Tamio Tsukamoto<tamio@mb.infoweb.ne.jp>',
        syntax => '&under(STRING)',
        description => 'under (Inline).',
        example => '&under(String)',
    };
}

1;

色を変える

wiki.cgiを変更する方法

RED:RED
BLUE:BLUE
GREEN:GREEN
RED BLUE GREEN
wiki.cgi の sub inline に
## Thanks to hash
    $line =~ s!^(RED|BLUE|GREEN):(.*)$!<font color="$1">$2</font>!g;  # Color
を追加

pluginによる方法(color.plを新規作成)

pluginでも&color(RED,赤にできます)。
pluginでも赤にできます
##### color.pl ######
use strict;

package color;

sub plugin_inline {
    my ($escaped_argument) = @_;
    my ($color_name, $string) = split(/,/, $escaped_argument);
    return qq(<font color="$color_name">$string</font>);
}

sub plugin_usage {
    return {
        name => 'color',
        version => '1.0',
        author => 'Tamio Tsukamoto<tamio@mb.infoweb.ne.jp>',
        syntax => '&color(COLOR_NAME,STRING)',
        description => 'Change Font Color (Inline).',
        example => '&color(RED,Red String)',
    };
}

1;

フォントの大きさを変える

wiki.cgiを変更する方法

LARGE:LARGE
SMALL:SMALL
LARGE SMALL
wiki.cgi の sub inline に
    $line =~ s!^(LARGE):(.*)$!<font size="+1">$2</font>!g;  # font size
    $line =~ s!^(SMALL):(.*)$!<font size="-1">$2</font>!g;  # font size
を追加

pluginによる方法(size.plを新規作成)

pluginでも&size(+20,大きく)も&size(-3,小さく)もできます。
pluginでも大きく小さくもできます。
#### size.pl ####
use strict;

package size;

sub plugin_inline {
    my ($escaped_argument) = @_;
    my ($font_size, $string) = split(/,/, $escaped_argument);
    return qq(<font size="$font_size">$string</font>);
}

sub plugin_usage {
    return {
        name => 'size',
        version => '1.0',
        author => 'Tamio Tsukamoto<tamio@mb.infoweb.ne.jp>',
        syntax => '&size(Font_Size,STRING)',
        description => 'Change Font Size(Inline).',
        example => '&size(+20,HUGE FONT)',
    };
}

1;

上付き文字、下付き文字

wiki.cgiを変更する方法

e^^-kt^^, CH__3__OH
e-kt, CH3OH

wiki.cgi の sub inline に
    $line =~ s|\^\^([^\^]*)\^\^|<SUP>$1</SUP>|g;            # SuperScript
    $line =~ s|__([^_]*)__|<SUB>$1</SUB>|g;                 # SubScript
を追加

plugin による方法

PyukiWiki 0.0.7より対応した plugin sup.pl, sub.plを用いる。 http://nekyo.hp.infoseek.co.jp/ を参照。

アマゾン(Amazon)関係の plugin

amazont.pl

結城浩さんのamazon.plを元に、ISBNよりリンクから該当書籍だけの新しいウインドウを開く amazont.plを作成。
use strict;

package amazont;

my $id = 'ここにアフィリエイトIDを記述';

sub plugin_inline {
    my ($escaped_argument) = @_;
    my ($caption, $number) = split(/,/, $escaped_argument);
    return qq(<a href="http://www.amazon.co.jp/exec/obidos/ASIN/$number/$id/ref=nosim" target="_blank">$caption</a>);
}

sub plugin_usage {
    return {
        name => 'amazont',
        version => '1.1',
        author => 'Based on amazon.pl by Hiroshi Yuki <hyuki@hyuki.com> modified by Tamio Tsukamoto',
        syntax => '&amazont(caption,isbn)',
        description => 'Create link to amazon.(Popup a New Window)',
        example => 'Please read &amazont(Alice in Cryptographic World,4797322977).',
    };
}

1;

Amazon.pl

アマゾンへのリンクを本の写真付きで生成するプラグイン。 $idはアフィリエイトIDを記述。ImageIDは和書は 09 、洋書は 01 。
use strict;

package Amazon;

my $id = 'ここにアフィリエイトIDを記述';

sub plugin_inline {
    my ($escaped_argument) = @_;
    my ($iid,$isbn) = split(/,/, $escaped_argument);
    return qq(
           <a href="http://www.amazon.co.jp/exec/obidos/ASIN/$isbn/$id/ref=nosim" target="_blank">
           <img src="http://images-jp.amazon.com/images/P/$isbn.$iid.MZZZZZZZ.jpg" alt=""></a>);
}

sub plugin_usage {
    return {
        name => 'Amazon',
        version => '1.1',
        author => 'Tamio Tsukamoto<tamio@mb.infoweb.ne.jp>',
        syntax => '&Amazonf(ImageID,ISBN)',
        description => 'Create link to Amazon with Image.',
        example => '&Amazon(01,0895792524).',
    };
}

1;

他サイトから導入したプラグイン

YukiWiki公式サイトのプラグイン機能のページ にある、或はそこからのリンクから、

amazon.pl

calendar.pl

linktree.pl

mimetex.pl

rssmix.pl

rssview.pl

search.pl

searchbox.pl

searchform.pl

similarity.pl

を入手し、追加。