Example #1
0
function ewiki_addpage($id, &$data, $version)
{
    $o = ewiki_make_title($id, $id, 2);
    #-- output page creation dialog
    if (empty($_REQUEST["new_id"])) {
        $o .= ewiki_t('<form action="' . ewiki_script("", $id) . '" method="POST" enctype="multipart/formdata"> ' . '_{name of the new page} <input type="text" name="new_id" size="26" value="">' . '<br />' . '<input type="submit" value="_{create}">' . '<br /><br />' . '<input type="checkbox" name="add_link_from" value="1" checked="checked">' . ' _{link it from} ' . '<input type="text" name="link_from" size="20" value="_{AddedPages}">' . '</form>');
    } else {
        $new_id = trim($_REQUEST["new_id"]);
        #-- add a link to new page
        if ($_REQUEST["add_link_from"] && ($from = $_REQUEST["link_from"])) {
            $row = ewiki_db::GET($from);
            if ($row && $row["version"]) {
                if (($row["flags"] & EWIKI_DB_F_TYPE) == EWIKI_DB_F_TEXT) {
                    $row["version"]++;
                    $row["content"] .= "\n* [{$new_id}]";
                    ewiki_scan_wikiwords($row["content"], $row["refs"], "_STRIP_EMAIL=1");
                    $row["refs"] = "\n\n" . implode("\n", array_keys($row["refs"])) . "\n\n";
                } else {
                    $row = false;
                }
            } else {
                $row = array("id" => $from, "version" => 1, "flags" => EWIKI_DB_F_TEXT, "created" => time(), "lastmodified" => time(), "hits" => 0, "meta" => "", "content" => "\n* [{$new_id}]", "refs" => "\n\n{$new_id}\n\n");
            }
            if ($row) {
                ewiki_db::WRITE($row);
            }
        }
        #-- call edit <form>
        $o = ewiki_page($new_id);
    }
    return $o;
}
Example #2
0
function ewiki_mpi_survey($action, &$args, &$iii, &$s)
{
    global $ewiki_id, $ewiki_plugins;
    $o = "";
    #-- load data page
    if (!($df = $args["data"])) {
        return;
    }
    unset($args["data"]);
    unset($args["_"]);
    unset($args[""]);
    $data = ewiki_db::GET($df);
    if (!$data["version"]) {
        $data = ewiki_new_data($df, EWIKI_DB_F_BINARY);
        $data["version"]--;
    }
    if ($data["flags"] != EWIKI_DB_F_BINARY) {
        return;
    }
    $survey = unserialize($data["content"]);
    #-- operation
    $vote = @$_REQUEST[EWIKI_UP_SURVEY];
    if ($vote == "\$") {
        $action = "show";
    }
    if ($action == "html") {
        #-- show entries
        if (!$vote) {
            $o = "\n" . '<form action="' . $_SERVER["REQUEST_URI"] . '" method="POST" enctype="multipart/form-data">' . '<input type="hidden" name="id" value="' . htmlentities($ewiki_id) . '">' . "\n";
            foreach ($args as $name => $text) {
                if (!$name || !$text || $name == "data") {
                    continue;
                }
                $o .= '<input type="radio" name="' . EWIKI_UP_SURVEY . '" value="' . htmlentities($name) . '"> ' . $text . "<br />\n";
            }
            $o .= '<input type="submit" value="vote">';
            $o .= "\n</form>\n<br /><br />\n";
            $o .= '<a href="' . ewiki_script("", $ewiki_id, array(EWIKI_UP_SURVEY => "\$")) . '">show results</a><br />';
        }
        #-- store an entry
        if ($vote) {
            $survey[$vote]++;
            $data["content"] = serialize($survey);
            $data["version"]++;
            $data["lastmodified"] = time();
            $data["author"] = ewiki_author();
            ewiki_db::WRITE($data);
            #-- show it
            $action = "show";
        }
    }
    if ($action == "show") {
        $o .= $ewiki_plugins["view_stat"][0]($survey, $args);
    }
    return $o;
}
Example #3
0
function ewiki_add_thread($id, $data, $action)
{
    global $ewiki_plugins;
    $id = $id . EWIKI_THREAD_SEPARATOR . $_REQUEST['threadname'];
    $save = array("id" => $id, "version" => 1, "flags" => '', "content" => "   ", "author" => ewiki_author(), "lastmodified" => time(), "created" => time(), "meta" => array('isThread' => '1'), "hits" => 0, "refs" => "");
    if (!ewiki_db::WRITE($save)) {
        return ewiki_t("ERRORSAVING");
    }
    return ewiki_add_post($id, array(), 'addpost');
}
Example #4
0
function ewiki_pingback_rpc($source_url, $target_url)
{
    global $ewiki_config;
    #-- does the target URL refer to a known WikiPage ?
    $id = ewiki_url2id($target_url);
    if (!$id) {
        xmlrpc_send_response(xmlrpc_error(0x21, "Could not determine PageName for the given target URL."));
    }
    if (!($data = ewiki_db::GET($id))) {
        xmlrpc_send_response(xmlrpc_error(0x20, "The given target page does not exist."));
    }
    #-- check if the caller really has a link as he claims
    ini_set("user_agent", $ewiki_config["ua"]);
    if (strpos($source_url, "http://") === 0 && ($test = ewiki_http_asis($source_url, 96256))) {
        $test = strtolower($test);
        $test_url = strtolower($target_url);
        if (!strpos($test, $test_url) and !strpos($test, htmlentities($test_url))) {
            return xmlrpc_error(0x11, "Sorry, but couldn't find a link to '{$target_url}' on your given '{$source_url}' page.");
        }
    } else {
        return xmlrpc_error(0x10, "Your given source URL does not exist, could not be retrieved.");
    }
    #-- reject other frivolous links
    if (preg_match('#^http://[^/]+/?$#', $source_url)) {
        return xmlrpc_error(0x11, "Rejected '{$source_url}' as frivolous.");
    }
    #-- check write permissions
    if (EWIKI_DB_F_TEXT != $data["flags"] & EWIKI_DB_F_TYPE or $data["flags"] & EWIKI_DB_F_READONLY) {
        return xmlrpc_error(0x31, "Sorry, but this page is write-protected or not a system page.");
    }
    #-- already on page
    if (strpos($data["content"], $source_url)) {
        return xmlrpc_error(0x30, "The given link does already exist on this page.");
    }
    #-- other go-away cases
    if (function_exists("ewiki_banned_url") && ewiki_banned_url($source_url) || function_exists("ewiki_blocked_url") && ewiki_blocked_url($source_url)) {
        return xmlrpc_error(0x100, "Your link is unwanted here (registered on BlockedLinks or BannedLinks).");
    }
    #-- else update page
    $data["content"] = rtrim($data["content"]) . "\n* {$source_url} (PingBack)\n";
    ewiki_db::UPDATE($data);
    $data["version"]++;
    $ok = ewiki_db::WRITE($data);
    #-- fin response
    if ($ok) {
        return "Link to '{$source_url}' was added to page '{$id}'.";
    } else {
        return xmlrpc_error(0x101, "Seems like a database/writing error occoured.");
    }
}
Example #5
0
function ewiki_mpi_registerspam($action, &$args, &$iii, &$s)
{
    global $ewiki_id;
    if (!$_POST["regspam"]) {
        return <<<END
<form action="{$_SERVER['REQUEST_URI']}" method="POST" enctype="multipart/form-data">
<textarea name="add_spam" cols="50" rows="3"></textarea><br/>
<input type="submit" name="regspam" value="add listed urls" />
</form>
END;
    } else {
        #-- scan for links
        $text = $_REQUEST["add_spam"];
        ewiki_scan_wikiwords($text, $uu);
        $ls = array();
        foreach ($uu as $href => $uu) {
            if ($l = strpos($href, "://")) {
                // filter out redundant pattern parts
                $href = substr($href, $l + 3);
                if (strpos($href, "www.") === 0) {
                    $href = substr($href, 4);
                }
                $href = trim($href, "/");
                $ls[] = strtok($href, " ");
            }
        }
        #-- reduce
        $ls = array_unique($ls);
        $data = ewiki_db::GET($ewiki_id);
        foreach (explode("\n", trim($data["refs"])) as $href) {
            if (in_array($href, $ls)) {
                unset($ls[array_search($href, $ls)]);
            }
        }
        #-- add to current page
        if ($ls) {
            $inj = "* [" . implode("], [", $ls) . "]\n";
            $data["content"] = preg_replace("/(^[-*#])/m", "{$inj}\$1", $data["content"], 1);
            ewiki_db::UPDATE($data);
            $data["version"]++;
            ewiki_db::WRITE($data);
            return "\n<div class=\"system-message ok\">new links added as patterns here (please go back and reload page to see it)</div>\n";
        } else {
            return "\n<div class=\"system-message failure\">no new links found, please add the patterns by hand then</div>\n";
        }
    }
}
Example #6
0
function ewiki_sync_local($func, $args = NULL)
{
    switch (strtoupper(trim($func, ":"))) {
        case "GET":
            return ewiki_db::GET($args[0], $args[1]);
        case "WRITE":
            return ewiki_db::WRITE($args);
        case "LIST":
            $all = ewiki_db::GETALL(array("id", "version"));
            $r = array();
            while ($row = $all->get()) {
                $r[$row["id"]] = $row["version"];
            }
            return $r;
        default:
    }
}
Example #7
0
function ewiki_action_image_append($id, $data, $action)
{
    #-- invalid $id value
    if (empty($data) || !$data["version"] || EWIKI_DB_F_TEXT != ($data["flags"] & EWIKI_DB_F_TYPE)) {
        $o = ewiki_t("CANNOTCHANGEPAGE");
    } elseif ($fa = $_FILES["imagefile"]) {
        #-- guess HTTP meta data
        $meta = array("X-Content-Type" => $fa["type"]);
        if ($s = $fa["name"]) {
            $meta["Content-Location"] = $s;
            $p = 0 or $p = strrpos($s, "/") and $p++ or $p = strrpos($s, '\\') and $p++;
            $meta["Content-Disposition"] = 'inline; filename="' . urlencode(substr($s, $p)) . '"';
        }
        #-- proceed an image (reject binary, resize if too large)
        $result = ewiki_binary_save_image($fa["tmp_name"], "", "RETURN", $meta, 0, 1);
        #-- database rejected file
        if (!$result) {
            $o = ewiki_t("BIN_NOIMG");
        } else {
            $loop = 3;
            while ($loop--) {
                $data = ewiki_db::GET($id);
                $data["version"]++;
                $data["content"] = rtrim($data["content"], "\n") . "\n\n" . "[\"AppendedPicture\"{$result}]\n\n\n";
                $result = ewiki_db::WRITE($data);
                if ($result) {
                    break;
                }
            }
            if ($result) {
                $o = ewiki_page("view/{$id}");
                ewiki_log("image appended to '{$id}'");
            } else {
                $o .= ewiki_t("NO_IMAGEAPPEND");
            }
        }
    } else {
        $o .= ewiki_t("BIN_NOIMG");
        #"You did not select an image, or something went really wrong during tansmission. Plase go back to the previous page.";
    }
    return $o;
}
Example #8
0
function ewiki_mpi_bugreportstate($action, $args, &$iii, &$s)
{
    global $ewiki_id;
    #-- possible states
    $values = array("open", "closed", "done", "frozen", "answered");
    foreach ($args as $i => $name) {
        if (is_int($i)) {
            if (preg_match("/^\\w+\$/", $name) && !in_array($name, $values)) {
                $values[] = $name;
            }
        }
    }
    $rxvals = implode("|", $values);
    #-- if button pressed
    if (($new = $_REQUEST["brs_change"]) && in_array($new, $values)) {
        $pages = ewiki_get_backlinks($ewiki_id);
        $pages[] = $ewiki_id;
        #-- change assoc pages
        foreach ($pages as $id) {
            $data = ewiki_db::GET($id);
            if (preg_match("/\n\\|.*stat(e|us).*\\|.*({$rxvals})/", $data["content"]) or preg_match("/\n\\|.*({$rxvals}).*\\|.*{$ewiki_id}/", $data["content"])) {
                $data["content"] = preg_replace("/(\n\\|.*stat(?:e|us).*\\|.*?)[_*]*(?:{$rxvals})[_*]*/", "\$1{$new}", $data["content"]);
                $data["content"] = preg_replace("/(\n\\|.*?)[_*]*(?:{$rxvals})[_*]*(.*?\\|.*{$ewiki_id})/", "\$1{$new}\$2", $data["content"]);
                ewiki_db::UPDATE($data);
                $data["version"]++;
                ewiki_db::WRITE($data);
            }
        }
        $o = "<p>(status changed)</p>";
        $iii[0][0] = preg_replace("/({$rxvals})/", "{$new}", $iii[0][0]);
    } else {
        $url = ewiki_script("", $ewiki_id);
        $o .= <<<EOT
<form action="{$url}#added" method="POST" enctype="multipart/form-data">
<input type="submit" name="brs_change" value="open">
<input type="submit" name="brs_change" value="closed">
<input type="submit" name="brs_change" value="frozen">
</form>
EOT;
    }
    return $o;
}
Example #9
0
function ewiki_mpi_addlink($action, $args, &$iii, &$s)
{
    global $ewiki_id, $ewiki_action;
    $o = "";
    #-- add URL
    if ($_REQUEST["link_save"]) {
        #-- check parameters
        $url = trim($_REQUEST["link_url"]);
        $text = "";
        $title = $desc = "";
        if (!strpos($url, "example.com") && strlen($url) > 12 && preg_match('#^https?://#', $url)) {
            $text = implode("", file($url));
            if ($text) {
                preg_match('#<title[^>]*>([^<]+)</title>#ims', $text, $uu) and $title = $uu[1] or preg_match('#//([^/]+)#', $url, $uu) and $title = $uu[1];
                preg_match('#<meta[^>]+name=["\']description["\'][^>]+content=["\']([^"\']+)["\']#ims', $text, $uu) and $desc = $uu[1] or preg_match('#<body[^>]+>(.+?)</body#ims', $text, $uu) and $desc = strip_tags($uu[1]);
                $desc = substr(preg_replace('/\\s+/', " ", $desc), 0, 300);
            }
            $add = ":{$title}:\n   {$url} %%%\n   {$desc}\n";
        }
        #-- store bugreport
        if ($text) {
            $data = ewiki_db::GET($ewiki_id);
            $data["content"] = rtrim($data["content"]) . "\n" . $add;
            ewiki_data_update($data);
            $data["version"]++;
            ewiki_db::WRITE($data);
            #-- append to page output
            $iii[] = array($add, 0xffff, "core");
        }
    } else {
        $url = ewiki_script("", $ewiki_id);
        $o .= <<<EOT
<form style="border:2px #333370 solid; background:#7770B0; padding:5px;"class="BugReport" action="{$url}" method="POST" enctype="multipart/form-data">
<input type="hidden" name="id" value="{$ewiki_action}/{$ewiki_id}">
Link <input type="text" name="link_url" value="http://www.example.com/" size="50">
<input type="submit" name="link_save" value="hinzufügen">
</form>
EOT;
    }
    return $o;
}
Example #10
0
function ewiki_editable_intermap($id, $data, $action)
{
    global $ewiki_config;
    $o = "";
    if (($url = $_REQUEST["add_url"]) && ($moni = $_REQUEST["add_moniker"])) {
        if (!preg_match('#^http[sz]?://(\\w{2,}\\.)+\\w{2,}(:\\d+)?[^\\[\\]\\"\\s]+$#', $url) || strpos($url, "example")) {
            $o .= "URL was rejected.";
        } elseif (!preg_match('#^([' . EWIKI_CHARS_U . ']+[' . EWIKI_CHARS_L . ']+){2,}[' . EWIKI_CHARS . ']+$#', $moni) || $moni == "WikiName") {
            $o .= "Choosen InterWiki moniker not acceptable.";
        } else {
            if ($ewiki_config["interwiki"][$moni]) {
                $o .= "(Note: eventually overriding earlier entry.)<br />";
            }
            $data["content"] = "\n" . trim($data["content"]) . "\n" . ":{$moni}:{$url}" . "\n";
            ewiki_data_update($data);
            $data["version"]++;
            if (ewiki_db::WRITE($data)) {
                $o .= "Map was updated.";
            } else {
                $o .= "Error occoured when saving your changes.";
            }
        }
        $o .= "<br />";
    }
    $o .= ewiki_make_title($id, $id, 2);
    $o .= ewiki_page_view($id, $data, $action, 0);
    $o .= ewiki_t(<<<EOT
    <form class="intermap-append" action="{$_SERVER['REQUEST_URI']}" method="POST" enctype="multipart/form-data">
      <hr>
      <input type="hidden" name="id" value="{$id}">
      :<input name="add_moniker" value="WikiName" size="16">:<input name="add_url" value="http://www.example.com/..." size="42">
      <br />
      <input type="submit" value="_{add}">
    </form>
EOT
);
    return $o;
}
Example #11
0
function ewiki_cache_url($url, $cache_min = 1200)
{
    global $ewiki_cache_ctype;
    #-- check if fresh enough in cache (20min)
    $data = ewiki_db::GET($url);
    if (time() <= $data["lastmodified"] + $cache_min) {
        $ewiki_cache_ctype = $data["Content-Type"];
        return $data["content"];
    }
    #-- retrieve
    $req = new http_request("GET", $url);
    $req->header["Accept"] = "application/atom+xml, application/rss+xml, text/rss, xml/*, */*rss*";
    if ($data["meta"]["Last-Modified"]) {
        $req->headers["If-Modified-Since"] = $data["meta"]["Last-Modified"];
    }
    if ($data["meta"]["Etag"]) {
        $req->headers["If-None-Match"] = $data["meta"]["Etag"];
    }
    $result = $req->go();
    #-- create/overwrite cache entry
    if ($result->status == 200) {
        $data = ewiki_db::CREATE($url, 0x0, "ewiki_cache_url");
        $data["flags"] = 0x0;
        $data["content"] = $result->body;
        foreach ($result->headers as $i => $v) {
            $data["meta"][$i] = $v;
        }
        $data["meta"]["class"] = "temp";
        $data["meta"]["kill-after"] = time() + $cache_min;
        if ($t = $data["meta"]["Last-Modified"]) {
            //    $data["lastmodified"] = ewiki_decode_datetime($t);
        }
        ewiki_db::WRITE($data, "_OVERWRITE=1");
    }
    $ewiki_cache_ctype = $data["Content-Type"];
    return $data["content"];
}
Example #12
0
function ewiki_cache_generated_pages($id, &$data, $action)
{
    global $ewiki_plugins, $ewiki_ring;
    $o = ewiki_make_title($id, $id, 1);
    if (empty($_REQUEST["generate_cache"])) {
        $o .= "Use this page plugin/tool to generate text database entries for\nall generated ('internal' or 'static') pages available, so those can later\nbe found using the search functions.<br /><br />";
        $o .= '<form action="' . ewiki_script("", $id) . '" method="POST" enctype="text/html">' . '<input type="hidden" name="id" value="' . $id . '">' . '<input type="submit" value="generate cache" name="generate_cache">' . '</form>';
    } elseif (!ewiki_auth($id, $data, $action, $ring = 0, "_FORCE_AUTH=1") || !isset($ewiki_ring) || $ewiki_ring > 0) {
        if (is_array($data)) {
            $data = "You'll need to be admin. See ewiki_auth() and _PROTECTED_MODE in the README.";
        }
        $o .= $data;
    } else {
        unset($_REQUEST["generate_cache"]);
        $o .= "generating cache versions from:<ul>\n";
        foreach ($ewiki_plugins["page"] as $pid => $pf) {
            #echo "$pid:";
            $d = ewiki_db::GET($pid);
            if (empty($d) || empty($d["content"])) {
                $d = array("id" => $pid, "version" => 1, "flags" => EWIKI_DB_F_TEXT, "created" => time(), "content" => "", "meta" => "", "hits" => 0, "refs" => "");
            }
            $d["last_modified"] = time();
            $d["hits"]++;
            $d["content"] = $pf($pid, $d, "view");
            //@ADD - transform <html> back to wikimarkup
            //       here?
            if (ewiki_db::WRITE($d, true)) {
                $o .= "<li>{$pid}</li>\n";
            }
            unset($d);
        }
        $o .= "</ul>";
        ewiki_log("page search cache was updated", 2);
    }
    return $o;
}
Example #13
0
    if ($_REQUEST["update"]["lastmodified"]) {
        $data["lastmodified"] = time();
    }
    // {refs}
    if ($_REQUEST["update"]["refs"]) {
        ewiki_scan_wikiwords($data["content"], $links, "_STRIP_EMAIL=1");
        $data["refs"] = "\n\n" . implode("\n", array_keys($links)) . "\n\n";
    } else {
        $data["refs"] = "\n\n" . trim(trim($data["refs"], "\n"), "\r") . "\n\n";
    }
    // {content}
    if ($data["flags"] & EWIKI_DB_F_TEXT) {
        $data["content"] = preg_replace("/\r*(\n)\r?/", "\$1", $data["content"]);
    }
    #-- ok, throw into DB
    if (ewiki_db::WRITE($data, $overwrite = 1)) {
        echo "<div class=\"msg\">page written into database</div>\n\n";
    } else {
        echo "<div class=\"msg\">error writing entry to db</div>\n\n";
    }
}
#-- fill with inital data
if ($_REQUEST["create"] && !$data) {
    $data = ewiki_db::CREATE($id);
}
#-- start output
echo '<form action="edit.php" method="POST" enctype="multipart/form-data">';
echo '<input type="hidden" name="id" value="' . htmlentities($id) . '">';
#-- {id}
print_field($data, "id", 32);
#-- {version}
Example #14
0
function cmd_touch($ls)
{
    foreach ($ls as $id) {
        if ($data = ewiki_db::GET($id)) {
            echo "{$data['id']}<br>\n";
            $data["lastmodified"] = time();
            ewiki_db::WRITE($data, $overwrite = 1);
        } else {
            echo "'{$id}' does not exist<br>\n";
        }
    }
}
Example #15
0
function ewiki_action_control_page($id, &$data, $action)
{
    global $ewiki_ring, $ewiki_config, $ewiki_plugins;
    $a_flagnames = array("_TEXT", "_BINARY", "_DISABLED", "_HTML", "_READONLY", "_WRITEABLE", "_APPENDONLY", "_SYSTEM", "_PART", "_MINOR", "_HIDDEN", "_ARCHIVE", "_UU12", "_UU13", "_UU14", "_UU15", "_UU16", "_EXEC", "_UU18", "_UU19");
    $o = ewiki_make_title($id, "control {$id}", 2);
    #-- admin requ. ---------------------------------------------------------
    if (!ewiki_auth($id, $data, $action, $ring = 0, "_FORCE_LOGIN=1") || !isset($ewiki_ring) || $ewiki_ring > 1) {
        if (is_array($data)) {
            $data = "You'll need to be admin. See ewiki_auth() and _PROTECTED_MODE in the README.";
        }
        $o .= $data;
    } elseif (@$_REQUEST["pgc_setflags"]) {
        #-- setted new flags
        $new_f = 0;
        foreach ($_REQUEST["sflag"] as $n => $b) {
            if ($b) {
                $new_f |= 1 << $n;
            }
        }
        #-- administrator may change all flags
        if ($ewiki_ring == 0) {
            $data["flags"] = $new_f;
        } else {
            $data["flags"] = $data["flags"] & ~EWIKI_DB_F_MODERATORFLAGS | $new_f & EWIKI_DB_F_MODERATORFLAGS;
        }
        $data["lastmodified"] = time();
        $data["version"]++;
        if (ewiki_db::WRITE($data)) {
            $o .= "Page flags were updated correctly.";
            ewiki_log("page flags of '{$id}' were set to {$data['flags']}");
        } else {
            $o .= "A database error occoured.";
        }
    } elseif (@$_REQUEST["pgc_rename"] && strlen($new_id = $_REQUEST["mv_to"])) {
        $old_id = $id;
        $report = "";
        $preg_id = "/" . addcslashes($old_id, ".+*?|/\\()\$[]^#") . "/" . ($_REQUEST["mv_cr1"] ? "i" : "");
        #-- check if new name does not already exist in database
        $exists = ewiki_db::GET($new_id);
        if ($exists || !empty($exists)) {
            return $o .= "Cannot overwrite an existing database entry.";
        }
        #-- copy from old name to new name
        $max_ver = $data["version"];
        $data = array();
        for ($v = 1; $v <= $max_ver; $v++) {
            $row = ewiki_db::GET($old_id, $v);
            $row["id"] = $new_id;
            $row["lastmodified"] = time();
            $row["content"] = preg_replace($preg_id, $new_id, $row["content"]);
            ewiki_scan_wikiwords($row["content"], $links, "_STRIP_EMAIL=1");
            $row["refs"] = "\n\n" . implode("\n", array_keys($links)) . "\n\n";
            $row["author"] = ewiki_author("control/");
            if (!ewiki_db::WRITE($row)) {
                $report .= "error while copying version {$v},<br />\n";
            }
        }
        #-- proceed if previous actions error_free
        if (empty($report)) {
            #-- deleting old versions
            for ($v = 1; $v <= $max_ver; $v++) {
                ewiki_db::DELETE($old_id, $v);
            }
            #-- adjust links/references to old page name
            if ($_REQUEST["mv_cr0"]) {
                $result = ewiki_db::SEARCH("refs", $old_id);
                while ($result && ($row = $result->get())) {
                    $row = ewiki_db::GET($row["id"]);
                    if (preg_match($preg_id, $row["content"], $uu)) {
                        $row["content"] = preg_replace($preg_id, $new_id, $row["content"]);
                        $row["lastmodified"] = time();
                        $row["version"]++;
                        ewiki_scan_wikiwords($row["content"], $links, "_STRIP_EMAIL=1");
                        $row["refs"] = "\n\n" . implode("\n", array_keys($links)) . "\n\n";
                        $row["author"] = ewiki_author("control/");
                        if (!ewiki_db::WRITE($row)) {
                            $report .= "could not update references in " . $row['id'] . ",<br />\n";
                        } else {
                            $report .= "updated references in " . $row['id'] . ",<br />\n";
                        }
                    }
                }
            }
            $o .= "This page was correctly renamed from '{$old_id}' to '{$new_id}'.<br /><br />\n{$report}";
            ewiki_log("page renamed from '{$old_id}' to '{$new_id}'", 2);
        } else {
            $o .= "Some problems occoured while processing your request, therefor the old page still exists:<br />\n" . $report;
        }
    } elseif (@$_REQUEST["pgc_setmeta"] && $ewiki_ring == 0 && ($set = explode("\n", $_REQUEST["pgc_meta"]))) {
        $new_meta = array();
        foreach ($set as $line) {
            if (($line = trim($line)) && ($key = trim(strtok($line, ":"))) && ($value = trim(strtok("")))) {
                $new_meta[$key] = $value;
            }
        }
        $data["meta"] = $new_meta;
        $data["lastmodified"] = time();
        $data["version"]++;
        if (ewiki_db::WRITE($data)) {
            $o .= "The {meta} field was updated.";
        } else {
            $o .= "A database error occoured.";
        }
    } elseif (@$_REQUEST["pgc_purge"] && $_REQUEST["pgc_purge1"]) {
        $loop = 3;
        do {
            $verZ = $data["version"];
            while ($verZ > 0) {
                ewiki_db::DELETE($id, $verZ);
                $verZ--;
            }
        } while ($loop-- && ($data = ewiki_db::GET($id)));
        if (empty($data)) {
            $o .= "Page completely removed from database.";
            ewiki_log("page '{$id}' was deleted from db", 2);
        } else {
            $o .= "Page still here.";
        }
    } else {
        $o .= '<form action="' . ewiki_script("{$action}", $id) . '" method="POST" enctype="text/html">' . '<input type="hidden" name="id" value="' . "{$action}/{$id}" . '">';
        #-- flags
        $o .= '<div class="flags">';
        $o .= "<h4>page flags</h4>\n";
        foreach ($a_flagnames as $n => $s) {
            $disabled = $ewiki_ring == 1 && !(1 << $n & EWIKI_DB_F_MODERATORFLAGS) ? ' disabled="disabled"' : "";
            $checked = $data["flags"] & 1 << $n ? ' checked="checked"' : "";
            $a[$n] = '<input type="checkbox" name="sflag[' . $n . ']" value="1"' . $checked . $disabled . '> ' . $s;
        }
        $o .= '<table border="0" class="list">' . "\n";
        for ($n = 0; $n < count($a_flagnames); $n++) {
            $y = $n >> 2;
            $x = $n & 0x3;
            if ($x == 0) {
                $o .= "<tr>";
            }
            $o .= "<td>" . $a[4 * $y + $x] . "</td>";
            if ($x == 3) {
                $o .= "</tr>\n";
            }
        }
        $o .= '</table>';
        $o .= '<input type="submit" name="pgc_setflags" value="chmod">';
        $o .= "\n<br /><br /><hr></div>\n";
        #-- rename
        $o .= '<div class="rename">';
        $o .= "<h4>rename page</h4>\n";
        $o .= 'new page name: <input type="text" size="30" name="mv_to" value="' . htmlentities($id) . '">' . '<br />' . '<input type="checkbox" name="mv_cr0" value="1" checked> also try to change all references from other pages accordingly ' . '(<input type="checkbox" name="mv_cr1" value="1" checked> and act case-insensitive when doing so) ';
        $o .= '<br /><input type="submit" name="pgc_rename" value="mv">';
        $o .= "\n<br /><br /><hr></div>\n";
        #-- meta
        if (isset($ewiki_ring) && $ewiki_ring == 0) {
            $o .= '<div class="meta">';
            $o .= "<h4>meta data</h4>\n";
            $o .= '<textarea cols="40" rows="6" name="pgc_meta">';
            if (($uu = @$data["meta"]) && is_array($uu)) {
                foreach ($uu as $key => $value) {
                    if (is_array($value)) {
                        $value = serialize($array);
                    }
                    $o .= htmlentities($key . ": " . trim($value)) . "\n";
                }
            }
            $o .= "</textarea>\n";
            $o .= '<br /><input type="submit" name="pgc_setmeta" value="set">';
            $o .= "\n<br /><br /><hr></div>\n";
        }
        #-- delete
        $o .= '<div class="delete">';
        $o .= "<h4>delete page</h4>\n";
        $o .= '<input type="checkbox" name="pgc_purge1" value="1"> I\'m sure';
        $o .= '<br /><input type="submit" name="pgc_purge" value="rm">';
        $o .= "\n<br /><br /><hr></div>\n";
        $o .= '</form>';
    }
    return $o;
}
         $id = "{$prefix}{$fn}";
         #-- checking for entry
         if ($data = ewiki_db::GET($id)) {
             // our cache entries don't have any flag set
             if ($data["flags"] & EWIKI_DB_F_TYPE) {
                 continue;
                 // real page exists, definetely won't overwrite
             }
         }
         #-- read
         $content = file_get_contents("{$dir}/{$fn}");
         $data = ewiki_db::CREATE($id, 0x0);
         $data["content"] = $content;
         $data["meta"]["class"] = "search";
         #-- write
         ewiki_db::WRITE($id, "_OVERWRITE=1");
     }
 }
 #-- returns only filenames (no dirs) with leading dirspec omitted
 function scan_dir($dir, $pfix = "")
 {
     $r = array();
     $dh = opendir($dir);
     while ($fn = readdir($dh)) {
         if (is_dir("{$dir}/{$pfix}{$fn}")) {
             $r += scan_dir($dir, "{$pfix}{$fn}/");
         } else {
             $r[] = "{$pfix}{$fn}";
         }
     }
     return $r;
Example #17
0
function ewiki_xpi_plugin_control_centre()
{
    ewiki_xpi_load_registry($registry, $registry_hash);
    #-- title
    $o = '<div class="xpi-settings"><h4>plugin control</h4>';
    #-- delete plugins
    if ($access && ($uu = $_REQUEST["xpi_rm"])) {
        foreach ($uu as $id => $del) {
            if ($del) {
                $id = rawurldecode($id);
                $dat = ewiki_db::GET($id);
                $vZ = $dat["version"];
                for ($v = 1; $v <= $vZ; $v++) {
                    ewiki_db::DELETE($id, $v);
                }
                unset($registry[$id]);
                $vZ += 0;
                $o .= "<b>i</b>: Purged {$vZ} versions of '{$id}' and removed xpi registry entry.<br /><br />";
                ewiki_log("uninstalled .xpi/.jpi plugin '{$id}'", 0);
            }
        }
        $_REQUEST["setup_xpi"] = 1;
    }
    #-- update config settings
    if ($_REQUEST["setup_xpi"]) {
        if ($access) {
            foreach ($registry as $id => $uu) {
                $registry[$id]["state"] = $_REQUEST["xpi_set"][rawurlencode($id)] ? 1 : 0;
            }
            $registry_hash["content"] = serialize($registry);
            ewiki_data_update($registry_hash);
            $registry_hash["version"]++;
            ewiki_db::WRITE($registry_hash);
        } else {
            $o .= "You have no privileges to change the status of installed .xpi plugins.<br />\n";
        }
    }
    #-- enable/disable checkboxes
    $o .= '<table border="0" cellspacing="1" cellpadding="2">';
    foreach ($registry as $dat) {
        $enabled = $dat["state"] == 1;
        $hard = $dat["type"] == "page";
        $title = $hard ? ewiki_link($dat["id"]) : $dat["id"];
        $o .= '<tr>' . '<td><tt>' . $dat["type"] . '</tt></td>' . '<td class="xs-check"><input type="checkbox" name="xpi_set[' . rawurlencode($dat["id"]) . ']" value="1"' . ($enabled ? " checked" : "") . ($hard ? " disabled" : "") . '></td>' . '<td class="xs-id">' . $title . '</td>' . '<td><small>' . htmlentities($dat["description"]) . '</small></td>' . '<td>' . $dat["author"] . ", " . $dat["license"] . '</td>' . '<td class="xs-check"><input type="submit" name="xpi_rm[' . rawurlencode($dat["id"]) . ']" value="rm" title="uninstall plugin"' . ($access ? "" : " disabled") . '></td>' . '</tr>';
    }
    $o .= '</table>';
    $o .= '<br /><input type="submit" name="setup_xpi" value="configure"' . ($access ? "" : " disabled") . '>';
    $o .= '</form></div>';
    return $o;
}
Example #18
0
function ewiki_page_userregistry($id, &$data, $action)
{
    global $ewiki_plugins, $ewiki_config, $ewiki_auth_user;
    $o = ewiki_make_title($id, $id, 2, $action);
    $url = ewiki_script("", $id);
    #-- auto-login
    if ($ewiki_auth_user && empty($_REQUEST["userreg_name"])) {
        $user = $ewiki_auth_user;
        $uu = ewiki_auth_userdb_userregistry($ewiki_auth_user);
        $pw = $uu[0];
        $_REQUEST["userreg_login"] = 1;
    } else {
        $user = trim($_REQUEST["userreg_name"]);
        $pw = $_REQUEST["userreg_pw"];
    }
    #-- try to get user entry
    $ue = ewiki_auth_userdb_userregistry($user);
    #-- account creation ---------------------------------------------------
    if ($_REQUEST["userreg_register"] && empty($ue)) {
        $o .= ewiki_t(<<<END
<h4>_{New Account}</h4>
<form action="{$url}" method="POST" enctype="multipart/form-data" accept-encoding="ISO-8859-1">
_{user/login name} <input type="text" size="14" name="userreg_name" value="{$user}"> <br />
<input type="hidden" name="userreg_pw" value="">
<br />
_{password} <input type="password" name="new_pw" size="10" maxsize="12" value="{$pw}"> <br />
_{retype} <input type="password" name="new_pw2" size="10" maxsize="12" value=""> <br />
<br />
<input type="submit" name="userreg_store" value="_{create account}">
</form><br /><br />
END
);
        return $o;
        // finished here, prevent fallthrough-display of login-form
    }
    #-- check password
    if ($ue && $user && !ewiki_auth_user($user, $pw)) {
        $o .= $_REQUEST["userreg_register"] ? ewiki_t("USERNAME_ALREADY_USED") : ewiki_t("WRONG_PW") . "\n" . ewiki_t("PLEASE_RETRY");
        return $o;
    }
    #-- set fallback settings for account creation
    if (empty($ue) && $_REQUEST["userreg_store"]) {
        $ue = $_REQUEST["userreg_ue"] = array($pw, EWIKI_REGISTERED_LEVEL, "", "", "");
    }
    #-- check username
    if (preg_match("/[^" . EWIKI_CHARS_U . EWIKI_CHARS_L . "]/", $user . $pw)) {
        $o .= ewiki_t("PW_ONLY_LETTERS") . "\n" . ewiki_t("PLEASE_RETRY");
        return $o;
    } elseif ($name && strlen($user) < 3) {
        return $o . ewiki_t("USERNAME_MIN");
    }
    #-- save changes -------------------------------------------------------
    if ($_REQUEST["userreg_store"] && $user) {
        #-- new user entry
        $new_ue = $_REQUEST["userreg_ue"] or $new_ue = array();
        $new_ue[0] = $pw;
        $new_ue[1] = $ue[1] or $new_ue[1] = EWIKI_REGISTERED_LEVEL;
        if ($new_pw = $_REQUEST["new_pw"]) {
            if ($new_pw == $_REQUEST["new_pw2"]) {
                $new_ue[0] = md5($new_pw);
            } else {
                $o .= ewiki_t("RETYPE_PW") . "\n<br />";
                return $o;
            }
        }
        foreach ($new_ue as $i => $v) {
            $new_ue[$i] = preg_replace("/[^-@._ \\w\\d" . EWIKI_CHARS_L . EWIKI_CHARS_U . "]/", " ", $v);
        }
        #-- get user db page
        $data = ewiki_db::GET(EWIKI_USERDB_USERREGISTRY) or $data = array("id" => EWIKI_USERDB_USERREGISTRY, "version" => 1, flags => 0, "created" => time(), "lastmodified" => time(), "content" => "nobody:*:3::", "meta" => "", "author" => ewiki_author("{$user}@{$id}"));
        $data["flags"] |= EWIKI_DB_F_SYSTEM;
        $list = explode("\n", $data["content"]);
        #-- update entry
        ksort($new_ue);
        $new_ue = $user . ":" . implode(":", $new_ue);
        $found = 0;
        foreach ($list as $i => $line) {
            $line = trim($line);
            if (strtok($line, ":") == $user) {
                $list[$i] = $new_ue;
                $found = 1;
            }
        }
        if (!$found) {
            $list[] = $new_ue;
        }
        #-- save back
        $data["content"] = implode("\n", $list);
        $retry = 3;
        while ($retry--) {
            $data["version"]++;
            if ($ok = ewiki_db::WRITE($data)) {
                break;
            }
        }
        if ($ok) {
            $o .= ewiki_t("Data saved") . "\n<br />";
        } else {
            $o .= ewiki_t("Error saving") . "\n<br />";
            ewiki_log("_userdb_userregistry: failed to update db for user {$user}, retries={$retry}", 2);
        }
        #-- fallthru to view_settings
        $_REQUEST["userreg_login"] = 1;
        $ue = ewiki_auth_userdb_userregistry($user);
    }
    #-- view settings ----------------------------------------------------
    if ($_REQUEST["userreg_login"]) {
        #-- edit <form>
        $o .= ewiki_t(<<<END
<h4>_{Account Settings}</h4>
<form action="{$url}" method="POST" enctype="multipart/form-data" accept-encoding="ISO-8859-1">
<input type="hidden" name="userreg_name" value="{$user}">
<input type="hidden" name="userreg_pw" value="{$pw}">
<b>_{change password}</b><br />
_{new password} <input type="password" size="10" maxsize="12" name="new_pw" value=""> <br />
_{retype} <input type="password" size="10" maxsize="12" name="new_pw2" value=""> <br />
<br />
<b>_{optional infos}</b><br />
_{personal WikiPage} <input type="text" name="userreg_ue[2]" value="{$ue[2]}"><br />
_{email address} <input type="text" name="userreg_ue[3]" value="{$ue[3]}"><br />
<!--
opt string <input type="text" name="userreg_ue[4]" value="{$ue[4]}"><br />
opt string <input type="text" name="userreg_ue[5]" value="{$ue[5]}"><br />
opt string <input type="text" name="userreg_ue[6]" value="{$ue[6]}"><br />
-->
<br />
<input type="submit" name="userreg_store" value="_{save}">
</form><br /><br />
END
);
    } else {
        $url = ewiki_script("", $id);
        $o .= ewiki_t(<<<END
<form action="{$url}" method="POST" enctype="multipart/form-data" accept-encoding="ISO-8859-1">
<div class="userreg-form-settings">
<div class="userreg-form-register">
_{name} <input type="text" size="14" name="userreg_name"> &nbsp;
<input type="submit" name="userreg_register" value="_{create account}"><br />
</div>
<br />
_{password} <input type="password" size="10" maxsize="12" name="userreg_pw"><br />
<br />
<input type="submit" name="userreg_login" value="_{change settings}">
</div>
</form><br /><br />
END
);
    }
    return $o;
}
Example #19
0
function ewiki_mpi_tableeditor($action, $args, &$iii, &$s)
{
    global $ewiki_id, $ewiki_data;
    #-- config
    $rel = 5 / 2;
    // favoured ratio width to height
    $SEP = "|";
    // table cell separator ("|", or "||" for other Wikis);
    $add_empty_row = 1;
    $w_min = 7;
    $w_stretch = 1.17;
    // + 17%
    $w_max = 35;
    $h_min = 2;
    $h_max = 12;
    #-- analyze current table for cell sizes
    $t = array();
    foreach (explode("\n", trim($args["_"])) as $row) {
        $t[] = explode($SEP, trim(trim($row), $SEP));
    }
    $t_widths = array();
    $t_heights = array();
    $x = count($t[0]);
    $y = count($t);
    for ($row = 0; $row < $y; $row++) {
        for ($col = 0; $col < $x; $col++) {
            $len = strlen($t[$row][$col]);
            $w = sqrt($rel * $len);
            if ($w < $w_min) {
                $w = $w_min;
            }
            $h = max((int) ($len / $w), $h_min);
            $w = (int) ($w * $w_stretch);
            $h = min($h, $h_max);
            $w = min($w, $w_max);
            $t_widths[$col] = max($t_widths[$col], $w);
            $t_heights[$row] = max($t_heights[$row], $h);
        }
    }
    #-- store -----------------------------------------------------------
    $o = '<div class="mpi TableEditor">';
    if ($_REQUEST["te_save"]) {
        $data = ewiki_db::GET($ewiki_id);
        if ($data && $_REQUEST["te_d_ver"] == $data["version"]) {
            if (!preg_match_all('/<\\?plugin:?\\s*TableEditor/i', $data["content"], $uu)) {
                $o .= "Could not detect the exact position of the TableEditor inside the page. Not saved.<br />";
            } elseif (count($uu[0]) >= 2) {
                $o .= "There can only be <b>one</b> TableEditor call in a page!<br />";
            } else {
                $src = "";
                $t = $_REQUEST["te_d"];
                foreach ($t as $y => $row) {
                    $empty = 1;
                    foreach ($row as $x => $cell) {
                        $t[$y][$x] = trim(strtr($cell, "\r\n\t\f", "    "));
                        $empty = $empty && empty($t[$y][$x]);
                    }
                    if ($empty) {
                        unset($t[$y]);
                        continue;
                    }
                    $src .= "{$SEP} " . implode(" {$SEP} ", $t[$y]) . " {$SEP}\n";
                }
                $data["content"] = preg_replace('/<\\?plugin:?\\s*TableEditor.+?\\?>/is', "<?plugin TableEditor\n\n{$src}\n?>", $data["content"]);
                ewiki_data_update($data);
                $data["version"]++;
                ewiki_db::WRITE($data);
            }
        } else {
            $o .= ewiki_t("ERRVERSIONSAVE") . "<br />\n";
        }
    }
    #-- output start ----------------------------------------------------
    $o .= '<form action="' . $_SERVER["REQUEST_URI"] . '" method="POST" enctype="multipart/form-data">' . '<input type="hidden" name="te_d_ver" value="' . $ewiki_data["version"] . '">' . '<input type="hidden" name="id" value="' . htmlentities($ewiki_id) . '">';
    #-- print <textarea> table variant
    if ($_REQUEST["te_load"]) {
        $o .= '<input type="submit" name="te_save" value="SaveTable"><br />';
        $o .= '<table border="1" cellspacing="1" cellpadding="2">';
        if ($add_empty_row) {
            $y++;
        }
        for ($row = 0; $row < $y; $row++) {
            for ($col = 0; $col < $x; $col++) {
                $t[$row][$col] = "<textarea style=\"border:none;background:transparent;\" name=\"te_d[{$row}][{$col}]\" cols=\"{$t_widths[$col]}\" rows=\"{$t_heights[$row]}\" wrap=\"soft\">" . htmlentities(trim($t[$row][$col])) . "</textarea>";
            }
            $o .= '<tr><td>' . implode('</td><td>', $t[$row]) . '</td></tr>' . "\n";
        }
        $o .= "</table>\n";
    } else {
        #-- insert <html> form at current position
        $o .= '<input type="submit" name="te_load" value="TableEditor"><br />';
        $in = $s["in"];
        $iii[$in][0] = "WILL BE REPLACED with \$o...";
        #-- mk table markup, insert into $iii
        $src = "\n\n";
        foreach ($t as $row) {
            $src .= "{$SEP} " . implode(" {$SEP} ", $row) . " {$SEP}\n";
        }
        $src .= "\n";
        $iii = array_merge(array_slice($iii, 0, $in + 1), array(array($src, 0x137f, "core")), array_slice($iii, $in + 1));
        // the following return($o); will insert the <form> into
        // the current input buffer $iii[$in][0] later
    }
    $o .= "</form></div>\n";
    return $o;
}
Example #20
0
   -> creates a cache entry for pages with single-word and non-wiki names
*/
#-- cfg (already in the according plugin)
// define("EWIKI_AUTOLINKING_CACHE", "system/tmp/autolinking");
#-- start if plugin loaded / constant defined
if (defined("EWIKI_AUTOLINKING_CACHE")) {
    #-- start list
    $pages = array();
    #-- find AllPages
    $result = ewiki_db::GETALL(array("id", "flags"));
    while ($row = $result->get()) {
        if (EWIKI_DB_F_TEXT != ($row["flags"] & EWIKI_DB_F_TYPE)) {
            continue;
        }
        $id = $row["id"];
        #-- only care about pagenames, which are words but no WikiWords
        if (!strpos($id, " ") && preg_match('/^\\w+$/', $id) && !preg_match('/^([' . EWIKI_CHARS_U . ']+[' . EWIKI_CHARS_L . ']+){2,}[\\w\\d]*$/', $id)) {
            $pages[] = $id;
        }
    }
    #-- save found pages in cache entry
    $DEST = EWIKI_AUTOLINKING_CACHE;
    $save = array("id" => $DEST, "version" => 1, "flags" => EWIKI_DB_F_SYSTEM, "created" => time(), "lastmodified" => time(), "author" => ewiki_author("PrepareAutolinking"), "content" => "", "meta" => "", "refs" => "\n\n" . implode("\n", $pages) . "\n\n");
    $ok = ewiki_db::WRITE($save, true);
    #-- output results
    if ($ok) {
        echo "[{$cron}]: Written informations about " . count($pages) . " pages into the database cache entry '{$DEST}'" . "\n   These pages will then get autolinked by the according plugin.\n";
    } else {
        echo "[{$cron}]: Error writing the database cache entry '{$DEST}'. Autolinking pages won't work now.\n";
    }
}
Example #21
0
function ewiki_uservars_pages_store($data = NULL, $username = NULL)
{
    global $ewiki_uservars, $ewiki_errmsg;
    if (!isset($username)) {
        $username = $GLOBALS['ewiki_auth_user'];
    }
    if ($username == $GLOBALS['ewiki_auth_user']) {
        if (!isset($data)) {
            $data = $ewiki_uservars;
        } else {
            $ewiki_uservars = $data;
        }
    }
    //echo("<p>Storing user variables for $username</p>");
    $oldpage = ewiki_db::GET(EWIKI_USERVARS_PAGENAME_PREFIX . $username);
    //if there was already an existing, non-system page, fail out.
    if ($oldpage['version'] > 0 && !($oldpage["flags"] & EWIKI_DB_F_SYSTEM)) {
        $ewiki_errmsg = ewiki_t('ERRORSAVING');
        return 0;
    }
    $save = array("id" => EWIKI_USERVARS_PAGENAME_PREFIX . $username, "version" => @$oldpage["version"] + 1, "flags" => EWIKI_DB_F_SYSTEM, "content" => serialize($data), "author" => ewiki_author(), "lastmodified" => time(), "created" => ($uu = @$oldpage["created"]) ? $uu : time(), "meta" => ($uu = @$oldpage["meta"]) ? $uu : "", "hits" => ($uu = @$oldpage["hits"]) ? $uu : "0");
    return ewiki_db::WRITE($save);
}
Example #22
0
        }
        echo '<TR><TD BGCOLOR="#9090B0">';
        echo '<INPUT NAME="file[' . $fn . ']" TYPE="checkbox" VALUE="1" ' . ($sel ? " CHECKED" : "") . '>';
        echo " " . $fn;
        echo "</TD>\n" . '<TD BGCOLOR="#9090B0">';
        echo $reason . "</TD></TR>\n";
    }
    echo '</TABLE>' . '<INPUT TYPE="submit" NAME="insert" VALUE="&nbsp;  insert files  &nbsp;">' . '</FORM>';
} else {
    $from = $_REQUEST["from"];
    $files = $_REQUEST["file"];
    if (strstr(substr($from, 3), "/")) {
        die("unallowed subdir name");
    }
    $from .= "/";
    foreach ($files as $fn => $uu) {
        if (strstr($fn, "/") || strstr($fn, ".") || !$uu) {
            echo "filename '{$fn}' not allowed (NOTE: no versioned pages!)...<br>\n";
            continue;
        }
        $ctime = filectime($from . $fn);
        $content = implode("", file($from . $fn));
        $prev = ewiki_db::GET($fn);
        $data = array("id" => $fn, "version" => 1 + @$prev["version"], "author" => ewiki_author("ewiki_backdown"), "flags" => EWIKI_DB_F_TEXT | @$prev["flags"], "content" => $content, "created" => $ctime, "lastmodified" => time(), "refs" => "\n", "meta" => "", "hits" => 0 + @$prev["hits"]);
        $r = ewiki_db::WRITE($data) ? "ok" : "error";
        echo "writing '{$fn}'... [{$r}]<br>\n";
    }
}
?>
</body>
</html>
Example #23
0
            if ($idf != EWIKI_TRANSFER_IDF) {
                die("This is not an ewiki transfer binary. (wrong magic code 0x" . bin2hex($idf) . ")");
            }
        }
        $count = $fgets($i, 4096);
        if ($count === false || ($count = trim($count)) <= 0) {
            if ($feof($i)) {
                $fclose($i);
                die("<br><b>finished reading</b> {$n} entries");
            } else {
                die("<br><b>file broken</b> (zero count block) after {$n} entries");
            }
        }
        $row = $fread($i, $count);
        $row = unserialize($row);
        if (ewiki_db::WRITE($row)) {
            echo $row["id"] . "." . $row["version"] . " &nbsp;\n";
        }
        $n++;
    }
} else {
    ?>
<html>
<head>
 <title>make binary backup of whole database</title>
 <link rel="stylesheet" type="text/css" href="t_config.css">
</head>
<body bgcolor="#ffffff" text="#000000">

     <h1>database dump</h1>
     If you cannot make use of the <b>ewikictl</b> cmdline utility, and need
Example #24
0
function ewiki_put_cache($action, $id, &$o)
{
    #-- save into cache dir
    if (defined("EWIKI_CACHE_DIR") && EWIKI_CACHE_DIR) {
        $file = EWIKI_CACHE_DIR . "/" . $action . "," . urlencode($id);
        $f = gzopen($file, "w9");
        if ($f) {
            gzwrite($f, $o);
            fclose($f);
        }
    } elseif (defined("EWIKI_CACHE_DB") && EWIKI_CACHE_DB) {
        $id = EWIKI_CACHE_DB . "{$action}/{$id}";
        $save = array("id" => $id, "version" => 1, "flags" => EWIKI_DB_F_BINARY¦EWIKI_DB_F_TEXT | EWIKI_DB_F_HTML, "created" => $data["lastmodified"], "lastmodified" => time(), "content" => &$o, "meta" => array("class" => "cache"), "author" => ewiki_author("ewiki_cache"));
        ewiki_db::WRITE($save, true);
    }
}
Example #25
0
function ewiki_mpi_bugreport($action, $args, &$iii, &$s)
{
    global $ewiki_id;
    $MAIN = $ewiki_id;
    //"BugReports";
    $ELSE = $args[0] or $ELSE = rtrim($MAIN, "s");
    $o = "";
    if ($_REQUEST["br_save"]) {
        #-- check parameters
        $content = $_REQUEST["content"];
        $title = $_REQUEST["title"];
        $author = $_REQUEST["author"];
        if (strlen($content) < 50) {
            return "<p><b>Insufficient information for a useful BugReport.</b></p>";
        }
        if (strstr($title, "???")) {
            $title = substr($content, 0, 50);
        }
        #-- make page name for bug report
        $new_id = ewiki_title_to_pagename($title, $ELSE);
        #-- generate bug page text
        $new = "This page is part of the {$MAIN} series. Please go there to submit a new bug or to see the list of all existing reports.\n";
        if ($m = $_REQUEST["br_notify"]) {
            $new .= "\n[notify:{$m}]\n";
        }
        $new .= "\n----\n\n" . "!! {$title}\n\n";
        foreach ($_REQUEST["i"] as $i => $v) {
            if ($v != "unknown") {
                $new .= "| {$i} | {$v} |\n";
            }
        }
        $new .= "| status | __open__ |\n <?plugin BugReportState ?" . "> \n";
        $new .= "\n{$author}: {$content}\n\n";
        #-- create new bug report page
        $data = ewiki_db::CREATE($new_id);
        $data["content"] = $new;
        ewiki_db::UPDATE($data);
        $data["version"] = 1;
        $ok = ewiki_db::WRITE($data);
        if (!$ok) {
            return "<b>Error</b> while creating new bug report page. Please go back and change the title (at least two words required), so we can try again.";
        }
        #-- store bugreport entry on main page
        $data = ewiki_db::GET($MAIN);
        $list_e = "| __open__ | {$new_id} | {$title} |\n";
        $data["content"] = preg_replace("/(\n\\|.+\\|.+\\|\\s*\n)/", "\$1{$list_e}", $data["content"], 1);
        ewiki_db::UPDATE($data);
        $data["version"]++;
        ewiki_db::WRITE($data);
        if ($notify = function_exists($pf = "ewiki_notify_edit_hook")) {
            $pf($MAIN, $data, $uu);
        }
        #-- append to page output
        $iii[] = array("\n\n| new bug report [#added \"added\"] as {$new_id} |\n\n", 0xffff, "core");
    } else {
        $url = ewiki_script("", $ewiki_id);
        $ver = EWIKI_VERSION;
        $current_vers = "<option>{$ver}";
        for ($i = $ver[strlen($ver) - 1] - 1; $i > 0; $i--) {
            $current_vers .= "<option>" . substr($ver, 0, strlen($ver) - 1) . $i;
        }
        $o .= <<<EOT
<form style="border:2px #444455 solid; background:#9999aa; padding:5px;"class="BugReport" action="{$url}#added" method="POST" enctype="multipart/form-data">
bug title: <input type="text" name="title" value="???" size="50">
<br/>
<br/>
YourName: <input type="text" name="author" value="anonymous" size="30">
<br/>
<br/>
your ewiki version: <select name="i[ewiki version]"><option>unknown<option>other{$current_vers}<option>CVS today<option>CVS yesterday<option>CVS last week<option>two weeks old<option>latest -dev<option>R1.02a<option>R1.01f<option>R1.01e<option>R1.01d<option>R1.01c<option>R1.01b<option>R1.01a</select>
plattform: <select name="i[operating system]"><option>unknown<option>other<option>Win4<option>NT (2K,XP)<option>Unix<option>Linux<option>OS X</select>
<br/>
database: <select name="i[database backend]"><option>unknown<option>mysql<option>db_flat_files<option>db_fast_files<option>anydb: other<option>anydb: pgsql<option>dzf2<option>dba/dbm<option>phpwiki13<option>zip<option>other<option>own</select>
php version: <select name="i[php version]"><option>unknown<option>4.0.x<option>4.1.x<option>4.2.x<option>4.3.x<option>4.4/4.5 (CVS)<option>5.0-beta/rc<option>5.0.x<option>CGI/suPHP<option>PHP/FastCGI<option>SafeMode 4.x</select>
<br>
problem category (vague): <select name="i[bug category]"><option>unknown<option>general<option>feature request<option>get running<option>markup<option>links<option>error message<option>plugin<option>page plugin<option>action plugin<option>auth plugin<option>aview plugin<option>edit plugin<option>feature extension<option>link tweak plugin<option>mpi plugin<option>spages<option>lib extension<option>module plugin<option>db plugin<option>configuration<option>documentation</select>
<br/>
<br/>
long error description:<br /> 
<textarea name="content" cols="75" rows="8">
</textarea>
<br/><br/>
<input type="submit" name="br_save" value="create bug page">
<br/>
<br/>
email notification <input type="text" name="br_notify" value="" size="16">
<br/><small>(opt., only enter if you want get notified on any responses)</small>
<br/>
</form>
EOT;
    }
    return $o;
}
Example #26
0
function ewiki_initialization_wizard($id, &$data, &$action)
{
    global $ewiki_plugins;
    #-- proceed only if frontpage missing or explicetely requested
    if (strtolower($id) == "wikisetupwizard" || $id == EWIKI_PAGE_INDEX && $action == "edit" && empty($data["version"]) && !$_REQUEST["abort"]) {
        if ($_REQUEST["abort"]) {
        } elseif (empty($_REQUEST["init"])) {
            $o = "<h2>WikiSetupWizard</h2>\n";
            $o .= "You don't have any pages in your Wiki yet, so we should try to read-in the default ones from <tt>init-pages/</tt> now.<br /><br />";
            $o .= '<a href="' . ewiki_script("", $id, array("init" => "now")) . '">[InitializeWikiDatabase]</a>';
            $o .= " &nbsp; ";
            $o .= '<a href="' . ewiki_script("", $id, array("abort" => "this")) . '">[NoThanks]</a>';
            $o .= "<br /><br />";
            #-- analyze and print settings and misconfigurations
            $pf_db = $ewiki_plugins["database"][0];
            $db = substr("_{$pf_db}", strrpos($pf_db, "_") + 1);
            $o .= '<table border="0" width="90%" class="diagnosis">';
            $o .= '<tr><td>DatabaseBackend</td><td>';
            $o .= "<b>" . $db . "</b><br />";
            if ($db == "files" || strstr($db, "f2")) {
                $o .= "<small>_DBFILES_DIR='</small><tt>" . EWIKI_DBFILES_DIRECTORY . "'</tt>";
                if (strpos(EWIKI_DBFILES_DIRECTORY, "tmp")) {
                    $o .= "<br /><b>Warning</b>: Storing your pages into a temporary directory is not what you want (there they would get deleted randomly), except for testing purposes of course. See the README.";
                }
            } else {
                $o .= "(looks ok)";
            }
            $o .= "</td></tr>";
            $o .= '<tr><td>WikiSoftware</td><td>ewiki ' . EWIKI_VERSION . "</td></tr>";
            $o .= "</table>";
            #-- more diagnosis
            if (ini_get("magic_quotes")) {
                $o .= "<b>Warning</b>: Your PHP interpreter has enabled the ugly and outdated '<i>magic_quotes</i>'. This will lead to problems, so please ask your provider to correct it; or fix it yourself with .htaccess settings as documented in the README. Otherwise don't forget to include() the <tt>fragments/strip_wonderful_slashes.php</tt> (it's ok to proceed for the moment).<br /><br />";
            }
            if (ini_get("register_globals")) {
                $o .= "<b>Security warning</b>: The horrible '<i>register_globals</i>' setting is enabled. Without always using <tt>fragments/strike_register_globals.php</tt> or letting your provider fix that, you could get into trouble some day.<br /><br />";
            }
            return '<div class="wiki view WikiSetupWizard">' . $o . '</div>';
        } else {
            ewiki_db::INIT();
            if ($dh = @opendir($path = EWIKI_INIT_PAGES)) {
                while ($filename = readdir($dh)) {
                    if (preg_match('/^([' . EWIKI_CHARS_U . ']+[' . EWIKI_CHARS_L . ']+\\w*)+/', $filename)) {
                        $found = ewiki_db::FIND(array($filename));
                        if (!$found[$filename]) {
                            $content = implode("", file("{$path}/{$filename}"));
                            ewiki_scan_wikiwords($content, $ewiki_links, "_STRIP_EMAIL=1");
                            $refs = "\n\n" . implode("\n", array_keys($ewiki_links)) . "\n\n";
                            $save = array("id" => "{$filename}", "version" => "1", "flags" => "1", "content" => $content, "author" => ewiki_author("ewiki_initialize"), "refs" => $refs, "lastmodified" => filemtime("{$path}/{$filename}"), "created" => filectime("{$path}/{$filename}"));
                            ewiki_db::WRITE($save);
                        }
                    }
                }
                closedir($dh);
                ewiki_log("initializing database", 0);
            } else {
                return "<b>ewiki error</b>: could not read from directory " . realpath($path) . "<br />\n";
            }
            #-- try to view/ that newly inserted page
            if ($data = ewiki_db::GET($id)) {
                $action = "view";
            }
            #-- let ewiki_page() proceed as usual
            return "";
        }
    }
}
Example #27
0
    }
    echo '</table><input type="submit" value="&nbsp;    change settings    &nbsp;"></form>';
} else {
    foreach ($_REQUEST["set"] as $page => $fa) {
        $page = rawurldecode($page);
        $flags = 0;
        $fstr = "";
        foreach ($fa as $num => $isset) {
            if ($isset) {
                $flags += $num;
                $fstr .= ($fstr ? "," : "") . $FD[$num];
            }
        }
        echo "· " . htmlentities($page) . " ({$flags}=<small>[{$fstr}]</small>)";
        $data = ewiki_db::GET($page);
        if ($data["flags"] != $flags) {
            $data["flags"] = $flags;
            $data["author"] = "ewiki-tools, " . ewiki_author();
            $data["version"]++;
            ewiki_db::WRITE($data);
            echo " <b>[set]</b>";
        } else {
            echo " [not changed]";
        }
        echo "<br>\n";
    }
}
function strong_htmlentities($str)
{
    return preg_replace('/([^-., \\w\\d])/e', '"&#".ord("\\1").";"', $str);
}
Example #28
0
<?php

