1<?php
2/**
3 * @package tikiwiki
4 */
5// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
6//
7// All Rights Reserved. See copyright.txt for details and a complete list of authors.
8// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
9// $Id$
10
11$section = 'wiki page';
12require_once('tiki-setup.php');
13$structlib = TikiLib::lib('struct');
14
15$wikilib = TikiLib::lib('wiki');
16
17$parserlib = TikiLib::lib('parser');
18
19if ($prefs['feature_categories'] == 'y') {
20	$categlib = TikiLib::lib('categ');
21}
22
23$access->check_feature('feature_wiki');
24
25// Create the HomePage if it doesn't exist
26if (! $tikilib->page_exists($prefs['wikiHomePage'])) {
27	$tikilib->create_page($prefs['wikiHomePage'], 0, '', $tikilib->now, 'Tiki initialization');
28}
29
30if (! isset($_SESSION["thedate"])) {
31	$thedate = $tikilib->now;
32} else {
33	$thedate = $_SESSION["thedate"];
34}
35
36// Get the page from the request var or default it to HomePage
37if (! isset($_REQUEST["page"])) {
38	$_REQUEST["page"] = $wikilib->get_default_wiki_page();
39}
40$page = $_REQUEST['page'];
41$smarty->assign('page', $page);
42
43if (! $tikilib->page_exists($prefs['wikiHomePage'])) {
44	$tikilib->create_page($prefs['wikiHomePage'], 0, '', $tikilib->now, 'Tiki initialization');
45}
46
47if (! ($info = $tikilib->get_page_info($page))) {
48	$smarty->assign('msg', tra('Page cannot be found'));
49	$smarty->display('error.tpl');
50	die;
51}
52
53require_once 'lib/wiki/renderlib.php';
54$pageRenderer = new WikiRenderer($info, $user);
55$objectperms = $pageRenderer->applyPermissions();
56
57if ($prefs['flaggedrev_approval'] == 'y' && isset($_REQUEST['latest']) && $objectperms->wiki_view_latest) {
58	$pageRenderer->forceLatest();
59}
60
61$access->check_permission('tiki_p_view', '', 'wiki page', $page);
62
63// BreadCrumbNavigation here
64// Remember to reverse the array when posting the array
65
66if (! isset($_SESSION["breadCrumb"])) {
67	$_SESSION["breadCrumb"] = [];
68}
69
70if (! in_array($page, $_SESSION["breadCrumb"])) {
71	if (count($_SESSION["breadCrumb"]) > $prefs['userbreadCrumb']) {
72		array_shift($_SESSION["breadCrumb"]);
73	}
74
75	array_push($_SESSION["breadCrumb"], $page);
76} else {
77	// If the page is in the array move to the last position
78	$pos = array_search($page, $_SESSION["breadCrumb"]);
79
80	unset($_SESSION["breadCrumb"][$pos]);
81	array_push($_SESSION["breadCrumb"], $page);
82}
83
84// Now increment page hits since we are visiting this page
85$tikilib->add_hit($page);
86
87$smarty->assign('page_user', $info['user']);
88
89if (($tiki_p_admin_wiki == 'y')
90	|| ($user and ($user == $info['user']) and ($tiki_p_lock == 'y') and ($prefs['feature_wiki_usrlock'] == 'y'))) {
91	if (isset($_REQUEST["action"])) {
92		check_ticket('index-p');
93		if ($_REQUEST["action"] == 'unlock') {
94			$wikilib->unlock_page($page);
95		}
96	}
97}
98
99// Save to notepad if user wants to
100if ($user && $prefs['feature_wiki_notepad'] == 'y' && $tiki_p_notepad == 'y' && $prefs['feature_notepad'] == 'y' && isset($_REQUEST['savenotepad'])) {
101		check_ticket('index-p');
102	include_once('lib/notepad/notepadlib.php');
103
104	$notepadlib->replace_note($user, 0, $_REQUEST['page'], $info['data']);
105}
106
107// Verify lock status
108if ($info["flag"] == 'L') {
109	$smarty->assign('lock', true);
110} else {
111	$smarty->assign('lock', false);
112}
113
114// If not locked and last version is user version then can undo
115$smarty->assign('canundo', 'n');
116
117if ($info["flag"] != 'L' && (($tiki_p_edit == 'y' && $info["user"] == $user) || ($tiki_p_remove == 'y'))) {
118	$smarty->assign('canundo', 'y');
119}
120
121if ($tiki_p_admin_wiki == 'y') {
122	$smarty->assign('canundo', 'y');
123}
124
125if (isset($_REQUEST['refresh'])) {
126	$tikilib->invalidate_cache($page);
127}
128
129$smarty->assign('cached_page', 'n');
130
131if (! isset($_REQUEST['pagenum'])) {
132	$_REQUEST['pagenum'] = 1;
133}
134
135if (isset($_REQUEST['pagenum']) && $_REQUEST['pagenum'] > 0) {
136	$pageRenderer->setPageNumber((int) $_REQUEST['pagenum']);
137}
138
139
140include_once('tiki-section_options.php');
141
142$pageRenderer->runSetups();
143
144ask_ticket('index-p');
145
146// disallow robots to index page
147$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
148// Display the Index Template
149$smarty->display("tiki-index_p.tpl");
150