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