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