Beispiel #1
0
 /**
  * Generate macro output
  *
  * @return     string
  */
 public function render()
 {
     static $wm;
     if (!is_object($wm)) {
         $wm = new stdClass();
         $wm->footnotes = array();
         $wm->footnotes_notes = array();
         $wm->footnotes_count = 0;
     }
     $note = $this->args;
     if ($note) {
         $p = new WikiParser('Footnotes', $this->option, $this->scope, $this->pagename, $this->pageid, $this->filepath, $this->domain);
         //echo $note . '<br /><br />';
         $note = $p->parse(trim($note));
         $wm->footnotes_count++;
         if (in_array($note, $wm->footnotes_notes)) {
             $i = array_search($note, $wm->footnotes_notes) + 1;
             $k = $wm->footnotes_count;
             $wm->footnotes[$i - 1]->refs[] = 'fndef-' . $k;
             return '<sup><a name="fndef-' . $k . '"></a><a href="#fnref-' . $i . '">&#91;' . $i . '&#93;</a></sup>';
         }
         $i = count($wm->footnotes) + 1;
         $footnote = new stdClass();
         $footnote->content = $note;
         $footnote->id = 'fnref-' . $i;
         $footnote->refs = array('fndef-' . $i);
         $wm->footnotes_notes[] = $note;
         $wm->footnotes[] = $footnote;
         return '<sup><a name="fndef-' . $i . '"></a><a href="#fnref-' . $i . '">&#91;' . $i . '&#93;</a></sup>';
     } else {
         $letters = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
         $html = '<ol class="footnotes">';
         foreach ($wm->footnotes as $i => $footnote) {
             $html .= '<li><p>';
             if (count($footnote->refs) > 1) {
                 $html .= '^ ';
                 foreach ($footnote->refs as $key => $ref) {
                     $html .= '<sup><a href="#' . $ref . '">' . strtolower($letters[$key]) . '</a></sup> ';
                 }
             } else {
                 if (count($footnote->refs) == 1) {
                     $html .= '<a href="#' . $footnote->refs[0] . '">^</a> ';
                 }
             }
             $html .= '<a name="fnref-' . ($i + 1) . '"></a>' . substr($footnote->content, 3);
             $html .= '</li>';
         }
         $html .= '</ol>';
         $wm = null;
         return $html;
     }
 }
 public function formatRaw($string)
 {
     include_once SIMPLEWIKI_DIR . '/thirdparty/wikiparser-1.0/class_WikiParser.php';
     $parser = new WikiParser();
     $parser->emphasis = array();
     $parser->preformat = false;
     // need to change [] urls before parsing the text otherwise
     // the wiki parser breaks...
     $string = preg_replace('/\\[sitetree_link id=(\\d+)\\]/', '|sitetree_link id=\\1|', $string);
     $string = $parser->parse($string, '');
     $string = preg_replace('/\\|sitetree_link id=(\\d+)\\|/', '[sitetree_link id=\\1]', $string);
     return $string;
 }
 function wiki2html($text)
 {
     $myWikiParser = new WikiParser();
     $text = $myWikiParser->parse($text);
     return $text;
 }
Beispiel #4
0
 /**
  * Used to add a wiki page revision by a given user to a wiki page
  * of a given name in a given group viewing the group under a given
  * language. If the page does not exist yet it, and its corresponding
  * discussion thread is created. Two pages are used for storage
  * GROUP_PAGE which contains a parsed to html version of the most recent
  * revision of a wiki page and GROUP_PAGE_HISTORY which contains non-parsed
  * versions of all revisions
  *
  * @param int $user_id identifier of who is adding this revision
  * @param int $group_id which group the wiki page revision if being done in
  * @param string $page_name title of page being revised
  * @param string $page wiki page with potential wiki mark up containing the
  *     revision
  * @param string $locale_tag locale we are adding the revision to
  * @param string $edit_comment user's reason for making the revision
  * @param string $thread_title if this is the first revision, then this
  *     should contain the title for the discussion thread about the
  *     revision
  * @param string $thread_description if this is the first revision, then
  *     this should be the body of the first post in discussion thread
  * @param string $base_address default url to be used in links
  *     on wiki page that use short syntax
  * @param array $additional_substitutions list of pairs additional wiki
  *      page rewrites to do when parsing wiki pages
  */
 function setPageName($user_id, $group_id, $page_name, $page, $locale_tag, $edit_comment, $thread_title, $thread_description, $base_address = "", $additional_substitutions = array())
 {
     $db = $this->db;
     $pubdate = time();
     $parser = new WikiParser($base_address, $additional_substitutions);
     $parsed_page = $parser->parse($page);
     if ($page_id = $this->getPageID($group_id, $page_name, $locale_tag)) {
         //can only add and use resources for a page that exists
         $parsed_page = $this->insertResourcesParsePage($group_id, $page_id, $locale_tag, $parsed_page);
         $sql = "UPDATE GROUP_PAGE SET PAGE=? WHERE ID = ?";
         $result = $db->execute($sql, array($parsed_page, $page_id));
     } else {
         $discuss_thread = $this->addGroupItem(0, $group_id, $user_id, $thread_title, $thread_description . " " . date("r", $pubdate), WIKI_GROUP_ITEM);
         $sql = "INSERT INTO GROUP_PAGE (DISCUSS_THREAD, GROUP_ID,\n                TITLE, PAGE, LOCALE_TAG) VALUES (?, ?, ?, ?, ?)";
         $result = $db->execute($sql, array($discuss_thread, $group_id, $page_name, $parsed_page, $locale_tag));
         $page_id = $db->insertID("GROUP_PAGE");
     }
     $sql = "INSERT INTO GROUP_PAGE_HISTORY (PAGE_ID, EDITOR_ID,\n            GROUP_ID, TITLE, PAGE, LOCALE_TAG, PUBDATE, EDIT_COMMENT)\n            VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
     $result = $db->execute($sql, array($page_id, $user_id, $group_id, $page_name, $page, $locale_tag, $pubdate, $edit_comment));
 }
Beispiel #5
0
 protected function org2html($section_subject, $section_content, $type_handle)
 {
     $fragments = explode(':', $type_handle);
     $type = $fragments[0];
     if ($type == 'code' || $type == 'post-answer') {
         $code_lang = $fragments[1];
         $format = 'plain';
     } else {
         if ($type == 'feature') {
             $feature_icon = $fragments[1];
             $format = 'markdown';
         } else {
             $format = $fragments[1];
         }
     }
     switch ($format) {
         case 'media_wiki':
             $wiki = new WikiParser();
             $section_content_formatted = $wiki->parse($section_content);
             break;
         case 'markdown':
             //$section_content = strip_tags ($section_content, self::RESERVED_TAGS);
             $section_content_formatted = \Michelf\Markdown::defaultTransform($section_content);
             $config = array('safe' => 1);
             $section_content_formatted = htmLawed($section_content_formatted, $config);
             break;
         case 'markdown_extra':
         case 'markdown_safe':
             //$section_content = strip_tags ($section_content, self::RESERVED_TAGS);
             $parser = new \Michelf\MarkdownExtra();
             $parser->code_class_prefix = 'brush:';
             $parser->code_attr_on_pre = true;
             $parser->code_no_code_tag = true;
             $section_content_formatted = $parser->transform($section_content);
             $config = array('safe' => 1);
             $section_content_formatted = htmLawed($section_content_formatted, $config);
             break;
         default:
             $section_content_formatted = htmlspecialchars($section_content, ENT_NOQUOTES | ENT_HTML5);
             break;
     }
     switch ($type) {
         case 'feature':
             $section_subject_formatted = htmlspecialchars($section_subject, ENT_NOQUOTES | ENT_HTML5);
             $section_content_html = "<div class=\"feature\">\n";
             $section_content_html .= "\t<div class=\"feature-icon\">\n";
             $section_content_html .= "\t\t<span class=\"glyphicon glyphicon-" . $feature_icon . "\"></span>\n";
             $section_content_html .= "\t</div>\n";
             $section_content_html .= "\t<h2>" . $section_subject_formatted . "</h2>\n";
             $section_content_html .= "\t{$section_content_formatted}\n";
             $section_content_html .= "</div>\n";
             break;
         case 'post':
         case 'plain':
         case 'post-question':
         case 'post-note':
         case 'post-reference':
             $section_content_html = "<div>\n" . $section_content_formatted . "\n</div>\n";
             break;
         case 'quotation':
             $section_content_html = "<blockquote>\n" . $section_content_formatted . "\n</blockquote>\n";
             break;
         case 'quotation-reverse':
             $section_content_html = "<blockquote class=\"blockquote-reverse\">\n" . $section_content_formatted . "\n</blockquote>\n";
             break;
         case 'address':
             $section_content_html = "<address>\n" . $section_content_formatted . "\n</address>\n";
             break;
         case 'code':
         case 'post-answer':
             $section_content_html = "<pre class=\"brush:{$code_lang}\">\n";
             $section_content_html .= $section_content_formatted;
             $section_content_html .= "\n</pre>\n";
             break;
         case 'member':
             $style = $fragments[3];
             $section_content_html = "<div class=\"panel panel-{$style}\">\n" . $section_content_formatted . "\n</div>\n";
             break;
         case 'pre':
         default:
             $section_content_html = "<pre>\n" . $section_content_formatted . "\n</pre>\n";
             break;
     }
     return $section_content_html;
 }
