From 993e0a863c5bcd5847520f817c0d88dff6fb1958 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sun, 27 Jul 2008 20:18:56 +0200 Subject: [PATCH] Use core engine for the wiki. Signed-off-by: Florent Bruneau --- core | 2 +- htdocs/xnet.php | 5 +- htdocs/xorg.php | 13 +- include/wiki.inc.php | 314 ------------------------------------------------ include/wiki/engine.php | 145 ---------------------- 5 files changed, 10 insertions(+), 469 deletions(-) delete mode 100644 include/wiki.inc.php delete mode 100644 include/wiki/engine.php diff --git a/core b/core index 8bdb07e..2b27ff9 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 8bdb07ee8944d8ef3d37b733477834a64a897aa6 +Subproject commit 2b27ff99ce8ff74aa0e8a2a3e51c02d1c0655e13 diff --git a/htdocs/xnet.php b/htdocs/xnet.php index e6daefe..b1363f0 100644 --- a/htdocs/xnet.php +++ b/htdocs/xnet.php @@ -23,16 +23,15 @@ $GLOBALS['IS_XNET_SITE'] = true; require_once dirname(__FILE__).'/../include/xnet.inc.php'; +$platal = new Xnet('xnet', 'xnetgrp', 'xnetlists', 'xnetevents', 'geoloc', 'payment', 'bandeau'); if (!($path = Env::v('n')) || substr($path, 0, 4) != 'Xnet') { - $platal = new Xnet('xnet', 'xnetgrp', 'xnetlists', 'xnetevents', 'geoloc', 'payment', 'bandeau'); $platal->run(); - exit; } /*** WIKI CODE ***/ -include 'wiki/engine.php'; +include dirname(__FILE__) . '/../core/include/wiki.engine.inc.php'; // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?> diff --git a/htdocs/xorg.php b/htdocs/xorg.php index 3dc92b2..affbb37 100644 --- a/htdocs/xorg.php +++ b/htdocs/xorg.php @@ -21,19 +21,20 @@ require_once dirname(__FILE__).'/../include/xorg.inc.php'; +$platal = new Platal('auth', 'carnet', 'email', 'events', 'forums', + 'geoloc', 'lists', 'marketing', 'payment', 'platal', + 'profile', 'register', 'search', 'stats', 'admin', + 'newsletter', 'axletter', 'bandeau', 'survey', + 'gadgets', 'googleapps'); + if (!($path = Env::v('n')) || ($path{0} < 'A' || $path{0} > 'Z')) { - $platal = new Platal('auth', 'carnet', 'email', 'events', 'forums', - 'geoloc', 'lists', 'marketing', 'payment', 'platal', - 'profile', 'register', 'search', 'stats', 'admin', - 'newsletter', 'axletter', 'bandeau', 'survey', - 'gadgets', 'googleapps'); $platal->run(); exit; } /*** WIKI CODE ***/ -include 'wiki/engine.php'; +include dirname(__FILE__) . '/../core/include/wiki.engine.inc.php'; // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?> diff --git a/include/wiki.inc.php b/include/wiki.inc.php deleted file mode 100644 index 0abf171..0000000 --- a/include/wiki.inc.php +++ /dev/null @@ -1,314 +0,0 @@ -spoolroot.'/spool/wiki.d'; -} - -function wiki_clear_all_cache() -{ - system('rm -f '.wiki_work_dir().'/cache_*'); -} - -function wiki_perms_options() { - return array('public' => 'Public', 'logged' => 'Connecté', - 'mdp' => 'Authentifié', 'admin' => 'Admin'); -} - -function wiki_get_perms($n) -{ - $file = wiki_work_dir().'/'.wiki_filename(str_replace('/', '.', $n)); - $lines = explode("\n", @file_get_contents($file)); - foreach ($lines as $line) { - @list($k, $v) = explode('=', $line, 2); - if ($k == 'platal_perms') { - return explode(':', $v); - } - } - return array('logged', 'admin'); -} - -function wiki_putfile($f, $s) -{ - $fp = fopen($f, 'w'); - fputs($fp, $s); - fclose($fp); -} - -function wiki_set_perms($n, $pr, $pw) -{ - $file = wiki_work_dir().'/'.wiki_filename(str_replace('/', '.', $n)); - if (!file_exists($file)) { - return false; - } - - $p = $pr . ':' . $pw; - - $lines = explode("\n", file_get_contents($file)); - foreach ($lines as $i => $line) { - list($k, $v) = explode('=', $line, 2); - if ($k == 'platal_perms') { - $lines[$i] = 'platal_perms='.$p; - wiki_putfile($file, join("\n", $lines)); - return true; - } - } - - array_splice($lines, 1, 0, array('platal_perms='.$p)); - wiki_putfile($file, join("\n", $lines)); - return true; -} - -function wiki_may_have_perms($perm) { - switch ($perm) { - case 'public': return true; - case 'logged': return S::logged(); - case 'mdp': return S::logged(); - default: return S::has_perms(); - } -} - -function wiki_apply_feed_perms($perm) -{ - if ($perm == 'public') { - return; - } - - require_once 'rss.inc.php'; - $uid = init_rss(null, Env::v('user'), Env::v('hash')); - if (is_null($uid)) { - exit; - } - if ($perm == 'logged' || S::has_perms()) { - return; - } - exit; -} - -function wiki_apply_perms($perm) -{ - global $platal, $globals; - $page =& Platal::page(); - - switch ($perm) { - case 'public': - return; - - case 'logged': - if (!call_user_func(array($globals->session, 'doAuthCookie'))) { - $platal = empty($GLOBALS['IS_XNET_SITE']) ? new Platal() : new Xnet(); - $platal->force_login($page); - } - return; - - default: - if (!call_user_func(array($globals->session, 'doAuth'))) { - $platal = empty($GLOBALS['IS_XNET_SITE']) ? new Platal() : new Xnet(); - $platal->force_login($page); - } - if ($perm == 'admin') { - check_perms(); - } - return; - } -} - -function wiki_require_page($pagename) -{ - global $globals; - $pagename_slashes = str_replace('.','/',$pagename); - $pagename_dots = str_replace('/','.',$pagename); - if (is_file(wiki_work_dir().'/cache_'.$pagename_dots.'.tpl')) { - return; - } - system('wget --no-check-certificate '. escapeshellarg($globals->baseurl.'/'.$pagename_slashes) . ' -O /dev/null'); -} - -function wiki_delete_page($pagename) -{ - $pagename_dots = str_replace('/','.',$pagename); - if (!strpos($pagename_dots, '.')) { - return false; - } - $file = wiki_work_dir().'/'.wiki_filename($pagename_dots); - $cachefile = wiki_work_dir().'/cache_'.$pagename_dots.'.tpl'; - if (is_file($cachefile)) { - unlink($cachefile); - } - if (!is_file($file)) { - return false; - } - unlink($file); - return true; -} - -function wiki_links_in_line($line, $groupname) -{ - $links = array(); - if (preg_match_all('@\[\[([^~][^\]\|\?#]*)((\?|#)[^\]\|]+)?(\\|[^\]]+)?\]\]@', $line, $matches, PREG_OFFSET_CAPTURE)) { - foreach ($matches[1] as $j => $link) if (!preg_match('@http://@', $link[0])) { - $mylink = str_replace('/','.',trim($link[0])); - $sup = trim(substr($matches[2][$j][0],1)); - $alt = trim(substr($matches[4][$j][0],1)); - $newlink = str_replace(' ','',ucwords($mylink)); - if (strpos($newlink,'.') === false) { - $newlink = $groupname.'.'.$newlink; - } - if (!$alt && $mylink != $newlink) { - $alt = trim($link[0]); - } - $links[] = array( - 'pos' => $matches[0][$j][1], - 'size' => strlen($matches[0][$j][0]), - 'href' => $newlink, - 'sup' => $sup, - 'alt' => $alt, - 'group' => substr($mylink, 0, strpos($mylink, '.'))); - } - } - return $links; -} - -function wiki_rename_page($pagename, $newname, $changeLinks = true) -{ - $pagename_dots = str_replace('/','.',$pagename); - $newname_dots = str_replace('/','.',$newname); - if (!strpos($pagename_dots, '.') || !strpos($newname_dots, '.')) { - return false; - } - $groupname = substr($pagename_dots, 0, strpos($pagename_dots,'.')); - $newgroupname = substr($newname_dots, 0, strpos($pagename_dots,'.')); - - $file = wiki_work_dir().'/'.wiki_filename($pagename_dots); - $newfile = wiki_work_dir().'/'.wiki_filename($newname_dots); - if (!is_file($file)) { - // old page doesn't exist - return false; - } - if (!rename($file, $newfile)) { - // impossible to renama page - return false; - } - - if (!$changeLinks) { - return true; - } - - $changedLinks = 0; - // change name inside this folder and ingroup links if changing group - $lines = explode("\n", file_get_contents($newfile)); - $changed = false; - foreach ($lines as $i => $line) { - list($k, $v) = explode('=', $line, 2); - if ($k == 'name' && $v == $pagename_dots) { - $lines[$i] = 'name='.$newname_dots; - $changed = true; - } else if ($groupname != $newgroupname) { - $links = wiki_links_in_line($line, $groupname); - $newline = ''; $last = 0; - foreach ($links as $link) if ($link['group'] == $groupname) { - $newline .= substr($line, $last, $link['pos']); - $newline .= '[['.$link['href'].$link['sup'].($link['alt']?(' |'.$link['alt']):'').']]'; - $last = $link['pos']+$link['size']; - $changedLinks++; - } - if ($last != 0) { - $newline .= substr($line, $last); - $lines[$i] = $newline; - $changed = true; - } - } - } - wiki_putfile($newfile, join("\n", $lines)); - - // change wiki links in all wiki pages - $endname = substr($pagename_dots, strpos($pagename_dots,'.')+1); - $pages = array(); - exec("grep ".$endname." ".wiki_work_dir()."/* -sc", $pages); - foreach($pages as $line) { - if (preg_match('%/([^/:]+):([0-9]+)$%', $line, $vals) && $vals[2] > 0) { - $inpage = $vals[1]; - $lines = explode("\n", file_get_contents(wiki_work_dir().'/'.$inpage)); - $changed = false; - // find all wiki links in page and change if linked to this page - foreach ($lines as $i => $line) { - $links = wiki_links_in_line($line, substr($inpage, 0, strpos($inpage, '.'))); - $newline = ''; $last = 0; - foreach ($links as $link) { - if ($link['href'] == $pagename_dots) { - $newline .= substr($line, $last, $link['pos']); - $newline .= '[['.$newname_dots.$link['sup'].($link['alt']?(' |'.$link['alt']):'').']]'; - $last = $link['pos']+$link['size']; - $changedLinks++; - } - } - if ($last != 0) { - $newline .= substr($line, $last); - $lines[$i] = $newline; - $changed = true; - } - } - if ($changed) - { - wiki_putfile(wiki_work_dir().'/'.$inpage, join("\n", $lines)); - } - } - } - if ($changedLinks > 0) { - return $changedLinks; - } - return true; -} - -function wiki_rename_folder($pagename, $newname, $changeLinks = true) -{ -} - -// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: -?> diff --git a/include/wiki/engine.php b/include/wiki/engine.php deleted file mode 100644 index fb3a61e..0000000 --- a/include/wiki/engine.php +++ /dev/null @@ -1,145 +0,0 @@ -trigSuccess('Permissions mises à jour'); - } -} - -if ($p = Post::v('setwperms')) { - wiki_apply_perms('admin'); - if (wiki_set_perms($n, $perms[0], $p)) { - $perms = wiki_get_perms($n); - $page->trigSuccess('Permissions mises à jour'); - } -} - -// Generate cache even if we don't have access rights -$wiki_cache = wiki_work_dir().'/cache_'.wiki_filename($n).'.tpl'; -$cache_exists = file_exists($wiki_cache); -if (Env::v('action') || !$cache_exists) { - if ($cache_exists && !$feed) { - unlink($wiki_cache); - $files = glob($globals->spoolroot . '/spool/templates_c/*cache_' . wiki_filename($n) . '.tpl*'); - foreach ($files as $file) { - unlink($file); - } - } - - // we leave pmwiki do whatever it wants and store everything - ob_start(); - require_once($globals->spoolroot.'/wiki/pmwiki.php'); - - $wikiAll = ob_get_clean(); - pl_clear_errors(); - - // the pmwiki skin we are using (almost empty) has these keywords: - $i = strpos($wikiAll, ""); - $j = strpos($wikiAll, "", $i); -} - -$wiki_exists = file_exists(wiki_work_dir() . '/' . wiki_filename($n)); - -if ($feed) { - $wikiAll = str_replace('dc:contributor', 'author', $wikiAll); - $wikiAll = preg_replace('!.*?\..*?\.(\d{4})\|(.*?)!u', '$2 (X$1)', $wikiAll); - $wikiAll = str_replace('./', '' . $globals->baseurl . '/' . $platal->ns, $wikiAll); - echo $wikiAll; - pl_clear_errors(); - exit; -} elseif (Env::v('action')) { - $page->assign('pl_extra_header', substr($wikiAll, 0, $i)); - $wikiAll = substr($wikiAll, $j); -} else { - if (!$cache_exists && $wiki_exists) { - $wikiAll = substr($wikiAll, $j); - wiki_putfile($wiki_cache, $wikiAll); - } elseif ($cache_exists) { - $wikiAll = file_get_contents($wiki_cache); - } elseif (S::has_perms()) { - $wikiAll = "

La page de wiki $n n'existe pas. " - . "Il te suffit de l'éditer

"; - } else { - $page->changeTpl('core/404.tpl'); - } -} - -// Check user perms -wiki_apply_perms($perms[0]); - -$page->assign('perms', $perms); -$page->assign('perms_opts', wiki_perms_options()); - -$page->assign('canedit', wiki_may_have_perms($perms[1])); -$page->assign('has_perms', wiki_may_have_perms('admin')); - -$page->assign('wikipage', str_replace('.', '/', $n)); -if (!$feed && $perms[1] == 'admin' && !Env::v('action') && $wiki_exists) { - $page->assign('pmwiki_cache', $wiki_cache); -} else { - $page->assign('pmwiki', $wikiAll); - $page->assign('text', true); -} -$page->addCssLink('wiki.css'); -$page->addJsLink('wiki.js'); -if (!Env::v('action')) { - $url = '/' . str_replace('.', '/', $n) . '?action=rss'; - if (S::logged()) { - $url .= '&user=' . S::v('forlife') . '&hash=' . S::v('core_rss_hash'); - } - $page->setRssLink($n, $url); -} - -$page->run(); - -// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: -?> -- 2.1.4