if (!isset($_REQUEST["newver"])) { $_REQUEST["newver"] = count($history); } if (isset($_REQUEST["compare"])) { foreach ($history as $old) { if ($old["version"] == $_REQUEST["oldver"]) { break; } } $smarty->assign_by_ref('old', $old); foreach ($history as $new) { if ($new["version"] == $_REQUEST["newver"]) { break; } } $smarty->assign_by_ref('new', $new); if (!isset($_REQUEST["diff_style"]) || $_REQUEST["diff_style"] == "old") { $_REQUEST["diff_style"] = 'unidiff'; } $smarty->assign('diff_style', $_REQUEST["diff_style"]); if ($_REQUEST["diff_style"] != "sideview") { require_once 'lib/diff/difflib.php'; $html = diff2($old["data"], $new["data"], $_REQUEST["diff_style"]); $smarty->assign_by_ref('diffdata', $html); } } else { $smarty->assign('diff_style', ''); } // Get templates from the templates/modules directori $smarty->assign('mid', 'map/tiki-map_history.tpl'); $smarty->display("tiki.tpl");
function update_comment($threadId, $title, $comment_rating, $data, $type = 'n', $summary = '', $smiley = '', $objectId = '', $contributions = '') { global $prefs; $comments = $this->table('tiki_comments'); $hash = md5($title . $data); $existingThread = $comments->fetchColumn('threadId', array('hash' => $hash)); // if exactly same title and data comment does not already exist, and is not the current thread if (empty($existingThread) || in_array($threadId, $existingThread)) { $object = explode(":", $objectId, 2); if ($prefs['feature_actionlog'] == 'y') { $comment = $this->get_comment($threadId); include_once 'lib/diff/difflib.php'; $bytes = diff2($comment['data'], $data, 'bytes'); global $logslib; include_once 'lib/logs/logslib.php'; if ($object[0] == 'forum') { $logslib->add_action('Updated', $object[1], $object[0], "comments_parentId={$threadId}&{$bytes}#threadId{$threadId}", '', '', '', '', $contributions); } else { $logslib->add_action('Updated', $object[1], 'comment', "type=" . $object[0] . "&{$bytes}#threadId{$threadId}", '', '', '', '', $contributions); } } $comments->update(array('title' => $title, 'comment_rating' => (int) $comment_rating, 'data' => $data, 'type' => $type, 'summary' => $summary, 'smiley' => $smiley, 'hash' => $hash), array('threadId' => (int) $threadId)); if ($prefs['feature_contribution'] == 'y') { $contributionlib = TikiLib::lib('contribution'); $contributionlib->assign_contributions($contributions, $threadId, 'comment', $title, '', ''); } $type = $this->update_index($object[0], $threadId); $href = $this->getHref($object[0], $object[1], $threadId); global $tikilib; $tikilib->object_post_save(array('type' => $type, 'object' => $threadId, 'description' => '', 'href' => $href, 'name' => $title), array('content' => $data)); $this->update_comment_links($data, $object[0], $threadId); } // end hash check }
/** Update a wiki page @param array $hash- lock_it,contributions, contributors @param int $saveLastModif - modification time - pass null for now, unless importing a Wiki page **/ function update_page($pageName, $edit_data, $edit_comment, $edit_user, $edit_ip, $edit_description = null, $edit_minor = 0, $lang = '', $is_html = null, $hash = null, $saveLastModif = null, $wysiwyg = '', $wiki_authors_style = '') { global $prefs; $histlib = TikiLib::lib('hist'); if (!$edit_user) { $edit_user = '******'; } $this->invalidate_cache($pageName); // Collect pages before modifying edit_data (see update of links below) $pages = $this->get_pages($edit_data, true); $this->check_alias($edit_data, $pageName); if (!$this->page_exists($pageName)) { return false; } // Get this page information $info = $this->get_page_info($pageName); if ($edit_description === null) { $edit_description = $info['description']; } // Use largest version +1 in history table rather than tiki_page because versions used to be bugged // tiki_history is also bugged as not all changes get stored in the history, like minor changes // and changes that do not modify the body of the page. Both numbers are wrong, but the largest of // them both is right. $old_version = max($info["version"], $histlib->get_page_latest_version($pageName)); $user = $info["user"] ? $info["user"] : '******'; $data = $info["data"]; $willDoHistory = $prefs['feature_wiki_history_full'] == 'y' || $data != $edit_data || $info['description'] != $edit_description || $info["comment"] != $edit_comment; $version = $old_version + ($willDoHistory ? 1 : 0); if ($is_html === null) { $html = $info['is_html']; } else { $html = $is_html ? 1 : 0; } if ($wysiwyg == '') { $wysiwyg = $info['wysiwyg']; } if ($wysiwyg == 'y' && $html != 1 && $prefs['wysiwyg_htmltowiki'] != 'y') { // correct for html only wysiwyg $html = 1; } $parserlib = TikiLib::lib('parser'); $edit_data = $parserlib->process_save_plugins($edit_data, array('type' => 'wiki page', 'itemId' => $pageName, 'user' => $user)); if ($html == 1 && $prefs['feature_purifier'] != 'n') { $parserlib->isHtmlPurifying = true; $parserlib->isEditMode = true; $noparsed = array(); $parserlib->plugins_remove($edit_data, $noparsed); require_once 'lib/htmlpurifier_tiki/HTMLPurifier.tiki.php'; $edit_data = HTMLPurifier($edit_data); $parserlib->plugins_replace($edit_data, $noparsed, true); $parserlib->isHtmlPurifying = false; $parserlib->isEditMode = false; } if (is_null($saveLastModif)) { $saveLastModif = $this->now; } $queryData = array('description' => $edit_description, 'data' => $edit_data, 'comment' => $edit_comment, 'lastModif' => (int) $saveLastModif, 'version' => $version, 'version_minor' => $edit_minor, 'user' => $edit_user, 'ip' => $edit_ip, 'page_size' => strlen($edit_data), 'is_html' => $html, 'wysiwyg' => $wysiwyg, 'wiki_authors_style' => $wiki_authors_style, 'lang' => $lang); if ($hash !== null) { if (!empty($hash['lock_it']) && ($hash['lock_it'] == 'y' || $hash['lock_it'] == 'on')) { $queryData['flag'] = 'L'; $queryData['lockedby'] = $user; } else { if (empty($hash['lock_it']) || $hash['lock_it'] == 'n') { $queryData['flag'] = ''; $queryData['lockedby'] = ''; } } } if ($prefs['wiki_comments_allow_per_page'] != 'n') { if (!empty($hash['comments_enabled']) && $hash['comments_enabled'] == 'y') { $queryData['comments_enabled'] = 'y'; } else { if (empty($hash['comments_enabled']) || $hash['comments_enabled'] == 'n') { $queryData['comments_enabled'] = 'n'; } } } if (empty($hash['contributions'])) { $hash['contributions'] = ''; } if (empty($hash['contributors'])) { $hash2 = ''; } else { foreach ($hash['contributors'] as $c) { $hash3['contributor'] = $c; $hash2[] = $hash3; } } $this->table('tiki_pages')->update($queryData, array('pageName' => $pageName)); // Synchronize object comment if ($prefs['feature_wiki_description'] == 'y') { $query = 'update `tiki_objects` set `description`=? where `itemId`=? and `type`=?'; $this->query($query, array($edit_description, $pageName, 'wiki page')); } //update status, page storage was updated in tiki 9 to be non html encoded $wikilib = TikiLib::lib('wiki'); $converter = new convertToTiki9(); $converter->saveObjectStatus($this->getOne("SELECT page_id FROM tiki_pages WHERE pageName = ?", array($pageName)), 'tiki_pages'); // Parse edit_data updating the list of links from this page $this->clear_links($pageName); // Pages collected above foreach ($pages as $page => $types) { $this->replace_link($pageName, $page, $types); } if (strtolower($pageName) != 'sandbox' && !$edit_minor) { $maxversions = $prefs['maxVersions']; if ($maxversions && ($nb = $histlib->get_nb_history($pageName)) > $maxversions) { // Select only versions older than keep_versions days $keep = $prefs['keep_versions']; $oktodel = $saveLastModif - $keep * 24 * 3600 + 1; $history = $this->table('tiki_history'); $result = $history->fetchColumn('version', array('pageName' => $pageName, 'lastModif' => $history->lesserThan($oktodel)), $nb - $maxversions, 0, array('lastModif' => 'ASC')); foreach ($result as $toRemove) { $histlib->remove_version($pageName, $toRemove); } } } // This if no longer checks for minor-ness of the change; sendWikiEmailNotification does that. if ($willDoHistory) { $this->replicate_page_to_history($pageName); if (strtolower($pageName) != 'sandbox') { if ($prefs['feature_contribution'] == 'y') { // transfer page contributions to the history $contributionlib = TikiLib::lib('contribution'); $history = $this->table('tiki_history'); $historyId = $history->fetchOne($history->max('historyId'), array('pageName' => $pageName, 'version' => (int) $old_version)); $contributionlib->change_assigned_contributions($pageName, 'wiki page', $historyId, 'history', '', $pageName . '/' . $old_version, "tiki-pagehistory.php?page={$pageName}&preview={$old_version}"); } } include_once 'lib/diff/difflib.php'; if (strtolower($pageName) != 'sandbox') { $logslib = TikiLib::lib('logs'); $bytes = diff2($data, $edit_data, 'bytes'); $logslib->add_action('Updated', $pageName, 'wiki page', $bytes, $edit_user, $edit_ip, '', $this->now, $hash['contributions'], $hash2); if ($prefs['feature_contribution'] == 'y') { $contributionlib = TikiLib::lib('contribution'); $contributionlib->assign_contributions($hash['contributions'], $pageName, 'wiki page', $edit_description, $pageName, "tiki-index.php?page=" . urlencode($pageName)); } } if ($prefs['feature_multilingual'] == 'y' && $lang) { // Need to update the translated objects table when an object's language changes. $this->table('tiki_translated_objects')->update(array('lang' => $lang), array('type' => 'wiki page', 'objId' => $info['page_id'])); } if ($prefs['wiki_watch_minor'] != 'n' || !$edit_minor) { // Deal with mail notifications. include_once 'lib/notifications/notificationemaillib.php'; $histlib = TikiLib::lib('hist'); $old = $histlib->get_version($pageName, $old_version); $foo = parse_url($_SERVER["REQUEST_URI"]); $machine = self::httpPrefix(true) . dirname($foo["path"]); $diff = diff2($old["data"], $edit_data, "unidiff"); sendWikiEmailNotification('wiki_page_changed', $pageName, $edit_user, $edit_comment, $old_version, $edit_data, $machine, $diff, $edit_minor, $hash['contributions'], 0, 0, $lang); } } $tx = $this->begin(); TikiLib::events()->trigger('tiki.wiki.update', array('type' => 'wiki page', 'object' => $pageName, 'namespace' => $wikilib->get_namespace($pageName), 'reply_action' => 'comment', 'user' => $GLOBALS['user'], 'page_id' => $info['page_id'], 'version' => $version, 'data' => $edit_data, 'old_data' => $info['data'])); $tx->commit(); }
/** * Return the difference of to strings. * * @param $original original string * @param $new new string * @return string */ protected function _diff($original, $new) { return diff2($original, $new, 'htmldiff'); }
/** * @param $url * @param bool $use_tidy * @return array */ function verif_url($url, $use_tidy = TRUE) { global $cookies; static $purifier; static $loaded = false; $smarty = TikiLib::lib('smarty'); $result = array(); $get = get_from_dom($url->getElementsByTagName('get')->item(0)); $post = get_from_dom($url->getElementsByTagName('post')->item(0)); $xpath = $url->getElementsByTagName('xpath')->item(0)->textContent; $data = $url->getElementsByTagName('data')->item(0)->textContent; $urlstr = $url->getAttribute('src'); if (extension_loaded('http')) { $options['timeout'] = 2; $options['connecttimeout'] = 2; $options['url'] = $url->getAttribute('src'); $options['referer'] = $url->getAttribute('referer'); $options['redirect'] = 0; $options['cookies'] = $cookies; $options['cookiestore'] = tempnam('/tmp/', 'tiki-tests'); // Close the session to avoid timeout session_write_close(); switch (strtolower($url->getAttribute('method'))) { case 'get': $buffer = http_get($urlstr, $options, $info); break; case 'post': $buffer = http_post_fields($urlstr, $post, NULL, $options, $info); } $headers = http_parse_headers($buffer); if (isset($headers['Set-Cookie'])) { foreach ($headers['Set-Cookie'] as $c) { TikiLib::parse_str($c, $cookies); } } $buffer = http_parse_message($buffer)->body; } elseif (extension_loaded('curl')) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $urlstr); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl, CURLOPT_TIMEOUT, 2); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_HEADER, true); curl_setopt($curl, CURLOPT_REFERER, $url->getAttribute('referer')); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false); curl_setopt($curl, CURLOPT_USERAGENT, 'TikiTest'); // We deal with the cookies $cookies_string = ''; foreach ($cookies as $c => $v) { $cookies_string .= "{$c}={$v}; path=/;"; } curl_setopt($curl, CURLOPT_COOKIE, $cookies_string); switch (strtolower($url->getAttribute('method'))) { case 'get': curl_setopt($curl, CURLOPT_HTTPGET, true); break; case 'post': curl_setopt($curl, CURLOPT_POST, true); $post_string = ''; foreach ($post as $p => $v) { if ($post_string != '') { $post_string .= '&'; } $post_string .= "{$p}={$v}"; } curl_setopt($curl, CURLOPT_POSTFIELDS, $post_string); } // Close the session to avoid timeout session_write_close(); $http_response = curl_exec($curl); $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); $header = substr($http_response, 0, $header_size); $body = substr($http_response, $header_size); preg_match_all('|Set-Cookie: (.*);|U', $header, $cookies_array); foreach ($cookies_array[1] as $c) { $cookies_tmp .= "&{$c}"; } TikiLib::parse_str($cookies_tmp, $cookies_titi); if (!is_array($cookies)) { $cookies = array(); } $cookies = array_merge($cookies, $cookies_titi); $buffer = $body; curl_close($curl); } if (extension_loaded('tidy')) { $data = tidy_parse_string($data, array(), 'utf8'); $buffer = tidy_parse_string($buffer, array(), 'utf8'); if ($use_tidy) { tidy_diagnose($data); $result['ref_error_count'] = tidy_error_count($data); $result['ref_error_msg'] = tidy_get_error_buffer($data); tidy_diagnose($buffer); $result['replay_error_count'] = tidy_error_count($buffer); $result['replay_error_msg'] = tidy_get_error_buffer($buffer); } } else { if (!$loaded) { require_once 'lib/htmlpurifier_tiki/HTMLPurifier.tiki.php'; $config = getHTMLPurifierTikiConfig(); $purifier = new HTMLPurifier($config); $loaded = true; } if ($purifier) { $data = '<html><body>' . $purifier->purify($data) . '</body></html>'; $buffer = '<html><body>' . $purifier->purify($buffer) . '</body></html>'; } $result['ref_error_msg'] = tra('The Tidy extension is not present'); $result['replay_error_msg'] = tra('The Tidy extension is not present'); } // If we have a XPath then we extract the new DOM and print it in HTML if (trim($xpath) != '') { $dom_ref = DOMDocument::loadHTML($data); $xp_ref = new DomXPath($dom_ref); $res_ref = $xp_ref->query($xpath); $new_data = new DOMDocument('1.0'); $root = $new_data->createElement('html'); $root = $new_data->appendChild($root); $body = $new_data->createElement('html'); $body = $root->appendChild($body); foreach ($res_ref as $ref) { $tmp = $new_data->importNode($ref, TRUE); $body->appendChild($tmp); } $data = $new_data->saveHTML(); $dom_buffer = DOMDocument::loadHTML($buffer); $xp_buffer = new DomXPath($dom_buffer); $res_buffer = $xp_buffer->query($xpath); $new_buffer = new DOMDocument('1.0'); $root = $new_buffer->createElement('html'); $root = $new_buffer->appendChild($root); $body = $new_buffer->createElement('html'); $body = $root->appendChild($body); foreach ($res_buffer as $ref) { $tmp = $new_buffer->importNode($ref, TRUE); $body->appendChild($tmp); } $buffer = $new_buffer->saveHTML(); } $tmp = diff2($data, $buffer, "htmldiff"); if (trim($xpath) != '') { $result['html'] = preg_replace(array("/<html>/", "/<\\/html>/"), array("<div style='overflow: auto; width:500px; text-align: center'> ", "</div>"), $tmp); } else { $result['html'] = preg_replace(array("/<html.*<body/U", "/<\\/body><\\/html>/U"), array("<div style='overflow: auto; width:500px; text-align: center' ", "</div>"), $tmp); } $result['url'] = $urlstr; $result['method'] = $url->getAttribute('method'); if (strtolower($result['method']) == 'post') { $result['post'] = $post; } return $result; }
function action_preview($input) { Services_Exception_Disabled::check('feature_warn_on_edit'); global $user, $prefs, $page; $tikilib = TikiLib::lib('tiki'); $autoSaveIdParts = explode(':', $input->autoSaveId->text()); // user, section, object id foreach ($autoSaveIdParts as &$part) { $part = urldecode($part); } $page = $autoSaveIdParts[2]; // plugins use global $page for approval if (!Perms::get('wiki page', $page)->edit || $user != $tikilib->get_semaphore_user($page)) { return ''; } $info = $tikilib->get_page_info($page, false); if (empty($info)) { $info = array('data' => ''); } $info['is_html'] = $input->allowHtml->int(); if (!isset($info['wysiwyg']) && isset($_SESSION['wysiwyg'])) { $info['wysiwyg'] = $_SESSION['wysiwyg']; } $options = array('is_html' => $info['is_html'], 'preview_mode' => true, 'process_wiki_paragraphs' => $prefs['wysiwyg_htmltowiki'] === 'y' || $info['wysiwyg'] == 'n', 'page' => $page); if (count($autoSaveIdParts) === 3 && !empty($user) && $user === $autoSaveIdParts[0] && $autoSaveIdParts[1] === 'wiki_page') { $editlib = TikiLib::lib('edit'); $smarty = TikiLib::lib('smarty'); $wikilib = TikiLib::lib('wiki'); $smarty->assign('inPage', $input->inPage->int() ? true : false); if ($input->inPage->int()) { $diffstyle = $input->diff_style->text(); if (!$diffstyle) { // use previously set diff_style $diffstyle = getCookie('preview_diff_style', 'preview', ''); } $data = $editlib->partialParseWysiwygToWiki(TikiLib::lib('autosave')->get_autosave($input->editor_id->text(), $input->autoSaveId->text())); TikiLib::lib('smarty')->assign('diff_style', $diffstyle); if ($diffstyle) { if (!empty($info['created'])) { $info = $tikilib->get_page_info($page); // get page with data this time } if ($input->hdr->int()) { // TODO refactor with code in editpage if ($input->hdr->int() === 0) { list($real_start, $real_len) = $tikilib->get_wiki_section($info['data'], 1); $real_len = $real_start; $real_start = 0; } else { list($real_start, $real_len) = $tikilib->get_wiki_section($info['data'], $input->hdr->int()); } $info['data'] = substr($info['data'], $real_start, $real_len); } require_once 'lib/diff/difflib.php'; if ($info['is_html'] == 1) { $diffold = $tikilib->htmldecode($info['data']); } else { $diffold = $info['data']; } if ($info['is_html']) { $diffnew = $tikilib->htmldecode($data); } else { $diffnew = $data; } if ($diffstyle === 'htmldiff') { $diffnew = $tikilib->parse_data($diffnew, $options); $diffold = $tikilib->parse_data($diffold, $options); } $data = diff2($diffold, $diffnew, $diffstyle); $smarty->assign_by_ref('diffdata', $data); $smarty->assign('translation_mode', 'y'); $data = $smarty->fetch('pagehistory.tpl'); } else { $data = $tikilib->parse_data($data, $options); } $parsed = $data; } else { // popup window TikiLib::lib('header')->add_js(' function get_new_preview() { $("body").css("opacity", 0.6); location.reload(true); } $(window).on("load", function(){ if (typeof opener != "undefined") { opener.ajaxPreviewWindow = this; } }).on("unload", function(){ if (typeof opener.ajaxPreviewWindow != "undefined") { opener.ajaxPreviewWindow = null; } }); '); $smarty->assign('headtitle', tra('Preview')); $data = '<div id="c1c2"><div id="wrapper"><div id="col1"><div id="tiki-center" class="wikitext">'; if (TikiLib::lib('autosave')->has_autosave($input->editor_id->text(), $input->autoSaveId->text())) { $parserlib = TikiLib::lib('parser'); $data .= $parserlib->parse_data($editlib->partialParseWysiwygToWiki(TikiLib::lib('autosave')->get_autosave($input->editor_id->text(), $input->autoSaveId->text())), $options); } else { if ($autoSaveIdParts[1] == 'wiki_page') { $canBeRefreshed = false; $data .= $wikilib->get_parse($autoSaveIdParts[2], $canBeRefreshed); } } $data .= '</div></div></div></div>'; $smarty->assign_by_ref('mid_data', $data); $smarty->assign('mid', ''); $parsed = $smarty->fetch("tiki_full.tpl"); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'xmlhttprequest'; // to fool Services_Broker into putputting full page } if ($prefs['feature_wiki_footnotes']) { $footnote = $input->footnote->text(); if ($footnote) { $footnote = $tikilib->parse_data($footnote); } else { $footnote = $wikilib->get_footnote($user, $page); } } return array('parsed' => $parsed, 'parsed_footnote' => $footnote); } }
function histlib_helper_setup_diff( $page, $oldver, $newver ) { global $smarty, $histlib, $tikilib, $prefs; $prefs['wiki_edit_section'] = 'n'; $info = $tikilib->get_page_info($page); if ($oldver == 0 || $oldver == $info["version"]) { $old = & $info; $smarty->assign_by_ref('old', $info); } else { // fetch the required page from history, including its content while( $oldver > 0 && ! ($exists = $histlib->version_exists($page, $oldver) ) ) --$oldver; if ( $exists ) { $old = $histlib->get_page_from_history($page, $oldver, true); $smarty->assign_by_ref('old', $old); } } if ($newver == 0 || $newver >= $info["version"]) { $new =& $info; $smarty->assign_by_ref('new', $info); } else { // fetch the required page from history, including its content while( $newver > 0 && ! ($exists = $histlib->version_exists($page, $newver) ) ) --$newver; if ( $exists ) { $new = $histlib->get_page_from_history($page, $newver, true); $smarty->assign_by_ref('new', $new); } } $oldver_mod = $oldver; if ($oldver == 0) { $oldver_mod = 1; } $query = "SELECT `comment`, `version` from `tiki_history` WHERE `pageName`=? and `version` BETWEEN ? AND ? ORDER BY `version` DESC"; $result = $histlib->query($query, array($page,$oldver_mod,$newver)); $diff_summaries = array(); if ($oldver == 0) { $diff_summaries[] = $old['comment']; } while ($res = $result->fetchRow()) { $aux = array(); $aux["comment"] = $res["comment"]; $aux["version"] = $res["version"]; $diff_summaries[] = $aux; } $smarty->assign('diff_summaries', $diff_summaries); if (!isset($_REQUEST["diff_style"]) || $_REQUEST["diff_style"] == "old") { $_REQUEST["diff_style"] = 'unidiff'; } $smarty->assign('diff_style', $_REQUEST["diff_style"]); if ($_REQUEST["diff_style"] == "sideview") { $old["data"] = $tikilib->parse_data($old["data"], array('preview_mode' => true)); $new["data"] = $tikilib->parse_data($new["data"], array('preview_mode' => true)); } else { require_once('lib/diff/difflib.php'); if ($info['is_html'] == 1 and $_REQUEST["diff_style"] != "htmldiff") { $search[] = "~</(table|td|th|div|p)>~"; $replace[] = "\n"; $search[] = "~<(hr|br) />~"; $replace[] = "\n"; $old['data'] = strip_tags(preg_replace($search, $replace, $old['data']), '<h1><h2><h3><h4><b><i><u><span>'); $new['data'] = strip_tags(preg_replace($search, $replace, $new['data']), '<h1><h2><h3><h4><b><i><u><span>'); } if ($_REQUEST["diff_style"] == "htmldiff") { $parse_options = array('is_html' => ($old['is_html'] == 1), 'noheadinc' => true, 'suppress_icons' => true); $old["data"] = $tikilib->parse_data($old["data"], $parse_options); $new["data"] = $tikilib->parse_data($new["data"], $parse_options); $old['data'] = histlib_strip_irrelevant($old['data']); $new['data'] = histlib_strip_irrelevant($new['data']); } # If the user doesn't have permission to view # source, strip out all tiki-source-based comments global $tiki_p_wiki_view_source; if ($tiki_p_wiki_view_source != 'y' && $_REQUEST["diff_style"] != "htmldiff") { $old["data"] = preg_replace(';~tc~(.*?)~/tc~;s', '', $old["data"]); $new["data"] = preg_replace(';~tc~(.*?)~/tc~;s', '', $new["data"]); } $html = diff2($old["data"], $new["data"], $_REQUEST["diff_style"]); $smarty->assign_by_ref('diffdata', $html); } }
/** Update a wiki page @param array $hash- lock_it,contributions, contributors **/ function update_page($pageName, $edit_data, $edit_comment, $edit_user, $edit_ip, $description = '', $minor = false, $lang = '', $is_html = false, $hash = null, $saveLastModif = null, $wysiwyg = '', $wiki_authors_style) { global $smarty, $prefs, $dbTiki, $histlib, $quantifylib; include_once "lib/wiki/histlib.php"; include_once "lib/commentslib.php"; $commentslib = new Comments($dbTiki); if (!$edit_user) { $edit_user = '******'; } $this->invalidate_cache($pageName); // Collect pages before modifying edit_data (see update of links below) $pages = $this->get_pages($edit_data); if (!$this->page_exists($pageName)) { return false; } // Get this page information $info = $this->get_page_info($pageName); // Use largest version +1 in history table rather than tiki_page because versions used to be bugged // tiki_history is also bugged as not all changes get stored in the history, like minor changes // and changes that do not modify the body of the page. Both numbers are wrong, but the largest of // them both is right. $old_version = max($info["version"], $histlib->get_page_latest_version($pageName) + 1); $lastModif = $info["lastModif"]; $user = $info["user"]; if (!$user) { $user = '******'; } $ip = $info["ip"]; $comment = $info["comment"]; $data = $info["data"]; // WARNING: POTENTIAL BUG // The line below is not consistent with the rest of Tiki // (I commented it out so it can be further examined by CVS change control) //$pageName=addslashes($pageName); // But this should work (comment added by redflo): $version = $old_version + 1; if ($prefs['quantify_changes'] == 'y' && $prefs['feature_multilingual'] == 'y') { include_once 'lib/wiki/quantifylib.php'; $quantifylib->recordChangeSize($info['page_id'], $version, $info['data'], $edit_data); } $html = $is_html ? 1 : 0; if ($html && $prefs['feature_purifier'] != 'n') { require "HTMLPurifier.auto.php"; $purifier = new HTMLPurifier(); $edit_data = $purifier->purify($edit_data); } $mid = ''; if (is_null($saveLastModif)) { $saveLastModif = $this->now; } $bindvars = array($description, $edit_data, $edit_comment, (int) $saveLastModif, $version, $edit_user, $edit_ip, (int) strlen($data), $html, $wysiwyg, $wiki_authors_style); if ($lang) { $mid .= ', `lang`=? '; $bindvars[] = $lang; } if (!empty($hash['lock_it']) && ($hash['lock_it'] == 'y' || $hash['lock_it'] == 'on')) { $mid .= ', `flag`=?, `lockedby`=? '; $bindvars[] = 'L'; $bindvars[] = $user; } else { if (empty($hash['lock_it']) || $hash['lock_it'] == 'n') { $mid .= ', `flag`=?, `lockedby`=? '; $bindvars[] = ''; $bindvars[] = ''; } } if (empty($hash['contributions'])) { $hash['contributions'] = ''; } if (empty($hash['contributors'])) { $hash2 = ''; } else { foreach ($hash['contributors'] as $c) { $hash3['contributor'] = $c; $hash2[] = $hash3; } } $bindvars[] = $pageName; $query = "update `tiki_pages` set `description`=?, `data`=?, `comment`=?, `lastModif`=?, `version`=?, `user`=?, `ip`=?, `page_size`=?, `is_html`=?, `wysiwyg`=?, `wiki_authors_style`=? {$mid} where `pageName`=?"; $result = $this->query($query, $bindvars); // Parse edit_data updating the list of links from this page $this->clear_links($pageName); // Pages collected above foreach ($pages as $page) { $this->replace_link($pageName, $page); } if (strtolower($pageName) != 'sandbox' && !$minor) { $maxversions = $prefs['maxVersions']; if ($maxversions && ($nb = $histlib->get_nb_history($pageName)) > $maxversions) { // Select only versions older than keep_versions days $keep = $prefs['keep_versions']; $oktodel = $saveLastModif - $keep * 24 * 3600; $query = "select `pageName` ,`version`, `historyId` from `tiki_history` where `pageName`=? and `lastModif`<=? order by `lastModif` asc"; $result = $this->query($query, array($pageName, $oktodel), $nb - $maxversions); $toelim = $result->numRows(); while ($res = $result->fetchRow()) { $page = $res["pageName"]; $version = $res["version"]; $query = "delete from `tiki_history` where `pageName`=? and `version`=?"; $this->query($query, array($pageName, $version)); if ($prefs['feature_contribution'] == 'y') { global $contributionlib; include_once 'lib/contribution/contributionlib.php'; $contributionlib->remove_history($res['historyId']); } } } } // This if no longer checks for minor-ness of the change; sendWikiEmailNotification does that. if ($prefs['feature_wiki_history_full'] == 'y' || $data != $edit_data || $description != $info["description"] || $comment != $edit_comment) { if (strtolower($pageName) != 'sandbox') { $query = "insert into `tiki_history`(`pageName`, `version`, `lastModif`, `user`, `ip`, `comment`, `data`, `description`)\n\t\t values(?,?,?,?,?,?,?,?)"; # echo "<pre>";print_r(get_defined_vars());echo "</pre>";die(); $result = $this->query($query, array($pageName, (int) $old_version, (int) $lastModif, $user, $ip, $comment, $data, $description)); if ($prefs['feature_contribution'] == 'y') { // transfer page contributions to the history global $contributionlib; include_once 'lib/contribution/contributionlib.php'; $query = 'select max(`historyId`) from `tiki_history`where `pageName`=? and `version`=?'; $historyId = $this->getOne($query, array($pageName, (int) $old_version)); $contributionlib->change_assigned_contributions($pageName, 'wiki page', $historyId, 'history', '', $pageName . '/' . $old_version, "tiki-pagehistory.php?page={$pageName}&preview={$old_version}"); } /* the following doesn't work because tiki dies if the above query fails if (!$result) { $query2 = "delete from `tiki_history` where `pageName`=? and `version`=?"; $result = $this->query($query2,array($pageName,(int) $version)); $result = $this->query($query,array($pageName,(int) $version,(int) $lastModif,$user,$ip,$comment,$data,$description)); } */ } if (strtolower($pageName) != 'sandbox') { global $logslib; include_once 'lib/logs/logslib.php'; include_once 'lib/diff/difflib.php'; $bytes = diff2($data, $edit_data, 'bytes'); $logslib->add_action('Updated', $pageName, 'wiki page', $bytes, $edit_user, $edit_ip, '', $this->now, $hash['contributions'], $hash2); if ($prefs['feature_contribution'] == 'y') { global $contributionlib; include_once 'lib/contribution/contributionlib.php'; $contributionlib->assign_contributions($hash['contributions'], $pageName, 'wiki page', $description, $pageName, "tiki-index.php?page=" . urlencode($pageName)); } } if ($prefs['feature_multilingual'] == 'y' && $lang) { // Need to update the translated objects table when an object's language changes. $this->query("UPDATE tiki_translated_objects SET lang = ? WHERE objId = ? AND type = 'wiki page'", array($lang, $info['page_id'])); } if ($prefs['feature_user_watches'] == 'y' && $prefs['wiki_watch_minor'] != 'n') { // Deal with mail notifications. include_once 'lib/notifications/notificationemaillib.php'; global $histlib; include_once "lib/wiki/histlib.php"; $old = $histlib->get_version($pageName, $old_version); $foo = parse_url($_SERVER["REQUEST_URI"]); $machine = $this->httpPrefix() . dirname($foo["path"]); require_once 'lib/diff/difflib.php'; $diff = diff2($old["data"], $edit_data, "unidiff"); sendWikiEmailNotification('wiki_page_changed', $pageName, $edit_user, $edit_comment, $old_version, $edit_data, $machine, $diff, $minor, $hash['contributions']); } $query = "delete from `tiki_page_drafts` where `user`=? and `pageName`=?"; $this->query($query, array($GLOBALS['user'], $pageName)); if ($prefs['feature_score'] == 'y') { $this->score_event($user, 'wiki_edit'); } } if ($prefs['feature_search'] == 'y' && $prefs['feature_search_fulltext'] != 'y' && $prefs['search_refresh_index_mode'] == 'normal') { require_once 'lib/search/refresh-functions.php'; refresh_index('pages', $pageName); } }
// get last 2 versions of the page and parse them $curr_page = $tikilib->get_page_info($data["pageName"]); $pageversion = (int) $histlib->get_page_latest_version($data["pageName"]); if ($pageversion == FALSE) { $prev_page = $curr_page; $prev_page["data"] = ""; } else { $prev_page = $histlib->get_page_from_history($data["pageName"], $pageversion, true); } $_REQUEST['redirectpage'] = 'y'; //block the redirect interpretation $curr_page_p = $tikilib->parse_data($curr_page["{$descId}"]); $prev_page_p = $tikilib->parse_data($prev_page["{$descId}"]); // do a diff between both pages require_once 'lib/diff/difflib.php'; $diff = diff2($prev_page_p, $curr_page_p, "unidiff"); $result = "<style TYPE=\"text/css\"> .diffchar { color:red; } </style>"; foreach ($diff as $part) { if ($part["type"] == "diffdeleted") { foreach ($part["data"] as $chunk) { $result .= "- " . $chunk; } } if ($part["type"] == "diffadded") { foreach ($part["data"] as $chunk) { $result .= "+ " . $chunk; } } } $data["{$descId}"] = $result; // hand over the version of the second page
/** * @param $threadId * @param $title * @param $comment_rating * @param $data * @param string $type * @param string $summary * @param string $smiley * @param string $objectId * @param string $contributions */ function update_comment($threadId, $title, $comment_rating, $data, $type = 'n', $summary = '', $smiley = '', $objectId = '', $contributions = '') { global $prefs; $comments = $this->table('tiki_comments'); $hash = md5($title . $data); $existingThread = $comments->fetchColumn('threadId', array('hash' => $hash)); // if exactly same title and data comment does not already exist, and is not the current thread if (empty($existingThread) || in_array($threadId, $existingThread)) { $comment = $this->get_comment($threadId); if ($prefs['feature_actionlog'] == 'y') { include_once 'lib/diff/difflib.php'; $bytes = diff2($comment['data'], $data, 'bytes'); global $logslib; include_once 'lib/logs/logslib.php'; if ($comment['objectType'] == 'forum') { $logslib->add_action('Updated', $comment['object'], $comment['objectType'], "comments_parentId={$threadId}&{$bytes}#threadId{$threadId}", '', '', '', '', $contributions); } else { $logslib->add_action('Updated', $comment['object'], 'comment', "type=" . $comment['objectType'] . "&{$bytes}#threadId{$threadId}", '', '', '', '', $contributions); } } $comments->update(array('title' => $title, 'comment_rating' => (int) $comment_rating, 'data' => $data, 'type' => $type, 'summary' => $summary, 'smiley' => $smiley, 'hash' => $hash), array('threadId' => (int) $threadId)); if ($prefs['feature_contribution'] == 'y') { $contributionlib = TikiLib::lib('contribution'); $contributionlib->assign_contributions($contributions, $threadId, 'comment', $title, '', ''); } $this->update_comment_links($data, $comment['objectType'], $threadId); $type = $this->update_index($comment['objectType'], $threadId); if ($type == 'forum post') { TikiLib::events()->trigger('tiki.forumpost.update', array('type' => $type, 'object' => $threadId, 'forum_id' => $comment['object'], 'user' => $GLOBALS['user'], 'title' => $title, 'content' => $data, 'index_handled' => true)); } else { if ($comment['objectType'] == 'trackeritem') { $parentobject = TikiLib::lib('trk')->get_tracker_for_item($comment['object']); } else { $parentobject = 'not implemented'; } TikiLib::events()->trigger('tiki.comment.update', array('type' => $comment['objectType'], 'object' => $comment['object'], 'parentobject' => $parentobject, 'title' => $title, 'comment' => $threadId, 'user' => $GLOBALS['user'], 'content' => $data)); } } // end hash check }
function update_comment($threadId, $title, $comment_rating, $data, $type = 'n', $summary = '', $smiley = '', $objectId = '', $contributions = '') { global $prefs; $hash = md5($title . $data); $query = "select `threadId` from `tiki_comments` where `hash`=?"; $result = $this->query($query, array($hash)); $existingThread = array(); while ($res = $result->fetchRow()) { $existingThread[] = $res['threadId']; } // if exactly same title and data comment does not already exist, and is not the current thread if (!$result->numRows() || in_array($threadId, $existingThread)) { if ($prefs['feature_actionlog'] == 'y') { $object = explode(":", $objectId, 2); $comment = $this->get_comment($threadId); include_once 'lib/diff/difflib.php'; $bytes = diff2($comment['data'], $data, 'bytes'); global $logslib; include_once 'lib/logs/logslib.php'; if ($object[0] == 'forum') { $logslib->add_action('Updated', $object[1], $object[0], "comments_parentId={$threadId}&{$bytes}#threadId{$threadId}", '', '', '', '', $contributions); } else { $logslib->add_action('Updated', $object[1], 'comment', "type=" . $object[0] . "&{$bytes}#threadId{$threadId}", '', '', '', '', $contributions); } } $query = "update `tiki_comments` set `title`=?, `comment_rating`=?,\n\t`data`=?, `type`=?, `summary`=?, `smiley`=?, `hash`=?\n\t where `threadId`=?"; $result = $this->query($query, array($title, (int) $comment_rating, $data, $type, $summary, $smiley, $hash, (int) $threadId)); if ($prefs['feature_contribution'] == 'y') { global $contributionlib; include_once 'lib/contribution/contributionlib.php'; $contributionlib->assign_contributions($contributions, $threadId, 'comment', $title, '', ''); } if ($prefs['feature_search'] == 'y' && $prefs['feature_search_fulltext'] != 'y' && $prefs['search_refresh_index_mode'] == 'normal') { require_once 'lib/search/refresh-functions.php'; refresh_index('comments', $threadId); } $this->update_comment_links($data, $object[0], $threadId); } // end hash check }
$curr_page = $tikilib->get_page_info($data["pageName"]); $pageversion = (int) $histlib->get_page_latest_version($data["pageName"]); if ($pageversion == false) { $prev_page = $curr_page; $prev_page["data"] = ""; } else { $prev_page = $histlib->get_page_from_history($data["pageName"], $pageversion, true); } $_REQUEST['redirectpage'] = 'y'; //block the redirect interpretation $_REQUEST['page'] = $data["pageName"]; $curr_page_p = $tikilib->parse_data($curr_page[$descId], array('print' => true, 'is_html' => $curr_page['is_html'])); $prev_page_p = $tikilib->parse_data($prev_page[$descId], array('print' => true, 'is_html' => $curr_page['is_html'])); // do a diff between both pages require_once 'lib/diff/difflib.php'; $diff = diff2($prev_page_p, $curr_page_p, $curr_page['is_html'] ? 'htmldiff' : 'unidiff'); if (is_array($diff)) { foreach ($diff as $part) { if ($part["type"] == "diffdeleted") { foreach ($part["data"] as $chunk) { $result .= "<blockquote>- {$chunk}</blockquote>"; } } if ($part["type"] == "diffadded") { foreach ($part["data"] as $chunk) { $result .= "<blockquote>+ {$chunk}</blockquote>"; } } } } else { $result = strpos($diff, '<tr>') === 0 ? '<table>' . $diff . '</table>' : $diff;
<html> <head> <title>Parser Diff</title> <?php require_once 'tiki-setup.php'; global $tikilib, $prefs; $_REQUEST = array_merge(array("page" => "HomePage", "id" => ""), $_REQUEST); $data = $tikilib->getOne('SELECT data FROM tiki_pages WHERE pageName = ? OR page_id = ?', array($_REQUEST['page'], $_REQUEST['id'])); $prefs['feature_jison_wiki_parser'] = ''; $oldParsed = $tikilib->parse_data($data); $prefs['feature_jison_wiki_parser'] = 'y'; $newParsed = $tikilib->parse_data($data); include_once 'lib/diff/difflib.php'; $diff = diff2($oldParsed, $newParsed); ?> </head> <body> <table style="width: 100%;"> <tr> <td>Old Parser</td> <td>New Parser</td> </tr> <tr> <td><?php echo $oldParsed; ?> </td> <td><?php echo $newParsed; ?> </td>
} $info['data'] = substr($info['data'], $real_start, $real_len); } require_once 'lib/diff/difflib.php'; if ($info['is_html'] == 1) { $diffold = $tikilib->htmldecode($info['data']); } else { $diffold = $info['data']; } $_REQUEST['allowHtml'] = isset($_REQUEST['allowHtml']) ? $_REQUEST['allowHtml'] : $info['is_html']; if ($_REQUEST['allowHtml']) { $diffnew = $tikilib->htmldecode($data); } else { $diffnew = $data; } $data = diff2($diffold, $diffnew, $_REQUEST["diff_style"]); $smarty->assign_by_ref('diffdata', $data); $smarty->assign('translation_mode', 'y'); $data = $smarty->fetch('pagehistory.tpl'); } } else { $data = $tikilib->parse_data($data, $options); } echo $data; } else { // popup window TikiLib::lib('header')->add_js('function get_new_preview() { $("body").css("opacity", 0.6); location.replace("' . $tikiroot . 'tiki-auto_save.php?editor_id=' . $_REQUEST['editor_id'] . '&autoSaveId=' . $_REQUEST['autoSaveId'] . '"); } $(window).load(function(){
function histlib_helper_setup_diff($page, $oldver, $newver) { global $smarty, $histlib, $tikilib; $info = $tikilib->get_page_info($page); if ($oldver == 0 || $oldver == $info["version"]) { $old =& $info; $smarty->assign_by_ref('old', $info); } else { // fetch the required page from history, including its content while ($oldver > 0 && !($exists = $histlib->version_exists($page, $oldver))) { --$oldver; } if ($exists) { $old = $histlib->get_page_from_history($page, $oldver, true); $smarty->assign_by_ref('old', $old); } } if ($newver == 0 || $newver >= $info["version"]) { $new =& $info; $smarty->assign_by_ref('new', $info); } else { // fetch the required page from history, including its content while ($newver > 0 && !($exists = $histlib->version_exists($page, $newver))) { --$newver; } if ($exists) { $new = $histlib->get_page_from_history($page, $newver, true); $smarty->assign_by_ref('new', $new); } } if (!isset($_REQUEST["diff_style"]) || $_REQUEST["diff_style"] == "old") { $_REQUEST["diff_style"] = 'unidiff'; } $smarty->assign('diff_style', $_REQUEST["diff_style"]); if ($_REQUEST["diff_style"] == "sideview") { $old["data"] = $tikilib->parse_data($old["data"]); $new["data"] = $tikilib->parse_data($new["data"]); } else { require_once 'lib/diff/difflib.php'; if ($info['is_html'] == 1 and $_REQUEST["diff_style"] != "htmldiff") { $search[] = "~</(table|td|th|div|p)>~"; $replace[] = "\n"; $search[] = "~<(hr|br) />~"; $replace[] = "\n"; $old['data'] = strip_tags(preg_replace($search, $replace, $old['data']), '<h1><h2><h3><h4><b><i><u><span>'); $new['data'] = strip_tags(preg_replace($search, $replace, $new['data']), '<h1><h2><h3><h4><b><i><u><span>'); } if ($_REQUEST["diff_style"] == "htmldiff") { $old["data"] = $tikilib->parse_data($old["data"], $info['is_html'] == 1); $new["data"] = $tikilib->parse_data($new["data"], $info['is_html'] == 1); } $html = diff2($old["data"], $new["data"], $_REQUEST["diff_style"]); $smarty->assign_by_ref('diffdata', $html); } }