OSDN Git Service

BugTrack2/151: lastmodified_add() now treats page deletion
authorhenoheno <henoheno>
Sun, 30 Apr 2006 03:58:35 +0000 (12:58 +0900)
committerhenoheno <henoheno>
Sun, 30 Apr 2006 03:58:35 +0000 (12:58 +0900)
lib/file.php

index c262903..d06600c 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: file.php,v 1.66 2006/04/29 02:37:33 henoheno Exp $
+// $Id: file.php,v 1.67 2006/04/30 03:58:35 henoheno Exp $
 // Copyright (C)
 //   2002-2006 PukiWiki Developers Team
 //   2001-2002 Originally written by yu-ji
@@ -204,10 +204,11 @@ function file_write($dir, $page, $str, $notimestamp = FALSE)
                // Update RecentDeleted (Add the $page)
                add_recent($page, $whatsdeleted, '', $maxshow_deleted);
 
+               // Remove the page
                unlink($file);
 
-               // Update RecentChanges (Remove the $page from RecentChanges)
-               put_lastmodified();
+               // Update RecentDeleted, and remove the page from RecentChanges
+               lastmodified_add($whatsdeleted, $page);
 
                // Clear is_page() cache
                is_page($page, TRUE);
@@ -305,7 +306,7 @@ function add_recent($page, $recentpage, $subject = '', $limit = 0)
 
 // Update PKWK_MAXSHOW_CACHE itself (Add or renew about the $page) (Light)
 // Use without $autolink
-function lastmodified_add($page = '')
+function lastmodified_add($update = '', $remove = '')
 {
        global $maxshow, $whatsnew, $autolink;
 
@@ -315,7 +316,8 @@ function lastmodified_add($page = '')
                return;
        }
 
-       if (check_non_list($page)) return; // No need
+       if (($update == '' || check_non_list($update)) && $remove == '')
+               return; // No need
 
        $file = CACHE_DIR . PKWK_MAXSHOW_CACHE;
        if (! file_exists($file)) {
@@ -337,20 +339,33 @@ function lastmodified_add($page = '')
                        $recent_pages[$matches[2]] = $matches[1];
 
        // Remove if it exists inside
-       if (isset($recent_pages[$page])) unset($recent_pages[$page]);
+       if (isset($recent_pages[$update])) unset($recent_pages[$update]);
+       if (isset($recent_pages[$remove])) unset($recent_pages[$remove]);
 
        // Add to the top: like array_unshift()
-       if ($page != '') $recent_pages = array($page => get_filetime($page)) + $recent_pages;
+       if ($update != '')
+               $recent_pages = array($update => get_filetime($update)) + $recent_pages;
 
-       // Write
-       ftruncate($fp, 0);
-       rewind($fp);
-       foreach ($recent_pages as $_page=>$time)
-               fputs($fp, $time . "\t" . $_page . "\n");
+       // Check
+       $abort = count($recent_pages) < $maxshow;
+
+       if (! $abort) {
+               // Write
+               ftruncate($fp, 0);
+               rewind($fp);
+               foreach ($recent_pages as $_page=>$time)
+                       fputs($fp, $time . "\t" . $_page . "\n");
+       }
 
        flock($fp, LOCK_UN);
        fclose($fp);
 
+       if ($abort) {
+               put_lastmodified(); // Try to (re)create ALL
+               return;
+       }
+
+
 
        // ----
        // Update the page 'RecentChanges'