/*
   This part writes back the $anacron[] timestamps, so we can keep track
   of when we run which parts in here.
*/
#-- update
if ($anacron && ANACRON_ID) {
    echo "[{$cron}]: writing back anacron timestamps\n";
    #-- get old
    $data = ewiki_db::GET(ANACRON_ID) or $data = ewiki_db::CREATE(ANACRON_ID);
    #-- vars
    $data["flags"] = EWIKI_DB_F_SYSTEM;
    ewiki_db::UPDATE($data);
    $data["lastmodified"] = $anacron["last"] = EWIKI_CRON;
    $data["content"] = serialize($anacron);
    #-- overwrite
    ewiki_db::WRITE($data, 1) or $data["version"]++ && ewiki_db::WRITE($data);
}
Example #29
0
 function PUT($path, $ct, $charset)
 {
     #-- let's call the auth routine once more??
     $this->auth();
     #-- get old page version
     $id = $this->id($path);
     $data = ewiki_db::GET($id) or $data = ewiki_db::CREATE($id);
     #-- read from whereever
     $data["content"] = $this->get_body();
     #-- check content-type
     if ($ct != "text/wiki" && $ct != "text/plain") {
         return "422 Only WikiPages Accepted";
     }
     #-- save back to db
     ewiki_db::UPDATE($data);
     $data["version"] += 1;
     $ok = ewiki_db::WRITE($data);
     #-- handle response here
     if ($ok) {
         return "200 Written Successfully";
     }
     return "500 Couldn't Save";
 }
