]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RecentChangesCached.php
Remove rcs_id
[SourceForge/phpwiki.git] / lib / plugin / RecentChangesCached.php
1 <?php // -*-php-*-
2 // $Id$
3 /**
4  * Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
5  * Copyright (C) 2002 Johannes Große                                   |
6  *
7  * This file is part of PhpWiki.
8  *
9  * PhpWiki is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * PhpWiki is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with PhpWiki; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 /* There is a bug in it:
25    When the cache is empty and you safe the wikipages,
26    an immediately created cached output of
27    RecentChanges will at the rss-image-link include
28    an action=edit
29 */
30
31 require_once "lib/WikiPluginCached.php";
32 require_once "lib/plugin/RecentChanges.php";
33
34 class WikiPlugin_RecentChangesCached
35 extends WikiPluginCached
36 {
37     function getPluginType() {
38         return PLUGIN_CACHED_HTML;
39     }
40
41     function getName() {
42         return "RecentChangesCached";
43     }
44
45     function getDescription() {
46         return 'Caches output of RecentChanges called with default arguments.';
47     }
48
49     function getDefaultArguments() {
50         return WikiPlugin_RecentChanges::getDefaultArguments();
51     }
52
53     function getExpire($dbi, $argarray, $request) {
54         return '+900'; // 15 minutes
55     }
56
57     // We don't go through pi parsing, instead we go directly to the
58     // better plugin methods.
59     function getHtml($dbi, $args, $request, $basepage) {
60         $plugin = new WikiPlugin_RecentChanges();
61         $changes = $plugin->getChanges($dbi, $args);
62         return $plugin->format($changes, $args);
63         /*
64         $loader = new WikiPluginLoader;
65         return $loader->expandPI('<?plugin RecentChanges '
66             . WikiPluginCached::glueArgs($argarray)
67                                  . ' ?>', $request, $this, $basepage);
68         */
69     }
70
71     // ->box is used to display a fixed-width, narrow version with common header.
72     // Just a limited list of pagenames, without date.
73     // This does not use ->run, to avoid pi construction and deconstruction
74     function box($args = false, $request = false, $basepage = false, $do_save = false) {
75         if (!$request) $request =& $GLOBALS['request'];
76         if (!isset($args['limit'])) $args['limit'] = 12;
77         $args['format'] = 'box';
78         $args['show_minor'] = false;
79         $args['show_major'] = true;
80         $args['show_deleted'] = 'sometimes';
81         $args['show_all'] = false;
82         $args['days'] = 90;
83
84         $cache = $this->newCache();
85         if (is_array($args))
86             ksort($args);
87         $argscopy = $args;
88         unset($argscopy['limit']);
89         $this->_args =& $args;
90         $this->_type = $this->getPluginType();
91         $this->_static = false;
92
93         /* OLD: */
94         //list($id, $url) = $this->genUrl($cache, $args);
95
96         /* NEW: This cache entry needs an update on major changes.
97          * So we should rather use an unique ID, because there will only be
98          * one global cached box.
99          */
100         $id = $cache->generateId(serialize(array("RecentChangesCachedBox", $argscopy)));
101         $content = $cache->get($id, 'imagecache');
102         if ($do_save || !$content || !$content['html']) {
103             $this->resetError();
104             $plugin = new WikiPlugin_RecentChanges();
105             $title = WikiLink($this->getName(), '', SplitPagename($this->getName()));
106             $changes = $plugin->getChanges($request->_dbi, $args);
107             $content['html'] =
108                       $this->makeBox($title,
109                                      $plugin->format($changes, $args));
110             if ($errortext = $this->getError()) {
111                 $this->printError($errortext, 'html');
112                 return HTML();
113             }
114             $do_save = true;
115         }
116         if ($do_save) {
117             $content['args'] = md5($this->_pi);
118             $expire = $this->getExpire($request->_dbi, $content['args'], $request);
119             $cache->save($id, $content, $expire, 'imagecache');
120         }
121         if ($content['html'])
122             return $content['html'];
123         return HTML();
124     }
125
126     // force box cache update on major changes.
127     function box_update($args = false, $request = false, $basepage = false) {
128             $this->box($args, $request, $basepage, true);
129     }
130
131
132 }
133
134 // Local Variables:
135 // mode: php
136 // tab-width: 8
137 // c-basic-offset: 4
138 // c-hanging-comment-ender-p: nil
139 // indent-tabs-mode: nil
140 // End:
141 ?>