author | Dan |
Sat, 12 Apr 2008 17:57:58 -0400 | |
changeset 533 | 698a8f04957c |
parent 519 | 94214ec0871c |
child 536 | 218a627eb53e |
permissions | -rw-r--r-- |
403 | 1 |
<?php |
519
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents:
504
diff
changeset
|
2 |
/**!info** |
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents:
504
diff
changeset
|
3 |
{ |
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents:
504
diff
changeset
|
4 |
"Plugin Name" : "plugin_specialrecentchanges_title", |
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents:
504
diff
changeset
|
5 |
"Plugin URI" : "http://enanocms.org/", |
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents:
504
diff
changeset
|
6 |
"Description" : "plugin_specialrecentchanges_desc", |
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents:
504
diff
changeset
|
7 |
"Author" : "Dan Fuhry", |
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents:
504
diff
changeset
|
8 |
"Version" : "1.1.3", |
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents:
504
diff
changeset
|
9 |
"Author URI" : "http://enanocms.org/" |
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents:
504
diff
changeset
|
10 |
} |
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents:
504
diff
changeset
|
11 |
**!*/ |
403 | 12 |
|
13 |
/* |
|
14 |
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
|
504
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
430
diff
changeset
|
15 |
* Version 1.1.3 (Caoineag alpha 3) |
403 | 16 |
* Copyright (C) 2006-2007 Dan Fuhry |
17 |
* |
|
18 |
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
|
19 |
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
|
20 |
* |
|
21 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
|
22 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
|
23 |
*/ |
|
24 |
||
25 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
26 |
||
27 |
$plugins->attachHook('session_started', ' |
|
28 |
global $paths; |
|
29 |
$paths->add_page(Array( |
|
30 |
\'name\'=>\'specialpage_recent_changes\', |
|
31 |
\'urlname\'=>\'RecentChanges\', |
|
32 |
\'namespace\'=>\'Special\', |
|
33 |
\'special\'=>0,\'visible\'=>1,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\', |
|
34 |
)); |
|
35 |
'); |
|
36 |
||
37 |
function page_Special_RecentChanges() |
|
38 |
{ |
|
39 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
40 |
global $lang; |
|
41 |
||
42 |
// One super-loaded SQL query to fetch all the info we need: |
|
43 |
// (theoretical) |
|
44 |
// SELECT ( CHAR_LENGTH(l1.page_text) - CHAR_LENGTH(l2.page_text) ) AS size_change, l1.author, l1.page_id, l1.namespace, l1.edit_summary, |
|
45 |
// l1.time_id AS currev_time, l2.time_id AS oldrev_time |
|
46 |
// FROM logs AS l1 |
|
47 |
// LEFT JOIN logs AS l2 |
|
48 |
// ON ( l1.log_type = l2.log_type AND l1.action = 'edit' AND l1.action = l2.action AND l2.time_id < l1.time_id AND l1.page_id = l2.page_id AND l1.namespace = l2.namespace ) |
|
49 |
// WHERE l2.time_id IS NOT NULL |
|
50 |
// GROUP BY l1.page_id, l1.namespace |
|
51 |
// ORDER BY l2.time_id DESC, l1.time_id DESC; |
|
52 |
// (the actual query is generated based on filter criteria) |
|
53 |
// How it works: |
|
54 |
// * Join the logs table with itself |
|
55 |
// * Select the size_change virtual column, which is based on current_rev_length - old_rev_length |
|
56 |
// * Use GROUP BY to group rows from the same page together |
|
57 |
// * Make sure that the time_id in the second instance (l2) of enano_logs is LESS than the time_id in the first instance (l1) |
|
58 |
// * Use ORDER BY to ensure that the latest revision before current is selected |
|
59 |
||
60 |
$where_extra = ''; |
|
61 |
if ( isset($_GET['filter_author']) && is_array($_GET['filter_author']) ) |
|
62 |
{ |
|
63 |
$f_author = $_GET['filter_author']; |
|
64 |
foreach ( $f_author as &$author ) |
|
65 |
{ |
|
66 |
$author = $db->escape($author); |
|
67 |
} |
|
68 |
$f_author = "\n AND (\n l1.author = '" . implode("'\n OR l1.author = '", $f_author) . "'\n )"; |
|
69 |
$where_extra .= $f_author; |
|
70 |
} |
|
71 |
||
72 |
if ( ENANO_DBLAYER == 'MYSQL' ) |
|
73 |
{ |
|
74 |
$sql = 'SELECT ( CHAR_LENGTH(l1.page_text) - CHAR_LENGTH(l2.page_text) ) AS size_change, l1.author, l1.page_id, l1.namespace, l1.edit_summary, |
|
75 |
l1.time_id AS currev_time, l2.time_id AS oldrev_time |
|
76 |
FROM ' . table_prefix . 'logs AS l1 |
|
77 |
LEFT JOIN ' . table_prefix . 'logs AS l2 |
|
414
818b4cd12b8b
Added "is_draft != 1" where appropriate in SQL queries to prevent drafts from being treated as real revisions.
Dan
parents:
411
diff
changeset
|
78 |
ON ( l1.log_type = l2.log_type AND l1.action = \'edit\' AND l1.action = l2.action AND l2.time_id < l1.time_id AND l1.page_id = l2.page_id AND l1.namespace = l2.namespace AND l2.is_draft != 1 ) |
403 | 79 |
WHERE l2.time_id IS NOT NULL' . $where_extra . ' |
414
818b4cd12b8b
Added "is_draft != 1" where appropriate in SQL queries to prevent drafts from being treated as real revisions.
Dan
parents:
411
diff
changeset
|
80 |
AND l1.is_draft != 1 |
403 | 81 |
GROUP BY oldrev_time |
82 |
ORDER BY l1.time_id DESC, l2.time_id DESC;'; |
|
83 |
} |
|
84 |
else |
|
85 |
{ |
|
86 |
$sql = 'SELECT DISTINCT ON (l1.time_id) ( CHAR_LENGTH(l1.page_text) - CHAR_LENGTH(l2.page_text) ) AS size_change, l1.author, l1.page_id, l1.namespace, l1.edit_summary, |
|
87 |
l1.time_id AS currev_time, l2.time_id AS oldrev_time |
|
88 |
FROM ' . table_prefix . 'logs AS l1 |
|
89 |
LEFT JOIN ' . table_prefix . 'logs AS l2 |
|
90 |
ON ( l1.log_type = l2.log_type AND l1.action = \'edit\' AND l1.action = l2.action AND l2.time_id < l1.time_id AND l1.page_id = l2.page_id AND l1.namespace = l2.namespace ) |
|
91 |
WHERE l2.time_id IS NOT NULL' . $where_extra . ' |
|
92 |
GROUP BY l1.time_id, l1.page_id, l1.namespace, l1.author, l1.edit_summary, l2.time_id, l1.page_text, l2.page_text |
|
93 |
ORDER BY l1.time_id DESC, l2.time_id DESC;'; |
|
94 |
} |
|
95 |
||
96 |
$template->header(); |
|
97 |
||
98 |
$q = $db->sql_unbuffered_query($sql); |
|
99 |
if ( !$q ) |
|
100 |
$db->_die(); |
|
101 |
||
102 |
if ( $row = $db->fetchrow($q) ) |
|
103 |
{ |
|
104 |
echo '<p>'; |
|
105 |
do |
|
106 |
{ |
|
107 |
$css = rch_get_css($row['size_change']); |
|
108 |
$pagekey = ( isset($paths->nslist[$row['namespace']]) ) ? $paths->nslist[$row['namespace']] . $row['page_id'] : $row['namespace'] . ':' . $row['page_id']; |
|
109 |
$pagekey = sanitize_page_id($pagekey); |
|
110 |
||
111 |
// diff button |
|
112 |
echo '('; |
|
113 |
if ( isPage($pagekey) ) |
|
114 |
{ |
|
115 |
echo '<a href="' . makeUrlNS($row['namespace'], $row['page_id'], "do=diff&diff1={$row['oldrev_time']}&diff2={$row['currev_time']}", true) . '">'; |
|
116 |
} |
|
117 |
echo $lang->get('pagetools_rc_btn_diff'); |
|
118 |
if ( isPage($pagekey) ) |
|
119 |
{ |
|
120 |
echo '</a>'; |
|
121 |
} |
|
122 |
echo ') '; |
|
123 |
||
124 |
// hist button |
|
125 |
echo '('; |
|
126 |
if ( isPage($pagekey) ) |
|
127 |
{ |
|
128 |
echo '<a href="' . makeUrlNS($row['namespace'], $row['page_id'], "do=history", true) . '">'; |
|
129 |
} |
|
130 |
echo $lang->get('pagetools_rc_btn_hist'); |
|
131 |
if ( isPage($pagekey) ) |
|
132 |
{ |
|
133 |
echo '</a>'; |
|
134 |
} |
|
135 |
echo ') . . '; |
|
136 |
||
137 |
// link to the page |
|
138 |
$cls = ( isPage($pagekey) ) ? '' : ' class="wikilink-nonexistent"'; |
|
139 |
echo '<a href="' . makeUrlNS($row['namespace'], $row['page_id']) . '"' . $cls . '>' . htmlspecialchars(get_page_title_ns($row['page_id'], $row['namespace'])) . '</a>; '; |
|
140 |
||
141 |
// date |
|
142 |
$today = time() - ( time() % 86400 ); |
|
143 |
$date = ( $row['currev_time'] > $today ) ? '' : MemberlistFormatter::format_date($row['currev_time']) . ' '; |
|
144 |
$date .= date('h:i s', $row['currev_time']); |
|
145 |
echo "$date . . "; |
|
146 |
||
147 |
// size counter |
|
148 |
$size_change = number_format($row['size_change']); |
|
149 |
if ( substr($size_change, 0, 1) != '-' ) |
|
150 |
$size_change = "+$size_change"; |
|
151 |
||
152 |
echo "<span style=\"$css\">({$size_change})</span>"; |
|
153 |
||
154 |
// link to userpage |
|
155 |
echo ' . . '; |
|
156 |
$cls = ( isPage($paths->nslist['User'] . $row['author']) ) ? '' : ' class="wikilink-nonexistent"'; |
|
157 |
echo '<a href="' . makeUrlNS('User', sanitize_page_id($row['author']), false, true) . '"' . $cls . '>' . htmlspecialchars($row['author']) . '</a> '; |
|
158 |
echo '('; |
|
159 |
echo '<a href="' . makeUrlNS('Special', 'PrivateMessages/Compose/To/' . sanitize_page_id($row['author']), false, true) . '">'; |
|
160 |
echo $lang->get('pagetools_rc_btn_pm'); |
|
161 |
echo '</a>, '; |
|
162 |
echo '<a href="' . makeUrlNS('User', sanitize_page_id($row['author']), false, true) . '#do:comments">'; |
|
163 |
echo $lang->get('pagetools_rc_btn_usertalk'); |
|
164 |
echo '</a>'; |
|
165 |
echo ') . . '; |
|
166 |
||
167 |
// Edit summary |
|
168 |
echo '<i>('; |
|
169 |
if ( empty($row['edit_summary']) ) |
|
170 |
{ |
|
171 |
echo '<span style="color: #808080;">' . $lang->get('history_summary_none_given') . '</span>'; |
|
172 |
} |
|
173 |
else |
|
174 |
{ |
|
175 |
echo RenderMan::parse_internal_links(htmlspecialchars($row['edit_summary'])); |
|
176 |
} |
|
177 |
echo ')</i>'; |
|
178 |
||
179 |
echo '<br />'; |
|
180 |
} |
|
181 |
while ( $row = $db->fetchrow($q) ); |
|
182 |
echo '</p>'; |
|
183 |
} |
|
184 |
||
185 |
$template->footer(); |
|
186 |
} |
|
187 |
||
188 |
function rch_get_css($change_size) |
|
189 |
{ |
|
190 |
// Hardly changed at all? Return a gray |
|
191 |
if ( $change_size <= 5 && $change_size >= -5 ) |
|
192 |
return 'color: #808080;'; |
|
193 |
// determine saturation based on size of change (1-500 bytes) |
|
194 |
$change_abs = abs($change_size); |
|
195 |
$index = 0x70 * ( $change_abs / 500 ); |
|
196 |
if ( $index > 0x70 ) |
|
197 |
$index = 0x70; |
|
198 |
$index = $index + 0x40; |
|
199 |
$index = dechex($index); |
|
200 |
if ( strlen($index) < 2 ) |
|
201 |
$index = "0$index"; |
|
202 |
$css = ( $change_size > 0 ) ? "color: #00{$index}00;" : "color: #{$index}0000;"; |
|
203 |
if ( $change_abs > 500 ) |
|
204 |
$css .= ' font-weight: bold;'; |
|
205 |
return $css; |
|
206 |
} |
|
207 |
||
208 |
?> |