Example #30
0
function ewiki_auth_get_users_groups($user)
{
    #-- get "system/groups" page
    $gp = ewiki_db::GET(EWIKI_USERDB_SYSTEMGROUPS);
    if ($gp["version"] && !($gp["flags"] & EWIKI_DB_F_SYSTEM)) {
        $gp["flags"] |= EWIKI_DB_F_SYSTEM;
        $gp["version"]++;
        ewiki_db::WRITE($gp);
        // secure it as _SYSTEM page
    }
    $user_groups = array();
    if (empty($user)) {
        return $user_groups;
    }
    #-- go through all the lines in the groups file
    if ($list = explode("\n", $gp["content"])) {
        foreach ($list as $line) {
            #--- quick initial check for string occourence
            if (strpos($line, $user)) {
                #-- break line into parts
                $line = trim($line);
                if ($line[0] == "#") {
                    continue;
                }
                if (!($group = strtok($line, ":"))) {
                    continue;
                }
                $uu = strtok(":");
                #-- this removes the "*:" we don't care
                $line = strtok("");
                if (strlen($uu) > 1) {
                    $line .= " {$uu}";
                }
                #-- convert delimeters into spaces and lookup $user string
                $line = strtr($line, EWIKI_USERDB_GROUPDELIMS, "        ");
                if (strpos(" {$line} ", " {$user} ")) {
                    $user_groups[] = $group;
                }
            }
        }
    }
    return $user_groups;
}