Beispiel #6
0
    // OK cool - then let's create a new cURL resource handle
    $ch = curl_init();
    // Now set some options (most are optional)
    // Set URL to download
    curl_setopt($ch, CURLOPT_URL, $Url);
    // Set a referer
    curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");
    // User agent
    curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
    // Include header in result? (0 = yes, 1 = no)
    curl_setopt($ch, CURLOPT_HEADER, 1);
    // Should cURL return or print out the data? (true = return, false = print)
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    // Timeout in seconds
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    // Download the given URL, and return output
    $output = curl_exec($ch);
    // Close the cURL resource, and free system resources
    curl_close($ch);
    return $output;
}
//echo '<!doctype html><html lang="pl" dir="ltr"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Grabdata</title></head><body>';
$wp = new WikiParser(null, null, null, 999);
$wp->run();
//echo '</body></html>';
function _d($arg)
{
    echo '<pre>';
    var_dump($arg);
    echo '</pre>';
}
Beispiel #7
0
 public function action_set()
 {
     $val = \Validation::forge();
     $val->add_field('wid', 'node type', 'required|min_length[1]');
     $val->add_field('data', 'data wiki', '');
     $val->add_field('cat', 'category wiki', 'required|min_length[1]');
     $val->add_field('title', 'title wiki', 'required|min_length[1]');
     if ($val->run()) {
         if ($val->validated('wid') == 'new') {
             $props = array('catID' => $val->validated('cat'), 'content' => $val->validated('data'), 'title' => $val->validated('title'), 'meta_update_time' => time(), 'meta_update_user' => $this->user);
             $wiki = new Model_Wiki($props);
             $wiki->save();
         } else {
             if ($val->validated('wid') == 0) {
                 $wiki = Model_Wiki::find()->get_one();
             } else {
                 $wiki = Model_Wiki::find($val->validated('wid'));
             }
             if ($wiki) {
                 $wiki->content = $val->validated('data');
                 $wiki->title = $val->validated('title');
                 $wiki->catID = $val->validated('cat');
                 $wiki->meta_update_time = time();
                 $wiki->save();
             }
         }
         $m = new \WikiParser();
         $data = $m->parse(htmlspecialchars($wiki->content));
         $data = $this->customCode($data);
         echo json_encode(array('data' => urlencode($data), 'id' => $wiki->id, 'title' => $wiki->title, 'catID' => $wiki->catID));
     }
 }
Beispiel #8
0
 function WikiList()
 {
     $name = $this->app->Secure->GetGET("name");
     if ($name != "") {
         $wikiname = $this->app->DB->Select("SELECT name FROM wiki WHERE name='{$name}' LIMIT 1");
         if ($wikiname == $name) {
             $content = $this->app->DB->Select("SELECT content FROM wiki WHERE name='{$name}' LIMIT 1");
             $wikiparser = new WikiParser();
             $content = $wikiparser->parse($content);
             $index = $wikiparser->BuildIndex();
             if ($index !== false) {
                 $this->app->Tpl->Set('INDEX', $index);
                 $this->app->Tpl->Parse('WIKIINDEX', 'wiki_index.tpl');
             }
             $this->app->Tpl->Set(TAB1, $content);
             // TODO Wiki Parser!!!!
         } else {
             $this->WikiCreateDialog();
         }
     } else {
         // hauptseite
         header("Location: index.php?module=wiki&action=list&name=Mainpage");
         exit;
     }
     $this->app->Tpl->Set(TABTEXT, "Wiki");
     $this->app->Tpl->Parse(PAGE, "wiki_list.tpl");
 }
