示例#1
0
function macro_info($formatter, $value, $options = array())
{
    global $DBInfo;
    if (empty($DBInfo->interwiki)) {
        $formatter->macro_repl('InterWiki', '', array('init' => 1));
    }
    $value = (empty($value) and !empty($DBInfo->info_options)) ? $DBInfo->info_options : $value;
    $args = explode(',', $value);
    if (is_array($args)) {
        foreach ($args as $arg) {
            $arg = trim($arg);
            if ($arg == 'simple') {
                $options['simple'] = 1;
            } else {
                if ($arg == 'ago') {
                    $options['ago'] = 1;
                }
            }
        }
    }
    $warn = '';
    if ($DBInfo->version_class) {
        $version = $DBInfo->lazyLoad('version', $DBInfo);
        $out = $version->rlog($formatter->page->name, '', '-r', '-z');
        // get the number of total revisions and the last revision.
        $total = 1;
        if (preg_match('/^total revisions: (\\d+);/m', $out, $m)) {
            $total = $m[1];
        }
        $rev = array();
        $rev0 = '';
        if (preg_match('/^revision 1.(\\d+)+\\s/m', $out, $m)) {
            $rev0 = $m[1];
            $rev[$rev0] = '1.' . $rev0;
        }
        if (!empty($DBInfo->rcs_check_broken) and method_exists($version, 'is_broken')) {
            $is_broken = $version->is_broken($formatter->page->name);
            if ($is_broken) {
                $warn = '<div class="warn">' . _("WARNING: ") . _("The history information of this page is broken.") . "</div>";
            }
        }
        // parse 'rev' query string
        $rev1 = '';
        if (!empty($options['rev']) and preg_match('/^1\\.(\\d+)$/', $options['rev'], $m)) {
            if ($m[1] < $rev0) {
                $rev[$m[1]] = '1.' . $m[1];
            }
        }
        $r = array_keys($rev);
        $range_max = !empty($DBInfo->info_range_max) ? $DBInfo->info_range_max : 30;
        $anon_range_limit = !empty($DBInfo->info_anonymous_range_limit) ? $DBInfo->info_anonymous_range_limit : $range_max;
        if ($options['id'] == 'Anonymous' && $r[0] - $r[1] > $anon_range_limit) {
            unset($rev[$r[1]]);
            unset($r[1]);
            $warn = '<div class="warn">' . _("WARNING: ") . _("Anonymous user is not allowed to see older versions.") . "</div>";
        }
        // make a range list like as "1.234:1.240\;1.110:1.140"
        $revstr = '';
        $count = 10;
        if (count($r) > 1) {
            if ($r[0] - $r[1] > $range_max) {
                $revstr .= '1.' . max($r[0] - 1, 0) . ':' . $rev[$r[0]];
                $revstr .= '\\;1.' . max($r[1] - $count, 0) . ':' . $rev[$r[1]];
                $options['count'] = $count + 2;
            } else {
                $revstr .= '1.' . max($r[1] - $count, 0) . ':' . $rev[$r[0]];
                $options['count'] = $r[0] - $r[1] + $count;
            }
        } else {
            $revstr .= '1.' . max($r[0] - $count, 0) . ':' . $rev[$r[0]];
        }
        $out = $version->rlog($formatter->page->name, '', "-r{$revstr}", '-z');
        if (!isset($out[0])) {
            $msg = _("No older revisions available");
            $info = "<h2>{$msg}</h2>";
        } else {
            $info = _parse_rlog($formatter, $out, $options);
        }
    } else {
        $msg = _("Version info is not available in this wiki");
        $info = "<h2>{$msg}</h2>";
    }
    return $warn . $info;
}
示例#2
0
function do_merge($formatter, $params = array())
{
    global $DBInfo;
    if ($_SERVER['REQUEST_METHOD'] == 'POST' && !$DBInfo->security->writable($params)) {
        $params['title'] = _("Page is not writable");
        return do_invalid($formatter, $params);
    }
    // check full permission to edit
    $full_permission = true;
    if (!empty($DBInfo->no_full_edit_permission) or $params['id'] == 'Anonymous' && !empty($DBInfo->anonymous_no_full_edit_permission)) {
        $full_permission = false;
    }
    // members always have full permission to edit
    if (in_array($params['id'], $DBInfo->members)) {
        $full_permission = true;
    }
    $is_new = !$formatter->page->exists();
    if (!$is_new and !$full_permission) {
        $formatter->send_header('', $params);
        $title = _("You do not have full permission to merge this page.");
        $formatter->send_title($title, '', $params);
        $formatter->send_footer('', $params);
        return;
    }
    $pagename = isset($params['name'][0]) ? $params['name'] : '';
    $formatter->send_header('', $params);
    $force = 1;
    if (isset($_POST['name'][0]) and $DBInfo->hasPage($_POST['name'])) {
        $force = 0;
        if ($_POST['force']) {
            $force = 1;
        }
    }
    // validate rev
    if (!empty($params['rev'])) {
        $info = $formatter->page->get_info($params['rev']);
        if (empty($info[0])) {
            unset($params['rev']);
            if (!empty($_POST['rev'])) {
                unset($_POST['rev']);
            }
        }
    }
    if (!empty($_POST['rev']) and isset($_POST['name'][0]) and $pagename !== $formatter->page->name and $DBInfo->hasPage($pagename)) {
        if (!empty($DBInfo->version_class)) {
            $REMOTE_ADDR = $_SERVER['REMOTE_ADDR'];
            $user =& $DBInfo->user;
            $comment = _stripslashes($params['comment']);
            $tag = '{MERGE}';
            if (!empty($comment)) {
                $comment = $tag . ': ' . $comment . ': ';
            } else {
                $comment = $tag . ': ';
            }
            $log = $REMOTE_ADDR . ';;' . $user->id . ';;' . $comment;
            $version = $DBInfo->lazyLoad('version', $DBInfo);
            if (!method_exists($version, 'merge')) {
                // check merge method
                $formatter->send_title(_("No merge method available."), '', $params);
                $formatter->send_footer('', $params);
                return;
            }
            $params['log'] = $log;
            $ret = array();
            $params['retval'] =& $ret;
            // merge RCS revisions
            $merged = $version->merge($pagename, $formatter->page->name, $params);
            if (!$force) {
                $fname = tempnam($DBInfo->vartmp_dir, 'MERGED');
                $fp = fopen($fname . ',v', 'w');
                if (is_resource($fp)) {
                    fwrite($fp, $merged);
                    fclose($fp);
                }
                // parse rlog
                require_once dirname(__FILE__) . '/Info.php';
                $out = $version->rlog($fname . ',v', '');
                $params['simple'] = true;
                $info = _parse_rlog($formatter, $out, $params);
                @unlink($fname);
                @unlink($fname . ',v');
            } else {
                if ($merged !== false) {
                    // $params['retval']['comment'] has merged versions information
                    $log = $comment . $params['retval']['comment'];
                    $DBInfo->addLogEntry($pagename, $REMOTE_ADDR, $log, 'MERGE');
                    $indexer = $DBInfo->lazyLoad('titleindexer');
                    if ($is_new) {
                        $indexer->addPage($pagename);
                    } else {
                        $indexer->update($pagename);
                    }
                    $info = '';
                }
            }
        } else {
            $formatter->send_title(_("No version control available."), '', $params);
            $formatter->send_footer('', $params);
            return;
        }
        $params['.title'] = _("Merge result.");
        $formatter->send_title(sprintf(_("%s is successfully merged."), $formatter->page->name), '', $params);
        if (!$force) {
            echo '<h3>' . _("This is a testing merge. Please confirm force option to merge it.") . '</h3>';
        }
        echo $info;
        $formatter->send_footer('', $params);
        return;
    } else {
        if (!isset($params['name'][0]) || !$DBInfo->hasPage($params['name'])) {
            $title = _("Please select the original page to merge.");
        } else {
            if (empty($params['rev'])) {
                $title = _("Please select the revision to merge from.");
            } else {
                if ($DBInfo->hasPage($formatter->page->name)) {
                    $title = _("Are you really want to merge this page ?");
                }
            }
        }
        $params['.title'] = _("Merge Page history.");
        $formatter->send_title($title, '', $params);
    }
    $pname = _html_escape($pagename);
    $lab = _("Summary");
    $rev = !empty($params['rev']) ? _html_escape($params['rev']) : '';
    if (!empty($rev) && isset($pagename[0]) && $DBInfo->hasPage($pagename)) {
        $extra = '<input type="checkbox" name="force" />' . _("Force overwrite") . '<br />';
        $placeholder = sprintf(_("Merge [[%s]] with [[%s]] from r%s: "), $pname, _html_escape($formatter->page->name), $rev);
        echo "<form method='post'>\n{$lab}: <input name='comment' size='80' value='{$comment}' placeholder='{$placeholder}' /><br />\n";
        $btn = sprintf(_("Merge [[%s]] to [[%s]]:"), _html_escape($formatter->page->name), $pname);
        $msg = sprintf(_("Only WikiMaster can %s this page"), _("merge"));
        if ($DBInfo->security->is_protected("merge", $params)) {
            echo _("Password") . ": <input type='password' name='passwd' size='20' value='' />\n{$msg}<br />\n";
        }
        echo <<<FORM
    <input type='hidden' name='name' value='{$pname}' />
    <input type='hidden' name='action' value='merge' />
    <input type='hidden' name='rev' value='{$rev}' />
    <input type='submit' value='{$btn}' />{$extra}
    </form>
FORM;
    } else {
        $btn = _("Select Page to Merge");
        echo <<<FORM
    <form method='get'>
    <input name='name' value='{$pname}' />
    <input type='hidden' name='action' value='merge' />
    <input type='submit' value='{$btn}' />{$extra}
    </form>
FORM;
    }
    if (isset($pagename[0]) && $pagename !== $formatter->page->name && $DBInfo->hasPage($pagename)) {
        echo macro_Merge($formatter, $pagename, $params);
    }
    $formatter->send_footer('', $params);
    return;
}
示例#3
0
文件: Info.php 项目: sedrion/moniwiki
function macro_Info($formatter, $value = '', $options = array())
{
    global $DBInfo;
    if (empty($DBInfo->interwiki)) {
        $formatter->macro_repl('InterWiki', '', array('init' => 1));
    }
    $value = (empty($value) and !empty($DBInfo->info_options)) ? $DBInfo->info_options : $value;
    $args = explode(',', $value);
    if (is_array($args)) {
        if (isset($args[0][0]) && $DBInfo->hasPage($args[0])) {
            $pagename = $args[0];
            array_shift($args);
        }
        foreach ($args as $arg) {
            $arg = trim($arg);
            if ($arg == 'simple') {
                $options['simple'] = 1;
            } else {
                if ($arg == 'ago') {
                    $options['ago'] = 1;
                }
            }
        }
    }
    $pagename = isset($pagename) ? $pagename : $formatter->page->name;
    $warn = '';
    $archived = null;
    if ($DBInfo->version_class) {
        $version = $DBInfo->lazyLoad('version', $DBInfo);
        // setup suffix, rlog extra argments
        $args = array('-z');
        if (!empty($options['archive'])) {
            $archive = intval($options['archive']);
            $args['archive'] = $archive;
            $archived = $archive;
        }
        $out = $version->rlog($pagename, '', '-r', $args);
    } else {
        $msg = _("Version info is not available in this wiki");
        return "<h2>{$msg}</h2>";
    }
    if ($archived) {
        $options['title'] = '<h2>' . sprintf(_("Revision History. (archive number %d)"), $archived) . '</h2>' . "\n";
    } else {
        if (method_exists($version, 'attics')) {
            $ret = $version->attics($pagename);
            if ($ret !== false) {
                $count = count($ret);
                if ($count > 1) {
                    $msg = sprintf(_("%s archived log files available."), $count);
                } else {
                    $msg = sprintf(_("%s archived log file available."), $count);
                }
                $info = "<h2>{$msg}</h2>";
                $warn .= '<div class="warn">' . $info . "</div>";
            }
        }
    }
    if (!isset($out[0])) {
        if (empty($msg)) {
            $msg = _("No older revisions available");
            $info = "<h2>{$msg}</h2>";
        }
    } else {
        if (isset($out[0])) {
            // get the number of total revisions and the last revision.
            $total = 1;
            if (preg_match('/^total revisions: (\\d+);/m', $out, $m)) {
                $total = $m[1];
            }
            $rev = array();
            $rev0 = '';
            if (preg_match('/^revision 1.(\\d+)+\\s/m', $out, $m)) {
                $rev0 = $m[1];
                $rev[$rev0] = '1.' . $rev0;
            }
            if (!empty($DBInfo->rcs_check_broken) and method_exists($version, 'is_broken')) {
                $is_broken = $version->is_broken($pagename);
                if ($is_broken) {
                    $warn .= '<div class="warn">' . _("WARNING: ") . _("The history information of this page is broken.") . "</div>";
                }
            }
            // parse 'rev' query string
            $rev1 = '';
            if (!empty($options['rev']) and preg_match('/^1\\.(\\d+)$/', $options['rev'], $m)) {
                if ($m[1] < $rev0) {
                    $rev[$m[1]] = '1.' . $m[1];
                }
            }
            $r = array_keys($rev);
            $range_max = !empty($DBInfo->info_range_max) ? $DBInfo->info_range_max : 30;
            $anon_range_limit = !empty($DBInfo->info_anonymous_range_limit) ? $DBInfo->info_anonymous_range_limit : $range_max;
            if ($options['id'] == 'Anonymous' && $r[0] - $r[1] > $anon_range_limit) {
                unset($rev[$r[1]]);
                unset($r[1]);
                $warn .= '<div class="warn">' . _("WARNING: ") . _("Anonymous user is not allowed to see older versions.") . "</div>";
            }
            // make a range list like as "1.234:1.240\;1.110:1.140"
            $revstr = '';
            $count = 10;
            if (count($r) > 1) {
                if ($r[0] - $r[1] > $range_max) {
                    $revstr .= '1.' . max($r[0] - 1, 0) . ':' . $rev[$r[0]];
                    $revstr .= '\\;1.' . max($r[1] - $count, 0) . ':' . $rev[$r[1]];
                    $options['count'] = $count + 2;
                } else {
                    $revstr .= '1.' . max($r[1] - $count, 0) . ':' . $rev[$r[0]];
                    $options['count'] = $r[0] - $r[1] + $count;
                }
            } else {
                $revstr .= '1.' . max($r[0] - $count, 0) . ':' . $rev[$r[0]];
            }
            $out = $version->rlog($pagename, '', "-r{$revstr}", $args);
            if ($pagename != $formatter->page->name) {
                $p = $DBInfo->getPage($pagename);
                $f = new Formatter($p, $options);
            } else {
                $f =& $formatter;
            }
            $info = _parse_rlog($f, $out, $options);
        }
    }
    return $warn . $info;
}