2 // +---------------------------------------------------------------------+
4 // +---------------------------------------------------------------------+
5 // | Copyright (C) 2002 Johannes Große (Johannes Große) |
6 // | You may copy this code freely under the conditions of the GPL |
7 // +---------------------------------------------------------------------+
10 * Gets an image from the cache and prints it to the browser.
11 * This file belongs to WikiPluginCached.
12 * @author Johannes Große
16 include "lib/config.php";
17 include "lib/stdlib.php";
18 //include "lib/logger.php";
19 require_once('lib/Request.php');
20 require_once("lib/WikiUser.php");
21 require_once('lib/WikiDB.php');
23 require_once "lib/WikiPluginCached.php";
25 // -----------------------------------------------------------------------
27 // FIXME: do I need this? What the hell does it?
29 function deduce_pagename ($request) {
30 if ($request->getArg('pagename'))
31 return $request->getArg('pagename');
34 $pathinfo = $request->get('PATH_INFO');
35 if (ereg('^' . PATH_INFO_PREFIX . '(..*)$', $pathinfo, $m))
39 $query_string = $request->get('QUERY_STRING');
40 if (preg_match('/^[^&=]+$/', $query_string))
41 return urldecode($query_string);
43 return gettext("HomePage");
47 * Initializes PhpWiki and calls the plugin specified in the url to
48 * produce an image. Furthermore, allow the usage of Apache's
49 * ErrorDocument mechanism in order to make this file only called when
50 * image could not be found in the cache.
51 * (see PHPWIKI-CACHE.README for further information).
53 function mainImageCache() {
54 $request = new Request;
55 //$request->setArg('pagename', deduce_pagename($request));
56 //$pagename = $request->getArg('pagename');
58 // assume that every user may use the cache
59 global $user; // FIXME: necessary ?
60 $user = new WikiUser($request, 'ANON_OK');
62 $dbi = WikiDB::open($GLOBALS['DBParams']);
64 // Enable the output of most of the warning messages.
65 // The warnings will screw up zip files and setpref though.
66 // They will also screw up my images... But I think
67 // we should keep them.
69 $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE);
71 $id = $request->getArg('id');
72 $args = $request->getArg('args');
73 $request->setArg('action', 'imagecache');
76 // this indicates a direct call (script wasn't called as
79 // deduce image id or image args (plugincall) from
82 $uri = $request->get('REDIRECT_URL');
83 $query = $request->get('REDIRECT_QUERY_STRING');
84 $uri .= $query ? '?'.$query : '';
87 $uri = $request->get('REQUEST_URI');
90 WikiPluginCached::printError( 'png',
91 'Could not deduce image identifier or creation'
92 . ' parameters. (Neither REQUEST nor REDIRECT'
96 $cacheparams = $GLOBALS['CacheParams'];
97 if (!preg_match(':^(.*/)?'.$cacheparams['filename_prefix'].'([^\?/]+)\.img(\?args=([^\?&]*))?$:', $uri, $matches)) {
98 WikiPluginCached::printError('png', "I do not understand this URL: $uri");
102 $request->setArg('id',$matches[2]);
104 $request->setArg('args',rawurldecode($matches[4]));
106 $request->setStatus(200); // No, we do _not_ have an Error 404 :->
109 WikiPluginCached::fetchImageFromCache($dbi,$request,'png');
120 // c-hanging-comment-ender-p: nil
121 // indent-tabs-mode: nil