$value) unset($$key); // register_globals = off // SETTINGS - default settings, can be overrided in config.php $WIKI_TITLE = "My new wiki"; // name of the site $PASSWORD = ""; // if left blank, no password is required to edit. Consider also $PASSWORD_MD5 below // More secure way to use password protection, just insert MD5 hash into $PASSWORD_MD5 // if not empty, $PASSWORD is ignored and $PASSWORD_MD5 is used instead $PASSWORD_MD5 = ""; $TEMPLATE = "templates/dandelion.html"; // presentation template $USE_AUTOLANG = true; // should we try to detect language from browser? $LANG = "en"; // language code you want to use, used only when $USE_AUTOLANG = false $PROTECTED_READ = false; // if true, you need to fill password for reading pages too $NO_HTML = false; // XSS protection, meaningful only when password protection is enabled $USE_META = true; // use and create meta data. Small overhead, but edit summary and IP info $USE_HISTORY = true; // If you don't want to keep history of pages, change to false $START_PAGE = "Main page"; // Which page should be default (start page)? $SYNTAX_PAGE = "http://lionwiki.0o.cz/?page=Syntax+reference"; $DATE_FORMAT = "Y/m/d H:i"; $LOCAL_HOUR = "0"; $EDIT_SUMMARY_LEN = "128"; // don't play with this!!! @error_reporting(E_ERROR | E_WARNING | E_PARSE); set_magic_quotes_runtime(0); // turn off magic quotes $self = $_SERVER['PHP_SELF']; if(get_magic_quotes_gpc()) // magic_quotes_gpc can't be turned off for($i = 0, $_SG = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST), $c = count($_SG); $i < $c; ++$i) $_SG[$i] = array_map("stripslashes", $_SG[$i]); @include("config.php"); // config file is not required, see settings above if(empty($PASSWORD_MD5) && !empty($PASSWORD)) $PASSWORD_MD5 = md5($PASSWORD); $VAR_DIR = "var/"; $PAGES_DIR = $VAR_DIR."pages/"; $HISTORY_DIR = $VAR_DIR."history/"; $PLUGINS_DIR = "plugins/"; $PLUGINS_DATA_DIR = $VAR_DIR."plugins/"; $LANG_DIR = "lang/"; $WIKI_VERSION = "LionWiki 3.0.9"; umask(0); // sets default mask // some strings may not be translated, in that case, we'll use english translation, which should be always complete $T_HOME = "Main page"; $T_SYNTAX = "Syntax"; $T_DONE = "Save changes"; $T_DISCARD_CHANGES = "Discard changes"; $T_PREVIEW = "Preview"; $T_SEARCH = "Search"; $T_SEARCH_RESULTS = "Search results"; $T_LIST_OF_ALL_PAGES = "List of all pages"; $T_RECENT_CHANGES = "Recent changes"; $T_LAST_CHANGED = "Last changed"; $T_HISTORY = "History"; $T_RESTORE = "Restore"; $T_REV_DIFF = "Difference between revisions from {REVISION1} and {REVISION2}."; $T_REVISION = "'''This revision is from {TIME}. You can {RESTORE} it.'''\n\n"; $T_PASSWORD = "Password"; $T_EDIT = "Edit"; $T_EDIT_SUMMARY = "Edit summary"; $T_EDIT_CONFLICT = "Edit conflict: somebody saved this page after you started editing. It is strongly encouraged to see last {DIFF} before saving it. After reviewing and possibly merging changes, you can save page by clicking on save button."; $T_SHOW_SOURCE = "Show source"; $T_SHOW_PAGE = "Show page"; $T_ERASE_COOKIE = "Erase cookies"; $T_MOVE_TEXT = "New name"; $T_DIFF = "diff"; $T_CREATE_PAGE = "Create page"; $T_PROTECTED_READ = "You need to enter password to view content of site: "; $TE_WRONG_PASSWORD = "Password is incorrect."; // Default character set for auto content header @ini_set("default_charset", "UTF-8"); header("Content-type: text/html; charset=UTF-8"); // consider only first language, don't consider language variant (like en-us or pt-br) if($USE_AUTOLANG) list($LANG) = explode(",", $_SERVER['HTTP_ACCEPT_LANGUAGE']); $LANG = !empty($_COOKIE["LW_LANG"]) ? $_COOKIE["LW_LANG"] : $LANG; if(!empty($_GET["lang"])) { $LANG = $_GET["lang"]; setcookie('LW_LANG', $LANG, time() + 365 * 86400); } $LANG = sanitizeFilename($LANG); if(@file_exists($LANG_DIR . $LANG . ".php")) @include $LANG_DIR . $LANG . ".php"; else if(@file_exists($LANG_DIR . substr($LANG, 0, 2) . ".php")) @include $LANG_DIR . substr($LANG, 0, 2) . ".php"; else $LANG = "en"; if(!file_exists($VAR_DIR) && !mkdir(rtrim($VAR_DIR, "/"))) die("Can't create directory $VAR_DIR. Please create $VAR_DIR with 0777 rights."); foreach(array($PAGES_DIR, $HISTORY_DIR, $PLUGINS_DATA_DIR) as $DIR) if(!file_exists($DIR)) { mkdir(rtrim($DIR, "/"), 0777); $f = fopen($DIR . ".htaccess", "w"); fwrite($f, "deny from all"); fclose($f); } if($_GET["erasecookie"]) // remove cookie without reloading foreach($_COOKIE as $key => $value) if(!strcmp(substr($key, 0, 3), "LW_")) { setcookie($key); unset($_COOKIE[$key]); } $plugins = array(); $plugin_saveok = true; // is OK to save page changes (from plugins) if($dir = @opendir($PLUGINS_DIR)) // common plugins while($file = readdir($dir)) if(preg_match("/^.*wkp_(.+)\.php$/", $file, $matches) > 0) { require $PLUGINS_DIR . $file; $plugins[$matches[1]] = new $matches[1](); } plugin_call_method("pluginsLoaded"); // for admin plugin plugin_call_method("pluginsLoaded2"); // second pass ("for ordinary plugins") $req_conv = array("action", "query", "sc", "content", "page", "moveto", "restore", "f1", "f2", "error", "time", "esum", "preview", "last_changed", "gtime", "showsource", "par"); foreach($req_conv as $req) // export variables to main namespace $$req = $_REQUEST[$req]; $page = sanitizeFilename($page); $moveto = sanitizeFilename($moveto); $gtime = sanitizeFilename($gtime); $f1 = sanitizeFilename($f1); $f2 = sanitizeFilename($f2); if(!empty($preview)) { $action = "edit"; $CON = $content; } plugin_call_method("actionBegin"); // setting $PAGE_TITLE if($page || empty($action)) { $page = $page_nolang = $TITLE = $page ? $page : $START_PAGE; if($action == "" && file_exists($PAGES_DIR . $page . ".$LANG.txt")) // language variant $page = $TITLE = $page_nolang . "." . $LANG; else if(!file_exists($PAGES_DIR . $page . ".txt") && $action == "") $action = "edit"; // create page if it doesn't exist if(!empty($preview)) $TITLE = $T_PREVIEW . ": " . $page; } else if($action == "search") $TITLE = empty($query) ? $T_LIST_OF_ALL_PAGES : "$T_SEARCH_RESULTS $query"; else if($action == "recent") $TITLE = $T_RECENT_CHANGES; // does user need password to read content of site. If yes, ask for it. if(!authentified() && $PROTECTED_READ) { $CON = "
"; $action = "view-html"; $error = " "; // so we know that something went wrong } else if($action == "save" && authentified()) { // do we have page to save? $LAST_CHANGED_TIMESTAMP = @filemtime($PAGES_DIR . $page . ".txt"); if(trim($content) == "" && !$par) @unlink($PAGES_DIR . $page . ".txt"); elseif($last_changed < $LAST_CHANGED_TIMESTAMP) { $action = "edit"; $error = str_replace("{DIFF}", "$T_DIFF", $T_EDIT_CONFLICT); $CON = $content; } else if(!plugin_call_method("writingPage") || $plugin_saveok) { // are plugins happy with page? (no - spam, etc) if($par && is_numeric($par)) { $c = @file_get_contents($PAGES_DIR . $page . ".txt"); $par_content = $content; $content = str_replace(getParagraph($c, $par), $content, $c); } if(!$file = @fopen($PAGES_DIR . $page . ".txt", "w")) die("Could not write page $PAGES_DIR$page.txt!"); fwrite($file, $content, strlen($content)); fclose($file); if($USE_HISTORY) { // let's archive previous revision $complete_dir = $HISTORY_DIR . $page; if(!is_dir($complete_dir)) mkdir($complete_dir); $rightnow = date("Ymd-Hi-s", time() + $LOCAL_HOUR * 3600); $filename = $complete_dir . "/" . $rightnow . ".bak"; if(!$bak = @fopen($filename, "w")) die("Could not write backup $filename of page!"); fwrite($bak, $content, strlen($content)); fclose($bak); if($USE_META) $es = fopen($complete_dir . "/meta.dat", "ab"); if($es) { $filesize = filesize($PAGES_DIR . $page . ".txt"); // Strings are in UTF-8, it's dangerous to just cut off piece of string, therefore +2 fwrite($es, "!" . $rightnow . str_pad($_SERVER['REMOTE_ADDR'], 16, " ", STR_PAD_LEFT) . str_pad($filesize, 11, " ", STR_PAD_LEFT) . " " . str_pad(substr($esum, 0, $EDIT_SUMMARY_LEN), $EDIT_SUMMARY_LEN + 2)) . "\n"; fclose($es); } } plugin_call_method("pageWritten", $file); if($moveto != $page && !empty($moveto)) { if(file_exists($PAGES_DIR . $moveto . ".txt")) die("Error: target filename already exists. Page was not moved."); if(!rename($PAGES_DIR . $page . ".txt", $PAGES_DIR . $moveto . ".txt")) die("Unknown error! Page was not moved."); else if(!rename($HISTORY_DIR . $page, $HISTORY_DIR . $moveto)) { rename($PAGES_DIR . $moveto . ".txt", $PAGES_DIR . $page . ".txt"); // revert previous change die("Unknown error2! Page was not moved."); } else { @touch($PAGES_DIR . $moveto . ".txt"); // moved page should be at the top of recent ch. $page = $moveto; } } if(!($_REQUEST["ajax"] && $par)) { header("Location:?page=" . urlencode($page) . ($error ? ("&error=" . urlencode($error)) : "")); die(); } else $CON = $par_content; } else { // there's some problem with page, give user a chance to fix it (do not throw away submitted content) $CON = $content; $action = "edit"; } } else if($action == "save") { // wrong password, give user another chance (do not throw away submitted content) $error = $TE_WRONG_PASSWORD; $CON = $content; $action = "edit"; } if(@file_exists($PAGES_DIR . $page . ".txt")) { $LAST_CHANGED_TIMESTAMP = @filemtime($PAGES_DIR . $page . ".txt"); $LAST_CHANGED = date($DATE_FORMAT, $LAST_CHANGED_TIMESTAMP + $LOCAL_HOUR * 3600); if(!$CON) { $CON = @file_get_contents($PAGES_DIR . $page . ".txt"); if($par && is_numeric($par)) $CON = getParagraph($CON, $par); if(substr($CON, 0, 10) == "{redirect:" && $action == "") { header("Location:?page=".urlencode(substr($CON, 10, strpos($CON, "}") - 10))); die(); } } } // Restoring old version of page if($gtime && ($restore || $action == "rev")) { $CON = ""; if($action == "rev") { $rev_restore = "[$T_RESTORE|./$self?page=".urlencode($page)."&action=edit>ime=$gtime&restore=1]"; $CON = str_replace(array("{TIME}", "{RESTORE}"), array(revTime($gtime), $rev_restore), $T_REVISION); } $CON .= lwread($HISTORY_DIR.$page."/".$gtime); } plugin_call_method("pageLoaded"); if($action == "edit") { if(!authentified() && !$showsource) { // if not logged on, require password $FORM_PASSWORD = $T_PASSWORD; $FORM_PASSWORD_INPUT = ''; } if(!$showsource && !$par) { $RENAME_TEXT = $T_MOVE_TEXT; $RENAME_INPUT = ''; } $CON_FORM_BEGIN = ""; $CON_TEXTAREA = ''; if(!$showsource) { $CON_SUBMIT = ""; $EDIT_SUMMARY_TEXT = $T_EDIT_SUMMARY; $EDIT_SUMMARY = ''; } $CON_PREVIEW = ""; if($preview) $action = ""; } elseif($action == "rev" && !empty($gtime)) // show old revision of page $action = ""; elseif($action == "history") { // show whole history of page $complete_dir = $HISTORY_DIR . $page . "/"; if($opening_dir = @opendir($complete_dir)) { while($filename = @readdir($opening_dir)) if(preg_match('/(.+)\.bak.*$/', $filename)) $files[] = $filename; rsort($files); $CON = '"; } else $CON = $NO_HISTORY; } elseif($action == "diff") { if(empty($f1) && $opening_dir = @opendir($HISTORY_DIR . $page . "/")) { // diff is made on two last revisions while($filename = @readdir($opening_dir)) if(preg_match('/\.bak.*$/', $filename)) $files[] = basename(basename($filename, ".gz"), ".bz2"); rsort($files); header("Location: ?action=diff&page=" . urlencode($page) . "&f1=$files[0]&f2=$files[1]"); die(); } $r1 = "".revTime($f1).""; $r2 = "".revTime($f2).""; $CON = str_replace(array("{REVISION1}", "{REVISION2}"), array($r1, $r2), $T_REV_DIFF); $CON .= diff($f1, $f2); } elseif($action == "search") { $dir = opendir($PAGES_DIR); // offer to create page if it doesn't exist if($query && !file_exists($PAGES_DIR . $query . ".txt")) $CON = "$T_CREATE_PAGE ".htmlspecialchars($query).".
{{CODE}}
", $CON);
plugin_call_method("formatBegin");
// substituting special characters
$CON = str_replace("<-->", "↔", $CON); // <-->
$CON = str_replace("-->", "→", $CON); // -->
$CON = str_replace("<--", "←", $CON); // <--
$CON = preg_replace("/\([cC]\)/Umsi", "©", $CON); // (c)
$CON = preg_replace("/\([rR]\)/Umsi", "®", $CON); // (r)
$CON = preg_replace("/^([^!\*#\n][^\n]+)$/Um", "$1
", $CON); // sup and sub $CON = preg_replace("/\{sup\}(.*)\{\/sup\}/U", "$1", $CON); $CON = preg_replace("/\{sub\}(.*)\{\/sub\}/U", "$1", $CON); // small $CON = preg_replace("/\{small\}(.*)\{\/small\}/U", "$1", $CON); $rg_url = "[0-9a-zA-Z\.\#/~\-_%=\?\&,\+\:@;!\(\)\*\$']*"; $rg_img_local = "($rg_url\.(jpeg|jpg|gif|png))"; $rg_img_http = "h(ttps?://$rg_url\.(jpeg|jpg|gif|png))"; $rg_link_local = "($rg_url)"; $rg_link_http = "h(ttps?://$rg_url)"; // IMAGES // [http.png] / [http.png|right], [local.png] / [local.png|left] $CON = preg_replace("#\[$rg_img_http(\|(right|left))?\]#", '', $CON); $CON = preg_replace("#\[$rg_img_local(\|(right|left))?\]#", '', $CON); // [http|http], [http|local], [local|http], [local|local] $CON = preg_replace("#\[$rg_img_http\|$rg_link_http(\|(right|left))?\]#U", '', $CON); $CON = preg_replace("#\[$rg_img_http\|$rg_link_local(\|(right|left))?\]#U", '', $CON); $CON = preg_replace("#\[$rg_img_local\|$rg_link_http(\|(right|left))?\]#U", '', $CON); $CON = preg_replace("#\[$rg_img_local\|$rg_link_local(\|(right|left))?\]#U", '', $CON); $CON = preg_replace('#([0-9a-zA-Z\./~\-_]+@[0-9a-z/~\-_]+\.[0-9a-z\./~\-_]+)#i', '$0', $CON); // mail recognition // LINKS $CON = preg_replace("#\[([^\]]+)\|$rg_link_http\]#U", '$1', $CON); // local links has to start either with / or ./ $CON = preg_replace("#\[([^\]]+)\|\.\/$rg_link_local\]#U", '$1', $CON); $CON = preg_replace("#$rg_link_http#i", 'xx$1', $CON); $CON = preg_replace('#xxttp#', 'http', $CON); $CON = preg_replace('#\[\?(.*)\]#Ui', '$1', $CON); // Wikipedia preg_match_all("/\[([^|\]]+\|)?([^\]#]+)(#[^\]]+)?\]/", $CON, $matches, PREG_SET_ORDER); // matching Wiki links foreach($matches as $match) { $match[1] = empty($match[1]) ? $match[2] : rtrim($match[1], "|"); // is page label same as its name? if($match[3]) // link to the heading $match[3] = "#" . preg_replace("/[^\da-z]/i", "_", urlencode(substr($match[3], 1, strlen($match[3]) - 1))); if(file_exists("$PAGES_DIR$match[2].txt")) $CON = str_replace($match[0], ''.$match[1].'', $CON); else $CON = str_replace($match[0], ''.$match[1].'', $CON); } // LIST, ordered, unordered $CON = preg_replace('/^\*\*\*(.*)(\n)/Um', ""; for($i = 0; $i <= max(sizeof($a2), sizeof($a1)); $i++) { if($r1 = array_key_exists($i, $d1)) $ret .= ""; } function lwread($name) { if(file_exists($name)) return @file_get_contents($name); elseif(file_exists($name . ".gz")) return implode(@gzfile($name . ".gz")); elseif(file_exists($name . ".bz2")) return bzdecompress(@file_get_contents($name . ".bz2")); } function authentified() { global $PASSWORD_MD5, $PROTECTED_READ, $sc; if(empty($PASSWORD_MD5) || !strcasecmp($_COOKIE['LW_AUT'], $PASSWORD_MD5) || !strcasecmp(md5($sc), $PASSWORD_MD5)) { setcookie('LW_AUT', $PASSWORD_MD5, time() + ($PROTECTED_READ ? 4 * 3600 : 365 * 86400)); $_COOKIE['LW_AUT'] = $PASSWORD_MD5; return true; } else return false; } // returns "line" from meta.dat files. $lnum is number of line from the end of file starting with 1 function meta_getline($file, $lnum) { global $EDIT_SUMMARY_LEN; if(fseek($file, -($lnum * 175), SEEK_END) != 0) return false; $line = fread($file, 175); if($line[0] != "!") // control character return false; $date = substr($line, 1, 16); $ip = trim(substr($line, 19, 15)); $size = trim(substr($line, 35, 10)); $esum = trim(substr($line, 45, $EDIT_SUMMARY_LEN)); return array($date, $ip, $size, $esum); } // Call a method for all plugins, second to last arguments are forwarded to plugins as arguments // returns true if treated by a plugin function plugin_call_method($method) { $ret = false; $args = array_slice(func_get_args(), 1); foreach($GLOBALS["plugins"] as $plugin) if(method_exists($plugin, $method)) $ret |= call_user_func_array(array($plugin, $method), $args); return $ret; } function fallback_template() { return '".htmlspecialchars(trim($d1[$i]))."\n"; if($r2 = array_key_exists($i, $d2)) $ret .= "".htmlspecialchars(trim($d2[$i]))."\n"; if(!$r1 && !$r2) $ret .= htmlspecialchars(trim($a2[$i])) . "\n"; } return $ret . "
{HOME} {RECENT_CHANGES} | {EDIT} {SYNTAX} {HISTORY} | |
{PAGE_TITLE} | ||
---|---|---|
{ ERROR }
{CONTENT}
{CONTENT_FORM} {RENAME_TEXT} {RENAME_INPUT} {CONTENT_TEXTAREA} {FORM_PASSWORD} {FORM_PASSWORD_INPUT} {plugin:CAPTCHA_QUESTION} {plugin:CAPTCHA_INPUT} {EDIT_SUMMARY_TEXT} {EDIT_SUMMARY_INPUT} {CONTENT_SUBMIT} {CONTENT_PREVIEW} {/CONTENT_FORM} |
||
{SEARCH_FORM}{SEARCH_INPUT}{SEARCH_SUBMIT}{/SEARCH_FORM} |
Powered by LionWiki. {LAST_CHANGED_TEXT}: {LAST_CHANGED} {COOKIE} | {EDIT} {SYNTAX} {HISTORY} |