]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RecentChangesCached.php
getName should not translate
[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     function getPluginType()
38     {
39         return PLUGIN_CACHED_HTML;
40     }
41
42     function getDescription()
43     {
44         return 'Cache output of RecentChanges called with default arguments.';
45     }
46
47     function getDefaultArguments()
48     {
49         return WikiPlugin_RecentChanges::getDefaultArguments();
50     }
51
52     function getExpire($dbi, $argarray, $request)
53     {
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     {
61         $plugin = new WikiPlugin_RecentChanges();
62         $changes = $plugin->getChanges($dbi, $args);
63         return $plugin->format($changes, $args);
64         /*
65         $loader = new WikiPluginLoader();
66         return $loader->expandPI('<?plugin RecentChanges '
67             . WikiPluginCached::glueArgs($argarray)
68                                  . ' ?>', $request, $this, $basepage);
69         */
70     }
71
72     // ->box is used to display a fixed-width, narrow version with common header.
73     // Just a limited list of pagenames, without date.
74     // This does not use ->run, to avoid pi construction and deconstruction
75     function box($args = false, $request = false, $basepage = false, $do_save = false)
76     {
77         if (!$request) $request =& $GLOBALS['request'];
78         if (!isset($args['limit'])) $args['limit'] = 12;
79         $args['format'] = 'box';
80         $args['show_minor'] = false;
81         $args['show_major'] = true;
82         $args['show_deleted'] = 'sometimes';
83         $args['show_all'] = false;
84         $args['days'] = 90;
85
86         $cache = $this->newCache();
87         if (is_array($args))
88             ksort($args);
89         $argscopy = $args;
90         unset($argscopy['limit']);
91         $this->_args =& $args;
92         $this->_type = $this->getPluginType();
93         $this->_static = false;
94
95         /* OLD: */
96         //list($id, $url) = $this->genUrl($cache, $args);
97
98         /* NEW: This cache entry needs an update on major changes.
99          * So we should rather use an unique ID, because there will only be
100          * one global cached box.
101          */
102         $id = $cache->generateId(serialize(array("RecentChangesCachedBox", $argscopy)));
103         $content = $cache->get($id, 'imagecache');
104         if ($do_save || !$content || !$content['html']) {
105             $this->resetError();
106             $plugin = new WikiPlugin_RecentChanges();
107             $title = WikiLink($this->getName(), '', SplitPagename($this->getName()));
108             $changes = $plugin->getChanges($request->_dbi, $args);
109             $content['html'] =
110                 $this->makeBox($title,
111                     $plugin->format($changes, $args));
112             if ($errortext = $this->getError()) {
113                 $this->printError($errortext, 'html');
114                 return HTML();
115             }
116             $do_save = true;
117         }
118         if ($do_save) {
119             $content['args'] = md5($this->_pi);
120             $expire = $this->getExpire($request->_dbi, $content['args'], $request);
121             $cache->save($id, $content, $expire, 'imagecache');
122         }
123         if ($content['html'])
124             return $content['html'];
125         return HTML();
126     }
127
128     // force box cache update on major changes.
129     function box_update($args = false, $request = false, $basepage = false)
130     {
131         $this->box($args, $request, $basepage, true);
132     }
133
134 }
135
136 // Local Variables:
137 // mode: php
138 // tab-width: 8
139 // c-basic-offset: 4
140 // c-hanging-comment-ender-p: nil
141 // indent-tabs-mode: nil
142 // End: