Beispiel #1
0
<?php

# $Id$
# (c)2005,2006 Stepan Roh <*****@*****.**>
# Free to copy, free to modify, NO WARRANTY
/** @file
 * history page
 */
$page =& get_current_page();
render_ui(MW_LAYOUT_HEADER);
echo '<div class="history"><ul>', "\n";
$hist_pages = $page->get_all_revisions();
foreach ($hist_pages as $hist_page) {
    if (isset($hist_page->user)) {
        $user_page = new_user_page($hist_page->user);
    }
    echo '<li><a href="', url_for_page_action($hist_page, MW_ACTION_VIEW, true), '">', format_datetime($hist_page->last_modified), '</a>', isset($hist_page->user) && trim($hist_page->user) ? ' <span class="history-user"> - <a href="' . url_for_page_action($user_page, MW_ACTION_VIEW, true) . '">' . htmlspecialchars($hist_page->user, ENT_NOQUOTES) . '</a></span>' : '', isset($hist_page->raw_content_length) ? ' <span class="history-content-length">(' . $hist_page->raw_content_length . ' B)</span>' : '', isset($hist_page->message) && trim($hist_page->message) ? ' <span class="history-message">(' . htmlspecialchars($hist_page->message, ENT_NOQUOTES) . ')</span>' : '', '</li>', "\n";
}
echo '</ul></div>', "\n";
render_ui(MW_LAYOUT_FOOTER);
Beispiel #2
0
    /**
     * render Wiki markup to output
     * raw text is split into blocks (separated by empty lines) and then rendered,
     * text between <pre> and </pre> (must begin lines) is not Wiki-processed (regardless of blocks)
     */
    function render()
    {
        if (strlen($this->raw) == 0) {
            echo _t('(empty)'), "\n";
            return;
        }
        $src = str_replace("\r", '', $this->raw);
        $lines = explode("\n", $src);
        $in_pre = false;
        $current_chain = '';
        $notoc = false;
        $output = '';
        $if_skip_counter = 0;
        # the count() hack is because some our lines are empty which causes while(array_shift) to terminate prematurely
        while (count($lines) > 0) {
            $line = array_shift($lines);
            if ($if_skip_counter > 0) {
                if (strpos($line, '#ENDIF') === 0) {
                    $if_skip_counter--;
                } elseif (strpos($line, '#IF') === 0) {
                    $if_skip_counter++;
                }
                if ($if_skip_counter > 0) {
                    continue;
                }
            }
            if (!$in_pre && preg_match('/^<pre>/si', $line)) {
                $output .= $this->process_block_chain($current_chain);
                $current_chain = '';
                $in_pre = true;
                $line = substr($line, 5);
                $output .= '<pre>';
            }
            if ($in_pre) {
                if (preg_match(',^</pre>,si', $line)) {
                    $in_pre = 0;
                    $output .= "</pre>\n";
                } else {
                    $output .= htmlspecialchars($line, ENT_NOQUOTES) . "\n";
                }
            } elseif (strpos($line, '#NOTOC') === 0) {
                $notoc = true;
            } elseif (strpos($line, '#IF') === 0) {
                # for #IFEMPTY
                $empty_cond = strpos($line, 'EMPTY') === 3;
                $tokens = explode(' ', $line, 2);
                $value = $this->process_includes($tokens[1]);
                $is_empty = strlen(trim($value)) == 0;
                if (!($empty_cond && $is_empty || !$empty_cond && !$is_empty)) {
                    $if_skip_counter++;
                }
            } elseif (strpos($line, '#ENDPAGE') === 0) {
                $output .= $this->process_block_chain($current_chain);
                $current_chain = '';
                $output .= "\n</body>\n</html>\n";
            } elseif (strpos($line, '#PAGE') === 0) {
                $output .= $this->process_block_chain($current_chain);
                $current_chain = '';
                $output .= '<?xml version="1.0" encoding="' . config('encoding') . '"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>' . "\n";
            } elseif (strpos($line, '#ENDHEADER') === 0) {
                $output .= $this->process_block_chain($current_chain);
                $current_chain = '';
                $output .= "</head>\n<body>\n";
            } elseif (strpos($line, '#HEADER') === 0) {
                $output .= $this->process_block_chain($current_chain);
                $current_chain = '';
                $output .= '<head>
  <meta http-equiv="Content-Type" content="text/html; charset=' . config('encoding') . '"/>
  <meta name="generator" content="' . MW_NAME . '/' . MW_VERSION . '"/>' . "\n";
            } elseif (strpos($line, '#META') === 0) {
                $output .= $this->process_block_chain($current_chain);
                $current_chain = '';
                $tokens = explode(' ', $line, 3);
                $meta_name = $tokens[1];
                $meta_value = $this->process_includes($tokens[2]);
                if ($meta_name == 'title') {
                    $output .= '  <title>' . $meta_value . '</title>' . "\n";
                } elseif ($meta_name == 'stylesheet') {
                    $meta_value = $this->process_header_link($meta_value);
                    $output .= '  <link rel="stylesheet" type="text/css" href="' . $meta_value . '"/>' . "\n";
                } elseif ($meta_name == 'javascript') {
                    $meta_value = $this->process_header_link($meta_value);
                    $output .= '  <script type="text/javascript" src="' . $meta_value . '"></script>' . "\n";
                }
            } elseif (strpos($line, '#REDIRECT') === 0) {
                $tokens = explode(' ', $line, 2);
                if (count($tokens) > 1) {
                    $output .= '<div class="redirect-link">' . $this->process_internal_link($tokens[1], $tokens[1]) . '</div>' . "\n";
                }
            } elseif (strpos($line, '#FOREACH') === 0) {
                $tokens = explode(' ', $line, 3);
                if (count($tokens) > 2) {
                    $array_var = $tokens[1];
                    $index_var = $tokens[2];
                    $array_value = $this->wiki_variables->get($array_var);
                    if (!is_array($array_value)) {
                        $array_value = array();
                    }
                    $for_counter = 1;
                    $for_lines = array();
                    while (count($lines) > 0) {
                        $for_line = array_shift($lines);
                        if (strpos($for_line, '#FOREACH') === 0) {
                            $for_counter++;
                        } elseif (strpos($for_line, '#ENDFOR') === 0) {
                            $for_counter--;
                        }
                        if ($for_counter === 0) {
                            break;
                        }
                        array_push($for_lines, $for_line);
                    }
                    if (count($for_lines) > 0) {
                        $all_for_lines = array();
                        foreach ($array_value as $item) {
                            $new_for_lines = $for_lines;
                            $new_for_lines[0] = '{{&set|' . $index_var . '|' . $item . '}}' . $new_for_lines[0];
                            $all_for_lines = array_merge($all_for_lines, $new_for_lines);
                        }
                        $lines = array_merge($all_for_lines, $lines);
                    }
                }
            } elseif (strpos($line, '#') === 0) {
                # omit directives
            } elseif (strpos($line, '{{') !== false) {
                $process = true;
                if (strpos($line, '}}') === false) {
                    # multi-line include, must find the end
                    $proces = false;
                    while (count($lines) > 0) {
                        $next_line = array_shift($lines);
                        $line .= "\n" . $next_line;
                        if (strpos($next_line, '}}') !== false) {
                            $process = true;
                            break;
                        }
                    }
                }
                if ($process) {
                    $line = $this->process_includes($line);
                    # eat empty lines which resulted from {{...}} processing
                    if (!empty($line)) {
                        $lines = array_merge(explode("\n", $line), $lines);
                    }
                }
            } else {
                $current_chain .= $line . "\n";
            }
        }
        $output .= $this->process_block_chain($current_chain);
        # TOC
        if (!$notoc && count($this->headings)) {
            echo '<div class="toc">', "\n";
            echo '<ul>', "\n";
            foreach ($this->headings as $heading) {
                # we must override current actions we are rendered with
                $page =& get_current_page();
                echo '<li class="toc-level-', $heading["level"] - 1, '"><a href="' . url_for_page_action($page, MW_ACTION_VIEW, true, $heading['anchor']), '">', $heading['number'], ' ', $heading['title'], '</a></li>', "\n";
            }
            echo '</ul>', "\n";
            echo '</div>', "\n";
        }
        echo $output;
    }