~ampelbein/ubuntu/oneiric/heartbeat/lp-770743

« back to all changes in this revision

Viewing changes to website/moinmoin.php

  • Committer: Bazaar Package Importer
  • Author(s): Ante Karamatic
  • Date: 2009-08-10 19:29:25 UTC
  • mfrom: (5.2.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20090810192925-9zy2llcbgavbskf7
Tags: 2.99.2+sles11r9-5ubuntu1
* New upstream snapshot
* Adjusted heartbeat.install and rules for documentation path

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
# WikiWare - Standard MoinMoin Transclusion Function
 
4
# Dmytri Kleiner -- dmytrik@trickmedia.com
 
5
# Copyleft 2003 Idiosyntactix. All rights detourned.    
 
6
# License:      GNU General Public License (GPL)
 
7
 
 
8
# Usage Examples:
 
9
#   print MoinMoin("FrontPage");
 
10
#   print MoinMoin("FrontPage","costomregs.php");
 
11
#   print MoinMoin("FrontPage","costomregs.php",$cachesuffix);
 
12
 
 
13
# General Configuration
 
14
# ... moved into trick.php
 
15
 
 
16
#############################################################
 
17
#############################################################
 
18
#############################################################
 
19
 
 
20
/*
 
21
 *      All of these get set when a user presses shift-reload in mozilla
 
22
 *      Apache Environment:
 
23
 *      HTTP_CACHE_CONTROL:                                     "no-cache"
 
24
 *      HTTP_PRAGMA:                                            "no-cache"
 
25
 *      PHP Variables:          _SERVER["HTTP_CACHE_CONTROL"]:  "no-cache"
 
26
 *      HTTP request headers:   Cache-Control                   "no-cache"
 
27
 *
 
28
 *
 
29
 *      All of these get set when a user presses reload in mozilla
 
30
 *      HTTP_CACHE_CONTROL:                                     "max-age=0"
 
31
 *      PHP Variables:          _SERVER["HTTP_CACHE_CONTROL"]:  "max-age=0"
 
32
 *      HTTP request headers:   Cache-Control                   "max-age=0"
 
33
 *
 
34
 *      None of these are available when a "normal" page load is performed.
 
35
 *
 
36
 *      For now, we only pay attention to the shift-reload sequence.
 
37
 *
 
38
 */
 
39
 
 
40
function MoinMoinNoCache($cachefile)
 
41
{
 
42
        global $MOINMOINCacheLimit, $PageTitle, $MOINMOINurl, $MOINMOINfetched;
 
43
 
 
44
        if (isset($MOINMOINfetched[$cachefile])) {
 
45
                return false;
 
46
        }
 
47
        if (isset($MOINMOINCacheLimit[$PageTitle])) {
 
48
                $cachelimit = $MOINMOINCacheLimit[$PageTitle];
 
49
        }elseif (isset($MOINMOINCacheLimit['*'])) {
 
50
                $cachelimit = $MOINMOINCacheLimit['*'];
 
51
        }else{
 
52
                $cachelimit = -1;
 
53
        }
 
54
        if ($cachelimit >= 0) {
 
55
                $now = intval(date("U"));
 
56
                if (file_exists($cachefile)) {
 
57
                        clearstatcache();
 
58
                        $mtime = filemtime($cachefile);
 
59
                }else{
 
60
                        $mtime = $now;
 
61
                }
 
62
                if (($now-$mtime) >= $cachelimit) {
 
63
                        return true;
 
64
                }
 
65
        }
 
66
        if (isset($_SERVER["HTTP_CACHE_CONTROL"])) {
 
67
                return (0 == strcasecmp($_SERVER["HTTP_CACHE_CONTROL"], "no-cache"));
 
68
        }
 
69
        return false;
 
70
}
 
71
 
 
72
function MoinMoinLang ($ptitle, $INCLUDEPHP = false, $CACHESUFFIX = "")
 
73
{
 
74
        global $MOINMOINlang;
 
75
        if ($MOINMOINlang == "" || $MOINMOINlang == "en" || $MOINMOINlang == "us_en") {
 
76
            return "<!-- lang: en $MOINMOINlang --> " . MoinMoin($ptitle, $INCLUDEPHP, $CACHESUFFIX);
 
77
        }else{
 
78
            return "<!-- lang: $MOINMOINlang --> " .
 
79
                     MoinMoin($MOINMOINlang . "/" . $ptitle . "_" . $MOINMOINlang, $INCLUDEPHP, $CACHESUFFIX);
 
80
        }
 
81
}
 
82
 
 
83
$MOINMOIN404string = "<b>Page not found.</b> <!-- 404 -->";
 
84
 
 
85
function MoinMoin($ptitle, $INCLUDEPHP = false, $CACHESUFFIX = "")
 
86
{
 
87
        global $MOINMOINurl, $MOINMOINalias, $MOINMOINcachedir, $MOINMOINfilemod, $MOINMOINstandardsearch;
 
88
        global $MOINMOINstandardreplace, $current_cache_prefix, $current_cache_relprefix, $PageTitle;
 
89
        global $MOINMOINfetched, $MOINMOINpagename;
 
90
 
 
91
        #$PageTitle = str_replace("/","_", $ptitle);
 
92
        $PageTitle = $ptitle;
 
93
        $filename = "$MOINMOINurl/$PageTitle";
 
94
#       $cachefile = "$MOINMOINcachedir/$MOINMOINalias$PageTitle$CACHESUFFIX.html";
 
95
        $cachefile = sprintf("%s/%s%s%s.html", $MOINMOINcachedir, $MOINMOINalias, str_replace("/","_2f", $ptitle), $CACHESUFFIX);
 
96
        # for attachments and the like
 
97
        $PageTitleNoSlash = str_replace("/","_",$ptitle);
 
98
        $current_cache_prefix = "$MOINMOINcachedir/${MOINMOINalias}${PageTitleNoSlash}__";
 
99
        $current_cache_relprefix = "${MOINMOINalias}${PageTitle}__";
 
100
        set_time_limit(30);
 
101
        umask(077);
 
102
        
 
103
        if (MoinMoinNoCache($cachefile) && file_exists($cachefile)) {
 
104
                unlink($cachefile);
 
105
        }
 
106
        if (!file_exists($cachefile))
 
107
        {
 
108
                $content = wget_text($filename);
 
109
                if ($content == "")
 
110
                {
 
111
                        /* OOPS! ptitle URL is 404! */
 
112
                        global $MOINMOIN404string, $MOINMOINlang;
 
113
                        /* Try the English version of the page (if any) */
 
114
                        if (preg_match("/^$MOINMOINlang\/(.*)_$MOINMOINlang/"
 
115
                        ,       $ptitle, $match)) {
 
116
                                /* Better than nothing, eh? */
 
117
                                LogIt("SUBSTITUTED $match[1] for $ptitle");
 
118
                                return MoinMoin($match[1], $INCLUDEPHP, $CACHESUFFIX);
 
119
                        }
 
120
                        LogIt("GOT404 on $ptitle");
 
121
                        return $MOINMOIN404string;
 
122
                }
 
123
 
 
124
                if (!$GLOBALS["MOINMOINstandardregsloaded"])
 
125
                {
 
126
                        MOINMOINloadstandardregs();
 
127
                }
 
128
 
 
129
                if ($INCLUDEPHP)
 
130
                {
 
131
                        include($INCLUDEPHP);
 
132
 
 
133
                        $MOINMOINallsearch = array_merge($MOINMOINstandardsearch, $MOINMOINsearch);
 
134
                        $MOINMOINallreplace = array_merge($MOINMOINstandardreplace, $MOINMOINreplace);
 
135
 
 
136
                        unset($MOINMOINsearch);
 
137
                        unset($MOINMOINreplace);
 
138
                } else {
 
139
                        $MOINMOINallsearch = $MOINMOINstandardsearch;
 
140
                        $MOINMOINallreplace = $MOINMOINstandardreplace;
 
141
                }
 
142
                $body = preg_replace ($MOINMOINallsearch, $MOINMOINallreplace, $content);
 
143
                # Because we include things, these line numbers can easily wind up conflicting...
 
144
                $body  = preg_replace("'<span id=\"line-[0-9]+\"></span>'si", "", $body);
 
145
 
 
146
                $fd = fopen($cachefile, "w");
 
147
                fwrite($fd, $body);
 
148
                fclose ($fd);
 
149
                chmod($cachefile, $MOINMOINfilemod);
 
150
                $msg=sprintf("EXPANDED %d bytes into %s"
 
151
                ,       filesize($cachefile), $cachefile);
 
152
                $MOINMOINfetched[$cachefile] = true;
 
153
 
 
154
        } else {
 
155
                $body = implode("",file($cachefile));
 
156
                $msg=sprintf("READ %d bytes from %s"
 
157
                ,       filesize($cachefile), $cachefile);
 
158
                LogIt($msg);
 
159
        }
 
160
 
 
161
        return $body;
 
162
}
 
163
 
 
164
 
 
165
function MOINMOINloadstandardregs()
 
166
{
 
167
        global $MOINMOINstandardsearch, $MOINMOINstandardreplace, $MOINMOINalias
 
168
        ,       $local_cache_url_prefix, $MOINMOINExtraneousImages;
 
169
        global $MOINMOIN404string;
 
170
        
 
171
        if (!isset($MOINMOINstandardsearch)) { $MOINMOINstandardsearch = array(); }
 
172
        if (!isset($MOINMOINstandardreplace)) { $MOINMOINstandardreplace = array(); }
 
173
        set_time_limit(60);
 
174
                
 
175
        # Trap Pages Not In Wiki
 
176
        # FIXME
 
177
        $MOINMOINstandardsearch[] = "'^.*<a href=\"[^\">]*?\?action=edit\">Create this page</a>.*$'s";
 
178
        $MOINMOINstandardreplace[] = $MOINMOIN404string;
 
179
        
 
180
        # Eliminate Goto Link from Include Macro
 
181
        $MOINMOINstandardsearch[] = "'<div class=\"include-link\"><a [^>]*>.*?</a></div>'s";
 
182
        $MOINMOINstandardreplace[] = "";
 
183
 
 
184
        # Get Content Area
 
185
        $MOINMOINstandardsearch[] = "'.*<span class=\"anchor\" id=\"top\"></span>'s";
 
186
        $MOINMOINstandardreplace[] = "";
 
187
        $MOINMOINstandardsearch[] = "'<span class=\"anchor\" id=\"bottom\"></span></div>.*$'s";
 
188
        $MOINMOINstandardreplace[] = "";
 
189
        
 
190
        # Strip Wiki Class Tags
 
191
        $MOINMOINstandardsearch[] = "'(<[^>]*) class=\"[^\"]*\"([^>]*>)'U";
 
192
        $MOINMOINstandardreplace[] = "\\1\\2";
 
193
        
 
194
        # Clean Table Tags
 
195
        $MOINMOINstandardsearch[] = "'(<table\s)[^>]*(>)'Ui";
 
196
        $MOINMOINstandardreplace[] = "\\1\\2";
 
197
 
 
198
        # Fix Internal Links
 
199
        $MOINMOINstandardsearch[] = "'(<a\s[^>]*href=\")/$MOINMOINalias([^\">]*\">)'iU";
 
200
        $MOINMOINstandardreplace[] = "\\1$local_cache_url_prefix\\2";
 
201
 
 
202
        # Fix "illegal" id fields
 
203
        #   ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
 
204
        #   followed by any number of letters, digits ([0-9]), hyphens ("-"),
 
205
        #   underscores ("_"), colons (":"), and periods (".").
 
206
        $MOINMOINstandardsearch[] = "'id=\"([^\"]*)\"'ie";
 
207
        $MOINMOINstandardreplace[] = "'id=\"' . str_replace('/','_2f','\\1') . '\"'";
 
208
 
 
209
        # Strip out [WWW] [FTP] images, etc.
 
210
        foreach ($MOINMOINExtraneousImages as $im) {
 
211
                $MOINMOINstandardsearch[] = "'< *img +src=\"${im}\"[^>]*> 'i";
 
212
                $MOINMOINstandardreplace[] = '';
 
213
        }
 
214
 
 
215
        # Cache MoinMoin Images Locally
 
216
        $MOINMOINstandardsearch[]  = "'src=\"(/[^\"]*wiki[^\"]*img/([^\"]*))\"'ie";
 
217
        $MOINMOINstandardreplace[] = "MOINMOINcacheimages('\\1','\\2')";
 
218
 
 
219
        # Cache inline images (Attachments) Locally
 
220
        $MOINMOINstandardsearch[] = "'(<\s*img\s[^>]*src=\")/$MOINMOINalias([^\">]*?action=AttachFile&[^\">]*target=([^\">]*))(\"[^>]*>)'iUe";
 
221
        $MOINMOINstandardreplace[] = "stripslashes('\\1') . MOINMOINcacheattachments('\\2','\\3') . stripslashes('\\4')";
 
222
 
 
223
        # Cache MoinMoin Attachments Localy
 
224
        $MOINMOINstandardsearch[] = "'(<a\s*[^>]*href=\")/$MOINMOINalias([^\">]*?action=AttachFile&[^\">]*target=([^\">]*))(\"[^>]*>)'iUe";
 
225
        $MOINMOINstandardreplace[] = "stripslashes('\\1') . MOINMOINcacheattachments('\\2','\\3') . stripslashes('\\4')";
 
226
        # Cache MoinMoin EMBED/OBJECT Attachments Localy
 
227
        $MOINMOINstandardsearch[] = "'(<EMBED\s*[^>]*SRC=\")/$MOINMOINalias([^\">]*?action=AttachFile&[^\">]*target=([^\">]*))(\"[^>]*>)'iUe";
 
228
        $MOINMOINstandardreplace[] = "stripslashes('\\1') . MOINMOINcacheattachments('\\2','\\3') . stripslashes('\\4')";
 
229
 
 
230
        $GLOBALS["MOINMOINstandardregsloaded"] = true;
 
231
}
 
232
 
 
233
function browser_type() {
 
234
        $Browser="unknown";
 
235
        $Version="0.0";
 
236
        $MajorVers="0";
 
237
        if (isset($_SERVER["HTTP_USER_AGENT"])) {
 
238
                $ua = $_SERVER["HTTP_USER_AGENT"];
 
239
 
 
240
                $BrowserPats = array('%(MSIE|Opera) +(([1-9][0-9]*)\.[0-9.]+)%'
 
241
                ,       '%; +(Konqueror|Netscape)/(([1-9][0-9]*)\.[0-9.]+)%i'
 
242
                ,       '%(Mozilla)/(([1-9][0-9]*)\.[0-9.]+)%i');
 
243
 
 
244
                foreach ($BrowserPats as $pat) {
 
245
                        if (preg_match($pat, $ua, $match)) {
 
246
                                $Browser=$match[1];
 
247
                                $Version=$match[2];
 
248
                                $MajorVers=$match[3];
 
249
                                break;
 
250
                        }
 
251
                }
 
252
        }
 
253
        return array($Browser, $Version, intval($MajorVers));
 
254
}
 
255
 
 
256
function browser_compatibility() {
 
257
 
 
258
        $T=browser_type();
 
259
        if (strcasecmp($T[0], "Mozilla") == 0 && $T[2] >= 5) {
 
260
                return 2;
 
261
        }
 
262
        if (strcasecmp($T[0], "MSIE") == 0) {
 
263
                if ($T[2] >= 7) {
 
264
                        return 2;
 
265
                }else{
 
266
                        return 0;
 
267
                }
 
268
        }
 
269
        if (strcasecmp($T[0], "Konqueror") == 0) {
 
270
                if ($T[2] >= 3) {
 
271
                        return 2;
 
272
                }else{
 
273
                        return 1;
 
274
                }
 
275
        }
 
276
        if (strcasecmp($T[0], "Netscape") == 0) {
 
277
                if ($T[2] >= 7) {
 
278
                        return 2;
 
279
                }elseif ($T[2] >= 5) {
 
280
                        return 1;
 
281
                }
 
282
        }
 
283
        if (strcasecmp($T[0], "Opera") == 0) {
 
284
                if ($T[2] >= 6) {
 
285
                        return 2;
 
286
                }elseif ($T[2] == 5) {
 
287
                        return 1;
 
288
                }
 
289
        }
 
290
        return 0;
 
291
}
 
292
 
 
293
function browser_compatibility_messages() {
 
294
        $c = browser_compatibility();
 
295
        $ffurl="http://www.mozilla.org/products/firefox/";
 
296
        $ff="<a href=\"$ffurl\">Firefox </a>";
 
297
        $imgdir="http://sfx-images.mozilla.org/affiliates/Buttons";
 
298
        $ffbut1="<img border=\"0\" alt=\"Get Firefox!\" src=\"$imgdir/80x15/white_1.gif\"/>";
 
299
        $ffbut2="<img border=\"0\" alt=\"Get Firefox!\" height=\"24\" WIDTH=\"83\" src=\"$imgdir/110x32/trust.gif\"/>";
 
300
        $ff1="<a href=\"$ffurl\">Firefox $ffbut1</a>";
 
301
        $ff2="<a href=\"$ffurl\">Firefox $ffbut2</a>";
 
302
        if ($c >= 2) {
 
303
                return;
 
304
        }
 
305
        if ($c == 1) {
 
306
                echo '<font size="-2">This site best when viewed with a CSS-compatible browser. '
 
307
                .       "We recommend $ff1.</font>\n";
 
308
        }else{
 
309
                echo '<font size="-2">This site best when viewed with a modern standards-compliant browser. '
 
310
                .       "We recommend $ff2.</font>\n";
 
311
        }
 
312
}
 
313
 
 
314
function search_box_html($ncols)
 
315
{
 
316
echo "<TABLE><TR ALIGN=CENTER><TD>
 
317
<FORM method=GET action=\"http://www.google.com/search\">
 
318
<input type=hidden name=ie value=UTF-8><input type=hidden name=oe value=UTF-8>
 
319
<INPUT TYPE=text name=q size=$ncols maxlength=255 value=\"Enter search here.\"><BR>
 
320
<INPUT type=submit name=btnG VALUE=\"Site Search\"><BR>
 
321
<input type=hidden name=domains value=\"http://linux-ha.org\">
 
322
<input type=hidden name=sitesearch value=\"linux-ha.org\">
 
323
</FORM>
 
324
</TD></TR></TABLE>";
 
325
}
 
326
#       return array($Browser, $Version, intval($MajorVers));
 
327
function stylesheet_link()
 
328
{
 
329
        $T=browser_type();
 
330
        if (strcasecmp($T[0], "MSIE") == 0 && $T[2] < 7) {
 
331
                $ss="/linuxhaIE6.css";
 
332
        }else{
 
333
                $ss="/linuxha.css";
 
334
        }
 
335
        echo "<link rel=\"stylesheet\" href=\"$ss\" type=\"text/css\">\n";
 
336
}
 
337
 
 
338
function URLtoCacheFile($urlsuffix, $cacheprefix)
 
339
{
 
340
        global  $MOINMOINcachedir;
 
341
        /* FIXME:  Clean up $urlsuffix to make sure it's safe */
 
342
        # SECURITY ALERT
 
343
        # need to clean up sanitize $argTar, in a specially crafted wiki page
 
344
        # may be a special file name
 
345
        # hope this is enough, just in case:
 
346
        $urlsuffix = str_replace("/","_", "${cacheprefix}${urlsuffix}");
 
347
        return "${MOINMOINcachedir}/${urlsuffix}";
 
348
}
 
349
 
 
350
function CleanURL($urlprefix, $urlsuffix)
 
351
{
 
352
        /* FIXME:  Clean up $url to make sure it's safe */
 
353
        return $urlprefix . $urlsuffix;
 
354
}
 
355
 
 
356
function CacheURL($urlprefix, $urlsuffix, $cacheprefix)
 
357
{
 
358
        $cachefile = URLtoCacheFile($urlsuffix, $cacheprefix);
 
359
        $url = CleanURL($urlprefix , $urlsuffix);
 
360
        return CacheURL_ll($url, $cachefile);
 
361
}
 
362
 
 
363
function LogIt($message)
 
364
{
 
365
        $logfile="/tmp/linux-ha.web";
 
366
        $datestamp=date("Y/m/d_H:i:s");
 
367
        if (file_exists($logfile) && filesize($logfile) > 1000000) {
 
368
                rename($logfile, "$logfile.OLD");
 
369
                touch($logfile);
 
370
                chmod($logfile, 0644);
 
371
        }
 
372
        error_log("$datestamp   $message\n", 3, $logfile);
 
373
        chmod($logfile, 0644);
 
374
}
 
375
function ReportError($errorcode, $descr, $file, $line, $symtab)
 
376
{
 
377
        global $cachetmp;
 
378
        if (!isset($file)) {
 
379
                $file = "unknown";
 
380
        }
 
381
        if (!isset($line)) {
 
382
                $file = "?";
 
383
        }
 
384
        echo "ERROR: $errorcode $descr [$file:$line]";
 
385
        LogIt("ERROR: $errorcode $descr [$file:$line]");
 
386
        error_log("ERROR: $errorcode $descr [$file:$line]", 0);
 
387
        if (isset($cachetmp) && file_exists($cachetmp)) {
 
388
                unlink($cachetmp);
 
389
        }
 
390
        exit(1);
 
391
}
 
392
 
 
393
function wget($url, $file) {
 
394
        
 
395
        if (file_exists($file)) {
 
396
                unlink($file);
 
397
        }
 
398
        $WGET='/usr/bin/wget';
 
399
        $url = preg_replace('/\\\\/', '\\\\', $url);
 
400
        $url = preg_replace('/\'/', '\\\'', $url);
 
401
        $CMD="$WGET -q -U 'Mozilla/5.0' -S -nd -O '$file' '" . $url . '\'';
 
402
        system($CMD, $rc);
 
403
        if ($rc != 0) {
 
404
                /* LogIt("WGETFAIL: [$CMD] failed with $rc"); */
 
405
                if (file_exists($file)) {
 
406
                        unlink($file);
 
407
                }
 
408
        }else{
 
409
                /*LogIt(sprintf("wget %s got %d bytes", $url, filesize($file)))*/;
 
410
        }
 
411
        return $rc;
 
412
}
 
413
function wget_text($url) {
 
414
        $tmpname = tempnam("/var/tmp", "wget");
 
415
        if (wget($url, $tmpname) == 0) {
 
416
                $ret = implode("",file($tmpname));
 
417
                unlink($tmpname);
 
418
                return $ret;
 
419
        }
 
420
        /* LogIt("wget_text failed: [$url] failed"); */
 
421
        return "";
 
422
}
 
423
 
 
424
#       Inputs are the results from microtime()
 
425
function subtimes($lhs, $rhs)
 
426
{
 
427
        $lhsa = explode(" ", $lhs, 2);
 
428
        $lhsusec=intval(substr($lhsa[0], 2, 6));
 
429
        $lhssec=intval($lhsa[1]);
 
430
 
 
431
        $rhsa = explode(" ", $rhs, 2);
 
432
        $rhsusec=intval(substr($rhsa[0], 2, 6));
 
433
        $rhssec=intval($rhsa[1]);
 
434
 
 
435
        if ($lhsusec < $rhsusec) {
 
436
                $lhssec -= 1;
 
437
                $lhsusec += 1000000;
 
438
        }
 
439
        $usecs = ($lhssec - $rhssec) * 1000000;
 
440
        $usecs += ($lhsusec - $rhsusec);
 
441
        return (doubleval($usecs)/ 1000000.0);
 
442
}
 
443
 
 
444
function CacheURL_ll($url, $cachefile)
 
445
{
 
446
        global $MOINMOINfilemod, $MOINMOINcachedir, $MOINMOINurl;
 
447
        global $cachetmp,  $MOINMOINfetched;
 
448
        $cachetmp = tempnam($MOINMOINcachedir, 'TEMP_');
 
449
        set_time_limit(60);
 
450
        set_error_handler("ReportError");
 
451
        if (substr($url, 0, 1) == "/") {
 
452
                $url = "${MOINMOINurl}/${url}";
 
453
        }
 
454
 
 
455
        $start=microtime();
 
456
        if (wget($url, $cachetmp) != 0) {
 
457
                return false;
 
458
        }
 
459
        $end=microtime();
 
460
        $elapsed = subtimes($end, $start);
 
461
        chmod($cachetmp, $MOINMOINfilemod);
 
462
        
 
463
        $msg=sprintf("CACHED %d bytes in %.3f secs into %s"
 
464
        ,       filesize($cachetmp), $elapsed, $cachefile);
 
465
        LogIt($msg);
 
466
 
 
467
        if (file_exists($cachefile)) {
 
468
                unlink($cachefile);
 
469
        }
 
470
        rename($cachetmp, $cachefile);
 
471
        if (file_exists($cachetmp)) {
 
472
                unlink($cachetmp);
 
473
                unset($cachetmp);
 
474
        }
 
475
        $MOINMOINfetched[$cachefile] = true;
 
476
        return file_exists($cachefile);
 
477
}
 
478
 
 
479
 
 
480
function MOINMOINcacheattachments($argSrc, $argTar)
 
481
{
 
482
        global $MOINMOINurl, $current_cache_prefix, $local_cache_url_prefix;
 
483
 
 
484
        # SECURITY ALERT
 
485
        # need to clean up sanitize $argTar, in a specially crafted wiki page
 
486
        # may be a special file name
 
487
        # hope this is enough, just in case:
 
488
        $argTar = str_replace("/","_", $argTar);
 
489
 
 
490
        $cachefile = "$current_cache_prefix$argTar";
 
491
        if (MoinMoinNoCache($cachefile) || !file_exists($cachefile)) {
 
492
                CacheURL_ll("$MOINMOINurl/$argSrc", $cachefile);
 
493
        }
 
494
        return $local_cache_url_prefix . $cachefile;
 
495
}
 
496
 
 
497
function MOINMOINcacheimages($argSrc, $argTar)
 
498
{
 
499
        global $MOINMOINserver, $MOINMOINcachedir, $MOINMOINfilemod, $local_cache_url_prefix, $MOINMOINurl;
 
500
        
 
501
        # SECURITY ALERT
 
502
        # need to clean up sanitize $argTar, in a specially crafted wiki page
 
503
        # may be a special file name
 
504
        # hope this is enough, just in case:
 
505
 
 
506
        $argTar = str_replace("/","_", $argTar);
 
507
 
 
508
        $cachefile = URLtoCacheFile($argSrc, "");
 
509
        if (MoinMoinNoCache($cachefile) || !file_exists($cachefile)) {
 
510
                CacheURL($MOINMOINurl, $argSrc, "");
 
511
        }
 
512
        return "src=\"$local_cache_url_prefix$cachefile\"";
 
513
}
 
514
/*
 
515
 *      This is what google says we ought to do..
 
516
 *      Index the site from only one name - not from all possible names.
 
517
 *      (in our case, we own about 6 domain names)
 
518
 *      AND... tell robots to ignore any pages with ? in the name
 
519
 */
 
520
function robots_metadata()
 
521
{
 
522
        global $MOINMOINSitesToIndex;
 
523
        global $MOINMOINCacheLimit, $PageTitle, $MOINMOINpagename;
 
524
        $indexme = true;
 
525
        $followme = true;
 
526
        if (!isset($_SERVER["HTTP_HOST"])
 
527
        ||      !isset($MOINMOINSitesToIndex[$_SERVER["HTTP_HOST"]])
 
528
        ||      (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "")) {
 
529
                $indexme = false;
 
530
                $followme = false;
 
531
        }
 
532
        if (isset($MOINMOINCacheLimit[$MOINMOINpagename])) {
 
533
                $indexme = false;
 
534
        }
 
535
        if ($indexme) {
 
536
                $policy = '<META NAME="ROBOTS" CONTENT="INDEX';
 
537
        }else{
 
538
                $policy = '<META NAME="ROBOTS" CONTENT="NOINDEX';
 
539
        }
 
540
        if ($followme) {
 
541
                $policy .= ', FOLLOW">';
 
542
        }else{
 
543
                $policy .= ', NOFOLLOW">';
 
544
        }
 
545
        echo "$policy\n";
 
546
}
 
547
?>