3 * Copyright (C) 2002 Johannes Große
5 * This file is part of PhpWiki.
7 * PhpWiki is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * PhpWiki is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 * Gets an image from the cache and prints it to the browser.
24 * This file belongs to WikiPluginCached.
25 * @author Johannes Große
29 include_once 'lib/config.php';
30 require_once 'lib/stdlib.php';
31 require_once 'lib/Request.php';
32 require_once 'lib/WikiUser.php';
33 require_once 'lib/WikiDB.php';
34 require_once 'lib/WikiPluginCached.php';
36 // -----------------------------------------------------------------------
38 function deducePagename($request)
40 if ($request->getArg('pagename'))
41 return $request->getArg('pagename');
44 $pathinfo = $request->get('PATH_INFO');
45 $tail = substr($pathinfo, strlen(PATH_INFO_PREFIX));
46 if ($tail != '' and $pathinfo == PATH_INFO_PREFIX . $tail) {
49 } elseif ($this->isPost()) {
50 global $HTTP_GET_VARS;
51 if (isset($HTTP_GET_VARS['pagename'])) {
52 return $HTTP_GET_VARS['pagename'];
56 $query_string = $request->get('QUERY_STRING');
57 if (preg_match('/^[^&=]+$/', $query_string))
58 return urldecode($query_string);
63 function deduceUsername()
65 global $request, $HTTP_ENV_VARS;
66 if (!empty($request->args['auth']) and !empty($request->args['auth']['userid']))
67 return $request->args['auth']['userid'];
68 if (!empty($_SERVER['PHP_AUTH_USER']))
69 return $_SERVER['PHP_AUTH_USER'];
70 if (!empty($HTTP_ENV_VARS['REMOTE_USER']))
71 return $HTTP_ENV_VARS['REMOTE_USER'];
73 if ($user = $request->getSessionVar('wiki_user')) {
74 $request->_user = $user;
75 $request->_user->_authhow = 'session';
76 return $user->UserName();
78 if ($userid = $request->getCookieVar(getCookieName())) {
79 if (!empty($userid) and substr($userid, 0, 2) != 's:') {
80 $request->_user->authhow = 'cookie';
88 * Initializes PhpWiki and calls the plugin specified in the url to
89 * produce an image. Furthermore, allow the usage of Apache's
90 * ErrorDocument mechanism in order to make this file only called when
91 * image could not be found in the cache.
92 * (see doc/README.phpwiki-cache for further information).
94 function mainImageCache()
96 $request = new Request;
98 $request->setArg('pagename', deducePagename($request));
99 $pagename = $request->getArg('pagename');
100 $request->_dbi = WikiDB::open($GLOBALS['DBParams']);
101 $request->_user = new _AnonUser();
102 $request->_prefs =& $request->_user->_prefs;
104 // Enable the output of most of the warning messages.
105 // The warnings will screw up zip files and setpref though.
106 // They will also screw up my images... But I think
107 // we should keep them.
108 global $ErrorManager;
109 $ErrorManager->setPostponedErrorMask(E_NOTICE | E_USER_NOTICE);
111 $id = $request->getArg('id');
112 $args = $request->getArg('args');
113 $request->setArg('action', 'imagecache');
114 $cache = new WikiPluginCached;
117 // this indicates a direct call (script wasn't called as
118 // 404 ErrorDocument)
120 // deduce image id or image args (plugincall) from
123 $uri = $request->get('REDIRECT_URL');
124 $query = $request->get('REDIRECT_QUERY_STRING');
125 $uri .= $query ? '?' . $query : '';
128 $uri = $request->get('REQUEST_URI');
131 $cache->printError('png',
132 'Could not deduce image identifier or creation'
133 . ' parameters. (Neither REQUEST nor REDIRECT'
137 //$cacheparams = $GLOBALS['CacheParams'];
138 if (!preg_match(':^(.*/)?' . PLUGIN_CACHED_FILENAME_PREFIX . '([^\?/]+)\.img(\?args=([^\?&]*))?$:', $uri, $matches)) {
139 $cache->printError('png', "I do not understand this URL: $uri");
143 $request->setArg('id', $matches[2]);
146 $request->setArg('args', rawurldecode($matches[4]));
148 $request->setStatus(200); // No, we do _not_ have an Error 404 :->
151 $cache->fetchImageFromCache($request->_dbi, $request, 'png');
160 // c-hanging-comment-ender-p: nil
161 // indent-tabs-mode: nil