OSDN Git Service

BugTrack/2256 edit: Handle template loading button
[pukiwiki/pukiwiki.git] / plugin / recent.inc.php
index fb9adf6..5936879 100644 (file)
@@ -1,7 +1,7 @@
 <?php
-// $Id: recent.inc.php,v 1.20 2006/03/05 13:03:30 henoheno Exp $
+// $Id: recent.inc.php,v 1.27 2011/01/25 15:01:01 henoheno Exp $
 // Copyright (C)
-//   2002-2006 PukiWiki Developers Team
+//   2002-2007 PukiWiki Developers Team
 //   2002      Y.MASUI http://masui.net/pukiwiki/ masui@masui.net
 // License: GPL version 2
 //
@@ -15,9 +15,6 @@ define('PLUGIN_RECENT_DEFAULT_LINES', 10);
 // Limit number of executions
 define('PLUGIN_RECENT_EXEC_LIMIT', 2); // N times per one output
 
-// Show elapsed date of the page
-define('PLUGIN_RECENT_SHOW_PASSAGE', TRUE);
-
 // ----
 
 define('PLUGIN_RECENT_USAGE', '#recent(number-to-show)');
@@ -27,7 +24,7 @@ define('PLUGIN_RECENT_CACHE', CACHE_DIR . 'recent.dat');
 
 function plugin_recent_convert()
 {
-       global $vars, $date_format, $_recent_plugin_frame;
+       global $vars, $date_format, $_recent_plugin_frame, $show_passage;
        static $exec_count = 1;
 
        $recent_lines = PLUGIN_RECENT_DEFAULT_LINES;
@@ -47,17 +44,19 @@ function plugin_recent_convert()
                ++$exec_count;
        }
 
-       // Get latest N changes
-       if (file_exists(PLUGIN_RECENT_CACHE)) {
-               // BugTrack2/106: Only variables can be passed by reference from PHP 5.0.5
-               $file_array = file(PLUGIN_RECENT_CACHE); // with array_splice()
-               $lines      = array_splice($file_array, 0, $recent_lines);
-       } else {
-               return '#recent(): Cache file of RecentChanges not found' . '<br />';
+       if (! file_exists(PLUGIN_RECENT_CACHE)) {
+               put_lastmodified();
+               if (! file_exists(PLUGIN_RECENT_CACHE)) {
+                       return '#recent(): Cache file of RecentChanges not found' . '<br />';
+               }
        }
 
+       // Get latest N changes
+       $lines = file_head(PLUGIN_RECENT_CACHE, $recent_lines);
+       if ($lines == FALSE) return '#recent(): File can not open' . '<br />' . "\n";
+
        $script = get_script_uri();
-       $date = $items = $passage = '';
+       $date = $items = '';
        foreach ($lines as $line) {
                list($time, $page) = explode("\t", rtrim($line));
 
@@ -72,17 +71,16 @@ function plugin_recent_convert()
                                '<ul class="recent_list">' . "\n";
                }
 
-               $s_page = htmlspecialchars($page);
-               if($page == $vars['page']) {
+               $s_page = htmlsc($page);
+
+               if ($page === $vars['page']) {
                        // No need to link to the page you just read, or notify where you just read
                        $items .= ' <li>' . $s_page . '</li>' . "\n";
                } else {
-                       $r_page = rawurlencode($page);
-                       if (PLUGIN_RECENT_SHOW_PASSAGE) {
-                               $passage = ' title="' . $s_page . ' ' . get_passage($time) . '"';
-                       }
+                       $r_page = pagename_urlencode($page);
+                       $passage = $show_passage ? ' ' . get_passage($time) : '';
                        $items .= ' <li><a href="' . $script . '?' . $r_page . '"' . 
-                               $passage . '>' . $s_page . '</a></li>' . "\n";
+                               ' title="' . $s_page . $passage . '">' . $s_page . '</a></li>' . "\n";
                }
        }
        // End of the day
@@ -90,4 +88,4 @@ function plugin_recent_convert()
 
        return sprintf($_recent_plugin_frame, count($lines), $items);
 }
-?>
+