skip menu and go to main content

body start

MoniWiki

Open  다중위키(upload, text, cache) 1 ]

04.01.01-14:38:03

300158

Submitted by 김성훈

Assignee Nobody

View1449

Priority3

지난번 패치는 text_dir 만 virtual로 되었는데 upload, cache 모두 필요하더군요.

간단히 수정하였습니다.
  • monivirtual.diff (12 KB)
    • @@ -0,0 +1,163 @@
      1<?php
      2// This is part of MoniWiki and it is
      3// distributable under GPL see COPYING
      4//
      5// $Id: virtual.php,v 1.124 2003/12/19 13:48:17 wkpark Exp $
      6//
      7
      8
      9/**
      10 * Function - Find virtual sitename if available
      11 *
      12 * @param String virtual host name ( example: wiki.*.kldp.org)
      13 * @param String virtual sitename (Sitename for %2)
      14 * @return String virtual sitename or null
      15 */
      16function virtual_find_sitename($virtual_host, $virtual_sitename) {
      17 // It's basically same with virtual find text dir
      18 // Since virtual_sitename should "Sitename for %2"
      19 return virtual_find_dir($virtual_host, $virtual_sitename);
      20}
      21
      22/**
      23 * Function - General Find virtual directory if available
      24 *
      25 * @param String virtual host name ( example: wiki.*.kldp.org)
      26 * @param String virtual directory (/var/%2/dir)
      27 * @return String virtual dirrectory or null
      28 */
      29function virtual_find_dir($virtual_host, $virtual_dir) {
      30 // No sutable arguments
      31 if (!$virtual_host || !$virtual_dir) {
      32 return;
      33 }
      34
      35 // Check if is my host
      36 $host = $_SERVER['SERVER_NAME'];
      37 if (!virtual_is_my_host($virtual_host, $host)) {
      38 return;
      39 }
      40
      41 // Let's make a translate table
      42 $host_arr = split('\.', $host);
      43 for ($i=0; $i<count($host_arr); $i++) {
      44 $tr_table['%'.$i] = $host_arr[$i];
      45 }
      46
      47 // Replace %1, %2, %3 to real name
      48 $dir = strtr($virtual_dir, $tr_table);
      49 return $dir;
      50}
      51
      52/**
      53 * Function - Create virtual directory if available
      54 *
      55 * @param String text firectory
      56 * @param String Only create if referer is the virtual_ref
      57 * @param 0 or 1 Weather copy seed or not
      58 * @param String Wiki Seed directory
      59 * @return void
      60 */
      61function virtual_create_dir($text_dir, $virtual_ref,
      62 $is_text_dir=0, $auto_seed=0, $seed_dir="wikiseed") {
      63
      64 // Nothing to do
      65 if (is_dir($text_dir)) {
      66 return;
      67 }
      68
      69 if ($virtual_ref) {
      70 // Check referer
      71 $referer = $_SERVER['HTTP_REFERER'];
      72 if (!fnmatch($virtual_ref, $referer)) {
      73 return;
      74 }
      75 }
      76
      77 //#FIXME: Handle Any errors?
      78 mkdir($text_dir);
      79
      80 if ($is_text_dir) {
      81 // RCS directory to keep RCS files
      82 mkdir($text_dir."/RCS");
      83
      84 // touch edit log
      85 touch(virtual_edit_log($text_dir));
      86 }
      87
      88 // Not auto seed so all set
      89 if (!$auto_seed) {
      90 return;
      91 }
      92 // No seed directory
      93 if (!is_dir($seed_dir)) {
      94 return;
      95 }
      96
      97 // Auto seed copy
      98 $handle= opendir($seed_dir);
      99 while ($file = readdir($handle)) {
      100 // We don't copy directories
      101 if (is_dir($seed_dir.'/'.$file)) {
      102 continue;
      103 }
      104
      105 //#FIXME: Handle errors?
      106 copy($seed_dir.'/'.$file, $text_dir.'/'.$file);
      107 }
      108 closedir($handle);
      109}
      110
      111
      112/**
      113 * Function - Return edit log for virtual text dire
      114 *
      115 * @param String virtual text_dir
      116 * @return String edit log
      117 */
      118function virtual_edit_log($text_dir) {
      119 return dirname($text_dir).'/'. basename($text_dir).".editlog";
      120}
      121
      122
      123/**
      124 * Function - Check if it is my virtual host
      125 *
      126 * @param String virtual host
      127 * @param String hostname
      128 * @return true if it is my host. Otherwise false.
      129 */
      130function virtual_is_my_host($virtual_host, $host) {
      131 // Tokenize and put the into array
      132 $virtual_host_arr = split ('\.', $virtual_host);
      133 $host_arr = split("\.", $host);
      134
      135 // Diffrent number of array
      136 //# FIXME: www.kldp.net.. and www.kld.net have diffrent counter.
      137 // split(?, $host)
      138 /*
      139 if (count($virtual_host_arr) != count($host_arr)) {
      140 echo "Count??";
      141 return false;
      142 }
      143 */
      144
      145 for($i=0; $i< count($host_arr); $i++) {
      146 $virtual_one_name = $virtual_host_arr[$i];
      147 // We expecting * or real name
      148 if ($virtual_one_name == "*") { // Assume match
      149 continue;
      150 }
      151
      152 $host_one_name = $host_arr[$i];
      153
      154 // Compare each mane
      155 if ($host_one_name && strcasecmp($virtual_one_name, $host_one_name)) {
      156 return false;
      157 }
      158 }
      159
      160 // Passed all match tests
      161 return true;
      162}
      163?>
    • @@ -0,0 +1,84 @@
      1 Virtual Moni Wiki HOWTO
      2 Sung Kim (hunkim@cs.ucsc.edu)
      3 12/26/2003
      4This is a quick and dirty patch to support virtual Moni wiki.
      51. Motivation
      6 We want to have a separated Wiki space for each project (virtual host)
      7 even though there are many projects in a box.
      8 It is possible to have an http://wiki.kldp.org/<projectname> space for project,
      9 but still macros such as RecentChanges or TitleIndex shows all Wiki pages in the http://wiki.kldp.org/.
      10 We want to see only changes in our wiki space.
      11 Why we care about other wiki pages created by other projects or hosts?
      122. How it works
      13 It is vary similar to the virtual host setting in Apache.
      14 Define a virtual host name with virtual part (*).
      15 And define wiki text directory name with virtual part (%0, %1, ... %n).
      16 See more apache virtual host setting at http://httpd.apache.org/docs-2.0/mod/mod_vhost_alias.html
      173. config.php
      18 Those configuration are required to support virtual Wiki
      19 - virtual_host: define virtual host name. You can put * for the virtual part
      20 Ex: $virtual_host='wiki.*.kldp.org';
      21 - virtual_sitename: define the virtual site name for the virtual host.
      22 We can use %0, %2, ....
      23 Ex: $virtual_sitename="MiniWIki for %1 project";
      24 - virtual_text_dir: define text directory for virtual host wiki pages.
      25 %0, %1, ... will be replaced real host name.
      26 Note that the host name starts %0.
      27 Ex: $virtual_text_dir=$data_dir.'/virtual_text/%1/';
      28 - virtual_upload_dir: define upload directory for virtual host wiki pages.
      29 %0, %1, ... will be replaced real host name.
      30 Note that the host name starts %0.
      31 - virtual_cache_dir: define cache directory for virtual host wiki pages.
      32 %0, %1, ... will be replaced real host name.
      33 Note that the host name starts %0.
      34 - virtual_text_dir_auto_create: indicate weather create virtual text directory automatically.
      35 Ex: $virtual_text_dir_auto_create=1;
      36 $virtual_text_dir_auto_create=0;
      37 - virtual_text_dir_auto_seed: indicate weather copy seed Wikipages automatically.
      38 It works only if virtual_text_dir_aito_create is set to 1.
      39 Ex: $virtual_text_dir_auto_seed=1;
      40 $virtual_text_dir_auto_seed=0;
      41 - Virtual_text_dir_auto_create_ref: To avid creating unnecessarily virtual text directories
      42 By typo, this option limits auto creation only from the defined http referrer.
      43 For example to create a virtual host text directory, the Wiki page must be connected from the http referrer page.
      44 Note that text directory creation is the only one time event.
      45 After that, the virtual part doesn't check the http referrer.
      46
      47 You can use wild card (*, ?) like file match. We use fnmatch to check the referrers.
      48 If it is not defined and virtual_text_dir_auto_create is set,
      49 there is no limit to create virtual text directory.
      50 Ex: $virtual_text_dir_auto_create_ref="*://kachi.org/projects/*";
      51 For example with those setting, if a user connect to http://wiki.moni.kldp.org
      52 the virtual_text_dir would be "$data_dir/virtual_text/moni/",
      53 and sitename would be "MoniWiki for moni project".
      544. Directories and permission
      55 The virtual_text directory should be created by user to use virtual Wiki
      56 unless virtual_text_dir_auto_create is set.
      57
      58 Note that you also need to create RCS directory in the virtual_text_dir to keep RCS files.
      59 Otherwise you will see many *,v files in your wiki pages.
      60
      61 Make sure the httpd user can create files or directories in the virtual_text directory.
      62
      635. Questions
      64 http://moniwiki.sf.net
    • @@ -0,0 +1,47 @@
      1<?php
      2# automatically generated by monisetup
      3$sitename='UnnamedWiki';
      4$data_dir='./data';
      5$upload_dir='pds';
      6$text_dir=$data_dir.'/text';
      7$cache_dir=$data_dir.'/cache';
      8$intermap=$data_dir.'/intermap.txt';
      9$editlog_name=$data_dir.'/editlog';
      10$shared_metadb=$data_dir."/metadb";
      11$shared_intermap=$data_dir."/text/InterMap";
      12$url_prefix='/moniwiki';
      13$imgs_dir=$url_prefix.'/imgs';
      14$logo_img=$imgs_dir.'/moniwiki-logo.gif';
      15$query_prefix="/";
      16$css_url=$url_prefix.'/css/default.css';
      17$kbd_script=$url_prefix."/css/kbd2.js";
      18$logo_string='<img src="'.$logo_img.'" alt="" border="0" align="middle" />';
      19$use_smileys=1;
      20$use_counter=1;
      21$iconset='moni';
      22$enable_latex=0;
      23$lang='auto';
      24$charset='euc-kr';
      25$auto_linebreak=0;
      26$trail=0;
      27$notify=0;
      28$use_referer=0;
      29$use_sistersites=1;
      30$use_twinpages=1;
      31$use_trackback=0;
      32$rcs_user=www;
      33$virtual_host='wiki.*.kachi.org';
      34$virtual_sitename="MiniWIki for %1";
      35$virtual_text_dir=$data_dir.'/virtual/%1.text';
      36$virtual_upload_dir=$data_dir.'/virtual/%1.upload';
      37$virtual_cache_dir=$data_dir.'/virtual/%1.cache';
      38$virtual_text_dir_auto_create=1;
      39$virtual_text_dir_auto_create_ref="*://kachi.org/projects/*";
      40$virtual_text_dir_auto_seed=1;
      41#$menu=array('FrontPage'=>1,'FindPage'=>2,'TitleIndex'=>3,'RecentChanges'=>5,'PageHitsMacro'=>6,'http://kachi.org DFORGE|'=>9);
      42#$menu_sep='|';
      43#$menu_bra='';
      44#$menu_cat='';
      45$admin_passwd='0avdB.3Osdbhc';
      46?>
    • @@ -21,6 +21,7 @@
      21$timing=new Timer(); 22 23include("wikilib.php");
      24include("virtual.php");
      24 25function _preg_escape($val) { 26 return preg_replace('/([\$\^\.\[\]\{\}\|\(\)\+\*\/\\\\!\?]{1})/','\\\\\1',$val);
      @@ -564,6 +565,59 @@
      564 $this->security=new $class ($this); 565 } else 566 $this->security=new Security($this);
      568 // Virtual directory and name
      569 if ($this->virtual_host && $this->virtual_text_dir &&
      570 $virtual_text_dir = virtual_find_dir($this->virtual_host, $this->virtual_text_dir)) {
      571
      572 // Assing new text_dir for virtual host
      573 $this->text_dir = $virtual_text_dir;
      574 // Find virtual UPLOAD dir
      575 $virtual_upload_dir = virtual_find_dir($this->virtual_host, $this->virtual_upload_dir);
      576 if ($virtual_upload_dir) {
      577 $this->upload_dir= $virtual_upload_dir;
      578 }
      579 // Find virtual Cache dir
      580 $virtual_cache_dir = virtual_find_dir($this->virtual_host, $this->virtual_cache_dir);
      581 if ($virtual_cache_dir) {
      582 $this->cache_dir= $virtual_cache_dir;
      583 }
      584 // Fill virtual sitename if it is defined.
      585 if ($this->virtual_sitename) {
      586 $this->sitename = virtual_find_sitename($this->virtual_host, $this->virtual_sitename);
      587 }
      588 // Directory automatic creation and no directory
      589 if ($this->virtual_text_dir_auto_create && !is_dir($this->text_dir)) {
      590 virtual_create_dir($this->text_dir,
      591 $this->virtual_text_dir_auto_create_ref,
      592 1,
      593 $this->virtual_text_dir_auto_seed);
      594 // Create the UPLOAD directory
      595 virtual_create_dir($this->upload_dir,
      596 $this->virtual_text_dir_auto_create_ref);
      597
      598 // Create the UPLOAD directory
      599 virtual_create_dir($this->cache_dir,
      600 $this->virtual_text_dir_auto_create_ref);
      601 }
      602 // Set edit log file for virtual host
      603 // The edit log would be dirname(textdir).'/'.basename(textdir)."editlog"
      604 $this->editlog_name = virtual_edit_log($this->text_dir);
      605 // No text_dir for virtual host?
      606 //#FIXME: Is there more elegance way to show the error message?
      607 if (!is_dir($this->text_dir)) {
      608 echo "The directory for this virtual Wiki is not created.<BR>
      609 Make sure there is no typo in the URL and ask the administrator";
      610 exit(0);
      611 }
      612 }
      567 } 568 569 function Close() {

Comments on this artfact

1 Comments

김성훈

File added 84: monivirtual.diff

04.01.01-14:38:03

김성훈

Logged In: YES
user_id=675

감사합니다. Intermap 부분 추가 되었습니다.

Index: wiki.php
===========================================================
========
RCS file: /cvsroot/moniwiki/moniwiki/wiki.php,v
retrieving revision 1.125
diff -u -r1.125 wiki.php
--- wiki.php 30 Dec 2003 23:18:20 -0000 1.125
+++ wiki.php 2 Jan 2004 00:09:37 -0000
@@ -21,6 +21,7 @@
 $timing=new Timer();
 
 include("wikilib.php");
+include("virtual.php");
 
 function _preg_escape($val) {
   return preg_replace('/([\$\^\.\[\]\{\}\|\(\)\+\*\/\\\\!
\?]{1})/','\\\\\1',$val);
@@ -564,6 +565,62 @@
       $this->security=new $class ($this);
     } else
       $this->security=new Security($this);
+
+ // Virtual directory and name
+ if ($this->virtual_host && $this->virtual_text_dir &&
+ $virtual_text_dir = virtual_find_dir($this-
>virtual_host, $this->virtual_text_dir)) {
+
+ // Assing new text_dir for virtual host
+ $this->text_dir = $virtual_text_dir;
+
+ // Find virtual UPLOAD dir
+ $virtual_upload_dir = virtual_find_dir($this-
>virtual_host, $this->virtual_upload_dir);
+ if ($virtual_upload_dir) {
+ $this->upload_dir= $virtual_upload_dir;
+ }
+
+ // Find virtual Cache dir
+ $virtual_cache_dir = virtual_find_dir($this-
>virtual_host, $this->virtual_cache_dir);
+ if ($virtual_cache_dir) {
+ $this->cache_dir= $virtual_cache_dir;
+ }
+
+ // Fill virtual sitename if it is defined.
+ if ($this->virtual_sitename) {
+ $this->sitename = virtual_find_sitename($this-
>virtual_host, $this->virtual_sitename);
+ }
+
+ // Directory automatic creation and no directory
+ if ($this->virtual_text_dir_auto_create && !is_dir($this-
>text_dir)) {
+ virtual_create_dir($this->text_dir,
+ $this->virtual_text_dir_auto_create_ref,
+ 1,
+ $this->virtual_text_dir_auto_seed);
+ // Create the UPLOAD directory
+ virtual_create_dir($this->upload_dir,
+ $this->virtual_text_dir_auto_create_ref);
+
+ // Create the UPLOAD directory
+ virtual_create_dir($this->cache_dir,
+ $this->virtual_text_dir_auto_create_ref);
+ }
+
+
+ // Set edit log file for virtual host
+ // The edit log would be dirname(textdir).'/'.basename
(textdir)."editlog"
+ $this->editlog_name = virtual_edit_log($this->text_dir);
+
+ // The edit log would be dirname(textdir).'/'.basename
(textdir)."editlog"
+ $this->intermap = virtual_inter_map($this->text_dir);
+
+ // No text_dir for virtual host?
+ //#FIXME: Is there more elegance way to show the error
message?
+ if (!is_dir($this->text_dir)) {
+ echo "The directory for this virtual Wiki is not
created.<BR>
+ Make sure there is no typo in the URL
and ask the administrator";
+ exit(0);
+ }
+ }
   }
 
   function Close() {


Index: virtual.php
===========================================================
========
--- virtual.php (revision 27)
+++ virtual.php (working copy)
@@ -83,6 +83,9 @@
 
         // touch edit log
         touch(virtual_edit_log($text_dir));
+
+ // touch intermap
+ touch(virtual_inter_map($text_dir));
     }
 
     // Not auto seed so all set
@@ -110,7 +113,7 @@
 
 
 /**
- * Function - Return edit log for virtual text dire
+ * Function - Return edit log for virtual text directory
  *
  * @param String virtual text_dir
  * @return String edit log
@@ -119,7 +122,17 @@
     return dirname($text_dir).'/'. basename
($text_dir).".editlog";
 }
 
+/**
+ * Function - Return inter map log for virtual text
directory
+ *
+ * @param String virtual inter_map
+ * @return String inter map
+ */
+function virtual_inter_map($text_dir) {
+ return dirname($text_dir).'/'. basename
($text_dir).".intermap";
+}
 
+
 /**
  * Function - Check if it is my virtual host
  *

04.01.02-09:11:53

wkpark

"Tracker Type" was changed from "Bug Tracking" to "Patch Tracking"

10.08.11-11:09:54