Exemple #1
0
 function action_toggle($input)
 {
     global $user, $tikilib, $prefs, $artlib;
     if (!$user) {
         throw new Services_Exception(tr('Must be authenticated'), 403);
     }
     $type = $input->type->none();
     $object = $input->object->none();
     $target = $input->target->int();
     if (!$type || !$object) {
         throw new Services_Exception(tr('Invalid input'), 400);
     }
     $relationlib = TikiLib::lib('relation');
     $relations = $this->action_list($input);
     if ($target) {
         if (!in_array("{$type}:{$object}", $relations) && ($relationId = $relationlib->add_relation('tiki.user.favorite', 'user', $user, $type, $object))) {
             $relations[$relationId] = "{$type}:{$object}";
             TikiLib::lib('tiki')->refresh_index($type, $object);
         }
     } else {
         foreach ($relations as $id => $key) {
             if ($key === "{$type}:{$object}") {
                 $relationlib->remove_relation($id);
                 unset($relations[$id]);
                 TikiLib::lib('tiki')->refresh_index($type, $object);
             }
         }
     }
     if ($prefs['feature_score'] == 'y' && $target) {
         if ($type == 'forum post') {
             require_once 'lib/comments/commentslib.php';
             $commentslib = new Comments();
             $forum_id = $commentslib->get_comment_forum_id($object);
             $forum_info = $commentslib->get_forum($forum_id);
             $thread_info = $commentslib->get_comment($object, null, $forum_info);
             $item_user = $thread_info['userName'];
         } elseif ($type == 'article') {
             require_once 'lib/articles/artlib.php';
             $artlib = new ArtLib();
             $res = $artlib->get_article($object);
             $item_user = $res['author'];
         }
         $tikilib->score_event($user, 'item_favorited', "{$type}:{$object}");
         $tikilib->score_event($item_user, 'item_is_favorited', "{$user}:{$type}:{$object}");
     }
     return array('list' => $relations);
 }
 if (isset($forum_mode) && $forum_mode == 'y' && $forum_info['is_flat'] == 'y' && $_REQUEST["comments_grandParentId"] > 0) {
     $smarty->assign('msg', tra("This forum is flat and doesn't allow replies to other replies"));
     $smarty->display("error.tpl");
     die;
 }
 if (empty($_REQUEST["comments_parentId"])) {
     $_REQUEST["comments_parentId"] = 0;
 }
 $object = explode(':', $comments_objectId);
 if ($object[0] == 'forum' && !empty($_REQUEST["comments_grandParentId"])) {
     $parent_id = $_REQUEST["comments_grandParentId"];
 } else {
     $parent_id = $_REQUEST["comments_parentId"];
 }
 if (isset($_REQUEST["comments_reply_threadId"]) && !empty($_REQUEST["comments_reply_threadId"])) {
     $reply_info = $commentslib->get_comment($_REQUEST["comments_reply_threadId"]);
     $in_reply_to = $reply_info["message_id"];
 } else {
     $in_reply_to = '';
 }
 // Remove HTML tags and empty lines at the end of the posted comment
 $_REQUEST["comments_data"] = rtrim(strip_tags($_REQUEST["comments_data"]));
 if ($tiki_p_forum_autoapp != 'y' && ($forum_info['approval_type'] == 'queue_all' || !$user && $forum_info['approval_type'] == 'queue_anon')) {
     $smarty->assign('was_queued', 'y');
     $_REQUEST['was_queued'] = 'y';
     $qId = $commentslib->replace_queue(0, $_REQUEST['forumId'], $comments_objectId, $parent_id, $user, $_REQUEST["comments_title"], $_REQUEST["comments_data"], 'n', '', '', $thread_info['title'], $in_reply_to);
     // PROCESS ATTACHMENT HERE
     if ($qId && isset($_FILES['userfile1']) && !empty($_FILES['userfile1']['name'])) {
         if (is_uploaded_file($_FILES['userfile1']['tmp_name'])) {
             check_ticket('view-forum');
             $fp = fopen($_FILES['userfile1']['tmp_name'], "rb");
	) {
		$access->check_authenticity();
		$comments_show = 'y';
		$commentslib->remove_comment($_REQUEST['comments_threadId']);
		$commentslib->register_remove_post($_REQUEST['forumId'], 0);
	} else { // user can't edit this post
		$smarty->assign('msg', tra('You are not permitted to remove someone else\'s post!'));
		$smarty->assign('errortype', 'no_redirect_login');
		$smarty->display('error.tpl');
		die;
	}
	unset($_REQUEST['comments_threadId']);
}

if ($_REQUEST['comments_threadId'] > 0) {
	$comment_info = $commentslib->get_comment($_REQUEST['comments_threadId']);
	$smarty->assign('comment_title', isset($_REQUEST['comments_title']) ? $_REQUEST['comments_title'] : $comment_info['title']);
	$smarty->assign('comment_data', isset($_REQUEST['comments_data']) ? $_REQUEST['comments_data'] : $comment_info['data']);
	$smarty->assign(
					'comment_topictype', 
					isset($_REQUEST['comment_topictype']) ? $_REQUEST['comment_topictype'] : $comment_info['type']
	);
	$smarty->assign(
					'comment_topicsummary', 
					isset($_REQUEST['comment_topicsummary']) ? $_REQUEST['comment_topicsummary'] : $comment_info['summary']
	);
	$smarty->assign('comment_topicsmiley', $comment_info['smiley']);
} else {
	$smarty->assign('comment_title', isset($_REQUEST['comments_title']) ? $_REQUEST['comments_title'] : '');
	$smarty->assign('comment_data', isset($_REQUEST['comments_data']) ? $_REQUEST['comments_data'] : '');
	$smarty->assign('comment_topictype', isset($_REQUEST['comment_topictype']) ? $_REQUEST['comment_topictype'] : '');
if (!empty($_REQUEST['mass_ban_ip'])) {
	check_ticket('admin-banning');
	include_once ('lib/comments/commentslib.php');
	$commentslib = new Comments;
	$smarty->assign('mass_ban_ip', $_REQUEST['mass_ban_ip']);
	$info['mode'] = 'mass_ban_ip';
	$info['title'] = tr('Multiple IP Banning');
	$info['message'] = tr('Access from your localization was forbidden due to excessive spamming.');
	$info['date_to'] = $tikilib->now + 365 * 24 * 3600;
	$banId_list = explode('|', $_REQUEST['mass_ban_ip']);
	// Handle case when coming from tiki-list_comments with a list of IPs to ban and also delete the related comments
	if ( !empty($_REQUEST['mass_remove']) ) {
		$access->check_authenticity(tra('Delete comments then set banning rules'));
	}
	foreach ($banId_list as $id) {
		$ban_comment=$commentslib->get_comment($id);
		$ban_comments_list[$ban_comment['user_ip']][$id]['userName'] = $ban_comment['userName'];
		$ban_comments_list[$ban_comment['user_ip']][$id]['title'] = $ban_comment['title'];
		if ( !empty($_REQUEST['mass_remove']) ) {
			$commentslib->remove_comment($id);
		}
	}
	$smarty->assign_by_ref('ban_comments_list', $ban_comments_list);
}

// Handle case when coming from tiki-admin_actionlog with a list of IPs to ban
if (!empty($_REQUEST['mass_ban_ip_actionlog'])) {
	check_ticket('admin-banning');
	include_once ('lib/logs/logslib.php');
	$actionslib = new LogsLib;
	$smarty->assign('mass_ban_ip', $_REQUEST['mass_ban_ip_actionlog']);
         $_REQUEST['topic_smiley'] = '';
     }
     if (!isset($_REQUEST['type'])) {
         $_REQUEST['type'] = '';
     }
     if (!isset($_REQUEST['topic_title'])) {
         $_REQUEST['topic_title'] = '';
     }
     if (!isset($_REQUEST['in_reply_to'])) {
         $_REQUEST['in_reply_to'] = '';
     }
     if (!isset($_REQUEST['parentId'])) {
         $_REQUEST['parentId'] = $msg_info['parentId'];
     }
     if ($_REQUEST['parentId'] > 0) {
         $p_info = $commentslib->get_comment($_REQUEST['parentId']);
         $_REQUEST['topic_title'] = $p_info['title'];
     }
     $commentslib->replace_queue($_REQUEST['qId'], $_REQUEST['forumId'], 'forum' . $_REQUEST['forumId'], $_REQUEST['parentId'], $user, $_REQUEST['title'], $_REQUEST['data'], $_REQUEST['type'], $_REQUEST['topic_smiley'], $_REQUEST['summary'], $_REQUEST['topic_title'], $_REQUEST['in_reply_to']);
     if (isset($_REQUEST['saveapp'])) {
         $commentslib->approve_queued($_REQUEST['qId']);
     }
     unset($_REQUEST['qId']);
 }
 if (isset($_REQUEST['remove'])) {
     $access->check_authenticity();
     $smarty->assign('form', 'n');
     $commentslib->remove_queued($_REQUEST['qId']);
 }
 if (isset($_REQUEST['topicize'])) {
     check_ticket('forum-queue');
Exemple #6
0
 function create_page($info)
 {
     global $tikilib, $wikilib, $prefs, $tiki_p_wiki_attach_files, $tiki_p_edit_comments, $dbTiki, $tikidomain;
     if (($info['data'] = $this->zip->getFromName($info['zip'])) === false) {
         $this->errors[] = 'Can not unzip';
         $this->errorsArgs[] = $info['zip'];
         return false;
     }
     if ($this->page_exists($info['name'])) {
         $old = true;
         $tikilib->update_page($info['name'], $info['data'], 'Updated from import', !empty($this->config['fromUser']) ? $this->config['fromUser'] : $info['user'], !empty($this->config['fromSite']) ? $this->config['fromSite'] : $info['ip'], $info['description'], 0, isset($info['lang']) ? $info['lang'] : '', isset($info['is_html']) ? $info['is_html'] : false, null, null, isset($info['wysiwyg']) ? $info['wysiwyg'] : NULL);
     } else {
         $old = false;
         $tikilib->create_page($info['name'], $info['hits'], $info['data'], $info['lastModif'], $info['comment'], !empty($this->config['fromUser']) ? $this->config['fromUser'] : $info['user'], !empty($this->config['fromSite']) ? $this->config['fromSite'] : $info['ip'], $info['description'], isset($info['lang']) ? $info['lang'] : '', isset($info['is_html']) ? $info['is_html'] : false, null, isset($info['wysiwyg']) ? $info['wysiwyg'] : NULL, '', 0, $info['created']);
     }
     if ($prefs['feature_wiki_comments'] == 'y' && $tiki_p_edit_comments == 'y' && !empty($info['comments'])) {
         foreach ($info['comments'] as $comment) {
             global $commentslib;
             include_once 'lib/comments/commentslib.php';
             $commentslib = new Comments($dbTiki);
             $parentId = empty($comment['parentId']) ? 0 : $newThreadIds[$comment['parentId']];
             if ($parentId) {
                 $reply_info = $commentslib->get_comment($parentd);
                 $in_reply_to = $reply_info['message_id'];
             }
             $newThreadIds[$comment['threadId']] = $commentslib->post_new_comment('wiki page:' . $info['name'], $parentId, $config['fromUser'] ? $config['fromUser'] : $comment['user'], $comment['title'], $comment['data'], $message_id, $reply_to, 'n', '', '', '', '', $comment['date']);
         }
     }
     if ($prefs['feature_wiki_attachments'] == 'y' && $tiki_p_wiki_attach_files == 'y' && !empty($info['attachments'])) {
         foreach ($info['attachments'] as $attachment) {
             if (($attachment['data'] = $this->zip->getFromName($attachment['zip'])) === false) {
                 $this->errors[] = 'Can not unzip attachment';
                 $this->errorsArgs[] = $attachment['zip'];
                 return false;
             }
             if ($prefs['w_use_db'] == 'y') {
                 $fhash = '';
             } else {
                 $fhash = $this->get_attach_hash_file_name($attachment['filename']);
                 if ($fw = fopen($prefs['w_use_dir'] . $fhash, 'wb')) {
                     if (!fwrite($fw, $attachment['data'])) {
                         $this->errors[] = 'Cannot write to this file';
                         $this->errorsArgs[] = $prefs['w_use_dir'] . $fhash;
                     }
                     fclose($fw);
                     $attachment['data'] = '';
                 } else {
                     $this->errors[] = 'Cannot open this file';
                     $this->errorsArgs[] = $prefs['w_use_dir'] . $fhash;
                 }
             }
             global $wikilib;
             include_once 'lib/wiki/wikilib.php';
             $wikilib->wiki_attach_file($info['name'], $attachment['filename'], $attachment['filetype'], $attachment['filesize'], $attachment['data'], $attachment['comment'], $attachment['user'], $fhash, $attachment['created']);
             //change the page data attach is needed $res['attId']
             //$res = $wikilib->get_wiki_attach_file($info['name'], $attachment['filename'], $attachment['type'], $attachment['size']);
         }
     }
     if ($prefs['feature_wiki_pictures'] == 'y' && !empty($info['images'])) {
         foreach ($info['images'] as $image) {
             if (empty($image['zip'])) {
                 //external link to image
                 continue;
             }
             if (($image['data'] = $this->zip->getFromName($image['zip'])) === false) {
                 $this->errors[] = 'Can not unzip image';
                 $this->errorsArgs[] = $image['zip'];
                 return false;
             }
             if ($image['where'] == 'wiki') {
                 $wiki_up = 'img/wiki_up/';
                 if ($tikidomain) {
                     $wiki_up .= "{$tikidomain}/";
                 }
                 $name = str_replace('img/wiki_up/', '', $image['wiki']);
                 file_put_contents($wiki_up . $name, $image['data']);
                 chmod($wiki_up . $name, 0644);
             }
         }
     }
     if ($prefs['feature_history'] == 'y' && !empty($info['history'])) {
         $query = 'select max(`version`) from `tiki_history` where `pageName`=?';
         $maxVersion = $this->getOne($query, array($info['name']));
         if (!$maxVersion) {
             $maxVersion = 0;
         }
         $newVersion = $maxVersion;
         foreach ($info['history'] as $version) {
             if (($version['data'] = $this->zip->getFromName($version['zip'])) === false) {
                 $this->errors[] = 'Can not unzip history';
                 $this->errorsArgs[] = $version['version'];
                 return false;
             }
             $query = 'insert into `tiki_history`(`pageName`, `version`, `lastModif`, `user`, `ip`, `comment`, `data`, `description`) values(?,?,?,?,?,?,?,?)';
             $this->query($query, array($info['name'], $version['version'] + $maxVersion, $old ? $tikilib->now : $version['lastModif'], $version['user'], $version['ip'], $version['comment'], $version['data'], $version['description']));
             $newVersion = max($version['version'] + $maxVersion, $newVersion);
         }
         $query = 'update `tiki_pages` set `version`=? where `pageName`=?';
         $this->query($query, array($newVersion, $info['name']));
     }
     if ($prefs['feature_wiki_structure'] == 'y' && !empty($info['structure'])) {
         global $structlib;
         include_once 'lib/structures/structlib.php';
         //TODO alias
         if ($info['structure'] == 1) {
             $this->structureStack[$info['structure']] = $structlib->s_create_page(null, null, $info['name'], '');
             if (empty($this->structureStack[$info['structure']])) {
                 $this->errors[] = 'A structure already exists';
                 $this->errorsArgs[] = $info['name'];
                 return false;
             }
         } elseif (!empty($info['structure'])) {
             $this->structureStack[$info['structure']] = $structlib->s_create_page($this->structureStack[$info['structure'] - 1], isset($this->structureStack[$info['structure']]) ? $this->structureStack[$info['structure']] : '', $info['name'], '', $this->structureStack[1]);
         }
     }
     return true;
 }
function smarty_function_rating($params, $smarty)
{
    global $prefs, $ratinglib;
    require_once 'lib/rating/ratinglib.php';
    if (!isset($params['type'], $params['id'])) {
        return tra('No object information provided for rating.');
    }
    $type = $params['type'];
    $id = $params['id'];
    if (isset($params['changemandated']) && $params['changemandated'] == 'y') {
        $changemandated = true;
        // needed to fix multiple submission problem in comments
    } else {
        $changemandated = false;
    }
    if (isset($_REQUEST['rating_value'][$type][$id], $_REQUEST['rating_prev'][$type][$id])) {
        $value = $_REQUEST['rating_value'][$type][$id];
        $prev = $_REQUEST['rating_prev'][$type][$id];
        if ((!$changemandated || $value != $prev) && $ratinglib->record_vote($type, $id, $value)) {
            // Handle type-specific actions
            if ($type == 'comment') {
                global $user;
                require_once 'lib/comments/commentslib.php';
                if ($user) {
                    $commentslib = new Comments();
                    $commentslib->vote_comment($id, $user, $value);
                }
            } elseif ($type == 'article') {
                global $artlib, $user;
                require_once 'lib/articles/artlib.php';
                if ($user) {
                    $artlib->vote_comment($id, $user, $value);
                }
            }
            if ($prefs['feature_score'] == 'y' && $id) {
                global $tikilib;
                if ($type == 'comment') {
                    $forum_id = $commentslib->get_comment_forum_id($id);
                    $forum_info = $commentslib->get_forum($forum_id);
                    $thread_info = $commentslib->get_comment($id, null, $forum_info);
                    $item_user = $thread_info['userName'];
                } elseif ($type == 'article') {
                    require_once 'lib/articles/artlib.php';
                    $artlib = new ArtLib();
                    $res = $artlib->get_article($id);
                    $item_user = $res['author'];
                }
                if ($value == '1') {
                    $tikilib->score_event($item_user, 'item_is_rated', "{$user}:{$type}:{$id}");
                } elseif ($value == '2') {
                    $tikilib->score_event($item_user, 'item_is_unrated', "{$user}:{$type}:{$id}");
                }
            }
        } elseif ($value != $prev) {
            return tra('An error occurred.');
        }
    }
    $vote = $ratinglib->get_vote($type, $id);
    $options = $ratinglib->get_options($type, $id);
    if ($prefs['rating_smileys'] == 'y') {
        $smiles = $ratinglib->get_options_smiles($type, $id);
        $smarty->assign('rating_smiles', $smiles);
    }
    $smarty->assign('rating_type', $type);
    $smarty->assign('rating_id', $id);
    $smarty->assign('rating_options', $options);
    $smarty->assign('current_rating', $vote);
    return $smarty->fetch('rating.tpl');
}
        }
    }
}
if ($tiki_p_forums_report == 'y' && isset($_REQUEST['report'])) {
    check_ticket('view-forum');
    $commentslib->report_post($_REQUEST['forumId'], $_REQUEST['comments_parentId'], $_REQUEST['report'], $user, '');
    $url = "tiki-view_forum_thread.php?forumId=" . $_REQUEST['forumId'] . "&comments_parentId=" . $_REQUEST['comments_parentId'] . "&post_reported=y";
    header('location: ' . $url);
    die;
}
//shows a "thanks for reporting" message
if (isset($_REQUEST["post_reported"]) && $_REQUEST["post_reported"] == 'y') {
    $smarty->assign('post_reported', 'y');
}
$smarty->assign_by_ref('forum_info', $forum_info);
$thread_info = $commentslib->get_comment($_REQUEST["comments_parentId"]);
if (empty($thread_info)) {
    $smarty->assign('msg', tra("Incorrect thread"));
    $smarty->display("error.tpl");
    die;
}
if (!empty($thread_info['parentId'])) {
    $thread_info['topic'] = $commentslib->get_comment($thread_info['parentId']);
}
if ($tiki_p_admin_forum != 'y' && $thread_info['type'] == 'l') {
    $tiki_p_forum_post = 'n';
    $smarty->assign('tiki_p_forum_post', 'n');
}
//print_r($thread_info);
$smarty->assign_by_ref('thread_info', $thread_info);
$comments_per_page = $forum_info['commentsPerPage'];
Exemple #9
0
        check_ticket('view-forum');
        $comments_show = 'y';
        if (!$tikilib->user_has_voted($user, 'comment' . $_REQUEST["comments_threadId"])) {
            $commentslib->vote_comment($_REQUEST["comments_threadId"], $user, $_REQUEST["comments_vote"]);
            $tikilib->register_user_vote($user, 'comment' . $_REQUEST["comments_threadId"]);
        }
        $_REQUEST["comments_threadId"] = 0;
        $smarty->assign('comments_threadId', 0);
    }
}
if ($user) {
    $userinfo = $userlib->get_user_info($user);
    $smarty->assign_by_ref('userinfo', $userinfo);
}
if ($_REQUEST["comments_threadId"] > 0) {
    $comment_info = $commentslib->get_comment($_REQUEST["comments_threadId"]);
    $smarty->assign('comment_title', $comment_info["title"]);
    $smarty->assign('comment_data', $comment_info["data"]);
    $smarty->assign('comment_topictype', $comment_info["type"]);
    $smarty->assign('comment_topicsummary', $comment_info["summary"]);
    $smarty->assign('comment_topicsmiley', $comment_info["smiley"]);
} else {
    $smarty->assign('comment_title', isset($_REQUEST["comments_title"]) ? $_REQUEST["comments_title"] : '');
    $smarty->assign('comment_data', isset($_REQUEST["comments_data"]) ? $_REQUEST["comments_data"] : '');
    $smarty->assign('comment_topictype', isset($_REQUEST["comment_topictype"]) ? $_REQUEST["comment_topictype"] : '');
    $smarty->assign('comment_topictype', 'n');
    $smarty->assign('comment_topicsummary', '');
    $smarty->assign('comment_topicsmiley', '');
}
if (isset($_REQUEST["comments_remove"]) && isset($_REQUEST["comments_threadId"])) {
    if ($tiki_p_admin_forum == 'y' || $commentslib->user_can_edit_post($user, $_REQUEST["comments_threadId"]) && $tiki_p_forum_post_topic == 'y') {
Exemple #10
0
	function wiki_rename_page($oldName, $newName, $renameHomes = true)
	{
		global $prefs, $tikilib;
		// if page already exists, stop here
		$newName = trim($newName);
		if ($this->get_page_info($newName, false, true)) {
			// if it is a case change of same page: allow it, else stop here
			if (strcasecmp(trim($oldName), $newName) <> 0 ) throw new Exception("Page already exists", 2);
		}

		if ($this->contains_badchars($newName) && $prefs['wiki_badchar_prevent'] == 'y') {
			throw new Exception("Bad characters", 1);
		}

		$tmpName = "TmP".$newName."TmP";

		// 1st rename the page in tiki_pages, using a tmpname inbetween for
		// rename pages like ThisTestpage to ThisTestPage
		$query = 'update `tiki_pages` set `pageName`=? where `pageName`=?';
		$this->query($query, array( $tmpName, $oldName ));

		$query = 'update `tiki_pages` set `pageName`=? where `pageName`=?';
		$this->query($query, array( $newName, $tmpName ));

		// correct pageName in tiki_history, using a tmpname inbetween for
		// rename pages like ThisTestpage to ThisTestPage
		$query = 'update `tiki_history` set `pageName`=? where `pageName`=?';
		$this->query($query, array( $tmpName, $oldName ));

		$query = 'update `tiki_history` set `pageName`=? where `pageName`=?';
		$this->query($query, array( $newName, $tmpName ));

		// get pages linking to the old page
		$query = 'select `fromPage` from `tiki_links` where `toPage`=?';
		$result = $this->query($query, array( $oldName ));

		$linksToOld=array();
		while ($res = $result->fetchRow()) {
			$page = $res['fromPage'];

			$is_wiki_page = true;
			if (substr($page, 0, 11) == 'objectlink:') {
				$is_wiki_page = false;
				$objectlinkparts = explode(':', $page);
				$type = $objectlinkparts[1];
				$objectId = $objectlinkparts[2];
			}
			$linksToOld[] = $res['fromPage'];
			if ($is_wiki_page) {
				$info = $this->get_page_info($page);
				//$data=addslashes(str_replace($oldName,$newName,$info['data']));
				$data = $info['data'];
			} elseif ($type == 'forum post' || substr($type, -7) == 'comment') {
				include_once ('lib/comments/commentslib.php');
				global $dbTiki;
				$commentslib = new Comments($dbTiki);
				$comment_info = $commentslib->get_comment($objectId);
				$data = $comment_info['data'];
			}

			$quotedOldName = preg_quote($oldName, '/');
			global $semanticlib; require_once 'lib/wiki/semanticlib.php';

			foreach ( $semanticlib->getAllTokens() as $sem ) {
				$data = str_replace("($sem($oldName", "($sem($newName", $data);
			}

			if ($prefs['feature_wikiwords'] == 'y') {
				if (strstr($newName, ' '))
					$data = preg_replace("/(?<= |\n|\t|\r|\,|\;|^)$quotedOldName(?= |\n|\t|\r|\,|\;|$)/", '((' . $newName . '))', $data);
				else
					$data = preg_replace("/(?<= |\n|\t|\r|\,|\;|^)$quotedOldName(?= |\n|\t|\r|\,|\;|$)/", $newName, $data);
			}

			$data = preg_replace("/(?<=\(\()$quotedOldName(?=\)\)|\|)/i", $newName, $data);

			$quotedOldHtmlName = preg_quote(urlencode($oldName), '/');
			$htmlSearch = '/<a class="wiki" href="tiki-index\.php\?page=' . $quotedOldHtmlName . '([^"]*)"/i';
			$htmlReplace = '<a class="wiki" href="tiki-index.php?page=' . urlencode($newName) . '\\1"';
			$data = preg_replace($htmlSearch, $htmlReplace, $data);
			$htmlSearch = '/<a class="wiki" href="' . $quotedOldHtmlName . '"/i';
			$htmlReplace = '<a class="wiki" href="' . urlencode($newName) . '"';
			$data = preg_replace($htmlSearch, $htmlReplace, $data);

			$htmlWantedSearch = '/(' . $quotedOldName . ')?<a class="wiki wikinew" href="tiki-editpage\.php\?page=' . $quotedOldHtmlName . '"[^<]+<\/a>/i';
			$data = preg_replace($htmlWantedSearch, '((' . $newName . '))', $data);

			if ($is_wiki_page) {
				$query = "update `tiki_pages` set `data`=?,`page_size`=? where `pageName`=?";
				$this->query($query, array( $data,(int) strlen($data), $page));
			} elseif ($type == 'forum post' || substr($type, -7) == 'comment') {
				$query = "update `tiki_comments` set `data`=? where `threadId`=?";
				$this->query($query, array( $data, $objectId));
			}
			$this->invalidate_cache($page);
		}

		// correct toPage and fromPage in tiki_links
		// before update, manage to avoid duplicating index(es) when B is renamed to C while page(s) points to both C (not created yet) and B
		$query = 'select `fromPage` from `tiki_links` where `toPage`=?';
		$result = $this->query($query, array( $newName ));
		$linksToNew = array();

		while ($res = $result->fetchRow()) {
			$linksToNew[] = $res['fromPage'];
		}

		if ($extra = array_intersect($linksToOld, $linksToNew)) {
			$query = 'delete from `tiki_links` where `fromPage` in (' . implode(',', array_fill(0, count($extra), '?')) . ') and `toPage`=?';
			$this->query($query, array_merge($extra, array($oldName)));
		}

		$query = 'update `tiki_links` set `fromPage`=? where `fromPage`=?';
		$this->query($query, array( $newName, $oldName));

		$query = 'update `tiki_links` set `toPage`=? where `toPage`=?';
		$this->query($query, array( $newName, $oldName));

		// tiki_footnotes change pageName
		$query = 'update `tiki_page_footnotes` set `pageName`=? where `pageName`=?';
		$this->query($query, array( $newName, $oldName ));

		// in tiki_categorized_objects update objId
		$newcathref = 'tiki-index.php?page=' . urlencode($newName);
		$query = 'update `tiki_objects` set `itemId`=?,`name`=?,`href`=? where `itemId`=? and `type`=?';
		$this->query($query, array( $newName, $newName, $newcathref, $oldName, 'wiki page'));

		$this->rename_object('wiki page', $oldName, $newName);

		// update categories if new name has a category default
		$categlib = TikiLib::lib('categ');
		$categories = $categlib->get_object_categories('wiki page', $newName);
		$info = $this->get_page_info($newName);
		$categlib->update_object_categories($categories, $newName, 'wiki page', $info['description'], $newName, $newcathref);

		$query = 'update `tiki_wiki_attachments` set `page`=? where `page`=?';
		$this->query($query, array( $newName, $oldName ));

		// group home page
		if ($renameHomes) {
			$query = 'update `users_groups` set `groupHome`=? where `groupHome`=?';
			$this->query($query, array( $newName, $oldName ));
		}

		// copyright
		$query = 'update tiki_copyrights set `page`=? where `page`=?';
		$this->query($query, array( $newName, $oldName ));

		//breadcrumb
		if (isset($_SESSION['breadCrumb']) && in_array($oldName, $_SESSION['breadCrumb'])) {
			$pos = array_search($oldName, $_SESSION["breadCrumb"]);
			$_SESSION['breadCrumb'][$pos] = $newName;
		}

		global $prefs;
		global $tikilib;
		global $smarty;
		global $user;

		// first get all watches for this page ...
		if ($prefs['feature_user_watches'] == 'y') {
			$nots = $tikilib->get_event_watches('wiki_page_changed', $oldName);
		}

		// ... then update the watches table
		// user watches
		$query = "update `tiki_user_watches` set `object`=?, `title`=?, `url`=? where `object`=? and `type` = 'wiki page'";
		$this->query($query, array( $newName, $newName, 'tiki-index.php?page='.$newName, $oldName ));
		$query = "update `tiki_group_watches` set `object`=?, `title`=?, `url`=? where `object`=? and `type` = 'wiki page'";
		$this->query($query, array( $newName, $newName, 'tiki-index.php?page='.$newName, $oldName ));

		// now send notification email to all on the watchlist:
		if ($prefs['feature_user_watches'] == 'y') {
			if (!isset($_SERVER["SERVER_NAME"])) {
				$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
			}

			if (count($nots)) {
				include_once('lib/notifications/notificationemaillib.php');
				$smarty->assign('mail_site', $_SERVER['SERVER_NAME']);
				$smarty->assign('mail_oldname', $oldName);
				$smarty->assign('mail_newname', $newName);
				$smarty->assign('mail_user', $user);
				sendEmailNotification($nots, 'watch', 'user_watch_wiki_page_renamed_subject.tpl', $_SERVER['SERVER_NAME'], 'user_watch_wiki_page_renamed.tpl');
			}
		}

		require_once('lib/search/refresh-functions.php');
		refresh_index('pages', $newName);

		if ($renameHomes && $prefs['wikiHomePage'] == $oldName) {
			$tikilib->set_preference('wikiHomePage', $newName);
		}
		if ($prefs['feature_trackers'] == 'y') {
			global $trklib; include_once('lib/trackers/trackerlib.php');
			$trklib->rename_page($oldName, $newName);
		}

		return true;
	}