]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RecentChangesCached.php
Add class variables
[SourceForge/phpwiki.git] / lib / plugin / RecentChangesCached.php
1 <?php
2
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 along
20  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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     public $_args;
38     public $_type;
39     public $_static;
40     public $_dbi;
41
42     function getPluginType()
43     {
44         return PLUGIN_CACHED_HTML;
45     }
46
47     function getDescription()
48     {
49         return 'Cache output of RecentChanges called with default arguments.';
50     }
51
52     function getDefaultArguments()
53     {
54         return WikiPlugin_RecentChanges::getDefaultArguments();
55     }
56
57     function getExpire($dbi, $argarray, $request)
58     {
59         return '+900'; // 15 minutes
60     }
61
62     /**
63      * We don't go through pi parsing, instead we go directly to the
64      * better plugin methods.
65      *
66      * @param WikiDB $dbi
67      * @param string $args
68      * @param WikiRequest $request
69      * @param string $basepage
70      * @return mixed
71      */
72     protected function getHtml($dbi, $args, $request, $basepage)
73     {
74         $plugin = new WikiPlugin_RecentChanges();
75         $changes = $plugin->getChanges($dbi, $args);
76         return $plugin->format($changes, $args);
77         /*
78         $loader = new WikiPluginLoader();
79         return $loader->expandPI('<?plugin RecentChanges '
80             . WikiPluginCached::glueArgs($argarray)
81                                  . ' ?>', $request, $this, $basepage);
82         */
83     }
84
85     protected function getImage($dbi, $argarray, $request)
86     {
87         trigger_error('pure virtual', E_USER_ERROR);
88     }
89
90     protected function getMap($dbi, $argarray, $request)
91     {
92         trigger_error('pure virtual', E_USER_ERROR);
93     }
94
95     /**
96      * ->box is used to display a fixed-width, narrow version with common header.
97      * Just a limited list of pagenames, without date.
98      * This does not use ->run, to avoid pi construction and deconstruction
99      *
100      * @param string $args
101      * @param WikiRequest $request
102      * @param string $basepage
103      * @param bool $do_save
104      * @return $this|HtmlElement|XmlContent
105      */
106     function box($args = '', $request = null, $basepage = '', $do_save = false)
107     {
108         if (!$request) $request =& $GLOBALS['request'];
109         if (!isset($args['limit'])) $args['limit'] = 12;
110         $args['format'] = 'box';
111         $args['show_minor'] = false;
112         $args['show_major'] = true;
113         $args['show_deleted'] = 'sometimes';
114         $args['show_all'] = false;
115         $args['days'] = 90;
116
117         $cache = $this->newCache();
118         if (is_array($args))
119             ksort($args);
120         $argscopy = $args;
121         unset($argscopy['limit']);
122         $this->_args =& $args;
123         $this->_type = $this->getPluginType();
124         $this->_static = false;
125
126         /* OLD: */
127         //list($id, $url) = $this->genUrl($cache, $args);
128
129         /* NEW: This cache entry needs an update on major changes.
130          * So we should rather use an unique ID, because there will only be
131          * one global cached box.
132          */
133         $id = $cache->generateId(serialize(array("RecentChangesCachedBox", $argscopy)));
134         $content = $cache->get($id, 'imagecache');
135         if ($do_save || !$content || !$content['html']) {
136             $this->resetError();
137             $plugin = new WikiPlugin_RecentChanges();
138             $title = WikiLink($this->getName(), '', SplitPagename($this->getName()));
139             $changes = $plugin->getChanges($request->_dbi, $args);
140             $content['html'] =
141                 $this->makeBox($title,
142                     $plugin->format($changes, $args));
143             if ($errortext = $this->getError()) {
144                 $this->printError($errortext, 'html');
145                 return HTML();
146             }
147             $do_save = true;
148         }
149         if ($do_save) {
150             $content['args'] = md5($this->_pi);
151             $expire = $this->getExpire($request->_dbi, $content['args'], $request);
152             $cache->save($id, $content, $expire, 'imagecache');
153         }
154         if ($content['html'])
155             return $content['html'];
156         return HTML();
157     }
158
159     // force box cache update on major changes.
160     function box_update($args = false, $request = false, $basepage = false)
161     {
162         $this->box($args, $request, $basepage, true);
163     }
164
165 }
166
167 // Local Variables:
168 // mode: php
169 // tab-width: 8
170 // c-basic-offset: 4
171 // c-hanging-comment-ender-p: nil
172 // indent-tabs-mode: nil
173 // End: