function _changed($orig, $final) { // If we've already split on words, don't try to do so again - just display. if ($this->_split_level == 'words') { $prefix = ''; while ($orig[0] !== false && $final[0] !== false && substr($orig[0], 0, 1) == ' ' && substr($final[0], 0, 1) == ' ') { $prefix .= substr($orig[0], 0, 1); $orig[0] = substr($orig[0], 1); $final[0] = substr($final[0], 1); } return $prefix . $this->_deleted($orig) . $this->_added($final); } $text1 = implode("\n", $orig); $text2 = implode("\n", $final); // Non-printing newline marker. $nl = ""; // We want to split on word boundaries, but we need to preserve whitespace as well. // Therefore we split on words, but include all blocks of whitespace in the wordlist. $splitted_text_1 = $this->_split_on_words($text1, $nl); $splitted_text_2 = $this->_split_on_words($text2, $nl); $diff = new diff($splitted_text_1, $splitted_text_2); unset($splitted_text_1, $splitted_text_2); // Get the diff in inline format. $renderer = new diff_renderer_inline(array_merge($this->get_params(), array('split_level' => 'words'))); // Run the diff and get the output. return str_replace($nl, "\n", $renderer->render($diff)) . "\n"; }
function diff() { $page = Wiki::getPageById(get_id(), active_project()); if (!instance_of($page, 'WikiPage')) { flash_error('wiki page dnx'); $this->redirectTo('wiki'); } // if if (!$page->canView(logged_user())) { flash_error('no access permissions'); $this->redirectTo('wiki'); } // if $rev1 = $page->getRevision(array_var($_GET, 'rev1', -1)); $rev2 = $page->getRevision(array_var($_GET, 'rev2', -1)); if (!instance_of($rev1, 'Revision') || !instance_of($rev2, 'Revision')) { flash_error(lang('wiki page revision dnx')); $this->redirectTo('wiki'); } // if $this->addHelper('textile'); //Load text diff library Env::useLibrary('diff', 'wiki'); $diff = new diff($rev1->getContent(), $rev2->getContent()); $output = new diff_renderer_inline(); tpl_assign('diff', $output->render($diff)); tpl_assign('page', $page); tpl_assign('revision', $page->getLatestRevision()); tpl_assign('rev1', $rev1); tpl_assign('rev2', $rev2); }