changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / page / recentchanges.php
1 <?php
2
3 /*
4    Gives a more standard RecentChanges (besides the ewiki built-in
5    "UpdatedPages") in two different variants.
6 */
7
8
9 $ewiki_plugins["rc"][0] = "ewiki_page_rc_usemod";
10 //$ewiki_plugins["rc"][0] = "ewiki_page_rc_moin";
11
12 define("EWIKI_PAGE_RECENTCHANGES", "RecentChanges");
13
14 $ewiki_t["en"]["DAY"] = "%a, %d %b %G";
15 $ewiki_t["en"]["CLOCK"] = "%H:%M";
16 $ewiki_t["de"]["show last"] = "zeige letzte";
17 $ewiki_t["de"]["days"] = "Tage";
18
19
20
21 $ewiki_plugins["page"][EWIKI_PAGE_RECENTCHANGES] = "ewiki_page_recentchanges";
22 function ewiki_page_recentchanges($recentchanges, $data, $action) {
23
24    global $ewiki_plugins, $ewiki_links;
25
26    #-- start output
27    $ewiki_links = true;
28    $o = "";
29    $o .= ewiki_make_title($recentchanges, $recentchanges, 2);
30    
31    #-- options
32    $minor_edits = $_GET["minor"]?1:0;
33
34    #-- select timeframe
35    if (($days = $_REQUEST["days"]) < 1) {
36       $days = 7;
37    }
38    $timeframe = time() - $days * 24 * 3600;
39
40    #-- fetch pages modified in given timeframe
41    $result = ewiki_db::GETALL(array("meta", "lastmodified", "author"));
42    $changes = array();
43    $meta = array();
44    while ($row = $result->get(0, 0x0137, EWIKI_DB_F_TEXT)) {
45
46       if ($row["lastmodified"] >= $timeframe) {
47
48          #-- id->time array
49          $id = $row["id"];
50          $changes[$id] = $row["lastmodified"];
51
52          #-- collect also info for previous changes of current page
53          $meta[$id] = array();
54          ewiki_page_rc_more($row, $meta[$id], $timeframe, $minor_edits);
55       }
56    }
57
58    #-- sort results into date catalogue
59    arsort($changes);
60    $last_date = "";
61    $datestr = ewiki_t("DAY");
62    $e = array();
63    foreach ($changes as $id=>$date) {
64
65       $date = strftime($datestr, $date);
66       if ($date != $last_date) {
67          $last_date = $date;
68       }
69
70       $e[$date][] = $id;
71       unset($changes[$id]);
72    }
73
74
75    #-- mk output
76    $o .= $ewiki_plugins["rc"][0]($e, $meta);
77
78
79    #-- add an <form>
80    if ($days == 7) {
81       $days = 30;
82    }
83    $url = ewiki_script("", $recentchanges);
84    $o .= ewiki_t(<<<EOT
85    <br />
86    <form action="$url" method="GET">
87      <input type="hidden" name="id" value="$recentchanges">
88      _{show last} <input type="text" name="days" value="$days" size="5">
89      <input type="submit" value="_{days}">
90    </form>
91    <br />
92 EOT
93    );
94
95    return($o);
96 }
97
98
99 /*
100    UseMod like list output
101 */
102 function ewiki_page_rc_usemod(&$e, &$meta) {
103
104    $clockstr = ewiki_t("CLOCK");
105
106    foreach ($e as $datestr => $pages) {
107
108       $o .= "\n<h4 class=\"date\">$datestr</h4>\n";
109
110       foreach ($pages as $id) {
111
112          $diff = '<a href="'.ewiki_script("diff",$id).'">(diff)</a>';
113          $page = '<a href="'.ewiki_script("",$id).'">'.htmlentities($id).'</a>';
114          $time = strftime($clockstr, $meta[$id][0][2]);
115          $author = ewiki_author_html($meta[$id][0][0], 0);
116          $log = htmlentities($meta[$id][0][1]);
117          $changes = "";
118          if (($n = count($meta[$id])) > 1) {
119             $changes = "($n ".'<a href="'.ewiki_script("info", $id).'">changes</a>)';
120          }
121
122          $o .= '&middot; '
123              . $diff . ' '
124              . $page
125              . ' ' . $time . ' '
126              . $changes . ' '
127              . ($log ? '<b class="log">[' . $log . ']</b>' : '')
128              . ' . . . . . ' . $author
129              . '<br />' . "\n";
130       }
131    }
132    $o .= "\n";
133    return($o);
134 }
135
136
137 /*
138    MoinMoin table style changelog output
139 */
140 function ewiki_page_rc_moin(&$e, &$meta) {
141
142    $clockstr = ewiki_t("CLOCK");
143
144    $o .= '<table class="changes" border="0" width="100%">'
145       . '<colgroup><col width="35%"><col width="5%"><col width="25%"><col width="35%"></colgroup>';
146
147    foreach ($e as $datestr => $pages) {
148       $o .= "\n<tr><td colspan=\"3\"><br /><h4 class=\"date\">$datestr</h4></td></tr>\n";
149       foreach ($pages as $id) {
150
151          $link = '<a href="' . ewiki_script("", $id) . '">' . htmlentities($id) . '</a>';
152          $time = strftime($clockstr, $meta[$id][0][2]);
153          $changes = $meta[$id];
154          if (count($changes) >= 2) {
155
156             #-- enum unique author names
157             $a = array();
158             foreach ($changes as $i=>$str) {
159                $str = strtok($str[0], " <(");
160                $a[$str][] = ($i+1);
161             }
162             $str = "";
163             foreach ($a as $author=>$i) {
164                $author = ewiki_author_html($author, 0);
165                $str .= $author. "[".implode(",",$i)."]<br /> ";
166             }
167             $author = $str;
168
169             #-- enum log entries
170             $log = "";
171             foreach ($meta[$id] as $i=>$str) {
172                if ($str = $str[1]) {
173                   $log .= "#".($i+1)." " . htmlentities($str) . "<br />\n";
174                }
175             }
176          }
177          else {
178             $author = ewiki_author_html($meta[$id][0][0]);
179             $log = htmlentities($meta[$id][0][1]);
180          }
181
182          $o .= '<tr><td class="page"> &middot; ' . $link . '</td>'
183              . '<td class="time"> [' . $time . '] </td>'
184              . '<td class="author">' . $author . '</td>'
185              . '<td class="log">' . $log . '</td></tr>' . "\n";
186       }
187    }
188    $o .= "</table>\n";
189    return($o);
190 }
191
192
193 /*
194    fills $list with changeLOG entries of previous page ($row) versions
195 */
196 function ewiki_page_rc_more(&$row, &$list, $timeframe, $minor_edits) {
197
198    $id = $row["id"];
199    $ver = $row["version"];
200    while ($ver >= 1) {
201
202       if ($row["lastmodified"] >= $timeframe) {
203          if ($minor_edits || !($row["flags"] & EWIKI_DB_F_MINOR)) {
204             $list[] = array(
205                0 => $row["author"],
206                1 => $row["meta"]["log"],
207                2 => $row["lastmodified"],
208             );
209          }
210       }
211       else {
212          return;
213       }
214
215       $ver--;
216       if (!$ver || !($row = ewiki_db::GET($id, $ver))) { 
217          return;  // stops at revision holes
218       }
219    }
220 }
221
222 ?>