1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8require_once('tiki-setup.php');
9$histlib = TikiLib::lib('hist');
10$wikilib = TikiLib::lib('wiki');
11
12$access->check_feature('feature_wiki');
13
14// Get the page from the request var or default it to HomePage
15if (! isset($_REQUEST["page"])) {
16	$smarty->assign('msg', tra("No page indicated"));
17	$smarty->display("error.tpl");
18	die;
19} else {
20	$page = $_REQUEST["page"];
21	$smarty->assign_by_ref('page', $_REQUEST["page"]);
22}
23if (! isset($_REQUEST["version"])) {
24	$smarty->assign('msg', tra("No version indicated"));
25	$smarty->display("error.tpl");
26	die;
27} else {
28	$version = $_REQUEST["version"];
29	$smarty->assign_by_ref('version', $_REQUEST["version"]);
30}
31if (! ($info = $tikilib->get_page_info($page))) {
32	$smarty->assign('msg', tra('Page cannot be found'));
33	$smarty->display('error.tpl');
34	die;
35}
36if (! $histlib->version_exists($page, $version)) {
37	$smarty->assign('msg', tra("Non-existent version"));
38	$smarty->display("error.tpl");
39	die;
40}
41
42$tikilib->get_perm_object($page, 'wiki page', $info);
43$access->check_permission(['tiki_p_rollback', 'tiki_p_edit']);
44
45if (isset($_REQUEST["rollback"])) {
46	$access->check_authenticity(tr('Are you sure you want to roll back "%0" to version #%1?', $page, $version));
47
48	$comment = $_REQUEST["comment"];
49	$histlib->use_version($page, $version, $comment);
50	$tikilib->invalidate_cache($page);
51
52	header("location: tiki-index.php?page=" . urlencode($page));
53	die;
54}
55$version = $histlib->get_version($page, $version);
56$version["data"] = TikiLib::lib('parser')->parse_data($version["data"], ['preview_mode' => true, 'is_html' => $version['is_html']]);
57$smarty->assign_by_ref('preview', $version);
58// disallow robots to index page:
59$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
60$smarty->assign('mid', 'tiki-rollback.tpl');
61$smarty->display("tiki.tpl");
62