MDL-11517 reserved word MOD used in table alias in questions backup code
[moodle-pu.git] / mod / wiki / ewiki / plugins / moodle / diff.php
blob5a97691c77e3bb5759adfa15c112e756aeef5edf
1 <?php // $Id$
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
10 $ewiki_plugins["action"]["diff"] = "ewiki_page_stupid_diff";
11 $ewiki_config["action_links"]["info"]["diff"] = "diff";
15 function ewiki_page_stupid_diff($id, $data, $action) {
16 global $wiki, $moodle_format;
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));
22 else {
23 $new_ver = $data["version"];
24 $old_ver = $new_ver - 1;
26 if ($old_ver > 0) {
27 $data0 = ewiki_database("GET", array("id" => $id, "version" => $old_ver));
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));
35 # Different handling for html: closes Bug #1530 - Wiki diffs useless when using HTML editor
36 if($wiki->htmlmode==2) {
37 /// first do the formatiing to get normal display format without filters
38 $options = new object();
39 $options->smiley = false;
40 $options->filter = false;
41 $content0 = format_text($data0['content'], $moodle_format, $options);
42 $content = format_text($data['content'], $moodle_format, $options);
44 /// Remove all new line characters. They will be placed at HTML line breaks.
45 $content0 = preg_replace('/\n|\r/i', ' ', $content0);
46 $content0 = preg_replace('/(\S)\s+(\S)/', '$1 $2', $content0); // Remove multiple spaces.
47 $content = preg_replace('/\n|\r/i', ' ', $content);
48 $content = preg_replace('/(\S)\s+(\S)/', '$1 $2', $content);
50 /// Replace <p>&nbsp;</p>
51 $content0 = preg_replace('#(<p( [^>]*)?>(&nbsp;|\s+)</p>)|(<p( [^>]*)?></p>)#i', "\n", $content0);
52 $content = preg_replace('#(<p( [^>]*)?>(&nbsp;|\s+)</p>)|(<p( [^>]*)?></p>)#i', "\n", $content);
55 /// Place new line characters at logical HTML positions.
56 $htmlendings = array('+(<br.*?>)+iU', '+(<p( [^>]*)?>)+iU', '+(</p>)+i', '+(<hr.*?>)+iU', '+(<ol.*?>)+iU',
57 '+(</ol>)+i', '+(<ul.*?>)+iU', '+(</ul>)+i', '+(<li.*?>)+iU', '+(</li>)+i',
58 '+(</tr>)+i', '+(<div.*?>)+iU', '+(</div>)+i');
59 $htmlrepl = array("\n\$1\n", "\n\$1\n", "\n\$1\n", "\n\$1\n", "\n\$1\n",
60 "\n\$1\n", "\n\$1\n", "\n\$1\n", "\n\$1\n", "\n\$1\n",
61 "\n\$1\n", "\n\$1\n", "\n\$1\n");
62 $content0 = preg_replace($htmlendings, $htmlrepl, $content0);
63 $content = preg_replace($htmlendings, $htmlrepl, $content);
64 } else {
65 $content0=$data0["content"];
66 $content=$data["content"];
68 $txt0 = preg_split("+\s*\n+", trim($content0));
69 $txt2 = preg_split("+\s*\n+", trim($content));
71 $diff0 = array_diff($txt0, $txt2);
72 $diff2 = array_diff($txt2, $txt0);
74 foreach ($txt2 as $i => $line) {
75 $i2 = $i;
76 while ($rm = $diff0[$i2++]) {
77 if($wiki->htmlmode == 2) {
78 if ($rm == '<br />') { //ugly hack to fix line breaks
79 $rm = '';
81 $o .= "<b>-</b><font color=\"#990000\">".format_text($rm, $moodle_format, $options)."</font><br />\n";
82 } else {
83 $o .= "<b>-</b><font color=\"#990000\"><tt>".s($rm)."</tt></font><br />\n";
85 unset($diff0[$i2-1]);
88 if (in_array($line, $diff2)) {
89 if($wiki->htmlmode == 2) {
90 if ($line == '<br />') { //ugly hack to fix line breaks
91 $line = '';
93 $o .= "<b>+</b><font color=\"#009900\">".format_text($line, $moodle_format, $options)."</font><br />\n";
94 } else {
95 $o .= "<b>+</b><font color=\"#009900\"><tt>".s($line)."</tt></font><br />\n";
98 else {
99 if($wiki->htmlmode == 2) {
100 $o .= format_text($line, $moodle_format, $options)."\n";
101 } else {
102 $o .= "&nbsp; ".s($line)."<br />\n";
108 foreach ($diff0 as $rm) {
109 $o .= "<b>-</b><font color=\"#990000\"> <tt>".s($rm)."</tt></font><br />\n";
112 return($o);