Ejemplo n.º 1
0
function ewiki_handler_jump(&$id, &$data, &$action)
{
    global $ewiki_config;
    static $redirect_count = 5;
    $jump_markup = array("jump", "goto", "redirect", "location");
    #-- we only care about "view" action
    if ($action != "view") {
        return;
    }
    #-- escape from loop
    if (isset($_REQUEST[EWIKI_UP_REDIRECT_COUNT])) {
        $redirect_count = $_REQUEST[EWIKI_UP_REDIRECT_COUNT];
    }
    if ($redirect_count-- <= 0) {
        return ewiki_t("REDIRECTION_LOOP", array("id" => $id));
    }
    #-- search for [jump:...]
    if ($links = explode("\n", trim($data["refs"]))) {
        foreach ($links as $link) {
            if (strlen($link) && strpos($link, ":") && in_array(strtolower(strtok($link, ":")), $jump_markup) && ($dest = trim(strtok("\n")))) {
                #-- URL
                $url = "";
                if (strpos($dest, "://")) {
                    $url = $dest;
                } else {
                    $url = ewiki_interwiki($dest, $uu, $uu2);
                }
                #-- Location:
                if (EWIKI_JUMP_HTTP && EWIKI_HTTP_HEADERS && !headers_sent()) {
                    #-- simple PageLink
                    if (empty($url)) {
                        $url = ewiki_script("", $dest, array(EWIKI_UP_REDIRECT_COUNT => $redirect_count), 0, 0, ewiki_script_url());
                        $url .= defined("SID") ? EWIKI_ADDPARAMDELIM . SID : "";
                    }
                    header("Location: {$url}");
                    die;
                } elseif ($url) {
                    return "";
                    # the rendering kernel will just show up the [jump:]!
                    # (without the jump: of course)
                } else {
                    #-- we'll just restart ewiki
                    $data = array();
                    $id = $dest;
                    return ewiki_page("view/" . $id);
                }
            }
        }
    }
    #-search
}
Ejemplo n.º 2
0
function ewiki_add_action_link_for_translation($id, &$data, $action)
{
    global $language_comb, $language_service, $language_names, $ewiki_t, $ewiki_config;
    $o = "";
    $url = "";
    if ($data["version"]) {
        $lang_src = ewiki_guess_lang($data["content"]);
        #-- check if page is already in desired language
        if ($ewiki_t["languages"][0] == $lang_src) {
        } else {
            foreach ($ewiki_t["languages"] as $lang_dest) {
                $url = "";
                $comb = "{$lang_src}|{$lang_dest}";
                foreach ($language_service as $SERVICE => $params) {
                    if (in_array($comb, $language_comb[$SERVICE]) || $SERVICE == "intertran") {
                        if ($SERVICE == "babelfish") {
                            $lp = "&" . $params[1] . "=" . strtr($comb, "|", "_");
                        } elseif ($SERVICE == "google") {
                            $lp = "&" . $params[1] . "=" . $comb;
                        } else {
                            $from = $language_names[strtok($comb, "|")];
                            $to = $language_names[strtok("|")];
                            if (!$from || !$to) {
                                continue;
                            }
                            $lp = "&" . $params[1][0] . "=" . $from . "&" . $params[1][1] . "=" . $to;
                        }
                        $url = $params[0] . $lp . "&" . $params[2] . "=" . urlencode(ewiki_script($action, $id, "", 0, 0, ewiki_script_url()));
                        break;
                    }
                }
                #-- add translation link to page
                if ($url) {
                    $ewiki_config["action_links"]["view"][$url] = "TranslateInto" . $ewiki_t["C"][$lang_dest];
                    /*---
                         $o = "<br /><a class=\"tool-button\" href=\""
                         . $url . "\">"
                         . "TranslateInto" . $ewiki_t["C"][$lang_dest]
                         . "</a>\n";
                      ---*/
                    break;
                }
            }
        }
    }
    /*---
       return($o);
    ---*/
}
Ejemplo n.º 3
0
function ewiki_action_infoqdiff_plain($id, $data, $prev, $ver)
{
    $CLK = "%c";
    #-- get
    if ($d = ewiki_db::GET($id, $ver - 1)) {
        $curr = $prev;
        $prev = $d;
        $d = NULL;
    } else {
        continue;
    }
    #-- info header
    $o .= '<p>';
    $o .= 'Version: <b><a href="' . ewiki_script_url("", $id, "version={$ver}") . "\">version {$ver}</a></b> / " . 'Author: <b>' . ewiki_author_html($curr["author"]) . "</b> / " . 'Time: <b>' . strftime($CLK, $curr["lastmodified"]) . "</b>";
    $o .= '</p>';
    #-- diff part
    $diff = ewiki_stupid_diff($curr["content"], $prev["content"], $show_unchanged = 0, $magic_notes = 1);
    $o .= '<p>' . $diff . '</p>';
    return $o;
}
Ejemplo n.º 4
0
function ewiki_page_edit($id, $data, $action)
{
    global $ewiki_links, $ewiki_author, $ewiki_plugins, $ewiki_ring, $ewiki_errmsg;
    $content = optional_param('content', '');
    $version = optional_param('version', '');
    $preview = optional_param('preview', false);
    $save = optional_param('save', false);
    $hidden_postdata = array();
    #-- previous version come back
    if (@$data["forced_version"]) {
        $current = ewiki_database("GET", array("id" => $id));
        $data["version"] = $current["version"];
        unset($current);
        /// Is this done for somewhere else?
        $_REQUEST['content'] = $_POST['content'] = $_GET['content'] = null;
        $_REQUEST['version'] = $_POST['version'] = $_GET['version'] = null;
        $content = '';
        $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 ($preview) {
        $o .= $ewiki_plugins["edit_preview"][0]($data);
    }
    #-- save
    if ($save) {
        #-- normalize to UNIX newlines
        $content = str_replace("\r\n", "\n", $content);
        $content = str_replace("\r", "\n", $content);
        #-- check for concurrent version saving
        $error = 0;
        if (@$data["version"] >= 1 && $data["version"] != $version || $version < 1) {
            $pf = $ewiki_plugins["edit_patch"][0];
            if (!$pf || !$pf($id, $data)) {
                $error = 1;
                $o .= ewiki_t("ERRVERSIONSAVE") . "<br /><br />";
            }
        }
        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" => $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") . "<br /><br />";
                $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 .= '<meta http-equiv="Refresh" content="0; URL=' . s($url) . '">';
                    }
                }
            }
        }
        //@REWORK
        // header("Reload-Location: " . ewiki_script("", $id, "", 0, 0, ewiki_script_url()) );
    } else {
        #-- Edit <form>
        $o .= ewiki_page_edit_form($id, $data, $hidden_postdata);
        #-- additional forms
        if ($pf_a = $ewiki_plugins["edit_form_final"]) {
            foreach ($pf_a as $pf) {
                $pf($o, $id, $data, $action);
            }
        }
    }
    return $o;
}
Ejemplo n.º 5
0
<meta name="wiki.base" content="<?php 
echo ewiki_script_url();
?>
" />
<meta name="wiki.moniker" content="<?php 
echo EWIKI_NAME;
?>
" />
<?php 
/*
   adds a few html <head> meta tags, if appropriate:
   - NOINDEX for old revisions   
*/
if (isset($_REQUEST["version"]) or $ewiki_data["lastmodified"] + 12 * 60 * 60 > time()) {
    echo '<meta name="ROBOTS" content="NOINDEX,NOFOLLOW,NOCOUNT,NOARCHIVE" />' . "\n";
} elseif (isset($ewiki_id) && empty($ewiki_data["version"])) {
    echo '<meta name="ROBOTS" content="NOINDEX,NOARCHIVE" />' . "\n";
}
Ejemplo n.º 6
0
function ewiki_opensearch_api($query, $params)
{
    #-- database connection
    // should already be established
    #-- check request params
    $params = (array) $params + array("n_hit" => 1000, "m_title" => 3.0, "q_pos" => 2.0, "q_not" => 0.0, "limit" => 5000);
    $n_hit = $params["n_hit"];
    $q_pos = $params["q_pos"];
    $q_not = $params["q_not"];
    $calc = array();
    #-- search target field mapped to internal SQL row names
    $fieldnames = array("title" => "title", "text" => "text", "" => "content", "author" => "author", "links" => "links", "meta" => "meta", "filename" => "title");
    #-- sort request terms into MUST and NOT ------------------------ SQL ---
    $sql = array("MUST" => array(), "NOT" => array());
    foreach ($query as $i => $qterm) {
        list($pattern, $dep, $field, $flags) = $qterm;
        $f_regex = strpos($flags, "REGEX") !== false;
        $f_nocase = strpos($flags, "NOCASE") !== false;
        $m_field = isset($params["m_{$field}"]) ? $params["m_{$field}"] : 0;
        if ($field = $fieldnames[$field]) {
            $pattern = mysql_escape_string($pattern);
            if ($f_regex) {
                $s = "{$field} REGEXP '{$pattern}'";
            } elseif ($f_nocase) {
                $pattern = strtolower($pattern);
                $s = "LOCATE('{$pattern}', LCASE({$field})) > 0";
            } else {
                $s = "LOCATE('{$pattern}', {$field}) > 0";
            }
            #-- add
            $sql[$dep][] = "({$s})";
        }
        $calc[] = array($pattern, $dep, $field, $f_regex, $f_nocase, $m_field);
    }
    if ($q_not) {
        $sql_MUST = implode(" OR ", $sql["MUST"]);
        $sql_NOT = "";
    } else {
        $sql_MUST = implode(" AND ", $sql["MUST"]);
        $sql_NOT = implode(" OR ", $sql["NOT"]);
        if ($sql_NOT) {
            $sql_NOT = " AND NOT ({$sql_NOT})";
        }
    }
    #-- last validity checks
    if (!$sql_MUST) {
        // no way to send an error with ED xmlrpclib ?
        return "551: at least one MUST search term must be given";
    }
    #-- get hit list
    $sql_DB_F_TEXT = "((flags & 1) > 0) AND";
    $sql_query_result = mysql_query($sql = "\n      SELECT\n         pagename AS id, version AS version,\n         pagename AS title,\n         content AS text,\n         CONCAT(pagename, content) AS content,\n         meta,\n         author,\n         refs AS links,\n         lastmodified,\n         created,\n         flags\n      FROM\n         ewiki\n      WHERE\n         {$sql_DB_F_TEXT}\n         {$sql_MUST}\n         {$sql_NOT}\n      GROUP BY id ORDER BY version\n   ");
    #-- start hit score calculation ---------------------------------- CALC ---
    $result_list = array();
    $ordered_list = array();
    if ($sql_query_result) {
        while ($row = mysql_fetch_array($sql_query_result)) {
            $score = 0.0;
            // final score
            $m_fin = 1.0;
            // to eventually decrease it later
            #-- score each search term for hit
            foreach ($calc as $qterm) {
                list($pattern, $dep, $field, $f_regex, $f_nocase, $m_field) = $qterm;
                #-- minscore
                $add = $n_hit;
                if ($m_field) {
                    $add *= $m_field;
                }
                #-- regex hit
                if ($f_regex) {
                    $ok = preg_match($pattern, $row["field"]);
                    if ($dep == "MUST") {
                        $score += $add * ($ok ? 1.0 : $q_not);
                    } elseif ($dep == "NOT") {
                        if ($ok) {
                            $m_fin *= $q_not;
                        }
                    }
                } else {
                    $text = $f_nocase ? strtolower($row[$field]) : $row[$field];
                    $len = strlen($text) + 1;
                    #-- add points for each hit, weighted by match position
                    if ($dep == "MUST") {
                        $p = -1;
                        while (false !== ($p = strpos($text, $pattern, $p + 1))) {
                            $score += $add * ($q_pos - ($q_pos - 1) * ($p / $len));
                        }
                    } elseif (strpos($text, $pattern) !== false) {
                        $m_fin *= $q_not;
                    }
                }
            }
            #-- add to list
            if ($score *= $m_fin) {
                $result_list[] = array("title" => $row["title"], "url" => ewiki_script_url("", $row["title"]), "excerpt" => substr(strtr($row["text"], "\r\n\t\f", "    "), 0, 300), "score" => $score, "lastmodified" => $row["lastmodified"]);
                $ordered_list[] = $score;
            }
        }
    }
    #-- sort result?
    arsort($ordered_list);
    foreach ($ordered_list as $i => $uu) {
        $ordered_list[$i] = $result_list[$i];
        unset($result_list[$i]);
    }
    $result_list =& $ordered_list;
    #-- done
    return $ordered_list;
}
Ejemplo n.º 7
0
function ewiki_feed_rss1($info, $pages)
{
    header('Content-Type: application/rss+xml; revision="1.0"');
    $name = $info["title"];
    $urnpfix = "x-wiki";
    // uniform resource name prefix ("urn:x-wiki" was ok)
    #-- parts
    $_logo = $info["logo"] ? "<image rdf:resource=\"{$urnpfix}:{$name}:logo#1\" />\n" : "";
    echo <<<EOT
<?xml version="1.0" encoding="{$info['charset']}"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:RSS="http://purl.org/rss/1.0/"
xmlns:wiki="http://purl.org/rss/1.0/modules/wiki/">
  <RSS:channel rdf:about="{$info['url']}">
    <RSS:title>{$name}</RSS:title>
    <dc:title>{$name}</dc:title>
    <RSS:link>{$info['rc_url']}</RSS:link>
    <RSS:description>UpdatedPages on {$name}</RSS:description>
    <wiki:interwiki>{$name}</wiki:interwiki>
    {$_logo}
    <RSS:items>
      <rdf:Seq>

EOT;
    #-- output Seq ids
    foreach ($pages as $i => $data) {
        $pages[$i]["rdf_id"] = "{$urnpfix}:{$name}:" . ewiki_xmlentities(urlencode($data["id"])) . "#{$data['version']}_{$data['lastmodified']}";
        echo '        <rdf:li rdf:resource="' . $pages[$i]["rdf_id"] . '"/>' . "\n";
    }
    //<?
    echo <<<EOT
      </rdf:Seq>
    </RSS:items>
  </RSS:channel>
<!-- RDF associated data for references from above -->

EOT;
    #-- logo
    if ($_logo) {
        echo <<<EOT
  <RSS:image rdf:about="{$urnpfix}:{$name}:logo#1">
    <RSS:title>{$name}</RSS:title>
    <RSS:link>{$url}</RSS:link>
    <RSS:url>{$info['logo']}</RSS:url>
  </RSS:image>

EOT;
    }
    //<?
    #-- write items
    foreach ($pages as $i => $data) {
        preg_match('/^([^\\s]+).+\\(.*([\\d.]+)\\)/', $data["author"], $uu);
        $author_host = $uu[2];
        $author_name = $uu[1];
        $url_diff = ewiki_script_url("diff", $data["id"]);
        $url_info = ewiki_script_url("info", $data["id"]);
        $stat = $data["version"] == 1 ? "created" : "updated";
        echo <<<EOT
  <RSS:item rdf:about="{$data['rdf_id']}">
    <RSS:title>{$data['title']}</RSS:title>
    <dc:title>{$data['title']}</dc:title>
    <RSS:description>{$data['content']}</RSS:description>
    <RSS:link>{$data['url']}</RSS:link>
    <wiki:diff>{$url_diff}</wiki:diff>
    <wiki:history>{$url_info}</wiki:history>
    <wiki:version>{$data['version']}</wiki:version>
    <wiki:status>{$stat}</wiki:status>
    <dc:date>{$data['idate']}</dc:date>
    <dc:contributor>
      <rdf:Description wiki:host="{$author_host}">
        <rdf:value>{$author_name}</rdf:value>
      </rdf:Description>
    </dc:contributor>
  </RSS:item>

EOT;
    }
    //<?
    echo "</rdf:RDF>\n";
    die;
}
Ejemplo n.º 8
0
function ewiki_pingback_start()
{
    global $ewiki_plugins, $ewiki_config, $ewiki_id;
    $source_url = ewiki_script_url("", $ewiki_id);
    foreach ($ewiki_config["pingback"] as $target_url) {
        ewiki_pingback_ping($source_url, $target_url);
    }
}
Ejemplo n.º 9
0
                $m_flags .= " MINOR EDIT";
            }
            if ($row["flags"] & EWIKI_DB_F_APPENDONLY) {
                $m_flags .= " (append-only)";
            }
            if ($row["flags"] & EWIKI_DB_F_HIDDEN) {
                $m_flags .= " (hidden page)";
            }
            $datestr = strftime("%Y-%m-%d, %a", $lm);
            if ($lastdatestr != $datestr) {
                $lastdatestr = $datestr;
                $mail .= "\n{$datestr}\n";
            }
            $mail .= "· {$id} - [{$m_ver}]{$m_flags} {$m_time} . . .{$m_log} by {$m_author} / {$m_ua}\n";
            #-- check previous version of this page
            if ($ver-- && ($row = ewiki_db::GET($id, $ver))) {
                if ($row["lastmodified"] >= $min_time) {
                    $vers[$id] = $row["version"];
                    $rc[$id] = $row["lastmodified"];
                    arsort($rc);
                }
            }
        } while ($rc);
        #-- send it
        echo "{$mail}";
        $subj = RECENTNOTIFY . " on " . EWIKI_NAME;
        $to = implode(", ", $subscribers);
        $mail = "This is the full list of latest changes on " . EWIKI_NAME . ".\n" . ewiki_script_url("", EWIKI_PAGE_INDEX) . "\n" . "Unsubscribe yourself on " . ewiki_script_url("edit", RECENTNOTIFY) . "\n" . "\n" . $mail . "\n\n-- \nThere is no Web like WikiWikiWeb.\n";
        mail($to, $subj, $mail);
    }
}