/** * Creates the array which contains two compared page versions * * @author Johannes Klose <*****@*****.**> * @param string $origText Original page text * @param string $finalText Final page text * @param array $versions All page versions * @return array Page differences **/ function makeDiff($origText, $finalText, &$versions) { $diff = diff::getDiff($finalText, $origText); $origLines = explode("\n", $origText); $finalLines = explode("\n", $finalText); $lineCount = count($origLines) > count($finalLines) ? count($origLines) : count($finalLines); $origTextT = array(); $finalTextT = array(); $ol = 0; $fl = 0; for ($i = 0; $i <= $lineCount; $i++) { if (isset($diff[$i])) { $opType = $diff[$i][0]; $opVal = isset($diff[$i][1]) ? $diff[$i][1] : ''; if ($opType == '~') { $origTextT[] = htmlentities($origLines[$ol]); $finalTextT[] = array('type' => 'edit', 'line' => htmlentities($opVal)); $ol++; $fl++; } elseif ($opType == '+') { $origTextT[] = ''; $finalTextT[] = array('type' => 'add', 'line' => htmlentities($opVal)); $fl++; } else { $origTextT[] = htmlentities($origLines[$ol]); $finalTextT[] = array('type' => 'subs', 'line' => htmlentities($origLines[$ol])); $ol++; } } else { if (isset($origLines[$ol])) { $origTextT[] = htmlentities($origLines[$ol]); $ol++; } if (isset($finalLines[$fl])) { $finalTextT[] = array('type' => 'none', 'line' => htmlentities($finalLines[$fl])); $fl++; } } } return array('orig' => $origTextT, 'final' => $finalTextT); }
/** * Creates a changelog and version information * for a edited page. * * @author Johannes Klose <*****@*****.**> * @param int $pageId The page id * @param string $oldText Old page text * @param string $newText New page text * @param string $version Old page version * @param int $userId The authors id (if logged in) * @param string $userName The authors name (if it is an unregistered author) * @param string $summary Summary of changes * @return string New page version **/ function logChanges($pageId, $oldText, $newText, $version, $userId, $userName, $summary) { $db =& singleton('database'); $pageVersion = $version; $linesOld = explode("\n", $newText); $diff = diff::getDiff($oldText, $newText); if (count($diff) > 0) { $oldLineCount = count($linesOld); $changedLineCount = count($diff); $percentSteps = $oldLineCount / 100; $percentChanged = $changedLineCount / $percentSteps; if ($version != '') { $pageVersion = explode('.', $version); } else { $pageVersion = array(0, 0, 0); } if ($percentChanged <= 5 || count($diff) <= 5) { $pageVersion[2]++; } elseif ($percentChanged <= 25) { $pageVersion[1]++; $pageVersion[2] = 0; } else { $pageVersion[0]++; $pageVersion[1] = 0; $pageVersion[2] = 0; } $pageVersion = join('.', $pageVersion); $db->query('INSERT INTO ' . DB_PREFIX . 'changelog(log_page_id, ' . 'log_page_version, log_time, log_diff, log_user_id, log_user_name, ' . 'log_summary, log_ip) ' . 'VALUES(' . $pageId . ', \'' . $pageVersion . '\', ' . $this->time . ', ' . '\'' . addslashes(serialize($diff)) . '\', ' . $userId . ', ' . '\'' . addslashes($userName) . '\', \'' . addslashes($summary) . '\', ' . '\'' . addslashes($this->server['REMOTE_ADDR']) . '\')'); } return $pageVersion; }