diff --git a/lib/dtl/dbdata.xsd b/lib/dtl/dbdata.xsd index 745e2b154f3..874f5c669bb 100644 --- a/lib/dtl/dbdata.xsd +++ b/lib/dtl/dbdata.xsd @@ -2,15 +2,15 @@ - - - - + + + + - + use="required" /> + diff --git a/lib/lexer.php b/lib/lexer.php index cca3b85967c..5299f4c877c 100644 --- a/lib/lexer.php +++ b/lib/lexer.php @@ -5,7 +5,7 @@ * http://sourceforge.net/projects/lamplib * This project is administered by Markus Baker, Harry Fuecks and Matt * Mitchell, and the project code is in the public domain. - * + * * Thanks, guys! * * @package moodlecore @@ -23,7 +23,7 @@ define("LEXER_EXIT", 4); /** LEXER_SPECIAL = 5 */ define("LEXER_SPECIAL", 5); - + /** * Compounded regular expression. Any of * the contained patterns could match and @@ -37,7 +37,7 @@ var $_labels; var $_regex; var $_case; - + /** * Constructor. Starts with no patterns. * @param bool $case True for case sensitive, false @@ -75,7 +75,7 @@ $this->_labels[$count] = $label; $this->_regex = null; } - + /** * Attempts to match all patterns at once against * a string. @@ -101,7 +101,7 @@ } return true; } - + /** * Compounds the patterns into a single * regular expression separated with the @@ -121,7 +121,7 @@ } return $this->_regex; } - + /** * Accessor for perl regex mode flags to use. * @return string Flags as string. @@ -131,7 +131,7 @@ return ($this->_case ? "msS" : "msSi"); } } - + /** * States for a stack machine. * @@ -141,7 +141,7 @@ */ class StateStack { var $_stack; - + /** * Constructor. Starts in named state. * @param string $start Starting state name. @@ -169,7 +169,7 @@ function getCurrent() { return $this->_stack[count($this->_stack) - 1]; } - + /** * Adds a state to the stack and sets it * to be the current state. @@ -179,7 +179,7 @@ function enter($state) { array_push($this->_stack, $state); } - + /** * Leaves the current state and reverts * to the previous one. @@ -195,7 +195,7 @@ return true; } } - + /** * Accepts text and breaks it into tokens. * Some optimisation to make the sure the @@ -213,7 +213,7 @@ var $_mode; var $_mode_handlers; var $_case; - + /** * Sets up the lexer in case insensitive matching * by default. @@ -240,7 +240,7 @@ debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER); self::__construct($parser, $start, $case); } - + /** * Adds a token search pattern for a particular * parsing mode. The pattern does not change the @@ -258,7 +258,7 @@ } $this->_regexes[$mode]->addPattern($pattern); } - + /** * Adds a pattern that will enter a new parsing * mode. Useful for entering parenthesis, strings, @@ -278,7 +278,7 @@ } $this->_regexes[$mode]->addPattern($pattern, $new_mode); } - + /** * Adds a pattern that will exit the current mode * and re-enter the previous one. @@ -293,7 +293,7 @@ } $this->_regexes[$mode]->addPattern($pattern, "__exit"); } - + /** * Adds a pattern that has a special mode. * Acts as an entry and exit pattern in one go. @@ -311,7 +311,7 @@ } $this->_regexes[$mode]->addPattern($pattern, "_$special"); } - + /** * Adds a mapping from a mode to another handler. * @param string $mode Mode to be remapped. @@ -321,7 +321,7 @@ function mapHandler($mode, $handler) { $this->_mode_handlers[$mode] = $handler; } - + /** * Splits the page text into tokens. Will fail * if the handlers report an error or if no @@ -352,7 +352,7 @@ } return $this->_invokeParser($raw, LEXER_UNMATCHED); } - + /** * Sends the matched token and any leading unmatched * text to the parser changing the lexer to a new @@ -390,7 +390,7 @@ } return $this->_invokeParser($matched, LEXER_MATCHED); } - + /** * Calls the parser method named after the current * mode. Empty content will be ignored. @@ -409,7 +409,7 @@ } return $this->_parser->$handler($content, $is_match); } - + /** * Tries to match a chunk of text and if successful * removes the recognised chunk and any leading diff --git a/lib/tests/html2text_test.php b/lib/tests/html2text_test.php index 44c18b83f5c..692481c83bf 100644 --- a/lib/tests/html2text_test.php +++ b/lib/tests/html2text_test.php @@ -78,9 +78,9 @@ class core_html2text_testcase extends basic_testcase { */ public function test_build_link_list() { - // Note the trailing whitespace left intentionally in the text. + // Note the trailing whitespace left intentionally in the text after first link. $text = 'Total of + href="http://tr.mdl.org/sh.jspa?r=1&j=p+%3D+%22I+d%22+%3D"> ' . ' 27 issues and some other have been fixed last week'; diff --git a/mod/wiki/README b/mod/wiki/README index e7eaf50a849..822c279bc82 100644 --- a/mod/wiki/README +++ b/mod/wiki/README @@ -1,5 +1,5 @@ Wiki 2.0 -by Jordi Piguillem and Ludo (Marc Alier) 2008 - Universitat Politecnica de +by Jordi Piguillem and Ludo (Marc Alier) 2008 - Universitat Politecnica de Catalunya -http://www.upc.edu - http://dfwikilabs.org \ No newline at end of file +http://www.upc.edu - http://dfwikilabs.org diff --git a/mod/wiki/diff/diff_nwiki.php b/mod/wiki/diff/diff_nwiki.php index 6b224d13d03..bf7fc242417 100644 --- a/mod/wiki/diff/diff_nwiki.php +++ b/mod/wiki/diff/diff_nwiki.php @@ -17,15 +17,15 @@ class _WikiDiffOp { var $closing; function reverse() { - trigger_error("pure virtual", E_USER_ERROR); + trigger_error("pure virtual", E_USER_ERROR); } function norig() { - return $this->orig ? sizeof($this->orig) : 0; + return $this->orig ? sizeof($this->orig) : 0; } function nclosing() { - return $this->closing ? sizeof($this->closing) : 0; + return $this->closing ? sizeof($this->closing) : 0; } } @@ -33,14 +33,14 @@ class _WikiDiffOp_Copy extends _WikiDiffOp { var $type = 'copy'; public function __construct ($orig, $closing = false) { - if (!is_array($closing)) - $closing = $orig; - $this->orig = $orig; - $this->closing = $closing; + if (!is_array($closing)) + $closing = $orig; + $this->orig = $orig; + $this->closing = $closing; } function reverse() { - return new _WikiDiffOp_Copy($this->closing, $this->orig); + return new _WikiDiffOp_Copy($this->closing, $this->orig); } } @@ -48,12 +48,12 @@ class _WikiDiffOp_Delete extends _WikiDiffOp { var $type = 'delete'; public function __construct ($lines) { - $this->orig = $lines; - $this->closing = false; + $this->orig = $lines; + $this->closing = false; } function reverse() { - return new _WikiDiffOp_Add($this->orig); + return new _WikiDiffOp_Add($this->orig); } } @@ -61,12 +61,12 @@ class _WikiDiffOp_Add extends _WikiDiffOp { var $type = 'add'; public function __construct ($lines) { - $this->closing = $lines; - $this->orig = false; + $this->closing = $lines; + $this->orig = false; } function reverse() { - return new _WikiDiffOp_Delete($this->closing); + return new _WikiDiffOp_Delete($this->closing); } } @@ -74,12 +74,12 @@ class _WikiDiffOp_Change extends _WikiDiffOp { var $type = 'change'; public function __construct ($orig, $closing) { - $this->orig = $orig; - $this->closing = $closing; + $this->orig = $orig; + $this->closing = $closing; } function reverse() { - return new _WikiDiffOp_Change($this->closing, $this->orig); + return new _WikiDiffOp_Change($this->closing, $this->orig); } } @@ -89,14 +89,14 @@ class _WikiDiffOp_Change extends _WikiDiffOp { * * The algorithm used here is mostly lifted from the perl module * Algorithm::Diff (version 1.06) by Ned Konz, which is available at: - * http://www.perl.com/CPAN/authors/id/N/NE/NEDKONZ/Algorithm-Diff-1.06.zip + * http://www.perl.com/CPAN/authors/id/N/NE/NEDKONZ/Algorithm-Diff-1.06.zip * * More ideas are taken from: - * http://www.ics.uci.edu/~eppstein/161/960229.html + * http://www.ics.uci.edu/~eppstein/161/960229.html * * Some ideas are (and a bit of code) are from from analyze.c, from GNU * diffutils-2.7, which can be found at: - * ftp://gnudist.gnu.org/pub/gnu/diffutils/diffutils-2.7.tar.gz + * ftp://gnudist.gnu.org/pub/gnu/diffutils/diffutils-2.7.tar.gz * * closingly, some ideas (subdivision by NCHUNKS > 2, and some optimizations) * are my own. @@ -107,90 +107,90 @@ class _WikiDiffOp_Change extends _WikiDiffOp { class _WikiDiffEngine { function diff ($from_lines, $to_lines) { - $n_from = sizeof($from_lines); - $n_to = sizeof($to_lines); + $n_from = sizeof($from_lines); + $n_to = sizeof($to_lines); - $this->xchanged = $this->ychanged = array(); - $this->xv = $this->yv = array(); - $this->xind = $this->yind = array(); - unset($this->seq); - unset($this->in_seq); - unset($this->lcs); + $this->xchanged = $this->ychanged = array(); + $this->xv = $this->yv = array(); + $this->xind = $this->yind = array(); + unset($this->seq); + unset($this->in_seq); + unset($this->lcs); - // Skip leading common lines. - for ($skip = 0; $skip < $n_from && $skip < $n_to; $skip++) { - if ($from_lines[$skip] != $to_lines[$skip]) - break; - $this->xchanged[$skip] = $this->ychanged[$skip] = false; - } - // Skip trailing common lines. - $xi = $n_from; $yi = $n_to; - for ($endskip = 0; --$xi > $skip && --$yi > $skip; $endskip++) { - if ($from_lines[$xi] != $to_lines[$yi]) - break; - $this->xchanged[$xi] = $this->ychanged[$yi] = false; - } + // Skip leading common lines. + for ($skip = 0; $skip < $n_from && $skip < $n_to; $skip++) { + if ($from_lines[$skip] != $to_lines[$skip]) + break; + $this->xchanged[$skip] = $this->ychanged[$skip] = false; + } + // Skip trailing common lines. + $xi = $n_from; $yi = $n_to; + for ($endskip = 0; --$xi > $skip && --$yi > $skip; $endskip++) { + if ($from_lines[$xi] != $to_lines[$yi]) + break; + $this->xchanged[$xi] = $this->ychanged[$yi] = false; + } - // Ignore lines which do not exist in both files. - for ($xi = $skip; $xi < $n_from - $endskip; $xi++) - $xhash[$from_lines[$xi]] = 1; - for ($yi = $skip; $yi < $n_to - $endskip; $yi++) { - $line = $to_lines[$yi]; - if ( ($this->ychanged[$yi] = empty($xhash[$line])) ) - continue; - $yhash[$line] = 1; - $this->yv[] = $line; - $this->yind[] = $yi; - } - for ($xi = $skip; $xi < $n_from - $endskip; $xi++) { - $line = $from_lines[$xi]; - if ( ($this->xchanged[$xi] = empty($yhash[$line])) ) - continue; - $this->xv[] = $line; - $this->xind[] = $xi; - } + // Ignore lines which do not exist in both files. + for ($xi = $skip; $xi < $n_from - $endskip; $xi++) + $xhash[$from_lines[$xi]] = 1; + for ($yi = $skip; $yi < $n_to - $endskip; $yi++) { + $line = $to_lines[$yi]; + if ( ($this->ychanged[$yi] = empty($xhash[$line])) ) + continue; + $yhash[$line] = 1; + $this->yv[] = $line; + $this->yind[] = $yi; + } + for ($xi = $skip; $xi < $n_from - $endskip; $xi++) { + $line = $from_lines[$xi]; + if ( ($this->xchanged[$xi] = empty($yhash[$line])) ) + continue; + $this->xv[] = $line; + $this->xind[] = $xi; + } - // Find the LCS. - $this->_compareseq(0, sizeof($this->xv), 0, sizeof($this->yv)); + // Find the LCS. + $this->_compareseq(0, sizeof($this->xv), 0, sizeof($this->yv)); - // Merge edits when possible - $this->_shift_boundaries($from_lines, $this->xchanged, $this->ychanged); - $this->_shift_boundaries($to_lines, $this->ychanged, $this->xchanged); + // Merge edits when possible + $this->_shift_boundaries($from_lines, $this->xchanged, $this->ychanged); + $this->_shift_boundaries($to_lines, $this->ychanged, $this->xchanged); - // Compute the edit operations. - $edits = array(); - $xi = $yi = 0; - while ($xi < $n_from || $yi < $n_to) { - USE_ASSERTS_IN_WIKI && assert($yi < $n_to || $this->xchanged[$xi]); - USE_ASSERTS_IN_WIKI && assert($xi < $n_from || $this->ychanged[$yi]); + // Compute the edit operations. + $edits = array(); + $xi = $yi = 0; + while ($xi < $n_from || $yi < $n_to) { + USE_ASSERTS_IN_WIKI && assert($yi < $n_to || $this->xchanged[$xi]); + USE_ASSERTS_IN_WIKI && assert($xi < $n_from || $this->ychanged[$yi]); - // Skip matching "snake". - $copy = array(); - while ( $xi < $n_from && $yi < $n_to - && !$this->xchanged[$xi] && !$this->ychanged[$yi]) { - $copy[] = $from_lines[$xi++]; - ++$yi; - } - if ($copy) - $edits[] = new _WikiDiffOp_Copy($copy); + // Skip matching "snake". + $copy = array(); + while ( $xi < $n_from && $yi < $n_to + && !$this->xchanged[$xi] && !$this->ychanged[$yi]) { + $copy[] = $from_lines[$xi++]; + ++$yi; + } + if ($copy) + $edits[] = new _WikiDiffOp_Copy($copy); - // Find deletes & adds. - $delete = array(); - while ($xi < $n_from && $this->xchanged[$xi]) - $delete[] = $from_lines[$xi++]; + // Find deletes & adds. + $delete = array(); + while ($xi < $n_from && $this->xchanged[$xi]) + $delete[] = $from_lines[$xi++]; - $add = array(); - while ($yi < $n_to && $this->ychanged[$yi]) - $add[] = $to_lines[$yi++]; + $add = array(); + while ($yi < $n_to && $this->ychanged[$yi]) + $add[] = $to_lines[$yi++]; - if ($delete && $add) - $edits[] = new _WikiDiffOp_Change($delete, $add); - elseif ($delete) - $edits[] = new _WikiDiffOp_Delete($delete); - elseif ($add) - $edits[] = new _WikiDiffOp_Add($add); - } - return $edits; + if ($delete && $add) + $edits[] = new _WikiDiffOp_Change($delete, $add); + elseif ($delete) + $edits[] = new _WikiDiffOp_Delete($delete); + elseif ($add) + $edits[] = new _WikiDiffOp_Add($add); + } + return $edits; } @@ -198,7 +198,7 @@ class _WikiDiffEngine * [XOFF, XLIM) and [YOFF, YLIM) into NCHUNKS approximately equally * sized segments. * - * Returns (LCS, PTS). LCS is the length of the LCS. PTS is an + * Returns (LCS, PTS). LCS is the length of the LCS. PTS is an * array of NCHUNKS+1 (X, Y) indexes giving the diving points between * sub sequences. The first sub-sequence is contained in [X0, X1), * [Y0, Y1), the second in [X1, X2), [Y1, Y2) and so on. Note @@ -214,19 +214,19 @@ class _WikiDiffEngine $flip = false; if ($xlim - $xoff > $ylim - $yoff) { - // Things seems faster (I'm not sure I understand why) - // when the shortest sequence in X. - $flip = true; - list ($xoff, $xlim, $yoff, $ylim) - = array( $yoff, $ylim, $xoff, $xlim); - } + // Things seems faster (I'm not sure I understand why) + // when the shortest sequence in X. + $flip = true; + list ($xoff, $xlim, $yoff, $ylim) + = array( $yoff, $ylim, $xoff, $xlim); + } if ($flip) - for ($i = $ylim - 1; $i >= $yoff; $i--) - $ymatches[$this->xv[$i]][] = $i; + for ($i = $ylim - 1; $i >= $yoff; $i--) + $ymatches[$this->xv[$i]][] = $i; else - for ($i = $ylim - 1; $i >= $yoff; $i--) - $ymatches[$this->yv[$i]][] = $i; + for ($i = $ylim - 1; $i >= $yoff; $i--) + $ymatches[$this->yv[$i]][] = $i; $this->lcs = 0; $this->seq[0]= $yoff - 1; @@ -236,49 +236,49 @@ class _WikiDiffEngine $numer = $xlim - $xoff + $nchunks - 1; $x = $xoff; for ($chunk = 0; $chunk < $nchunks; $chunk++) { - if ($chunk > 0) - for ($i = 0; $i <= $this->lcs; $i++) - $ymids[$i][$chunk-1] = $this->seq[$i]; + if ($chunk > 0) + for ($i = 0; $i <= $this->lcs; $i++) + $ymids[$i][$chunk-1] = $this->seq[$i]; - $x1 = $xoff + (int)(($numer + ($xlim-$xoff)*$chunk) / $nchunks); - for ( ; $x < $x1; $x++) { - $line = $flip ? $this->yv[$x] : $this->xv[$x]; - if (empty($ymatches[$line])) - continue; - $matches = $ymatches[$line]; - reset($matches); + $x1 = $xoff + (int)(($numer + ($xlim-$xoff)*$chunk) / $nchunks); + for ( ; $x < $x1; $x++) { + $line = $flip ? $this->yv[$x] : $this->xv[$x]; + if (empty($ymatches[$line])) + continue; + $matches = $ymatches[$line]; + reset($matches); foreach ($matches as $y) - if (empty($this->in_seq[$y])) { - $k = $this->_lcs_pos($y); - USE_ASSERTS_IN_WIKI && assert($k > 0); - $ymids[$k] = $ymids[$k-1]; - break; + if (empty($this->in_seq[$y])) { + $k = $this->_lcs_pos($y); + USE_ASSERTS_IN_WIKI && assert($k > 0); + $ymids[$k] = $ymids[$k-1]; + break; } foreach ($matches as $y) { - if ($y > $this->seq[$k-1]) { - USE_ASSERTS_IN_WIKI && assert($y < $this->seq[$k]); - // Optimization: this is a common case: - // next match is just replacing previous match. - $this->in_seq[$this->seq[$k]] = false; - $this->seq[$k] = $y; - $this->in_seq[$y] = 1; - } - else if (empty($this->in_seq[$y])) { - $k = $this->_lcs_pos($y); - USE_ASSERTS_IN_WIKI && assert($k > 0); - $ymids[$k] = $ymids[$k-1]; - } - } - } - } + if ($y > $this->seq[$k-1]) { + USE_ASSERTS_IN_WIKI && assert($y < $this->seq[$k]); + // Optimization: this is a common case: + // next match is just replacing previous match. + $this->in_seq[$this->seq[$k]] = false; + $this->seq[$k] = $y; + $this->in_seq[$y] = 1; + } + else if (empty($this->in_seq[$y])) { + $k = $this->_lcs_pos($y); + USE_ASSERTS_IN_WIKI && assert($k > 0); + $ymids[$k] = $ymids[$k-1]; + } + } + } + } $seps[] = $flip ? array($yoff, $xoff) : array($xoff, $yoff); $ymid = $ymids[$this->lcs]; for ($n = 0; $n < $nchunks - 1; $n++) { - $x1 = $xoff + (int)(($numer + ($xlim - $xoff) * $n) / $nchunks); - $y1 = $ymid[$n] + 1; - $seps[] = $flip ? array($y1, $x1) : array($x1, $y1); - } + $x1 = $xoff + (int)(($numer + ($xlim - $xoff) * $n) / $nchunks); + $y1 = $ymid[$n] + 1; + $seps[] = $flip ? array($y1, $x1) : array($x1, $y1); + } $seps[] = $flip ? array($ylim, $xlim) : array($xlim, $ylim); return array($this->lcs, $seps); @@ -287,19 +287,19 @@ class _WikiDiffEngine function _lcs_pos ($ypos) { $end = $this->lcs; if ($end == 0 || $ypos > $this->seq[$end]) { - $this->seq[++$this->lcs] = $ypos; - $this->in_seq[$ypos] = 1; - return $this->lcs; - } + $this->seq[++$this->lcs] = $ypos; + $this->in_seq[$ypos] = 1; + return $this->lcs; + } $beg = 1; while ($beg < $end) { - $mid = (int)(($beg + $end) / 2); - if ( $ypos > $this->seq[$mid] ) - $beg = $mid + 1; - else - $end = $mid; - } + $mid = (int)(($beg + $end) / 2); + if ( $ypos > $this->seq[$mid] ) + $beg = $mid + 1; + else + $end = $mid; + } USE_ASSERTS_IN_WIKI && assert($ypos != $this->seq[$end]); @@ -323,46 +323,46 @@ class _WikiDiffEngine function _compareseq ($xoff, $xlim, $yoff, $ylim) { // Slide down the bottom initial diagonal. while ($xoff < $xlim && $yoff < $ylim - && $this->xv[$xoff] == $this->yv[$yoff]) { - ++$xoff; - ++$yoff; - } + && $this->xv[$xoff] == $this->yv[$yoff]) { + ++$xoff; + ++$yoff; + } // Slide up the top initial diagonal. while ($xlim > $xoff && $ylim > $yoff - && $this->xv[$xlim - 1] == $this->yv[$ylim - 1]) { - --$xlim; - --$ylim; - } + && $this->xv[$xlim - 1] == $this->yv[$ylim - 1]) { + --$xlim; + --$ylim; + } if ($xoff == $xlim || $yoff == $ylim) - $lcs = 0; + $lcs = 0; else { - // This is ad hoc but seems to work well. - //$nchunks = sqrt(min($xlim - $xoff, $ylim - $yoff) / 2.5); - //$nchunks = max(2,min(8,(int)$nchunks)); - $nchunks = min(7, $xlim - $xoff, $ylim - $yoff) + 1; - list ($lcs, $seps) - = $this->_diag($xoff,$xlim,$yoff, $ylim,$nchunks); - } + // This is ad hoc but seems to work well. + //$nchunks = sqrt(min($xlim - $xoff, $ylim - $yoff) / 2.5); + //$nchunks = max(2,min(8,(int)$nchunks)); + $nchunks = min(7, $xlim - $xoff, $ylim - $yoff) + 1; + list ($lcs, $seps) + = $this->_diag($xoff,$xlim,$yoff, $ylim,$nchunks); + } if ($lcs == 0) { - // X and Y sequences have no common subsequence: - // mark all changed. - while ($yoff < $ylim) - $this->ychanged[$this->yind[$yoff++]] = 1; - while ($xoff < $xlim) - $this->xchanged[$this->xind[$xoff++]] = 1; - } + // X and Y sequences have no common subsequence: + // mark all changed. + while ($yoff < $ylim) + $this->ychanged[$this->yind[$yoff++]] = 1; + while ($xoff < $xlim) + $this->xchanged[$this->xind[$xoff++]] = 1; + } else { - // Use the partitions to split this problem into subproblems. - reset($seps); - $pt1 = $seps[0]; - while ($pt2 = next($seps)) { - $this->_compareseq ($pt1[0], $pt2[0], $pt1[1], $pt2[1]); - $pt1 = $pt2; - } - } + // Use the partitions to split this problem into subproblems. + reset($seps); + $pt1 = $seps[0]; + while ($pt2 = next($seps)) { + $this->_compareseq ($pt1[0], $pt2[0], $pt1[1], $pt2[1]); + $pt1 = $pt2; + } + } } /* Adjust inserts/deletes of identical lines to join changes @@ -386,102 +386,102 @@ class _WikiDiffEngine $other_len = sizeof($other_changed); while (1) { - /* - * Scan forwards to find beginning of another run of changes. - * Also keep track of the corresponding point in the other file. - * - * Throughout this code, $i and $j are adjusted together so that - * the first $i elements of $changed and the first $j elements - * of $other_changed both contain the same number of zeros - * (unchanged lines). - * Furthermore, $j is always kept so that $j == $other_len or - * $other_changed[$j] == false. - */ - while ($j < $other_len && $other_changed[$j]) - $j++; + /* + * Scan forwards to find beginning of another run of changes. + * Also keep track of the corresponding point in the other file. + * + * Throughout this code, $i and $j are adjusted together so that + * the first $i elements of $changed and the first $j elements + * of $other_changed both contain the same number of zeros + * (unchanged lines). + * Furthermore, $j is always kept so that $j == $other_len or + * $other_changed[$j] == false. + */ + while ($j < $other_len && $other_changed[$j]) + $j++; - while ($i < $len && ! $changed[$i]) { - USE_ASSERTS_IN_WIKI && assert('$j < $other_len && ! $other_changed[$j]'); - $i++; $j++; - while ($j < $other_len && $other_changed[$j]) - $j++; - } + while ($i < $len && ! $changed[$i]) { + USE_ASSERTS_IN_WIKI && assert('$j < $other_len && ! $other_changed[$j]'); + $i++; $j++; + while ($j < $other_len && $other_changed[$j]) + $j++; + } - if ($i == $len) - break; + if ($i == $len) + break; - $start = $i; + $start = $i; - // Find the end of this run of changes. - while (++$i < $len && $changed[$i]) - continue; + // Find the end of this run of changes. + while (++$i < $len && $changed[$i]) + continue; - do { - /* - * Record the length of this run of changes, so that - * we can later determine whether the run has grown. - */ - $runlength = $i - $start; + do { + /* + * Record the length of this run of changes, so that + * we can later determine whether the run has grown. + */ + $runlength = $i - $start; - /* - * Move the changed region back, so long as the - * previous unchanged line matches the last changed one. - * This merges with previous changed regions. - */ - while ($start > 0 && $lines[$start - 1] == $lines[$i - 1]) { - $changed[--$start] = 1; - $changed[--$i] = false; - while ($start > 0 && $changed[$start - 1]) - $start--; - USE_ASSERTS_IN_WIKI && assert('$j > 0'); - while ($other_changed[--$j]) - continue; - USE_ASSERTS_IN_WIKI && assert('$j >= 0 && !$other_changed[$j]'); - } + /* + * Move the changed region back, so long as the + * previous unchanged line matches the last changed one. + * This merges with previous changed regions. + */ + while ($start > 0 && $lines[$start - 1] == $lines[$i - 1]) { + $changed[--$start] = 1; + $changed[--$i] = false; + while ($start > 0 && $changed[$start - 1]) + $start--; + USE_ASSERTS_IN_WIKI && assert('$j > 0'); + while ($other_changed[--$j]) + continue; + USE_ASSERTS_IN_WIKI && assert('$j >= 0 && !$other_changed[$j]'); + } - /* - * Set CORRESPONDING to the end of the changed run, at the last - * point where it corresponds to a changed run in the other file. - * CORRESPONDING == LEN means no such point has been found. - */ - $corresponding = $j < $other_len ? $i : $len; + /* + * Set CORRESPONDING to the end of the changed run, at the last + * point where it corresponds to a changed run in the other file. + * CORRESPONDING == LEN means no such point has been found. + */ + $corresponding = $j < $other_len ? $i : $len; - /* - * Move the changed region forward, so long as the - * first changed line matches the following unchanged one. - * This merges with following changed regions. - * Do this second, so that if there are no merges, - * the changed region is moved forward as far as possible. - */ - while ($i < $len && $lines[$start] == $lines[$i]) { - $changed[$start++] = false; - $changed[$i++] = 1; - while ($i < $len && $changed[$i]) - $i++; + /* + * Move the changed region forward, so long as the + * first changed line matches the following unchanged one. + * This merges with following changed regions. + * Do this second, so that if there are no merges, + * the changed region is moved forward as far as possible. + */ + while ($i < $len && $lines[$start] == $lines[$i]) { + $changed[$start++] = false; + $changed[$i++] = 1; + while ($i < $len && $changed[$i]) + $i++; - USE_ASSERTS_IN_WIKI && assert('$j < $other_len && ! $other_changed[$j]'); - $j++; - if ($j < $other_len && $other_changed[$j]) { - $corresponding = $i; - while ($j < $other_len && $other_changed[$j]) - $j++; - } - } - } while ($runlength != $i - $start); + USE_ASSERTS_IN_WIKI && assert('$j < $other_len && ! $other_changed[$j]'); + $j++; + if ($j < $other_len && $other_changed[$j]) { + $corresponding = $i; + while ($j < $other_len && $other_changed[$j]) + $j++; + } + } + } while ($runlength != $i - $start); - /* - * If possible, move the fully-merged run of changes - * back to a corresponding run in the other file. - */ - while ($corresponding < $i) { - $changed[--$start] = 1; - $changed[--$i] = 0; - USE_ASSERTS_IN_WIKI && assert('$j > 0'); - while ($other_changed[--$j]) - continue; - USE_ASSERTS_IN_WIKI && assert('$j >= 0 && !$other_changed[$j]'); - } - } + /* + * If possible, move the fully-merged run of changes + * back to a corresponding run in the other file. + */ + while ($corresponding < $i) { + $changed[--$start] = 1; + $changed[--$i] = 0; + USE_ASSERTS_IN_WIKI && assert('$j > 0'); + while ($other_changed[--$j]) + continue; + USE_ASSERTS_IN_WIKI && assert('$j >= 0 && !$other_changed[$j]'); + } + } } } @@ -497,13 +497,13 @@ class WikiDiff * Computes diff between sequences of strings. * * @param $from_lines array An array of strings. - * (Typically these are lines from a file.) + * (Typically these are lines from a file.) * @param $to_lines array An array of strings. */ public function __construct($from_lines, $to_lines) { - $eng = new _WikiDiffEngine; - $this->edits = $eng->diff($from_lines, $to_lines); - //$this->_check($from_lines, $to_lines); + $eng = new _WikiDiffEngine; + $this->edits = $eng->diff($from_lines, $to_lines); + //$this->_check($from_lines, $to_lines); } /** @@ -521,17 +521,17 @@ class WikiDiff * * SYNOPSIS: * - * $diff = new WikiDiff($lines1, $lines2); - * $rev = $diff->reverse(); + * $diff = new WikiDiff($lines1, $lines2); + * $rev = $diff->reverse(); * @return object A WikiDiff object representing the inverse of the - * original diff. + * original diff. */ function reverse () { $rev = $this; - $rev->edits = array(); - foreach ($this->edits as $edit) { - $rev->edits[] = $edit->reverse(); - } + $rev->edits = array(); + foreach ($this->edits as $edit) { + $rev->edits[] = $edit->reverse(); + } return $rev; } @@ -541,11 +541,11 @@ class WikiDiff * @return bool True iff two sequences were identical. */ function isEmpty () { - foreach ($this->edits as $edit) { - if ($edit->type != 'copy') - return false; - } - return true; + foreach ($this->edits as $edit) { + if ($edit->type != 'copy') + return false; + } + return true; } /** @@ -557,10 +557,10 @@ class WikiDiff */ function lcs () { $lcs = 0; - foreach ($this->edits as $edit) { - if ($edit->type == 'copy') - $lcs += sizeof($edit->orig); - } + foreach ($this->edits as $edit) { + if ($edit->type == 'copy') + $lcs += sizeof($edit->orig); + } return $lcs; } @@ -573,13 +573,13 @@ class WikiDiff * @return array The original sequence of strings. */ function orig() { - $lines = array(); + $lines = array(); - foreach ($this->edits as $edit) { - if ($edit->orig) - array_splice($lines, sizeof($lines), 0, $edit->orig); - } - return $lines; + foreach ($this->edits as $edit) { + if ($edit->orig) + array_splice($lines, sizeof($lines), 0, $edit->orig); + } + return $lines; } /** @@ -591,13 +591,13 @@ class WikiDiff * @return array The sequence of strings. */ function closing() { - $lines = array(); + $lines = array(); - foreach ($this->edits as $edit) { - if ($edit->closing) - array_splice($lines, sizeof($lines), 0, $edit->closing); - } - return $lines; + foreach ($this->edits as $edit) { + if ($edit->closing) + array_splice($lines, sizeof($lines), 0, $edit->closing); + } + return $lines; } /** @@ -606,34 +606,34 @@ class WikiDiff * This is here only for debugging purposes. */ function _check ($from_lines, $to_lines) { - if (serialize($from_lines) != serialize($this->orig())) - trigger_error("Reconstructed original doesn't match", E_USER_ERROR); - if (serialize($to_lines) != serialize($this->closing())) - trigger_error("Reconstructed closing doesn't match", E_USER_ERROR); + if (serialize($from_lines) != serialize($this->orig())) + trigger_error("Reconstructed original doesn't match", E_USER_ERROR); + if (serialize($to_lines) != serialize($this->closing())) + trigger_error("Reconstructed closing doesn't match", E_USER_ERROR); - $rev = $this->reverse(); - if (serialize($to_lines) != serialize($rev->orig())) - trigger_error("Reversed original doesn't match", E_USER_ERROR); - if (serialize($from_lines) != serialize($rev->closing())) - trigger_error("Reversed closing doesn't match", E_USER_ERROR); + $rev = $this->reverse(); + if (serialize($to_lines) != serialize($rev->orig())) + trigger_error("Reversed original doesn't match", E_USER_ERROR); + if (serialize($from_lines) != serialize($rev->closing())) + trigger_error("Reversed closing doesn't match", E_USER_ERROR); - $prevtype = 'none'; - foreach ($this->edits as $edit) { - if ( $prevtype == $edit->type ) - trigger_error("Edit sequence is non-optimal", E_USER_ERROR); - $prevtype = $edit->type; - } + $prevtype = 'none'; + foreach ($this->edits as $edit) { + if ( $prevtype == $edit->type ) + trigger_error("Edit sequence is non-optimal", E_USER_ERROR); + $prevtype = $edit->type; + } - $lcs = $this->lcs(); - trigger_error("WikiDiff okay: LCS = $lcs", E_USER_NOTICE); + $lcs = $this->lcs(); + trigger_error("WikiDiff okay: LCS = $lcs", E_USER_NOTICE); } } /** * FIXME: bad name. */ - + class MappedWikiDiff extends WikiDiff { @@ -647,41 +647,41 @@ extends WikiDiff * changes in white-space. * * @param $from_lines array An array of strings. - * (Typically these are lines from a file.) + * (Typically these are lines from a file.) * * @param $to_lines array An array of strings. * * @param $mapped_from_lines array This array should - * have the same size number of elements as $from_lines. - * The elements in $mapped_from_lines and - * $mapped_to_lines are what is actually compared - * when computing the diff. + * have the same size number of elements as $from_lines. + * The elements in $mapped_from_lines and + * $mapped_to_lines are what is actually compared + * when computing the diff. * * @param $mapped_to_lines array This array should - * have the same number of elements as $to_lines. + * have the same number of elements as $to_lines. */ public function __construct($from_lines, $to_lines, - $mapped_from_lines, $mapped_to_lines) { + $mapped_from_lines, $mapped_to_lines) { - assert(sizeof($from_lines) == sizeof($mapped_from_lines)); - assert(sizeof($to_lines) == sizeof($mapped_to_lines)); + assert(sizeof($from_lines) == sizeof($mapped_from_lines)); + assert(sizeof($to_lines) == sizeof($mapped_to_lines)); parent::__construct($mapped_from_lines, $mapped_to_lines); - $xi = $yi = 0; - for ($i = 0; $i < sizeof($this->edits); $i++) { - $orig = &$this->edits[$i]->orig; - if (is_array($orig)) { - $orig = array_slice($from_lines, $xi, sizeof($orig)); - $xi += sizeof($orig); - } + $xi = $yi = 0; + for ($i = 0; $i < sizeof($this->edits); $i++) { + $orig = &$this->edits[$i]->orig; + if (is_array($orig)) { + $orig = array_slice($from_lines, $xi, sizeof($orig)); + $xi += sizeof($orig); + } - $closing = &$this->edits[$i]->closing; - if (is_array($closing)) { - $closing = array_slice($to_lines, $yi, sizeof($closing)); - $yi += sizeof($closing); - } - } + $closing = &$this->edits[$i]->closing; + if (is_array($closing)) { + $closing = array_slice($to_lines, $yi, sizeof($closing)); + $yi += sizeof($closing); + } + } } } @@ -718,228 +718,228 @@ class WikiDiffFormatter */ function format($diff) { - $xi = $yi = 1; - $block = false; - $context = array(); + $xi = $yi = 1; + $block = false; + $context = array(); - $nlead = $this->leading_context_lines; - $ntrail = $this->trailing_context_lines; + $nlead = $this->leading_context_lines; + $ntrail = $this->trailing_context_lines; - $this->_start_diff(); + $this->_start_diff(); - foreach ($diff->edits as $edit) { - if ($edit->type == 'copy') { - if (is_array($block)) { - if (sizeof($edit->orig) <= $nlead + $ntrail) { - $block[] = $edit; - } - else{ - if ($ntrail) { - $context = array_slice($edit->orig, 0, $ntrail); - $block[] = new _WikiWikiDiffOp_Copy($context); - } - $this->_block($x0, $ntrail + $xi - $x0, - $y0, $ntrail + $yi - $y0, - $block); - $block = false; - } - } - $context = $edit->orig; - } - else { - if (! is_array($block)) { - $context = array_slice($context, sizeof($context) - $nlead); - $x0 = $xi - sizeof($context); - $y0 = $yi - sizeof($context); - $block = array(); - if ($context) - $block[] = new _WikiWikiDiffOp_Copy($context); - } - $block[] = $edit; - } + foreach ($diff->edits as $edit) { + if ($edit->type == 'copy') { + if (is_array($block)) { + if (sizeof($edit->orig) <= $nlead + $ntrail) { + $block[] = $edit; + } + else{ + if ($ntrail) { + $context = array_slice($edit->orig, 0, $ntrail); + $block[] = new _WikiWikiDiffOp_Copy($context); + } + $this->_block($x0, $ntrail + $xi - $x0, + $y0, $ntrail + $yi - $y0, + $block); + $block = false; + } + } + $context = $edit->orig; + } + else { + if (! is_array($block)) { + $context = array_slice($context, sizeof($context) - $nlead); + $x0 = $xi - sizeof($context); + $y0 = $yi - sizeof($context); + $block = array(); + if ($context) + $block[] = new _WikiWikiDiffOp_Copy($context); + } + $block[] = $edit; + } - if ($edit->orig) - $xi += sizeof($edit->orig); - if ($edit->closing) - $yi += sizeof($edit->closing); - } + if ($edit->orig) + $xi += sizeof($edit->orig); + if ($edit->closing) + $yi += sizeof($edit->closing); + } - if (is_array($block)) - $this->_block($x0, $xi - $x0, - $y0, $yi - $y0, - $block); + if (is_array($block)) + $this->_block($x0, $xi - $x0, + $y0, $yi - $y0, + $block); - return $this->_end_diff(); + return $this->_end_diff(); } function _block($xbeg, $xlen, $ybeg, $ylen, &$edits) { - $this->_start_block($this->_block_header($xbeg, $xlen, $ybeg, $ylen)); - foreach ($edits as $edit) { - if ($edit->type == 'copy') - $this->_context($edit->orig); - elseif ($edit->type == 'add') - $this->_added($edit->closing); - elseif ($edit->type == 'delete') - $this->_deleted($edit->orig); - elseif ($edit->type == 'change') - $this->_changed($edit->orig, $edit->closing); - else - trigger_error("Unknown edit type", E_USER_ERROR); - } - $this->_end_block(); + $this->_start_block($this->_block_header($xbeg, $xlen, $ybeg, $ylen)); + foreach ($edits as $edit) { + if ($edit->type == 'copy') + $this->_context($edit->orig); + elseif ($edit->type == 'add') + $this->_added($edit->closing); + elseif ($edit->type == 'delete') + $this->_deleted($edit->orig); + elseif ($edit->type == 'change') + $this->_changed($edit->orig, $edit->closing); + else + trigger_error("Unknown edit type", E_USER_ERROR); + } + $this->_end_block(); } function _start_diff() { - ob_start(); + ob_start(); } function _end_diff() { - $val = ob_get_contents(); - ob_end_clean(); - return $val; + $val = ob_get_contents(); + ob_end_clean(); + return $val; } function _block_header($xbeg, $xlen, $ybeg, $ylen) { - if ($xlen > 1) - $xbeg .= "," . ($xbeg + $xlen - 1); - if ($ylen > 1) - $ybeg .= "," . ($ybeg + $ylen - 1); + if ($xlen > 1) + $xbeg .= "," . ($xbeg + $xlen - 1); + if ($ylen > 1) + $ybeg .= "," . ($ybeg + $ylen - 1); - return $xbeg . ($xlen ? ($ylen ? 'c' : 'd') : 'a') . $ybeg; + return $xbeg . ($xlen ? ($ylen ? 'c' : 'd') : 'a') . $ybeg; } function _start_block($header) { - echo $header; + echo $header; } function _end_block() { } function _lines($lines, $prefix = ' ') { - foreach ($lines as $line) - echo "$prefix $line\n"; + foreach ($lines as $line) + echo "$prefix $line\n"; } function _context($lines) { - $this->_lines($lines); + $this->_lines($lines); } function _added($lines) { - $this->_lines($lines, ">"); + $this->_lines($lines, ">"); } function _deleted($lines) { - $this->_lines($lines, "<"); + $this->_lines($lines, "<"); } function _changed($orig, $closing) { - $this->_deleted($orig); - echo "---\n"; - $this->_added($closing); + $this->_deleted($orig); + echo "---\n"; + $this->_added($closing); } } /** - * Additions by Axel Boldt follow, partly taken from diff.php, phpwiki-1.3.3 + * Additions by Axel Boldt follow, partly taken from diff.php, phpwiki-1.3.3 * */ -define('NBSP', ' '); // iso-8859-x non-breaking space. +define('NBSP', ' '); // iso-8859-x non-breaking space. class _WikiHWLDF_WordAccumulator { public function __construct () { - $this->_lines = array(); - $this->_line = ''; - $this->_group = ''; - $this->_tag = ''; + $this->_lines = array(); + $this->_line = ''; + $this->_group = ''; + $this->_tag = ''; } function _flushGroup ($new_tag) { - if ($this->_group !== '') { + if ($this->_group !== '') { if ($this->_tag == 'mark') - $this->_line .= ''.$this->_group.''; + $this->_line .= ''.$this->_group.''; else - $this->_line .= $this->_group; + $this->_line .= $this->_group; } - $this->_group = ''; - $this->_tag = $new_tag; + $this->_group = ''; + $this->_tag = $new_tag; } function _flushLine ($new_tag) { - $this->_flushGroup($new_tag); - if ($this->_line != '') - $this->_lines[] = $this->_line; - $this->_line = ''; + $this->_flushGroup($new_tag); + if ($this->_line != '') + $this->_lines[] = $this->_line; + $this->_line = ''; } function addWords ($words, $tag = '') { - if ($tag != $this->_tag) - $this->_flushGroup($tag); + if ($tag != $this->_tag) + $this->_flushGroup($tag); - foreach ($words as $word) { - // new-line should only come as first char of word. - if ($word == '') - continue; - if ($word[0] == "\n") { - $this->_group .= NBSP; - $this->_flushLine($tag); - $word = substr($word, 1); - } - assert(!strstr($word, "\n")); - $this->_group .= $word; - } + foreach ($words as $word) { + // new-line should only come as first char of word. + if ($word == '') + continue; + if ($word[0] == "\n") { + $this->_group .= NBSP; + $this->_flushLine($tag); + $word = substr($word, 1); + } + assert(!strstr($word, "\n")); + $this->_group .= $word; + } } function getLines() { - $this->_flushLine('~done'); - return $this->_lines; + $this->_flushLine('~done'); + return $this->_lines; } } class WordLevelWikiDiff extends MappedWikiDiff { function __construct ($orig_lines, $closing_lines) { - list ($orig_words, $orig_stripped) = $this->_split($orig_lines); - list ($closing_words, $closing_stripped) = $this->_split($closing_lines); + list ($orig_words, $orig_stripped) = $this->_split($orig_lines); + list ($closing_words, $closing_stripped) = $this->_split($closing_lines); parent::__construct($orig_words, $closing_words, - $orig_stripped, $closing_stripped); + $orig_stripped, $closing_stripped); } function _split($lines) { - // FIXME: fix POSIX char class. -# if (!preg_match_all('/ ( [^\S\n]+ | [[:alnum:]]+ | . ) (?: (?!< \n) [^\S\n])? /xs', - if (!preg_match_all('/ ( [^\S\n]+ | [0-9_A-Za-z\x80-\xff]+ | . ) (?: (?!< \n) [^\S\n])? /xs', - implode("\n", $lines), - $m)) { - return array(array(''), array('')); - } - return array($m[0], $m[1]); + // FIXME: fix POSIX char class. +# if (!preg_match_all('/ ( [^\S\n]+ | [[:alnum:]]+ | . ) (?: (?!< \n) [^\S\n])? /xs', + if (!preg_match_all('/ ( [^\S\n]+ | [0-9_A-Za-z\x80-\xff]+ | . ) (?: (?!< \n) [^\S\n])? /xs', + implode("\n", $lines), + $m)) { + return array(array(''), array('')); + } + return array($m[0], $m[1]); } function orig () { - $orig = new _WikiHWLDF_WordAccumulator; + $orig = new _WikiHWLDF_WordAccumulator; - foreach ($this->edits as $edit) { - if ($edit->type == 'copy') - $orig->addWords($edit->orig); - elseif ($edit->orig) - $orig->addWords($edit->orig, 'mark'); - } - return $orig->getLines(); + foreach ($this->edits as $edit) { + if ($edit->type == 'copy') + $orig->addWords($edit->orig); + elseif ($edit->orig) + $orig->addWords($edit->orig, 'mark'); + } + return $orig->getLines(); } function closing () { - $closing = new _WikiHWLDF_WordAccumulator; + $closing = new _WikiHWLDF_WordAccumulator; - foreach ($this->edits as $edit) { - if ($edit->type == 'copy') - $closing->addWords($edit->closing); - elseif ($edit->closing) - $closing->addWords($edit->closing, 'mark'); - } - return $closing->getLines(); + foreach ($this->edits as $edit) { + if ($edit->type == 'copy') + $closing->addWords($edit->closing); + elseif ($edit->closing) + $closing->addWords($edit->closing, 'mark'); + } + return $closing->getLines(); } } @@ -949,62 +949,62 @@ class WordLevelWikiDiff extends MappedWikiDiff class TableWikiDiffFormatter extends WikiDiffFormatter { var $htmltable = array(); - + public function __construct() { $this->leading_context_lines = 2; $this->trailing_context_lines = 2; } - + function _block_header( $xbeg, $xlen, $ybeg, $ylen) { - + } - + function _start_block ($header) { } - + function _end_block() { } - + function _lines($lines, $prefix=' ', $color="white") { - + } - + function _added($lines) { global $htmltable; - foreach ($lines as $line) { - $htmltable[] = array('','+','
'.$line.'
'); - } + foreach ($lines as $line) { + $htmltable[] = array('','+','
'.$line.'
'); + } } function _deleted($lines) { global $htmltable; - foreach ($lines as $line) { - $htmltable[] = array('
'.$line.'
','-',''); - } + foreach ($lines as $line) { + $htmltable[] = array('
'.$line.'
','-',''); + } } - + function _context($lines) { global $htmltable; - foreach ($lines as $line) { - $htmltable[] = array($line,'',$line); - } + foreach ($lines as $line) { + $htmltable[] = array($line,'',$line); + } } - + function _changed( $orig, $closing ) { global $htmltable; - $diff = new WordLevelWikiDiff( $orig, $closing ); - $del = $diff->orig(); - $add = $diff->closing(); + $diff = new WordLevelWikiDiff( $orig, $closing ); + $del = $diff->orig(); + $add = $diff->closing(); - while ( $line = array_shift( $del ) ) { - $aline = array_shift( $add ); - $htmltable[] = array('
'.$line.'
','-','
'.$aline.'
'); - } - $this->_added( $add ); # If any leftovers + while ( $line = array_shift( $del ) ) { + $aline = array_shift( $add ); + $htmltable[] = array('
'.$line.'
','-','
'.$aline.'
'); + } + $this->_added( $add ); # If any leftovers } - + function get_result() { global $htmltable; return $htmltable; @@ -1014,28 +1014,28 @@ class TableWikiDiffFormatter extends WikiDiffFormatter /** - * Wikipedia Table style diff formatter. + * Wikipedia Table style diff formatter. * */ class TableWikiDiffFormatterOld extends WikiDiffFormatter { function TableWikiDiffFormatter() { - $this->leading_context_lines = 2; - $this->trailing_context_lines = 2; + $this->leading_context_lines = 2; + $this->trailing_context_lines = 2; } function _block_header( $xbeg, $xlen, $ybeg, $ylen ) { - $l1 = wfMsg( "lineno", $xbeg ); - $l2 = wfMsg( "lineno", $ybeg ); + $l1 = wfMsg( "lineno", $xbeg ); + $l2 = wfMsg( "lineno", $ybeg ); - $r = ''.$l1."\n" . - ''.$l2."\n"; - return $r; + $r = ''.$l1."\n" . + ''.$l2."\n"; + return $r; } function _start_block( $header ) { - global $wgOut; - $wgOut->addHTML( $header ); + global $wgOut; + $wgOut->addHTML( $header ); } function _end_block() { @@ -1045,59 +1045,59 @@ class TableWikiDiffFormatterOld extends WikiDiffFormatter } function addedLine( $line ) { - return '+' . - $line.''; + return '+' . + $line.''; } function deletedLine( $line ) { - return '-' . - $line.''; + return '-' . + $line.''; } function emptyLine() { - return ' '; + return ' '; } function contextLine( $line ) { - return ' '.$line.''; + return ' '.$line.''; } function _added($lines) { - global $wgOut; - foreach ($lines as $line) { - $wgOut->addHTML( '' . $this->emptyLine() . - $this->addedLine( $line ) . "\n" ); - } + global $wgOut; + foreach ($lines as $line) { + $wgOut->addHTML( '' . $this->emptyLine() . + $this->addedLine( $line ) . "\n" ); + } } function _deleted($lines) { - global $wgOut; - foreach ($lines as $line) { - $wgOut->addHTML( '' . $this->deletedLine( $line ) . - $this->emptyLine() . "\n" ); - } + global $wgOut; + foreach ($lines as $line) { + $wgOut->addHTML( '' . $this->deletedLine( $line ) . + $this->emptyLine() . "\n" ); + } } function _context( $lines ) { - global $wgOut; - foreach ($lines as $line) { - $wgOut->addHTML( '' . $this->contextLine( $line ) . - $this->contextLine( $line ) . "\n" ); - } + global $wgOut; + foreach ($lines as $line) { + $wgOut->addHTML( '' . $this->contextLine( $line ) . + $this->contextLine( $line ) . "\n" ); + } } function _changed( $orig, $closing ) { - global $wgOut; - $diff = new WordLevelWikiDiff( $orig, $closing ); - $del = $diff->orig(); - $add = $diff->closing(); + global $wgOut; + $diff = new WordLevelWikiDiff( $orig, $closing ); + $del = $diff->orig(); + $add = $diff->closing(); - while ( $line = array_shift( $del ) ) { - $aline = array_shift( $add ); - $wgOut->addHTML( '' . $this->deletedLine( $line ) . - $this->addedLine( $aline ) . "\n" ); - } - $this->_added( $add ); # If any leftovers + while ( $line = array_shift( $del ) ) { + $aline = array_shift( $add ); + $wgOut->addHTML( '' . $this->deletedLine( $line ) . + $this->addedLine( $aline ) . "\n" ); + } + $this->_added( $add ); # If any leftovers } } diff --git a/mod/wiki/diff/difflib.php b/mod/wiki/diff/difflib.php index 7dba6d71597..168a83a8609 100644 --- a/mod/wiki/diff/difflib.php +++ b/mod/wiki/diff/difflib.php @@ -6,156 +6,156 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @package ouwiki *//** */ - + // Standard diff -//////////////// - +//////////////// + /** * Basic diff utility function, using standard diff algorithm. * - * Based on Bell Laboratories Computing Science Technical Report #41, + * Based on Bell Laboratories Computing Science Technical Report #41, * July 1976, Hunt & McIlroy, Appendix A.1 and A.3. - * + * * http://www.cs.dartmouth.edu/~doug/diff.ps * * @param array $file1 Array of lines in file 1. The first line in the file * MUST BE INDEX 1 NOT ZERO!! * @param array $file2 Array of lines in file 2, again starting from 1. - * @return array An array with one entry (again 1-based) for each line in + * @return array An array with one entry (again 1-based) for each line in * file 1, with its corresponding position in file 2 or 0 if it isn't there. */ function ouwiki_diff_internal($file1,$file2) { - // Basic variables - $n=count($file2); - $m=count($file1); - + // Basic variables + $n=count($file2); + $m=count($file1); + // Special-case for empty file2 which otherwise causes error - if($n==0) + if($n==0) { $result=array(); - for($i=1;$i<=$m;$i++) + for($i=1;$i<=$m;$i++) { $result[$i]=0; } return $result; } - - // Step 1 Build list of elements - ///////// - - $V=array(); - for($j=1;$j<=$n;$j++) { - $V[$j]=new StdClass; - $V[$j]->serial=$j; - $V[$j]->hash=crc32($file2[$j]); - } - - // Step 2 Sort by hash,serial - ///////// - - usort($V,"ouwiki_diff_sort_v"); - + + // Step 1 Build list of elements + ///////// + + $V=array(); + for($j=1;$j<=$n;$j++) { + $V[$j]=new StdClass; + $V[$j]->serial=$j; + $V[$j]->hash=crc32($file2[$j]); + } + + // Step 2 Sort by hash,serial + ///////// + + usort($V,"ouwiki_diff_sort_v"); + // Make it start from 1 again array_unshift($V,'bogus'); unset($V[0]); - - // $V is now an array including the line number 'serial' and hash - // of each line in file 2, sorted by hash and then serial. - - // Step 3 Equivalence classes - ///////// - - $E=array(); - $E[0]=new StdClass; - $E[0]->serial=0; - $E[0]->last=true; - for($j=1;$j<=$n;$j++) { - $E[$j]=new StdClass; - $E[$j]->serial=$V[$j]->serial; - $E[$j]->last=$j===$n || $V[$j]->hash!==$V[$j+1]->hash; - } - // E is now an array sorted the same way as $V which includes - // the line number 'serial' and whether or not that is the 'last' - // line in the given equivalence class, i.e. set of identical lines - - // Step 4 For each line in file1, finds start of equivalence class - ///////// + // $V is now an array including the line number 'serial' and hash + // of each line in file 2, sorted by hash and then serial. + + // Step 3 Equivalence classes + ///////// + + $E=array(); + $E[0]=new StdClass; + $E[0]->serial=0; + $E[0]->last=true; + for($j=1;$j<=$n;$j++) { + $E[$j]=new StdClass; + $E[$j]->serial=$V[$j]->serial; + $E[$j]->last=$j===$n || $V[$j]->hash!==$V[$j+1]->hash; + } + + // E is now an array sorted the same way as $V which includes + // the line number 'serial' and whether or not that is the 'last' + // line in the given equivalence class, i.e. set of identical lines + + // Step 4 For each line in file1, finds start of equivalence class + ///////// $P=array(); - for($i=1;$i<=$m;$i++) { - // Find matching last entry from equivalence list - $P[$i]=ouwiki_diff_find_last($V,$E,crc32($file1[$i])); - } - - // P is now an array that finds the index (within $V) of the *first* - // matching line in $V (referencing file 2, but not a line number, - // because sorted in $V order) for each line in file 1. In other words - // if you were to start at the P-value in $V and continue through, you - // would find all the lines from file 2 that are equal to the given line - // from file 1. - - // Step 5 Initialise vector of candidates - ///////// - - // I do not trust PHP references further than I can throw them (preferably - // at the idiot who came up with the idea) so I am using a separate array - // to store candidates and all references are integers into that. - - $candidates=array(); - $candidates[0]=new StdClass; - $candidates[0]->a=0; - $candidates[0]->b=0; - $candidates[0]->previous=null; - $candidates[1]=new StdClass; - $candidates[1]->a=$m+1; - $candidates[1]->b=$n+1; - $candidates[1]->previous=null; - - $K=array(); - $K[0]=0; // Ref to candidate 0 - $K[1]=1; // Ref to candidate 1 - $k=0; - - // Step 6 Merge stage - ///////// - - for($i=1;$i<=$m;$i++) { - if($P[$i]!==0) { - ouwiki_diff_merge($K,$k,$i,$E,$P[$i],$candidates); - } - } - - // Step 7 - ///////// - - $J=array(); - for($i=1;$i<=$m;$i++) { - $J[$i]=0; - } - - // Step 8 Follow candidate chain to make nice representation - ///////// - - $index=$K[$k]; - while(!is_null($index)) { + for($i=1;$i<=$m;$i++) { + // Find matching last entry from equivalence list + $P[$i]=ouwiki_diff_find_last($V,$E,crc32($file1[$i])); + } + + // P is now an array that finds the index (within $V) of the *first* + // matching line in $V (referencing file 2, but not a line number, + // because sorted in $V order) for each line in file 1. In other words + // if you were to start at the P-value in $V and continue through, you + // would find all the lines from file 2 that are equal to the given line + // from file 1. + + // Step 5 Initialise vector of candidates + ///////// + + // I do not trust PHP references further than I can throw them (preferably + // at the idiot who came up with the idea) so I am using a separate array + // to store candidates and all references are integers into that. + + $candidates=array(); + $candidates[0]=new StdClass; + $candidates[0]->a=0; + $candidates[0]->b=0; + $candidates[0]->previous=null; + $candidates[1]=new StdClass; + $candidates[1]->a=$m+1; + $candidates[1]->b=$n+1; + $candidates[1]->previous=null; + + $K=array(); + $K[0]=0; // Ref to candidate 0 + $K[1]=1; // Ref to candidate 1 + $k=0; + + // Step 6 Merge stage + ///////// + + for($i=1;$i<=$m;$i++) { + if($P[$i]!==0) { + ouwiki_diff_merge($K,$k,$i,$E,$P[$i],$candidates); + } + } + + // Step 7 + ///////// + + $J=array(); + for($i=1;$i<=$m;$i++) { + $J[$i]=0; + } + + // Step 8 Follow candidate chain to make nice representation + ///////// + + $index=$K[$k]; + while(!is_null($index)) { // Stop when we reach the first, dummy candidate if($candidates[$index]->a!=0) { - $J[$candidates[$index]->a]=$candidates[$index]->b; + $J[$candidates[$index]->a]=$candidates[$index]->b; } - $index=$candidates[$index]->previous; - } - - // Step 9 Get rid of 'jackpots' (hash collisions) - ///////// - - for($i=1;$i<=$m;$i++) { - if($J[$i]!=0 && $file1[$i]!=$file2[$J[$i]]) { - $J[$i]=0; - } - } - - // Done! (Maybe.) - return $J; + $index=$candidates[$index]->previous; + } + + // Step 9 Get rid of 'jackpots' (hash collisions) + ///////// + + for($i=1;$i<=$m;$i++) { + if($J[$i]!=0 && $file1[$i]!=$file2[$J[$i]]) { + $J[$i]=0; + } + } + + // Done! (Maybe.) + return $J; } // Functions needed by parts of the algorithm @@ -163,68 +163,68 @@ function ouwiki_diff_internal($file1,$file2) { // Merge, from step 7 (Appendix A.3) function ouwiki_diff_merge(&$K,&$k,$i,&$E,$p,&$candidates) { - $r=0; - $c=$K[0]; - - while(true) { - $j=$E[$p]->serial; // Paper says 'i' but this is wrong (OCR) - - // Binary search in $K from $r to $k - $min=$r; - $max=$k+1; - - while(true) { - $try = (int)(($min+$max)/2); - if($candidates[$K[$try]]->b >= $j) { - $max=$try; - } else if($candidates[$K[$try+1]]->b <= $j) { - $min=$try+1; - } else { // $try is less and $try+1 is more - $s=$try; - break; - } - if($max<=$min) { - $s=-1; - break; - } - } + $r=0; + $c=$K[0]; + + while(true) { + $j=$E[$p]->serial; // Paper says 'i' but this is wrong (OCR) + + // Binary search in $K from $r to $k + $min=$r; + $max=$k+1; + + while(true) { + $try = (int)(($min+$max)/2); + if($candidates[$K[$try]]->b >= $j) { + $max=$try; + } else if($candidates[$K[$try+1]]->b <= $j) { + $min=$try+1; + } else { // $try is less and $try+1 is more + $s=$try; + break; + } + if($max<=$min) { + $s=-1; + break; + } + } + + if($s>-1) { + if($candidates[$K[$s+1]]->b > $j) { + // Create new candidate + $index=count($candidates); + $candidates[$index]=new StdClass; + $candidates[$index]->a=$i; + $candidates[$index]->b=$j; + $candidates[$index]->previous=$K[$s]; + $K[$r]=$c; + $r=$s+1; + $c=$index; // Or should this go before? + } + + if($s===$k) { + $K[$k+2]=$K[$k+1]; + $k++; + break; + } + } + + if($E[$p]->last) { + break; + } + + $p++; + } + $K[$r]=$c; - if($s>-1) { - if($candidates[$K[$s+1]]->b > $j) { - // Create new candidate - $index=count($candidates); - $candidates[$index]=new StdClass; - $candidates[$index]->a=$i; - $candidates[$index]->b=$j; - $candidates[$index]->previous=$K[$s]; - $K[$r]=$c; - $r=$s+1; - $c=$index; // Or should this go before? - } - - if($s===$k) { - $K[$k+2]=$K[$k+1]; - $k++; - break; - } - } - - if($E[$p]->last) { - break; - } - - $p++; - } - $K[$r]=$c; - } // From Step 2 function ouwiki_diff_sort_v($a,$b) { if($a->hash < $b->hash) { - return -1; + return -1; } else if($a->hash > $b->hash) { - return 1; + return 1; } else if($a->serial < $b->serial) { return -1; } else if($a->serial > $b->serial) { @@ -237,7 +237,7 @@ function ouwiki_diff_sort_v($a,$b) { // From Step 4 function ouwiki_diff_find_last(&$V,&$E,$hash) { // Binary search in $V until we find something with $hash - + // Min = 1, array is 1-indexed $min=1; // Max = 1 higher than highest key @@ -253,27 +253,27 @@ function ouwiki_diff_find_last(&$V,&$E,$hash) { break; } if($max<=$min) { - // No matching line + // No matching line return 0; } } - + // Now check back in $E to find the first line of that equivalence class for($j=$try;!$E[$j-1]->last;$j--) ; - return $j; + return $j; } /////////////////////////// /** - * Class representing one 'line' of HTML content for the purpose of - * text comparison. + * Class representing one 'line' of HTML content for the purpose of + * text comparison. */ class ouwiki_line { /** Array of ouwiki_words */ var $words=array(); - + /** * Construct line object based on a chunk of text. * @param string $data Text data that makes up this 'line'. (May include line breaks etc.) @@ -281,10 +281,10 @@ class ouwiki_line { */ public function __construct($data,$linepos) { // 1. Turn things we don't want into spaces (so that positioning stays same) - + // Whitespace replaced with space $data=preg_replace('/\s/',' ',$data); - + // Various ways of writing non-breaking space replaced with space // Note that using a single param for replace only works because all // the search strings are 6 characters long @@ -295,7 +295,7 @@ class ouwiki_line { return preg_replace("/./", " ", $matches[0]); }, $data); - // 2. Analyse string so that each space-separated thing + // 2. Analyse string so that each space-separated thing // is counted as a 'word' (note these may not be real words, // for instance words may include punctuation at either end) $pos=0; @@ -307,7 +307,7 @@ class ouwiki_line { // No more content break; } - + // Aaaand find the next space after that $space2=strpos($data,' ',$pos); if($space2===false) { @@ -344,7 +344,7 @@ class ouwiki_line { } return $result; } - + /** * Static function converts lines to strings. * @param array $lines Array of ouwiki_line @@ -353,12 +353,12 @@ class ouwiki_line { static function get_as_strings($lines) { $strings=array(); foreach($lines as $key=>$value) { - $strings[$key]=$value->get_as_string(); + $strings[$key]=$value->get_as_string(); } return $strings; } - - + + /** * @return True if there are no words in the line */ @@ -378,7 +378,7 @@ class ouwiki_word { var $word; /** Start position in original xhtml */ var $start; - + public function __construct($word,$start) { $this->word=$word; $this->start=$start; @@ -396,7 +396,7 @@ class ouwiki_word { } /** - * Prepares XHTML content for text difference comparison. + * Prepares XHTML content for text difference comparison. * @param string $content XHTML content [NO SLASHES] * @return array Array of ouwiki_line objects */ @@ -406,7 +406,7 @@ function ouwiki_diff_html_to_lines($content) { // consequence there is a lot of hackery going down. At every point we // replace things with spaces rather than getting rid, in order to store // positions within original content. - + // Get rid of all script, style, object tags (that might contain non-text // outside tags) $content=preg_replace_callback( @@ -416,7 +416,7 @@ function ouwiki_diff_html_to_lines($content) { // Get rid of all ` symbols as we are going to use these for a marker later. $content=preg_replace('/[`]/',' ',$content); - + // Put line breaks on block tags. Mark each line break with ` symbol $blocktags=array('p','div','h1','h2','h3','h4','h5','h6','td','li'); $taglist=''; @@ -429,7 +429,7 @@ function ouwiki_diff_html_to_lines($content) { $content = preg_replace_callback('/((' . $taglist . ')\s*)+/i', function($matches) { return "`" . preg_replace("/./", " ", substr($matches[0], 1)); }, $content); - + // Now go through splitting each line $lines=array(); $index=1; $pos=0; @@ -439,7 +439,7 @@ function ouwiki_diff_html_to_lines($content) { // No more line breaks? Take content to end $nextline=strlen($content); } - + $linestr=substr($content,$pos,$nextline-$pos); $line=new ouwiki_line($linestr,$pos); if(!$line->is_empty()) { @@ -447,13 +447,13 @@ function ouwiki_diff_html_to_lines($content) { } $pos=$nextline+1; } - return $lines; + return $lines; } -/** - * Represents a changed area of file and where it is located in the - * two source files. - */ +/** + * Represents a changed area of file and where it is located in the + * two source files. + */ class ouwiki_change_range { var $file1start,$file1count; var $file2start,$file2count; @@ -463,17 +463,17 @@ class ouwiki_change_range { * A more logical representation of the results from ouwiki_internal_diff() */ class ouwiki_changes { - + /** Array of indexes (in file 2) of added lines */ var $adds; - + /** Array of indexes (in file 1) of deleted lines */ var $deletes; - + /** Array of changed ranges */ var $changes; - - /** + + /** * @param array $diff Array from line indices in file1 * to indices in file2. All indices 1-based. * @param int $count2 Number of lines in file2 @@ -481,16 +481,16 @@ class ouwiki_changes { public function __construct($diff,$count2) { // Find deleted lines $this->deletes=self::internal_find_deletes($diff,$count2); - + // Added lines work the same way after the comparison is // reversed. $this->adds=self::internal_find_deletes( ouwiki_diff_internal_flip($diff,$count2),count($diff)); - + // Changed ranges are all the other lines from file 1 that - // weren't found in file 2 but aren't deleted, and the + // weren't found in file 2 but aren't deleted, and the // corresponding lines from file 2 (between the equivalent - // 'found' lines). + // 'found' lines). $this->changes=array(); $matchbefore=0; $inrange=-1; $lastrange=-1; @@ -503,8 +503,8 @@ class ouwiki_changes { $inrange=count($this->changes); $this->changes[$inrange]=new ouwiki_change_range; $this->changes[$inrange]->file1start=$index1; - $this->changes[$inrange]->file1count=1; - $this->changes[$inrange]->file2start=$matchbefore+1; // Last valid from file2 + $this->changes[$inrange]->file1count=1; + $this->changes[$inrange]->file2start=$matchbefore+1; // Last valid from file2 $this->changes[$inrange]->file2count=0; $lastrange=$inrange; } else { @@ -554,7 +554,7 @@ class ouwiki_changes { */ function internal_find_deletes($diff,$count2) { $deletes=array(); - + // 1. Create a new array that includes the lowest-valued // index2 value below each run of 0s. // I.e. if our array is say 1,2,0,0,0,3,0 then the @@ -570,28 +570,28 @@ class ouwiki_changes { $lowest=$index2; } } - - // 2. OK now we can use this new array to work out + + // 2. OK now we can use this new array to work out // items that are known to be deleted because we - // have matching items either side + // have matching items either side $highest=0; foreach($diff as $index1=>$index2) { if($index2===0) { if($highest===$count2 || $highest+1===$squidges[$index1]) { // Yep! Definitely deleted. - $deletes[]=$index1; - } + $deletes[]=$index1; + } } else { - $highest=$index2; + $highest=$index2; } } - return $deletes; + return $deletes; } } /** * Flips around the array returned by ouwiki_diff_internal - * so that it refers to lines from the other file. + * so that it refers to lines from the other file. * @param array $diff Array of index1=>index2 * @param int $count2 Count of lines in file 2 * @return array Flipped version @@ -615,7 +615,7 @@ function ouwiki_diff_internal_flip($diff,$count2) { * @param array $lines1 Array of ouwiki_line * @param array $lines2 Array of ouwiki_line * @return array (deleted,added); deleted and added are arrays of ouwiki_word with - * position numbers from $lines1 and $lines2 respectively + * position numbers from $lines1 and $lines2 respectively */ function ouwiki_diff_words($lines1,$lines2) { // Prepare arrays @@ -625,7 +625,7 @@ function ouwiki_diff_words($lines1,$lines2) { $linediff=ouwiki_diff( ouwiki_line::get_as_strings($lines1), ouwiki_line::get_as_strings($lines2)); - + // Handle lines that were entirely deleted foreach($linediff->deletes as $deletedline) { $deleted = array_merge($deleted, $lines1[$deletedline]->words); @@ -634,7 +634,7 @@ function ouwiki_diff_words($lines1,$lines2) { foreach($linediff->adds as $addedline) { $added = array_merge($added, $lines2[$addedline]->words); } - + // Changes get diffed at the individual-word level foreach($linediff->changes as $changerange) { // Build list of all words in each side of the range @@ -652,13 +652,13 @@ function ouwiki_diff_words($lines1,$lines2) { $file2words[]=$word; } } - + // Make arrays 1-based array_unshift($file1words,'dummy'); unset($file1words[0]); array_unshift($file2words,'dummy'); unset($file2words[0]); - + // Convert word lists into plain strings $file1strings=array(); foreach($file1words as $index=>$word) { @@ -668,7 +668,7 @@ function ouwiki_diff_words($lines1,$lines2) { foreach($file2words as $index=>$word) { $file2strings[$index]=$word->word; } - + // Run diff on strings $worddiff=ouwiki_diff($file1strings,$file2strings); foreach($worddiff->adds as $index) { @@ -688,7 +688,7 @@ function ouwiki_diff_words($lines1,$lines2) { } } } - + return array($deleted,$added); } @@ -717,7 +717,7 @@ function ouwiki_diff_add_markers($html,$words,$markerclass,$beforetext,$aftertex }); // Add marker for each word. We use an odd tag name which will - // be replaced by span later, this for ease of replacing + // be replaced by span later, this for ease of replacing $spanstart=""; $pos=0; $result=''; @@ -732,23 +732,23 @@ function ouwiki_diff_add_markers($html,$words,$markerclass,$beforetext,$aftertex // Add everything after last word $result.=substr($html,$pos); - + // If we end a marker then immediately start one, get rid of // both the end and start $result=preg_replace('^(\s*)^','$1',$result); - + // Turn markers into proper span $result=preg_replace('^^',$beforetext.'',$result); $result=preg_replace('^^',''.$aftertext,$result); - + return $result; } /** * Compares two HTML files. (This is the main function that everything else supports.) - * @param string $html1 XHTML for file 1 + * @param string $html1 XHTML for file 1 * @param string $html2 XHTML for file 2 - * @return array ($result1,$result2) to be displayed indicating the differences + * @return array ($result1,$result2) to be displayed indicating the differences */ function ouwiki_diff_html($html1,$html2) { $lines1=ouwiki_diff_html_to_lines($html1); @@ -760,6 +760,6 @@ function ouwiki_diff_html($html1,$html2) { $result2=ouwiki_diff_add_markers($html2,$added,'ouw_added', ''.get_string('addedbegins','wiki').'', ''.get_string('addedends','wiki').''); - return array($result1,$result2); + return array($result1,$result2); } diff --git a/mod/wiki/editors/wiki/buttons.js b/mod/wiki/editors/wiki/buttons.js index 52cd0008de8..ffdeae220e8 100644 --- a/mod/wiki/editors/wiki/buttons.js +++ b/mod/wiki/editors/wiki/buttons.js @@ -24,58 +24,58 @@ function insertTags(tagOpen, tagClose, sampleText) { // IE if(document.selection && !is_gecko) { - var theSelection = document.selection.createRange().text; - if(!theSelection) { theSelection=sampleText;} - txtarea.focus(); - if(theSelection.charAt(theSelection.length - 1) == " "){// exclude ending space char, if any - theSelection = theSelection.substring(0, theSelection.length - 1); - document.selection.createRange().text = tagOpen + theSelection + tagClose + " "; - } else { - document.selection.createRange().text = tagOpen + theSelection + tagClose; - } + var theSelection = document.selection.createRange().text; + if(!theSelection) { theSelection=sampleText;} + txtarea.focus(); + if(theSelection.charAt(theSelection.length - 1) == " "){// exclude ending space char, if any + theSelection = theSelection.substring(0, theSelection.length - 1); + document.selection.createRange().text = tagOpen + theSelection + tagClose + " "; + } else { + document.selection.createRange().text = tagOpen + theSelection + tagClose; + } // Mozilla } else if(txtarea.selectionStart || txtarea.selectionStart == '0') { - var startPos = txtarea.selectionStart; - var endPos = txtarea.selectionEnd; - var scrollTop=txtarea.scrollTop; - var myText = (txtarea.value).substring(startPos, endPos); - if(!myText) { myText=sampleText;} - if(myText.charAt(myText.length - 1) == " "){ // exclude ending space char, if any - subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " "; - } else { - subst = tagOpen + myText + tagClose; - } - txtarea.value = txtarea.value.substring(0, startPos) + subst + - txtarea.value.substring(endPos, txtarea.value.length); - txtarea.focus(); + var startPos = txtarea.selectionStart; + var endPos = txtarea.selectionEnd; + var scrollTop=txtarea.scrollTop; + var myText = (txtarea.value).substring(startPos, endPos); + if(!myText) { myText=sampleText;} + if(myText.charAt(myText.length - 1) == " "){ // exclude ending space char, if any + subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " "; + } else { + subst = tagOpen + myText + tagClose; + } + txtarea.value = txtarea.value.substring(0, startPos) + subst + + txtarea.value.substring(endPos, txtarea.value.length); + txtarea.focus(); - var cPos=startPos+(tagOpen.length+myText.length+tagClose.length); - txtarea.selectionStart=cPos; - txtarea.selectionEnd=cPos; - txtarea.scrollTop=scrollTop; + var cPos=startPos+(tagOpen.length+myText.length+tagClose.length); + txtarea.selectionStart=cPos; + txtarea.selectionEnd=cPos; + txtarea.scrollTop=scrollTop; // All others } else { - var copy_alertText=alertText; - var re1=new RegExp("\\$1","g"); - var re2=new RegExp("\\$2","g"); - copy_alertText=copy_alertText.replace(re1,sampleText); - copy_alertText=copy_alertText.replace(re2,tagOpen+sampleText+tagClose); - var text; - if (sampleText) { - text=prompt(copy_alertText); - } else { - text=""; - } - if(!text) { text=sampleText;} - text=tagOpen+text+tagClose; - document.infoform.infobox.value=text; - // in Safari this causes scrolling - if(!is_safari) { - txtarea.focus(); - } - noOverwrite=true; + var copy_alertText=alertText; + var re1=new RegExp("\\$1","g"); + var re2=new RegExp("\\$2","g"); + copy_alertText=copy_alertText.replace(re1,sampleText); + copy_alertText=copy_alertText.replace(re2,tagOpen+sampleText+tagClose); + var text; + if (sampleText) { + text=prompt(copy_alertText); + } else { + text=""; + } + if(!text) { text=sampleText;} + text=tagOpen+text+tagClose; + document.infoform.infobox.value=text; + // in Safari this causes scrolling + if(!is_safari) { + txtarea.focus(); + } + noOverwrite=true; } // reposition cursor if possible if (txtarea.createTextRange) txtarea.caretPos = document.selection.createRange().duplicate(); diff --git a/mod/wiki/parser/markups/nwiki.php b/mod/wiki/parser/markups/nwiki.php index 8d2d6a64b50..8c0a1dc54fd 100644 --- a/mod/wiki/parser/markups/nwiki.php +++ b/mod/wiki/parser/markups/nwiki.php @@ -12,7 +12,7 @@ include_once("wikimarkup.php"); class nwiki_parser extends wiki_markup_parser { - + protected $blockrules = array( 'nowiki' => array( 'expression' => "/^(.*?)<\/nowiki>/ims", @@ -53,7 +53,7 @@ class nwiki_parser extends wiki_markup_parser { 'tag' => 'p' ) ); - + protected $tagrules = array( 'nowiki' => array( 'expression' => "/(.*?)<\/nowiki>/is", @@ -93,11 +93,11 @@ class nwiki_parser extends wiki_markup_parser { 'token' => array("''", "''") ) ); - + protected function after_parsing() { parent::after_parsing(); } - + /** * Block hooks */ @@ -106,12 +106,12 @@ class nwiki_parser extends wiki_markup_parser { if($match[1] != $match[3]) { return $match[0]; } - + $num = strlen($match[1]); - + return $this->generate_header($match[2], $num); } - + protected function table_block_rule($match) { $rows = explode("\n|-", $match[1]); $table = array(); @@ -121,14 +121,14 @@ class nwiki_parser extends wiki_markup_parser { foreach($colsendline as $ce) { $cols = array_merge($cols, $this->get_table_cells($ce)); } - + if(!empty($cols)) { $table[] = $cols; } } return $this->generate_table($table); } - + private function get_table_cells($string) { $string = ltrim($string); $type = (!empty($string) && $string[0] == "!") ? 'header' : 'normal'; @@ -149,10 +149,10 @@ class nwiki_parser extends wiki_markup_parser { } $type = 'normal'; } - + return $cells; } - + protected function tab_paragraph_block_rule($match) { $num = strlen($match[1]); $text = $match[2]; @@ -160,31 +160,31 @@ class nwiki_parser extends wiki_markup_parser { for($i = 0; $i < $num - 1; $i++) { $html = parser_utils::h('p', $html, array('class' => 'wiki_tab_paragraph')); } - + return parser_utils::h('p', $text, array('class' => 'wiki_tab_paragraph')); } - + protected function desc_list_block_rule($match) { preg_match_all("/^(.+?)\:(.+?)\;$/ims", $match[0], $listitems, PREG_SET_ORDER); - + $list = ""; foreach($listitems as $li) { $term = $li[1]; $this->rules($term); - + $description = $li[2]; $this->rules($description); - + $list .= parser_utils::h('dt', $term).parser_utils::h('dd', $description); } - + return $list; } - + /** * Tag functions */ - + /** * Bold and italic similar to creole... */ @@ -193,23 +193,23 @@ class nwiki_parser extends wiki_markup_parser { if(strlen($match[2]) == 5) { $text .= "''"; } - + $this->rules($text, array('only' => array('bold'))); if(strpos($text, "''") !== false) { $text = str_replace("''", $this->protect("''"), $text); } - + return array($text, array()); } - + /** * Link tag functions */ - + protected function link_tag_rule($match) { return $this->format_link($match[1]); } - + protected function url_tag_tag_rule($match) { $text = trim($match[1]); if(preg_match("/(.+?)\|(.+)/is", $text, $matches)) { @@ -225,34 +225,34 @@ class nwiki_parser extends wiki_markup_parser { } return array($this->protect($text), array('href' => $this->protect($link))); } - + protected function url_tag_rule($match) { $url = $this->protect($match[1]); $options = array('href' => $url); - + return array($url, $options); } - + /** * Attachments & images */ - + protected function image_tag_rule($match) { return $this->format_image($match[1], $match[2]); } - - protected function attach_tag_rule($match) { + + protected function attach_tag_rule($match) { $parts = explode("|", $match[1]); - + $url = array_shift($parts); - + if(count($parts) > 0) { $text = array_shift($parts); } - + $extension = substr($url, strrpos($url, ".")); $text = empty($text) ? $url : $text; - + $imageextensions = array('jpg', 'jpeg', 'png', 'bmp', 'gif', 'tif'); if(in_array($extension, $imageextensions)) { $align = 'left'; diff --git a/mod/wiki/parser/utils.php b/mod/wiki/parser/utils.php index 9af567dabf7..f489ffd4360 100644 --- a/mod/wiki/parser/utils.php +++ b/mod/wiki/parser/utils.php @@ -10,9 +10,9 @@ */ require_once($CFG->dirroot . "/lib/outputcomponents.php"); - + class parser_utils { - + public static function h($tag, $text = null, $options = array(), $escape_text = false) { $tag = htmlentities($tag, ENT_COMPAT, 'UTF-8'); if(!empty($text) && $escape_text) { @@ -20,7 +20,7 @@ class parser_utils { } return html_writer::tag($tag, $text, $options); } - + /** * Default link generator */ @@ -77,7 +77,7 @@ class parser_utils { } else if($row[$i][0] == 'normal'){ $htmlrow .= "\n".parser_utils::h('td', $text)."\n"; - } + } } } $bodyhtml .= "\n".parser_utils::h('tr', $htmlrow)."\n"; @@ -86,11 +86,11 @@ class parser_utils { $html .= "\n".parser_utils::h('tbody', $bodyhtml)."\n"; return "\n".parser_utils::h('table', $html)."\n"; } - + /** * Default path converter */ - + public static function wiki_parser_real_path($url) { return $url; } diff --git a/webservice/wsdoc.php b/webservice/wsdoc.php index b3ed68e93c5..9c5002a26f4 100644 --- a/webservice/wsdoc.php +++ b/webservice/wsdoc.php @@ -44,7 +44,7 @@ $PAGE->navbar->ignore_active(true); $PAGE->navbar->add(get_string('preferences'), new moodle_url('/user/preferences.php')); $PAGE->navbar->add(get_string('useraccount')); $PAGE->navbar->add(get_string('securitykeys', 'webservice'), - new moodle_url('/user/managetoken.php', + new moodle_url('/user/managetoken.php', array('id' => $tokenid, 'sesskey' => sesskey()))); $PAGE->navbar->add(get_string('wsdocumentation', 'webservice'));