author | Dan |
Fri, 06 Mar 2009 11:18:34 -0500 | |
changeset 854 | 7707f60d4a71 |
parent 801 | eb8b23f11744 |
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", |
685
17ebe24cdf85
Rebranded as 1.1.5 (Caoineag alpha 5) and fixed a couple bugs related to CDN support in template_nodb and installerUI. Updated readme.
Dan
parents:
593
diff
changeset
|
8 |
"Version" : "1.1.5", |
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
|
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 |
|
801
eb8b23f11744
Two big commits in one day I know, but redid password storage to use HMAC-SHA1. Consolidated much AES processing to three core methods in session that should handle everything automagically. Installation works; upgrades should. Rebranded as 1.1.6.
Dan
parents:
685
diff
changeset
|
15 |
* Version 1.1.6 (Caoineag beta 1) |
536 | 16 |
* Copyright (C) 2006-2008 Dan Fuhry |
403 | 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 |
||
593
4f9bec0d65c1
More optimization work. Moved special page init functions to common instead of common_post hook. Allowed paths to cache page metadata on filesystem. Phased out the redundancy in $paths->pages that paired a number with every urlname as foreach loops are allowed now (and have been for some time). Fixed missing includes for several functions. Rewrote str_replace_once to be a lot more efficient.
Dan
parents:
590
diff
changeset
|
27 |
// $plugins->attachHook('session_started', 'SpecialRecentChanges_paths_init();'); |
590
03a60844c7c5
Several optimization changes including getting rid of a few eval()s. Added placeholder functions for the theme manager, which should be working now
Dan
parents:
564
diff
changeset
|
28 |
|
03a60844c7c5
Several optimization changes including getting rid of a few eval()s. Added placeholder functions for the theme manager, which should be working now
Dan
parents:
564
diff
changeset
|
29 |
function SpecialRecentChanges_paths_init() |
03a60844c7c5
Several optimization changes including getting rid of a few eval()s. Added placeholder functions for the theme manager, which should be working now
Dan
parents:
564
diff
changeset
|
30 |
{ |
403 | 31 |
global $paths; |
590
03a60844c7c5
Several optimization changes including getting rid of a few eval()s. Added placeholder functions for the theme manager, which should be working now
Dan
parents:
564
diff
changeset
|
32 |
$paths->add_page(Array( |
03a60844c7c5
Several optimization changes including getting rid of a few eval()s. Added placeholder functions for the theme manager, which should be working now
Dan
parents:
564
diff
changeset
|
33 |
'name'=>'specialpage_recent_changes', |
03a60844c7c5
Several optimization changes including getting rid of a few eval()s. Added placeholder functions for the theme manager, which should be working now
Dan
parents:
564
diff
changeset
|
34 |
'urlname'=>'RecentChanges', |
03a60844c7c5
Several optimization changes including getting rid of a few eval()s. Added placeholder functions for the theme manager, which should be working now
Dan
parents:
564
diff
changeset
|
35 |
'namespace'=>'Special', |
03a60844c7c5
Several optimization changes including getting rid of a few eval()s. Added placeholder functions for the theme manager, which should be working now
Dan
parents:
564
diff
changeset
|
36 |
'special'=>0,'visible'=>1,'comments_on'=>0,'protected'=>1,'delvotes'=>0,'delvote_ips'=>'', |
03a60844c7c5
Several optimization changes including getting rid of a few eval()s. Added placeholder functions for the theme manager, which should be working now
Dan
parents:
564
diff
changeset
|
37 |
)); |
03a60844c7c5
Several optimization changes including getting rid of a few eval()s. Added placeholder functions for the theme manager, which should be working now
Dan
parents:
564
diff
changeset
|
38 |
} |
403 | 39 |
|
40 |
function page_Special_RecentChanges() |
|
41 |
{ |
|
42 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
43 |
global $lang; |
|
44 |
||
45 |
// One super-loaded SQL query to fetch all the info we need: |
|
46 |
// (theoretical) |
|
47 |
// SELECT ( CHAR_LENGTH(l1.page_text) - CHAR_LENGTH(l2.page_text) ) AS size_change, l1.author, l1.page_id, l1.namespace, l1.edit_summary, |
|
48 |
// l1.time_id AS currev_time, l2.time_id AS oldrev_time |
|
49 |
// FROM logs AS l1 |
|
50 |
// LEFT JOIN logs AS l2 |
|
51 |
// 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 ) |
|
52 |
// WHERE l2.time_id IS NOT NULL |
|
53 |
// GROUP BY l1.page_id, l1.namespace |
|
54 |
// ORDER BY l2.time_id DESC, l1.time_id DESC; |
|
55 |
// (the actual query is generated based on filter criteria) |
|
56 |
// How it works: |
|
57 |
// * Join the logs table with itself |
|
58 |
// * Select the size_change virtual column, which is based on current_rev_length - old_rev_length |
|
59 |
// * Use GROUP BY to group rows from the same page together |
|
60 |
// * 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) |
|
61 |
// * Use ORDER BY to ensure that the latest revision before current is selected |
|
62 |
||
63 |
$where_extra = ''; |
|
64 |
if ( isset($_GET['filter_author']) && is_array($_GET['filter_author']) ) |
|
65 |
{ |
|
66 |
$f_author = $_GET['filter_author']; |
|
67 |
foreach ( $f_author as &$author ) |
|
68 |
{ |
|
69 |
$author = $db->escape($author); |
|
70 |
} |
|
71 |
$f_author = "\n AND (\n l1.author = '" . implode("'\n OR l1.author = '", $f_author) . "'\n )"; |
|
72 |
$where_extra .= $f_author; |
|
73 |
} |
|
74 |
||
75 |
if ( ENANO_DBLAYER == 'MYSQL' ) |
|
76 |
{ |
|
77 |
$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, |
|
78 |
l1.time_id AS currev_time, l2.time_id AS oldrev_time |
|
79 |
FROM ' . table_prefix . 'logs AS l1 |
|
80 |
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
|
81 |
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 | 82 |
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
|
83 |
AND l1.is_draft != 1 |
403 | 84 |
GROUP BY oldrev_time |
85 |
ORDER BY l1.time_id DESC, l2.time_id DESC;'; |
|
86 |
} |
|
87 |
else |
|
88 |
{ |
|
89 |
$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, |
|
90 |
l1.time_id AS currev_time, l2.time_id AS oldrev_time |
|
91 |
FROM ' . table_prefix . 'logs AS l1 |
|
92 |
LEFT JOIN ' . table_prefix . 'logs AS l2 |
|
93 |
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 ) |
|
94 |
WHERE l2.time_id IS NOT NULL' . $where_extra . ' |
|
95 |
GROUP BY l1.time_id, l1.page_id, l1.namespace, l1.author, l1.edit_summary, l2.time_id, l1.page_text, l2.page_text |
|
96 |
ORDER BY l1.time_id DESC, l2.time_id DESC;'; |
|
97 |
} |
|
98 |
||
99 |
$template->header(); |
|
100 |
||
101 |
$q = $db->sql_unbuffered_query($sql); |
|
102 |
if ( !$q ) |
|
103 |
$db->_die(); |
|
104 |
||
105 |
if ( $row = $db->fetchrow($q) ) |
|
106 |
{ |
|
107 |
echo '<p>'; |
|
108 |
do |
|
109 |
{ |
|
110 |
$css = rch_get_css($row['size_change']); |
|
111 |
$pagekey = ( isset($paths->nslist[$row['namespace']]) ) ? $paths->nslist[$row['namespace']] . $row['page_id'] : $row['namespace'] . ':' . $row['page_id']; |
|
112 |
$pagekey = sanitize_page_id($pagekey); |
|
113 |
||
114 |
// diff button |
|
115 |
echo '('; |
|
116 |
if ( isPage($pagekey) ) |
|
117 |
{ |
|
118 |
echo '<a href="' . makeUrlNS($row['namespace'], $row['page_id'], "do=diff&diff1={$row['oldrev_time']}&diff2={$row['currev_time']}", true) . '">'; |
|
119 |
} |
|
120 |
echo $lang->get('pagetools_rc_btn_diff'); |
|
121 |
if ( isPage($pagekey) ) |
|
122 |
{ |
|
123 |
echo '</a>'; |
|
124 |
} |
|
125 |
echo ') '; |
|
126 |
||
127 |
// hist button |
|
128 |
echo '('; |
|
129 |
if ( isPage($pagekey) ) |
|
130 |
{ |
|
131 |
echo '<a href="' . makeUrlNS($row['namespace'], $row['page_id'], "do=history", true) . '">'; |
|
132 |
} |
|
133 |
echo $lang->get('pagetools_rc_btn_hist'); |
|
134 |
if ( isPage($pagekey) ) |
|
135 |
{ |
|
136 |
echo '</a>'; |
|
137 |
} |
|
138 |
echo ') . . '; |
|
139 |
||
140 |
// link to the page |
|
141 |
$cls = ( isPage($pagekey) ) ? '' : ' class="wikilink-nonexistent"'; |
|
142 |
echo '<a href="' . makeUrlNS($row['namespace'], $row['page_id']) . '"' . $cls . '>' . htmlspecialchars(get_page_title_ns($row['page_id'], $row['namespace'])) . '</a>; '; |
|
143 |
||
144 |
// date |
|
145 |
$today = time() - ( time() % 86400 ); |
|
146 |
$date = ( $row['currev_time'] > $today ) ? '' : MemberlistFormatter::format_date($row['currev_time']) . ' '; |
|
147 |
$date .= date('h:i s', $row['currev_time']); |
|
148 |
echo "$date . . "; |
|
149 |
||
150 |
// size counter |
|
151 |
$size_change = number_format($row['size_change']); |
|
152 |
if ( substr($size_change, 0, 1) != '-' ) |
|
153 |
$size_change = "+$size_change"; |
|
154 |
||
155 |
echo "<span style=\"$css\">({$size_change})</span>"; |
|
156 |
||
157 |
// link to userpage |
|
158 |
echo ' . . '; |
|
159 |
$cls = ( isPage($paths->nslist['User'] . $row['author']) ) ? '' : ' class="wikilink-nonexistent"'; |
|
160 |
echo '<a href="' . makeUrlNS('User', sanitize_page_id($row['author']), false, true) . '"' . $cls . '>' . htmlspecialchars($row['author']) . '</a> '; |
|
161 |
echo '('; |
|
162 |
echo '<a href="' . makeUrlNS('Special', 'PrivateMessages/Compose/To/' . sanitize_page_id($row['author']), false, true) . '">'; |
|
163 |
echo $lang->get('pagetools_rc_btn_pm'); |
|
164 |
echo '</a>, '; |
|
165 |
echo '<a href="' . makeUrlNS('User', sanitize_page_id($row['author']), false, true) . '#do:comments">'; |
|
166 |
echo $lang->get('pagetools_rc_btn_usertalk'); |
|
167 |
echo '</a>'; |
|
168 |
echo ') . . '; |
|
169 |
||
170 |
// Edit summary |
|
171 |
echo '<i>('; |
|
172 |
if ( empty($row['edit_summary']) ) |
|
173 |
{ |
|
174 |
echo '<span style="color: #808080;">' . $lang->get('history_summary_none_given') . '</span>'; |
|
175 |
} |
|
176 |
else |
|
177 |
{ |
|
178 |
echo RenderMan::parse_internal_links(htmlspecialchars($row['edit_summary'])); |
|
179 |
} |
|
180 |
echo ')</i>'; |
|
181 |
||
182 |
echo '<br />'; |
|
183 |
} |
|
184 |
while ( $row = $db->fetchrow($q) ); |
|
185 |
echo '</p>'; |
|
186 |
} |
|
187 |
||
188 |
$template->footer(); |
|
189 |
} |
|
190 |
||
191 |
function rch_get_css($change_size) |
|
192 |
{ |
|
193 |
// Hardly changed at all? Return a gray |
|
194 |
if ( $change_size <= 5 && $change_size >= -5 ) |
|
195 |
return 'color: #808080;'; |
|
196 |
// determine saturation based on size of change (1-500 bytes) |
|
197 |
$change_abs = abs($change_size); |
|
198 |
$index = 0x70 * ( $change_abs / 500 ); |
|
199 |
if ( $index > 0x70 ) |
|
200 |
$index = 0x70; |
|
201 |
$index = $index + 0x40; |
|
202 |
$index = dechex($index); |
|
203 |
if ( strlen($index) < 2 ) |
|
204 |
$index = "0$index"; |
|
205 |
$css = ( $change_size > 0 ) ? "color: #00{$index}00;" : "color: #{$index}0000;"; |
|
206 |
if ( $change_abs > 500 ) |
|
207 |
$css .= ' font-weight: bold;'; |
|
208 |
return $css; |
|
209 |
} |
|
210 |
||
211 |
?> |