Beispiel #9
0
    /**
     * Handles requests to reading, editing, viewing history, reverting, etc
     * wiki pages
     * @return $data an associative array of form variables used to draw
     *     the appropriate wiki page
     */
    function wiki()
    {
        $parent = $this->parent;
        $controller_name = get_class($parent) == "AdminController" ? "admin" : "group";
        $data = array();
        $data["CONTROLLER"] = $controller_name;
        $other_controller_name = get_class($parent) == "AdminController" ? "group" : "admin";
        $data["ELEMENT"] = "wiki";
        $data["VIEW"] = "wiki";
        $data["SCRIPT"] = "";
        $data["INCLUDE_STYLES"] = array("editor");
        $group_model = $parent->model("group");
        $locale_tag = getLocaleTag();
        $data['CURRENT_LOCALE_TAG'] = $locale_tag;
        if (isset($_SESSION['USER_ID'])) {
            $user_id = $_SESSION['USER_ID'];
            $data['ADMIN'] = 1;
        } else {
            $user_id = PUBLIC_USER_ID;
        }
        $search_translation = tl('social_component_search');
        $search_form = <<<EOD
<form method="get" class="search-box \$2-search-box" >
<input type='hidden' name="its" value='\$1' />
<input type='text'  name='q'  value="" placeholder='\$3'
    title='\$3' class='search-input' />
<button type="submit" class='search-button'><img
    src='./resources/search-button.png'  alt='{$search_translation}'/></button>
</form>
EOD;
        $additional_substitutions[] = array('/{{\\s*search\\s*:\\s*(.+?)\\s*\\|' . '\\s*size\\s*:\\s*(.+?)\\s*\\|\\s*placeholder\\s*:\\s*(.+?)}}/', $search_form);
        $clean_array = array("group_id" => "int", "page_name" => "string", "page" => "string", "edit_reason" => "string", "filter" => 'string', "limit" => 'int', "num" => 'int', "page_id" => 'int', "show" => 'int', "diff" => 'int', "diff1" => 'int', "diff2" => 'int', "revert" => 'int');
        $strings_array = array("page_name" => TITLE_LEN, "page" => MAX_GROUP_PAGE_LEN, "edit_reason" => SHORT_TITLE_LEN, "filter" => SHORT_TITLE_LEN);
        $last_care_missing = 2;
        $missing_fields = false;
        $i = 0;
        if ($user_id == PUBLIC_USER_ID) {
            $_SESSION['LAST_ACTIVITY']['a'] = 'wiki';
        } else {
            unset($_SESSION['LAST_ACTIVITY']);
        }
        foreach ($clean_array as $field => $type) {
            if (isset($_REQUEST[$field])) {
                $tmp = $parent->clean($_REQUEST[$field], $type);
                if (isset($strings_array[$field])) {
                    $tmp = substr($tmp, 0, $strings_array[$field]);
                }
                if ($field == "page_name") {
                    $tmp = str_replace(" ", "_", $tmp);
                }
                ${$field} = $tmp;
                if ($user_id == PUBLIC_USER_ID) {
                    $_SESSION['LAST_ACTIVITY'][$field] = $tmp;
                }
            } else {
                if ($i < $last_care_missing) {
                    ${$field} = false;
                    $missing_fields = true;
                }
            }
            $i++;
        }
        if (isset($_REQUEST['group_id']) && $_REQUEST['group_id']) {
            $group_id = $parent->clean($_REQUEST['group_id'], "int");
        } else {
            if (isset($page_id)) {
                $page_info = $group_model->getPageInfoByPageId($page_id);
                if (isset($page_info["GROUP_ID"])) {
                    $group_id = $page_info["GROUP_ID"];
                    unset($page_info);
                } else {
                    $group_id = PUBLIC_GROUP_ID;
                }
            } else {
                $group_id = PUBLIC_GROUP_ID;
            }
        }
        $group = $group_model->getGroupById($group_id, $user_id);
        $data["CAN_EDIT"] = false;
        if (isset($_REQUEST['c']) && $_REQUEST['c'] == "api") {
            $data['MODE'] = 'api';
            $data['VIEW'] = 'api';
        } else {
            $data["MODE"] = "read";
        }
        if (!$group) {
            if ($data['MODE'] !== 'api') {
                $parent->redirectWithMessage(tl("group_controller_no_group_access"));
            } else {
                $data['errors'] = array();
                $data['errors'][] = tl("group_controller_no_group_access");
            }
            $group_id = PUBLIC_GROUP_ID;
            $group = $group_model->getGroupById($group_id, $user_id);
        } else {
            if ($group["OWNER_ID"] == $user_id || $group["STATUS"] == ACTIVE_STATUS && $group["MEMBER_ACCESS"] == GROUP_READ_WIKI) {
                $data["CAN_EDIT"] = true;
            }
        }
        $page_defaults = array('page_type' => 'standard', 'page_alias' => '', 'page_border' => 'solid', 'toc' => true, 'title' => '', 'author' => '', 'robots' => '', 'description' => '', 'page_header' => '', 'page_footer' => '');
        $data['page_types'] = array("standard" => tl('social_component_standard_page'), "page_alias" => tl('social_component_page_alias'), "media_list" => tl('social_component_media_list'), "presentation" => tl('social_component_presentation'));
        $data['page_borders'] = array("solid-border" => tl('social_component_solid'), "dashed-border" => tl('social_component_dashed'), "none" => tl('social_component_none'));
        if ($group_id == PUBLIC_GROUP_ID) {
            $read_address = "[{controller_and_page}]";
        } else {
            $read_address = "?c=[{controller}]&amp;a=wiki&amp;" . "arg=read&amp;group_id={$group_id}&amp;page_name=";
        }
        if (isset($_REQUEST["arg"])) {
            switch ($_REQUEST["arg"]) {
                case "edit":
                    if (!$data["CAN_EDIT"]) {
                        continue;
                    }
                    if (isset($_REQUEST['caret']) && isset($_REQUEST['scroll_top']) && !isset($page)) {
                        $caret = $parent->clean($_REQUEST['caret'], 'int');
                        $scroll_top = $parent->clean($_REQUEST['scroll_top'], 'int');
                        $data['SCRIPT'] .= "wiki = elt('wiki-page');" . "if (wiki.setSelectionRange) { " . "   wiki.focus();" . "   wiki.setSelectionRange({$caret}, {$caret});" . "} " . "wiki.scrollTop = {$scroll_top};";
                    }
                    if (isset($page)) {
                        $data["MODE"] = "read";
                    } else {
                        $data["MODE"] = "edit";
                    }
                    $page_info = $group_model->getPageInfoByName($group_id, $page_name, $locale_tag, 'resources');
                    /* if page not yet created than $page_info will be null
                         so in the below $page_info['ID'] won't be set.
                       */
                    if ($missing_fields) {
                        $parent->redirectWithMessage(tl("group_controller_missing_fields"));
                    } else {
                        if (!$missing_fields && isset($page)) {
                            $action = "wikiupdate_" . "group=" . $group_id . "&page=" . $page_name;
                            if (!$parent->checkCSRFTime(CSRF_TOKEN, $action)) {
                                $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >" . tl('social_component_wiki_edited_elsewhere') . "</h1>');";
                                break;
                            }
                            $write_head = false;
                            $head_vars = array();
                            $page_types = array_keys($data['page_types']);
                            $page_borders = array_keys($data['page_borders']);
                            foreach ($page_defaults as $key => $default) {
                                $head_vars[$key] = $default;
                                if (isset($_REQUEST[$key])) {
                                    $head_vars[$key] = trim($parent->clean($_REQUEST[$key], "string"));
                                    if ($key == 'page_type') {
                                        if (!in_array($head_vars[$key], $page_types)) {
                                            $head_vars[$key] = $default;
                                        }
                                    } else {
                                        if ($key == 'page_borders') {
                                            if (!in_array($head_vars[$key], $page_types)) {
                                                $head_vars[$key] = $default;
                                            }
                                        } else {
                                            $head_vars[$key] = trim(preg_replace("/\n+/", "\n", $head_vars[$key]));
                                        }
                                    }
                                    if ($head_vars[$key] != $default) {
                                        $write_head = true;
                                    }
                                } else {
                                    if ($key == 'toc') {
                                        if (isset($_REQUEST['title'])) {
                                            $head_vars[$key] = false;
                                        } else {
                                            $head_vars[$key] == true;
                                        }
                                    }
                                }
                            }
                            if ($write_head) {
                                $head_string = "";
                                foreach ($page_defaults as $key => $default) {
                                    $head_string .= $key . "=" . $head_vars[$key] . "\n\n";
                                }
                                $page = $head_string . "END_HEAD_VARS" . $page;
                            }
                            $group_model->setPageName($user_id, $group_id, $page_name, $page, $locale_tag, $edit_reason, tl('group_controller_page_created', $page_name), tl('group_controller_page_discuss_here'), $read_address, $additional_substitutions);
                            $parent->redirectWithMessage(tl("group_controller_page_saved"), array('arg', 'page_name', 'settings', 'caret', 'scroll_top', 'back_params'));
                        } else {
                            if (!$missing_fields && isset($_FILES['page_resource']['name']) && $_FILES['page_resource']['name'] != "") {
                                if (!isset($page_info['ID'])) {
                                    $parent->redirectWithMessage(tl('social_component_resource_save_first'), array('arg', 'page_name', 'settings', 'caret', 'scroll_top'));
                                } else {
                                    $upload_parts = array('name', 'type', 'tmp_name');
                                    $file = array();
                                    $upload_okay = true;
                                    foreach ($upload_parts as $part) {
                                        if (isset($_FILES['page_resource'][$part])) {
                                            $file[$part] = $parent->clean($_FILES['page_resource'][$part], 'string');
                                        } else {
                                            $upload_okay = false;
                                            break;
                                        }
                                    }
                                }
                                if ($upload_okay) {
                                    $group_model->copyFileToGroupPageResource($file['tmp_name'], $file['name'], $file['type'], $group_id, $page_info['ID']);
                                    $parent->redirectWithMessage(tl('social_component_resource_uploaded'), array('arg', 'page_name', 'settings', 'caret', 'scroll_top'));
                                } else {
                                    $parent->redirectWithMessage(tl('social_component_upload_error'), array('arg', 'page_name', 'settings', 'caret', 'scroll_top'));
                                }
                            } else {
                                if (!$missing_fields && isset($_REQUEST['delete'])) {
                                    $resource_name = $parent->clean($_REQUEST['delete'], "string");
                                    if (isset($page_info['ID']) && $group_model->deleteResource($resource_name, $group_id, $page_info['ID'])) {
                                        $parent->redirectWithMessage(tl('social_component_resource_deleted'), array('arg', 'page_name', 'settings', 'caret', 'scroll_top'));
                                    } else {
                                        $parent->redirectWithMessage(tl('social_component_resource_not_deleted'), array('arg', 'page_name', 'settings', 'caret', 'scroll_top'));
                                    }
                                } else {
                                    if (!$missing_fields && isset($_REQUEST['new_resource_name']) && isset($_REQUEST['old_resource_name'])) {
                                        $old_resource_name = $parent->clean($_REQUEST['old_resource_name'], "string");
                                        $new_resource_name = $parent->clean($_REQUEST['new_resource_name'], "string");
                                        if (isset($page_info['ID']) && $group_model->renameResource($old_resource_name, $new_resource_name, $group_id, $page_info['ID'])) {
                                            $parent->redirectWithMessage(tl('social_component_resource_renamed'), array('arg', 'page_name', 'settings', 'caret', 'scroll_top'));
                                        } else {
                                            $parent->redirectWithMessage(tl('social_component_resource_not_renamed'), array('arg', 'page_name', 'settings', 'caret', 'scroll_top'));
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (isset($page_info['ID'])) {
                        $data['RESOURCES_INFO'] = $group_model->getGroupPageResourceUrls($group_id, $page_info['ID']);
                    } else {
                        $data['RESOURCES_INFO'] = array();
                    }
                    break;
                case "history":
                    if (!$data["CAN_EDIT"] || !isset($page_id) || !$page_id) {
                        continue;
                    }
                    $data["MODE"] = "history";
                    $data["PAGE_NAME"] = "history";
                    $limit = isset($limit) ? $limit : 0;
                    $num = isset($_SESSION["MAX_PAGES_TO_SHOW"]) ? $_SESSION["MAX_PAGES_TO_SHOW"] : DEFAULT_ADMIN_PAGING_NUM;
                    $default_history = true;
                    if (isset($show)) {
                        $page_info = $group_model->getHistoryPage($page_id, $show);
                        if ($page_info) {
                            $data["MODE"] = "show";
                            $default_history = false;
                            $data["PAGE_NAME"] = $page_info["PAGE_NAME"];
                            $parser = new WikiParser($read_address, $additional_substitutions);
                            $parsed_page = $parser->parse($page_info["PAGE"]);
                            $data["PAGE_ID"] = $page_id;
                            $data[CSRF_TOKEN] = $parent->generateCSRFToken($user_id);
                            $history_link = "?c={$data['CONTROLLER']}&amp;" . "a=wiki&amp;" . CSRF_TOKEN . '=' . $data[CSRF_TOKEN] . '&amp;arg=history&amp;page_id=' . $data['PAGE_ID'];
                            $data["PAGE"] = "<div>&nbsp;</div>" . "<div class='black-box back-dark-gray'>" . "<div class='float-opposite'>" . "<a href='{$history_link}'>" . tl("group_controller_back") . "</a></div>" . tl("group_controller_history_page", $data["PAGE_NAME"], date("c", $show)) . "</div>" . $parsed_page;
                            $data["DISCUSS_THREAD"] = $page_info["DISCUSS_THREAD"];
                        }
                    } else {
                        if (isset($diff) && $diff && isset($diff1) && isset($diff2)) {
                            $page_info1 = $group_model->getHistoryPage($page_id, $diff1);
                            $page_info2 = $group_model->getHistoryPage($page_id, $diff2);
                            $data["MODE"] = "diff";
                            $default_history = false;
                            $data["PAGE_NAME"] = $page_info2["PAGE_NAME"];
                            $data["PAGE_ID"] = $page_id;
                            $data[CSRF_TOKEN] = $parent->generateCSRFToken($user_id);
                            $history_link = "?c={$data['CONTROLLER']}" . "&amp;a=wiki&amp;" . CSRF_TOKEN . '=' . $data[CSRF_TOKEN] . '&amp;arg=history&amp;page_id=' . $data['PAGE_ID'];
                            $out_diff = "<div>--- {$data["PAGE_NAME"]}\t" . "''{$diff1}''\n";
                            $out_diff .= "<div>+++ {$data["PAGE_NAME"]}\t" . "''{$diff2}''\n";
                            $out_diff .= diff($page_info1["PAGE"], $page_info2["PAGE"], true);
                            $data["PAGE"] = "<div>&nbsp;</div>" . "<div class='black-box back-dark-gray'>" . "<div class='float-opposite'>" . "<a href='{$history_link}'>" . tl("group_controller_back") . "</a></div>" . tl("group_controller_diff_page", $data["PAGE_NAME"], date("c", $diff1), date("c", $diff2)) . "</div>" . "{$out_diff}";
                        } else {
                            if (isset($revert)) {
                                $page_info = $group_model->getHistoryPage($page_id, $revert);
                                if ($page_info) {
                                    $action = "wikiupdate_" . "group=" . $group_id . "&page=" . $page_info["PAGE_NAME"];
                                    if (!$parent->checkCSRFTime(CSRF_TOKEN, $action)) {
                                        $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >" . tl('social_component_wiki_edited_elsewhere') . "</h1>');";
                                        break;
                                    }
                                    $group_model->setPageName($user_id, $group_id, $page_info["PAGE_NAME"], $page_info["PAGE"], $locale_tag, tl('group_controller_page_revert_to', date('c', $revert)), "", "", $read_address, $additional_substitutions);
                                    $parent->redirectWithMessage(tl("group_controller_page_reverted"), array('arg', 'page_name', 'page_id'));
                                } else {
                                    $parent->redirectWithMessage(tl("group_controller_revert_error"), array('arg', 'page_name', 'page_id'));
                                }
                            }
                        }
                    }
                    if ($default_history) {
                        $data["LIMIT"] = $limit;
                        $data["RESULTS_PER_PAGE"] = $num;
                        list($data["TOTAL_ROWS"], $data["PAGE_NAME"], $data["HISTORY"]) = $group_model->getPageHistoryList($page_id, $limit, $num);
                        if (!isset($diff1) || !isset($diff2)) {
                            $data['diff1'] = $data["HISTORY"][0]["PUBDATE"];
                            $data['diff2'] = $data["HISTORY"][0]["PUBDATE"];
                            if (count($data["HISTORY"]) > 1) {
                                $data['diff2'] = $data["HISTORY"][1]["PUBDATE"];
                            }
                        }
                    }
                    $data['page_id'] = $page_id;
                    break;
                case "media":
                    if (!isset($page_id) || !isset($_REQUEST['n'])) {
                        break;
                    }
                    $media_name = $parent->clean($_REQUEST['n'], "string");
                    $page_info = $group_model->getPageInfoByPageId($page_id);
                    $data['PAGE_NAME'] = $page_info['PAGE_NAME'];
                    $name_parts = pathinfo($media_name);
                    $file_name = $name_parts['filename'];
                    $data['MEDIA_NAME'] = $media_name;
                    $page_string = "((resource:{$media_name}|{$file_name}))";
                    $data["PAGE"] = $group_model->insertResourcesParsePage($group_id, $page_id, $locale_tag, $page_string);
                    $data["PAGE_ID"] = $page_id;
                    break;
                case "pages":
                    $data["MODE"] = "pages";
                    $limit = isset($limit) ? $limit : 0;
                    $num = isset($_SESSION["MAX_PAGES_TO_SHOW"]) ? $_SESSION["MAX_PAGES_TO_SHOW"] : DEFAULT_ADMIN_PAGING_NUM;
                    if (!isset($filter)) {
                        $filter = "";
                    }
                    if (isset($page_name)) {
                        $data['PAGE_NAME'] = $page_name;
                    }
                    $data["LIMIT"] = $limit;
                    $data["RESULTS_PER_PAGE"] = $num;
                    $data["FILTER"] = $filter;
                    $search_page_info = false;
                    if ($filter != "") {
                        $search_page_info = $group_model->getPageInfoByName($group_id, $filter, $locale_tag, "read");
                    }
                    if (!$search_page_info) {
                        list($data["TOTAL_ROWS"], $data["PAGES"]) = $group_model->getPageList($group_id, $locale_tag, $filter, $limit, $num);
                        if ($data["TOTAL_ROWS"] == 0 && $filter != "") {
                            $data["MODE"] = "read";
                            $page_name = $filter;
                        }
                    } else {
                        $data["MODE"] = "read";
                        $page_name = $filter;
                    }
                    break;
            }
        }
        if (!$page_name) {
            $page_name = tl('group_controller_main');
        }
        $data["GROUP"] = $group;
        if (in_array($data["MODE"], array("read", "edit", "media", "api"))) {
            if (!isset($data["PAGE"]) || !$data['PAGE']) {
                $data["PAGE_NAME"] = $page_name;
                if (isset($search_page_info) && $search_page_info) {
                    $page_info = $search_page_info;
                } else {
                    $page_info = $group_model->getPageInfoByName($group_id, $page_name, $locale_tag, $data["MODE"]);
                }
                $data["PAGE"] = $page_info["PAGE"];
                $data["PAGE_ID"] = $page_info["ID"];
                $data["DISCUSS_THREAD"] = $page_info["DISCUSS_THREAD"];
            }
            if ((!isset($data["PAGE"]) || !$data["PAGE"]) && $locale_tag != DEFAULT_LOCALE) {
                //fallback to default locale for translation
                $page_info = $group_model->getPageInfoByName($group_id, $page_name, DEFAULT_LOCALE, $data["MODE"]);
                $data["PAGE"] = $page_info["PAGE"];
                $data["PAGE_ID"] = $page_info["ID"];
                $data["DISCUSS_THREAD"] = $page_info["DISCUSS_THREAD"];
            }
            $view = $parent->view($data['VIEW']);
            $parent->parsePageHeadVars($view, $data["PAGE_ID"], $data["PAGE"]);
            $data["PAGE"] = $this->dynamicSubstitutions($group_id, $data, $view->page_objects[$data["PAGE_ID"]]);
            $data["HEAD"] = $view->head_objects[$data["PAGE_ID"]];
            if (isset($data["HEAD"]['page_type']) && $data["HEAD"]['page_type'] == 'page_alias' && $data["HEAD"]['page_alias'] != '' && $data['MODE'] == "read" && !isset($_REQUEST['noredirect'])) {
                $_REQUEST['page_name'] = $data["HEAD"]['page_alias'];
                $parent->redirectWithMessage("", array('page_name'));
            }
            if ($data['MODE'] == "read" && isset($data["HEAD"]['page_header']) && $data["HEAD"]['page_type'] != 'presentation') {
                $page_header = $group_model->getPageInfoByName($group_id, $data["HEAD"]['page_header'], $locale_tag, $data["MODE"]);
                if (isset($page_header['PAGE'])) {
                    $header_parts = explode("END_HEAD_VARS", $page_header['PAGE']);
                }
                $data["PAGE_HEADER"] = isset($header_parts[1]) ? $header_parts[1] : "" . $page_header['PAGE'];
                $data["PAGE_HEADER"] = $this->dynamicSubstitutions($group_id, $data, $data["PAGE_HEADER"]);
            }
            if ($data['MODE'] == "read" && isset($data["HEAD"]['page_footer']) && $data["HEAD"]['page_type'] != 'presentation') {
                $page_footer = $group_model->getPageInfoByName($group_id, $data["HEAD"]['page_footer'], $locale_tag, $data["MODE"]);
                if (isset($page_footer['PAGE'])) {
                    $footer_parts = explode("END_HEAD_VARS", $page_footer['PAGE']);
                }
                $data['PAGE_FOOTER'] = isset($footer_parts[1]) ? $footer_parts[1] : "" . $page_footer['PAGE'];
                $data["PAGE_FOOTER"] = $this->dynamicSubstitutions($group_id, $data, $data["PAGE_FOOTER"]);
            }
            if ($data['MODE'] == "read" && strpos($data["PAGE"], "`") !== false) {
                if (!isset($data["INCLUDE_SCRIPTS"])) {
                    $data["INCLUDE_SCRIPTS"] = array();
                }
                $data["INCLUDE_SCRIPTS"][] = "math";
            }
            if ($data['MODE'] == "read" && isset($data["HEAD"]['page_type'])) {
                if ($data["HEAD"]['page_type'] == 'media_list') {
                    $data['RESOURCES_INFO'] = $group_model->getGroupPageResourceUrls($group_id, $data['PAGE_ID']);
                }
                if ($data["HEAD"]['page_type'] == 'presentation' && $data['CONTROLLER'] == 'group') {
                    $data['page_type'] = 'presentation';
                    $data['INCLUDE_SCRIPTS'][] = "slidy";
                    $data['INCLUDE_STYLES'][] = "slidy";
                }
            }
            if ($data['MODE'] == "edit") {
                foreach ($page_defaults as $key => $default) {
                    $data[$key] = $default;
                    if (isset($data["HEAD"][$key])) {
                        $data[$key] = $data["HEAD"][$key];
                    }
                }
                $data['settings'] = "false";
                if (isset($_REQUEST['settings']) && $_REQUEST['settings'] == 'true') {
                    $data['settings'] = "true";
                }
                $data['current_page_type'] = $data["page_type"];
                $data['SCRIPT'] .= <<<EOD
                setDisplay('page-settings', {$data['settings']});
                function toggleSettings()
                {
                    var settings = elt('p-settings');
                    settings.value = (settings.value =='true')
                        ? 'false' : 'true';
                    var value = (settings.value == 'true') ? true : false;
                    setDisplay('page-settings', value);
                    var page_type = elt("page-type");
                    var cur_type = page_type.options[
                        page_type.selectedIndex].value;
                    if(cur_type == "media_list") {
                        setDisplay('save-container', value);
                    }
                }
                ptype = document.getElementById("page-type");
                is_media_list = ('media_list'=='{$data['current_page_type']}');
                is_settings = {$data['settings']};
                is_page_alias = ('page_alias'=='{$data['current_page_type']}');
                setDisplay('page-settings', is_settings || is_page_alias);
                setDisplay("media-list-page", is_media_list && !is_page_alias);
                setDisplay("page-container", !is_media_list && !is_page_alias);
                setDisplay("non-alias-type", !is_page_alias);
                setDisplay("alias-type", is_page_alias);
                setDisplay('save-container', !is_media_list || is_settings);
                setDisplay("toggle-settings", !is_page_alias, "inline");
                setDisplay("page-resources", !is_page_alias);
                ptype.onchange = function() {
                    var cur_type = ptype.options[ptype.selectedIndex].value;
                    if(cur_type == "media_list") {
                        setDisplay("media-list-page", true, "inline");
                        setDisplay("page-container", false);
                        setDisplay("toggle-settings", true);
                        setDisplay("non-alias-type", true);
                        setDisplay("alias-type", false);
                        setDisplay("page-resources", true);
                    } else if(cur_type == "page_alias") {
                        setDisplay("toggle-settings", false);
                        setDisplay("media-list-page", false);
                        setDisplay("page-container", false);
                        setDisplay("non-alias-type", false);
                        setDisplay("alias-type", true);
                        setDisplay("page-resources", false);
                    } else {
                        setDisplay("page-container", true);
                        setDisplay("media-list-page", false);
                        setDisplay("toggle-settings", true, "inline");
                        setDisplay("non-alias-type", true);
                        setDisplay("alias-type", false);
                        setDisplay("page-resources", true);
                    }
                }
EOD;
                $this->initializeWikiEditor($data);
            }
        }
        /** Check if back params need to be set. Set them if required.
         * the back params are usually sent when the wiki action is initiated
         * from within an open help article.
         */
        $data["OTHER_BACK_URL"] = "";
        if (isset($_REQUEST['back_params']) && (isset($_REQUEST['arg']) && in_array($parent->clean($_REQUEST['arg'], "string"), array('edit', 'read')) || isset($_REQUEST['page_name']))) {
            $back_params_cleaned = $_REQUEST['back_params'];
            array_walk($back_params_cleaned, array($parent, 'clean'));
            foreach ($back_params_cleaned as $back_param_key => $back_param_value) {
                $data['BACK_PARAMS']["back_params[{$back_param_key}]"] = $back_param_value;
                $data["OTHER_BACK_URL"] .= "&amp;back_params[{$back_param_key}]" . "=" . $back_param_value;
            }
            $data['BACK_URL'] = http_build_query($back_params_cleaned);
        }
        return $data;
    }