function ewiki_page_css_container(&$o, &$id, &$data, &$action) {
$o = "
| @µöäüÖÄÜߤ^°«»\'\\',
'- -----------------------------------------------')
. "\">\n"
. $o . "\n
\n";
}
function ewiki_split_title ($id='', $split=EWIKI_SPLIT_TITLE, $entities=1) {
strlen($id) or ($id = $GLOBALS["ewiki_id"]);
if ($split) {
$id = preg_replace("/([".EWIKI_CHARS_L."])([".EWIKI_CHARS_U."]+)/", "$1 $2", $id);
}
return($entities ? s($id) : $id);
}
function ewiki_add_title(&$html, $id, &$data, $action, $go_action="links") {
$html = ewiki_make_title($id, '', 1, $action, $go_action) . $html;
}
function ewiki_make_title($id='', $title='', $class=3, $action="view", $go_action="links", $may_split=1) {
global $ewiki_config, $ewiki_plugins, $ewiki_title, $ewiki_id;
#-- advanced handler
if ($pf = @$ewiki_plugins["make_title"][0]) {
return($pf($title, $class, $action, $go_action, $may_split));
}
#-- disabled
elseif (!$ewiki_config["print_title"]) {
return("");
}
#-- get id
if (empty($id)) {
$id = $ewiki_id;
}
#-- get title
if (!strlen($title)) {
$title = $ewiki_title; // already in &html; format
}
elseif ($ewiki_config["split_title"] && $may_split) {
$title = ewiki_split_title($title, $ewiki_config["split_title"], 0&($title!=$ewiki_title));
}
else {
$title = s($title);
}
#-- title mangling
if ($pf_a = @$ewiki_plugins["title_transform"]) {
foreach ($pf_a as $pf) { $pf($id, $title, $go_action); }
}
#-- clickable link or simple headline
if ($class <= $ewiki_config["print_title"]) {
if ($uu = @$ewiki_config["link_title_action"][$action]) {
$go_action = $uu;
}
if ($uu = @$ewiki_config["link_title_url"]) {
$href = $uu;
unset($ewiki_config["link_title_url"]);
}
else {
$href = ewiki_script($go_action, $id);
}
$o = '
' . ($title) . '';
}
else {
$o = $title;
}
return('
' . $o . '
'."\n");
}
function ewiki_page_view($id, &$data, $action, $all=1) {
global $ewiki_plugins, $ewiki_config;
$o = "";
#-- render requested wiki page <-- goal !!!
$render_args = array(
"scan_links" => 1,
"html" => (EWIKI_ALLOW_HTML||(@$data["flags"]&EWIKI_DB_F_HTML)),
);
$o .= $ewiki_plugins["render"][0] ($data["content"], $render_args);
if (!$all) {
return($o);
}
#### MOODLE CHANGE
/// Add Moodle filters to text porion of wiki.
global $moodle_format; // from wiki/view.php
$o = format_text($o, $moodle_format);
$o.= "
";
#-- control line + other per-page info stuff
if ($pf_a = $ewiki_plugins["view_append"]) {
ksort($pf_a);
foreach ($pf_a as $n => $pf) { $o .= $pf($id, $data, $action); }
}
if ($pf_a = $ewiki_plugins["view_final"]) {
ksort($pf_a);
foreach ($pf_a as $n => $pf) { $pf($o, $id, $data, $action); }
}
if (!empty($_REQUEST["thankyou"]) && $ewiki_config["edit_thank_you"]) {
$o = ewiki_t("THANKSFORCONTRIBUTION") . $o;
}
if (EWIKI_HIT_COUNTING) {
ewiki_database("HIT", $data);
}
return($o);
}
#-------------------------------------------------------------------- util ---
/* retrieves "$id/$action" string from URL / QueryString / PathInfo,
change this in conjunction with ewiki_script() to customize your URLs
further whenever desired
*/
function ewiki_id() {
($id = @$_REQUEST["id"]) or
($id = @$_REQUEST["name"]) or
($id = @$_REQUEST["page"]) or
($id = @$_REQUEST["file"]) or
(EWIKI_USE_PATH_INFO) and ($id = ltrim(@$_SERVER["PATH_INFO"], "/")) or
(!isset($_REQUEST["id"])) and ($id = trim(strtok($_SERVER["QUERY_STRING"], "&")));
if (!strlen($id) || ($id=="id=")) {
$id = EWIKI_PAGE_INDEX;
}
(EWIKI_URLDECODE) && ($id = urldecode($id));
return($id);
}
/* replaces EWIKI_SCRIPT, works more sophisticated, and
bypasses various design flaws
- if only the first parameter is used (old style), it can contain
a complete "action/WikiPage" - but this is ambigutious
- else $asid is the action, and $id contains the WikiPageName
- $ewiki_config["script"] will now be used in favour of the constant
- needs more work on _BINARY, should be a separate function
*/
## MOODLE-CHANGE: $asid="", Knows the devil why....
function ewiki_script($asid="", $id=false, $params="", $bin=0, $html=1, $script=NULL) {
global $ewiki_config, $ewiki_plugins;
#-- get base script url from config vars
if (empty($script)) {
$script = &$ewiki_config[!$bin?"script":"script_binary"];
}
#-- separate $action and $id for old style requests
if ($id === false) {
if (strpos($asid, EWIKI_ACTION_SEP_CHAR) !== false) {
$asid = strtok($asid, EWIKI_ACTION_SEP_CHAR);
$id = strtok("\000");
}
else {
$id = $asid;
$asid = "";
}
}
#-- prepare params
if (is_array($params)) {
$uu = $params;
$params = "";
if ($uu) foreach ($uu as $k=>$v) {
$params .= (strlen($params)?"&":"") . rawurlencode($k) . "=" . rawurlencode($v);
}
}
#-- action= parameter
if (EWIKI_USE_ACTION_PARAM >= 2) {
$params = "action=$asid" . (strlen($params)?"&":"") . $params;
$asid = "";
}
#-- workaround slashes in $id
if (empty($asid) && (strpos($id, EWIKI_ACTION_SEP_CHAR) !== false) && !$bin) {
$asid = "view";
}
/*paranoia*/ $asid = trim($asid, EWIKI_ACTION_SEP_CHAR);
#-- make url
if (EWIKI_URLENCODE) {
$id = urlencode($id);
$asid = urlencode($asid);
}
else {
# only urlencode &, %, ? for example
}
$url = $script;
if ($asid) {
$id = $asid . EWIKI_ACTION_SEP_CHAR . $id; #= "action/PageName"
}
if (strpos($url, "%s") !== false) {
$url = str_replace("%s", $id, $url);
}
else {
$url .= $id;
}
#-- add url params
if (strlen($params)) {
$url .= (strpos($url,"?")!==false ? "&":"?") . $params;
}
#-- fin
if ($html) {
//Don't replace & if it's part of encoded character (bug 2209)
$url = preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/","&", $url);
} else {
//This is going to be used in some header or meta redirect, so It cannot use & (bug 2620)
$url = preg_replace('/&/', '&', $url);
}
return($url);
}
/* this ewiki_script() wrapper is used to generate URLs to binary
content in the ewiki database
*/
function ewiki_script_binary($asid, $id=false, $params=array(), $upload=0) {
$upload |= is_string($params) && strlen($params) || count($params);
#-- generate URL directly to the plainly saved data file,
# see also plugins/binary_store
if (defined("EWIKI_DB_STORE_URL") && !$upload) {
$url = EWIKI_DB_STORE_URL . rawurlencode($id);
}
#-- else get standard URL (thru ewiki.php) from ewiki_script()
else {
$url = ewiki_script($asid, $id, $params, "_BINARY=1");
}
return($url);
}
/* this function returns the absolute ewiki_script url, if EWIKI_SCRIPT_URL
is set, else it guesses the value
*/
function ewiki_script_url() {
global $ewiki_action, $ewiki_id, $ewiki_config;
$scr_template = $ewiki_config["script"];
$scr_current = ewiki_script($ewiki_action, $ewiki_id);
$req_uri = $_SERVER["REQUEST_URI"];
if ($url = $ewiki_config["script_url"]) {
return($url);
}
elseif (strpos($req_uri, $scr_current) !== false) {
$url = str_replace($req_uri, $scr_current, $scr_template);
}
elseif (strpos($req_uri, "?") && (strpos($scr_template, "?") !== false)) {
$url = substr($req_uri, 0, strpos($req_uri, "?"))
. substr($scr_template, strpos($scr_template, "?"));
}
elseif (strpos($req_uri, $sn = $_SERVER["SCRIPT_NAME"])) {
$url = $sn . "?id=";
}
else {
return(NULL); #-- could not guess it
}
#$url = "http://" . $_SERVER["SERVER_NAME"] . $url;
return($url);
}
#------------------------------------------------------------ page plugins ---
function ewiki_page_links($id, &$data, $action) {
$o = ewiki_make_title($id, ewiki_t("PAGESLINKINGTO", array("title"=>$id)), 1, $action, "", "_MAY_SPLIT=1");
if ($pages = ewiki_get_backlinks($id)) {
$o .= ewiki_list_pages($pages);
} else {
$o .= ewiki_t("This page isn't linked from anywhere else.");
}
return($o);
}
function ewiki_get_backlinks($id) {
$result = ewiki_database("SEARCH", array("refs" => $id));
$pages = array();
while ($row = $result->get(0, 0x0020)) {
if ( strpos($row["refs"], "\n$id\n") !== false) {
$pages[] = $row["id"];
}
}
return($pages);
}
function ewiki_get_links($id) {
if ($data = ewiki_database("GET", array("id"=>$id))) {
$refs = explode("\n", trim($data["refs"]));
$r = array();
foreach (ewiki_database("FIND", $refs) as $id=>$exists) {
if ($exists) {
$r[] = $id;
}
}
return($r);
}
}
function ewiki_list_pages($pages=array(), $limit=EWIKI_LIST_LIMIT,
$value_as_title=0, $pf_list=false)
{
global $ewiki_plugins;
$o = "";
$is_num = !empty($pages[0]);
$lines = array();
$n = 0;
foreach ($pages as $id=>$add_text) {
$title = $id;
$params = "";
if (is_array($add_text)) {
list($id, $params, $title, $add_text) = $add_text;
}
elseif ($is_num) {
$id = $title = $add_text;
$add_text = "";
}
elseif ($value_as_title) {
$title = $add_text;
$add_text = "";
}
$lines[] = '
' . s($title) . ' ' . $add_text;
if (($limit > 0) && ($n++ >= $limit)) {
break;
}
}
if ($pf_a = @$ewiki_plugins["list_transform"])
foreach ($pf_a as $pf_transform) {
$pf_transform($lines);
}
if (($pf_list) || ($pf_list = @$ewiki_plugins["list_pages"][0])) {
$o = $pf_list($lines);
}
elseif($lines) {
$o = "· " . implode("
\n· ", $lines) . "
\n";
}
return($o);
}
function ewiki_page_ordered_list($orderby="created", $asc=0, $print, $title) {
$o = ewiki_make_title("", $title, 2, ".list", "links", 0);
$sorted = array();
$result = ewiki_database("GETALL", array($orderby));
while ($row = $result->get()) {
$row = ewiki_database("GET", array(
"id" => $row["id"],
($asc >= 0 ? "version" : "uu") => 1 // version 1 is most accurate for {hits}
));
#-- text page?
if (EWIKI_DB_F_TEXT == ($row["flags"] & EWIKI_DB_F_TYPE)) {
#-- viewing allowed?
if (!EWIKI_PROTECTED_MODE || !EWIKI_PROTECTED_MODE_HIDING || ewiki_auth($row["id"], $row, "view")) {
$sorted[$row["id"]] = $row[$orderby];
}
}
}
if ($asc != 0) { arsort($sorted); }
else { asort($sorted); }
foreach ($sorted as $name => $value) {
if (empty($value)) { $value = "0"; }
##### BEGIN MOODLE ADDITION #####
#$sorted[$name] = strftime(str_replace('%n', $value, $print), $value);
if($print=="LASTCHANGED") {
$value=strftime("%c",$value);
}
$sorted[$name] = get_string(strtolower($print),"wiki",$value);
##### BEGIN MOODLE ADDITION #####
}
$o .= ewiki_list_pages($sorted);
return($o);
}
function ewiki_page_newest($id=0, $data=0) {
return( ewiki_page_ordered_list("created", 1, "LASTCHANGED", ewiki_t(EWIKI_PAGE_NEWEST)) );
}
function ewiki_page_updates($id=0, $data=0) {
return( ewiki_page_ordered_list("lastmodified", -1, "LASTCHANGED", ewiki_t(EWIKI_PAGE_UPDATES)) );
}
function ewiki_page_hits($id=0, $data=0) {
##### BEGIN MOODLE ADDITION #####
return( ewiki_page_ordered_list("hits", 1, "hits", ewiki_t(EWIKI_PAGE_HITS)) );
}
function ewiki_page_versions($id=0, $data=0) {
return( ewiki_page_ordered_list("version", -1, "changes", ewiki_t(EWIKI_PAGE_VERSIONS)) );
##### END MOODLE ADDITION #####
}
function ewiki_page_search($id, &$data, $action) {
global $CFG;
$o = ewiki_make_title($id, $id, 2, $action);
if (! ($q = @$_REQUEST["q"])) {
$o .= '
';
}
else {
$found = array();
if ($CFG->unicodedb) {
$q = preg_replace('/\s*[\W]+\s*/u', ' ', $q);
} else {
$q = preg_replace('/\s*[^\w]+\s*/', ' ', $q);
}
foreach (explode(" ", $q) as $search) {
if (empty($search)) { continue; }
$result = ewiki_database("SEARCH", array("content" => $search));
while ($row = $result->get()) {
#-- show this entry in page listings?
if (EWIKI_PROTECTED_MODE && EWIKI_PROTECTED_MODE_HIDING && !ewiki_auth($row["id"], $row, "view")) {
continue;
}
$found[] = $row["id"];
}
}
$o .= ewiki_list_pages($found);
}
return($o);
}
function ewiki_page_info($id, &$data, $action) {
global $ewiki_plugins, $ewiki_config, $ewiki_links;
global $CFG, $course; // MOODLE HACK
$o = ewiki_make_title($id, ewiki_t("INFOABOUTPAGE")." '{$id}'", 2, $action,"", "_MAY_SPLIT=1");
$flagnames = array(
"TEXT", "BIN", "DISABLED", "HTML", "READONLY", "WRITEABLE",
"APPENDONLY", "SYSTEM",
);
$show = array(
"version", "author", "userid", "created",
"lastmodified", "refs",
"flags", "meta", "content"
);
#-- versions to show
$v_start = $data["version"];
if ( ($uu=@$_REQUEST[EWIKI_UP_PAGENUM]) && ($uu<=$v_start) ) {
$v_start = $uu;
}
$v_end = $v_start - $ewiki_config["list_limit"] + 1;
if ( ($uu=@$_REQUEST[EWIKI_UP_PAGEEND]) && ($uu<=$v_start) ) {
$v_end = $uu;
}
$v_end = max($v_end, 1);
#-- go
# the very ($first) entry is rendered more verbosely than the others
for ($v=$v_start,$first=1; ($v>=$v_end); $v--,$first=0) {
$current = ewiki_database("GET", array("id"=>$id, "version"=>$v));
if (!strlen(trim($current["id"])) || !$current["version"] || !strlen(trim($current["content"]))) {
continue;
}
$o .= '
' . "\n";
#-- additional info-actions
$commands = '';
foreach ($ewiki_config["action_links"]["info"] as $thisaction=>$title)
if (@$ewiki_plugins["action"][$thisaction] || @$ewiki_plugins["action_always"][$thisaction]) {
##### BEGIN MOODLE ADDITION #####
if ($commands) {
$commands .= ' ';
}
$commands .= '$current["version"])) .
'">' . get_string($title,"wiki") . '';
##### END MOODLE ADDITION #####
}
#-- print page database entry
foreach($show as $i) {
$value = @$current[$i];
#-- show database {fields} differently
if ($i == "meta") {
continue; // MOODLE DOESN'T USE IT
$str = "";
if ($first && $value) { foreach ($value as $n=>$d) {
$str .= s("$n: $d") . "
\n";
} }
$value = $str;
}
elseif ($value >= UNIX_MILLENNIUM) { #-- {lastmodified}, {created}
#### BEGIN MOODLE CHANGE
$value=userdate($value);
#$value = strftime("%c", $value);
#### END MOODLE CHANGE
}
elseif ($i == "content") {
continue; // MOODLE DOESN'T CARE
$value = strlen(trim($value)) . " bytes";
$i = "content size";
}
elseif ($first && ($i == "refs") && !(EWIKI_PROTECTED_MODE && (EWIKI_PROTECTED_MODE_HIDING>=2))) {
$a = explode("\n", trim($value));
$ewiki_links = ewiki_database("FIND", $a);
ewiki_merge_links($ewiki_links);
foreach ($a as $n=>$link) {
$a[$n] = ewiki_link_regex_callback(array("$link"), "force_noimg");
}
$value = trim(implode(", ", $a));
if (!$value) {
continue;
}
}
elseif (strpos($value, "\n") !== false) { #-- also for {refs}
$value = str_replace("\n", ", ", trim($value));
if (!$value) {
continue;
}
}
elseif ($i == "version") {
$value = '$value)) . '">' .
$value . ' '."($commands)";
}
elseif ($i == "flags") {
continue; // MOODLE DOESN'T USE IT
$fstr = "";
for ($n = 0; $n < 32; $n++) {
if ($value & (1 << $n)) {
if (! ($s=$flagnames[$n])) { $s = "UU$n"; }
$fstr .= $s . " ";
}
}
$value = $fstr;
}
elseif ($i == "author") {
continue;
$ewiki_links=1;
$value = preg_replace_callback("/((\w+:)?([".EWIKI_CHARS_U."]+[".EWIKI_CHARS_L."]+){2,}[\w\d]*)/", "ewiki_link_regex_callback", $value);
}
elseif ($i == "userid") {
$i = 'author';
if ($user = get_record('user', 'id', (int)$value)) {
if (!isset($course->id)) {
$course->id = 1;
}
$picture = print_user_picture($user->id, $course->id, $user->picture, false, true, true);
$value = $picture." wwwroot/user/view.php?id=$user->id&course=$course->id\">".fullname($user)."";
} else {
continue;
//$value = @$current['author'];
}
}
##### BEGIN MOODLE ADDITION #####
$o .= '' .ewiki_t($i). ': | ' .
'' . $value . " |
\n";
##### END MOODLE ADDITION #####
}
$o .= "
\n";
}
#-- page result split
if ($v >= 1) {
$o .= "
\n".get_string('showversions','wiki').' '.ewiki_chunked_page($action, $id, -1, $v, 1, 0, 0) . "\n
";
}
return($o);
}
function ewiki_chunked_page($action, $id, $dir=-1, $start=10, $end=1, $limit=0, $overlap=0.25, $collapse_last=0.67) {
global $ewiki_config;
if (empty($limit)) {
$limit = $ewiki_config["list_limit"];
}
if ($overlap < 1) {
$overlap = (int) ($limit * $overlap);
}
$p = "";
$n = $start;
while ($n) {
$n -= $dir * $overlap;
$e = $n + $dir * ($limit + $overlap) + 1;
if ($dir<0) {
$e = max(1, $e);
if ($e <= $collapse_last * $limit) {
$e = 1;
}
}
else {
$e = min($end, $e);
if ($e >= $collapse_last * $limit) {
$e = $end;
}
}
$o .= ($o?" · ":"")
. '
'. "$n-$e" . '';
if (($n=$e-1) < $end) {
$n = false;
}
}
return('
'. $o .'');
}
function ewiki_page_edit($id, $data, $action) {
global $ewiki_links, $ewiki_author, $ewiki_plugins, $ewiki_ring, $ewiki_errmsg;
$hidden_postdata = array();
#-- previous version come back
if (@$data["forced_version"]) {
$current = ewiki_database("GET", array("id"=>$id));
$data["version"] = $current["version"];
unset($current);
unset($_REQUEST["content"]);
unset($_REQUEST["version"]);
}
#-- edit hacks
if ($pf_a = @$ewiki_plugins["edit_hook"]) foreach ($pf_a as $pf) {
if ($output = $pf($id, $data, $hidden_postdata)) {
return($output);
}
}
#-- permission checks
if (isset($ewiki_ring)) {
$ring = $ewiki_ring;
} else {
$ring = 3;
}
$flags = @$data["flags"];
if (!($flags & EWIKI_DB_F_WRITEABLE)) {
#-- perform auth
$edit_ring = (EWIKI_PROTECTED_MODE>=2) ? (2) : (NULL);
if (EWIKI_PROTECTED_MODE && !ewiki_auth($id, $data, $action, $edit_ring, "FORCE")) {
return($ewiki_errmsg);
}
#-- flag checking
if (($flags & EWIKI_DB_F_READONLY) and ($ring >= 2)) {
return(ewiki_t("CANNOTCHANGEPAGE"));
}
if (($flags) and (($flags & EWIKI_DB_F_TYPE) != EWIKI_DB_F_TEXT) and ($ring >= 1)) {
return(ewiki_t("CANNOTCHANGEPAGE"));
}
}
#-- "Edit Me"
$o = ewiki_make_title($id, ewiki_t("EDITTHISPAGE").(" '{$id}'"), 2, $action, "", "_MAY_SPLIT=1");
#-- preview
if (isset($_REQUEST["preview"])) {
$o .= $ewiki_plugins["edit_preview"][0]($data);
}
#-- save
if (isset($_REQUEST["save"])) {
#-- normalize to UNIX newlines
$_REQUEST["content"] = str_replace("\015\012", "\012", $_REQUEST["content"]);
$_REQUEST["content"] = str_replace("\015", "\012", $_REQUEST["content"]);
#-- check for concurrent version saving
$error = 0;
if ((@$data["version"] >= 1) && ($data["version"] != @$_REQUEST["version"]) || (@$_REQUEST["version"] < 1)) {
$pf = $ewiki_plugins["edit_patch"][0];
if (!$pf || !$pf($id, $data)) {
$error = 1;
$o .= ewiki_t("ERRVERSIONSAVE") . "
";
}
}
if (!$error) {
#-- new pages` flags
if (! ($set_flags = @$data["flags"] & EWIKI_DB_F_COPYMASK)) {
$set_flags = 1;
}
if (EWIKI_ALLOW_HTML) {
$set_flags |= EWIKI_DB_F_HTML;
}
#-- mk db entry
$save = array(
"id" => $id,
"version" => @$data["version"] + 1,
"flags" => $set_flags,
"content" => $_REQUEST["content"],
"created" => ($uu=@$data["created"]) ? $uu : time(),
"meta" => ($uu=@$data["meta"]) ? $uu : "",
"hits" => ($uu=@$data["hits"]) ? $uu : "0",
);
ewiki_data_update($save);
#-- edit storage hooks
if ($pf_a = @$ewiki_plugins["edit_save"]) {
foreach ($pf_a as $pf) {
$pf($save, $data);
}
}
#-- save
if (!$save || !ewiki_database("WRITE", $save)) {
$o .= $ewiki_errmsg ? $ewiki_errmsg : ewiki_t("ERRORSAVING");
}
else {
#-- prevent double saving, when ewiki_page() is re-called
$_REQUEST = $_GET = $_POST = array();
$o = ewiki_t("THANKSFORCONTRIBUTION") . "
";
$o .= ewiki_page($id);
if (EWIKI_EDIT_REDIRECT) {
$url = ewiki_script("", $id, "thankyou=1", 0, 0, EWIKI_HTTP_HEADERS?ewiki_script_url():0);
if (EWIKI_HTTP_HEADERS && !headers_sent()) {
header("Status: 303 Redirect for GET");
header("Location: $url");
#header("URI: $url");
#header("Refresh: 0; URL=$url");
}
else {
$o .= '
';
}
}
}
}
//@REWORK
// header("Reload-Location: " . ewiki_script("", $id, "", 0, 0, ewiki_script_url()) );
}
else {
#-- Edit