Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

May fix Bug #1530 - Wiki diffs useless when using HTML editor.

  • Loading branch information...
commit 5beb559572a4fa0680d78701bb1e313967232de3 1 parent 0dc1d62
skaldrom authored
65 mod/wiki/ewiki/plugins/action/diff.php
... ... @@ -1,65 +0,0 @@
1   -<?php
2   -
3   - # this is the "stupid diff", which shows up changes between two
4   - # saved versions of a WikiPage; even if working very unclean it
5   - # allows to see what has changed
6   - # it is accessible through the "info about page" action
7   -
8   -
9   -
10   - $ewiki_plugins["action"]["diff"] = "ewiki_page_stupid_diff";
11   - $ewiki_config["action_links"]["info"]["diff"] = "diff";
12   -
13   -
14   -
15   - function ewiki_page_stupid_diff($id, $data, $action) {
16   -
17   -
18   - if ($uu=$GLOBALS["ewiki_diff_versions"]) {
19   - list($new_ver, $old_ver) = $uu;
20   - $data = ewiki_database("GET", array("id" => $id, "version" => $new_ver));
21   - }
22   - else {
23   - $new_ver = $data["version"];
24   - $old_ver = $new_ver - 1;
25   - }
26   - if ($old_ver > 0) {
27   - $data0 = ewiki_database("GET", array("id" => $id, "version" => $old_ver));
28   - }
29   -
30   - $o = ewiki_make_title($id, "Differences between version $new_ver and $old_ver of �{$id}�");
31   -
32   - $txt0 = preg_split("/\s*\n/", trim($data0["content"]));
33   - $txt2 = preg_split("/\s*\n/", trim($data["content"]));
34   -
35   - $diff0 = array_diff($txt0, $txt2);
36   - $diff2 = array_diff($txt2, $txt0);
37   -
38   - foreach ($txt2 as $i => $line) {
39   -
40   - $line = htmlentities($line);
41   -
42   - $i2 = $i;
43   - while ($rm = $diff0[$i2++]) {
44   - $o .= "<b>-</b><font color=\"#990000\"> <tt>$rm</tt></font><br>\n";
45   - unset($diff0[$i2-1]);
46   - }
47   -
48   - if (in_array($line, $diff2)) {
49   - $o .= "<b>+</b><font color=\"#009900\"> <tt>$line</tt></font><br>\n";
50   - }
51   - else {
52   - $o .= "&nbsp; $line<br>\n";
53   - }
54   -
55   - }
56   -
57   - foreach ($diff0 as $rm) {
58   - $o .= "<b>-</b><font color=\"#990000\"> <tt>$rm</tt></font><br>\n";
59   - }
60   -
61   - return($o);
62   - }
63   -
64   -
65   -?>
96 mod/wiki/ewiki/plugins/moodle/diff.php
... ... @@ -0,0 +1,96 @@
  1 +<?php
  2 +
  3 + # this is the "stupid diff", which shows up changes between two
  4 + # saved versions of a WikiPage; even if working very unclean it
  5 + # allows to see what has changed
  6 + # it is accessible through the "info about page" action
  7 +
  8 +
  9 +
  10 + $ewiki_plugins["action"]["diff"] = "ewiki_page_stupid_diff";
  11 + $ewiki_config["action_links"]["info"]["diff"] = "diff";
  12 +
  13 +
  14 +
  15 + function ewiki_page_stupid_diff($id, $data, $action) {
  16 + global $wiki;
  17 +
  18 + if ($uu=$GLOBALS["ewiki_diff_versions"]) {
  19 + list($new_ver, $old_ver) = $uu;
  20 + $data = ewiki_database("GET", array("id" => $id, "version" => $new_ver));
  21 + }
  22 + else {
  23 + $new_ver = $data["version"];
  24 + $old_ver = $new_ver - 1;
  25 + }
  26 + if ($old_ver > 0) {
  27 + $data0 = ewiki_database("GET", array("id" => $id, "version" => $old_ver));
  28 + }
  29 +
  30 + $a->new_ver=$new_ver;
  31 + $a->old_ver=$old_ver;
  32 + $a->pagename=$id;
  33 + $o = ewiki_make_title($id, get_string("differences","wiki",$a));
  34 +
  35 + # Different handling for html: closes Bug #1530 - Wiki diffs useless when using HTML editor
  36 + if($wiki->htmlmode==2) {
  37 + $htmlendings=array("<br />","<br>","</p>","<hr />","<hr>","</li>","</tr>");
  38 + $splitregexp="+\s*\n|\s*(".join("|",$htmlendings).")+";
  39 + $content0=preg_replace("+(".join("|",$htmlendings).")+","\n",$data0["content"]);
  40 + $content=preg_replace("+(".join("|",$htmlendings).")+","\n",$data["content"]);
  41 + } else {
  42 + $splitregexp="/\s*\n/";
  43 + $content0=$data0["content"];
  44 + $content=$data["content"];
  45 + }
  46 + $txt0 = preg_split($splitregexp, trim($content0));
  47 + $txt2 = preg_split($splitregexp, trim($content));
  48 +
  49 + /// Remove empty lines in html
  50 + if($wiki->htmlmode==2) {
  51 + $html0=$txt0;
  52 + $html2=$txt2;
  53 + $txt0=array();
  54 + $txt2=array();
  55 +
  56 + for($i=0;$i<count($html0);$i++) {
  57 + if(trim(strip_tags($html0[$i]))) { // There is something !
  58 + $txt0[]=$html0[$i];
  59 + }
  60 + }
  61 + for($i=0;$i<count($html2);$i++) {
  62 + if(trim(strip_tags($html2[$i]))) { // There is something !
  63 + $txt2[]=$html2[$i];
  64 + }
  65 + }
  66 + }
  67 +
  68 + $diff0 = array_diff($txt0, $txt2);
  69 + $diff2 = array_diff($txt2, $txt0);
  70 +
  71 + foreach ($txt2 as $i => $line) {
  72 + if($wiki->htmlmode != 2) {
  73 + $line = htmlentities($line);
  74 + }
  75 + $i2 = $i;
  76 + while ($rm = $diff0[$i2++]) {
  77 + $o .= "<b>-</b><font color=\"#990000\"><tt>$rm</tt></font><br>\n";
  78 + unset($diff0[$i2-1]);
  79 + }
  80 +
  81 + if (in_array($line, $diff2)) {
  82 + $o .= "<b>+</b><font color=\"#009900\"> <tt>$line</tt></font><br>\n";
  83 + }
  84 + else {
  85 + $o .= "&nbsp; $line<br>\n";
  86 + }
  87 +
  88 + }
  89 +
  90 + foreach ($diff0 as $rm) {
  91 + $o .= "<b>-</b><font color=\"#990000\"> <tt>$rm</tt></font><br>\n";
  92 + }
  93 +
  94 + return($o);
  95 + }
  96 +?>

0 comments on commit 5beb559

Please sign in to comment.
Something went wrong with that request. Please try again.