Blame
Date:
Tue Jun 21 04:00:33 2022 UTC
Message:
Daily backup
01
2021-12-17
jrmu
<?php if (!defined('PmWiki')) exit();
02
2021-12-17
jrmu
/* Copyright 2002-2018 Patrick R. Michaud (pmichaud@pobox.com)
03
2021-12-17
jrmu
This file is part of PmWiki; you can redistribute it and/or modify
04
2021-12-17
jrmu
it under the terms of the GNU General Public License as published
05
2021-12-17
jrmu
by the Free Software Foundation; either version 2 of the License, or
06
2021-12-17
jrmu
(at your option) any later version. See pmwiki.php for full details.
07
2021-12-17
jrmu
08
2021-12-17
jrmu
This script provides special handling for WikiWords that are
09
2021-12-17
jrmu
preceded by a $, treating them as PmWiki variables to be looked up
10
2021-12-17
jrmu
in the variable documentation pages if such documentation exists.
11
2021-12-17
jrmu
The $VarPagesFmt variable contains a list of pages to be searched
12
2021-12-17
jrmu
to build an index of the variable documentation. This index is
13
2021-12-17
jrmu
generated only once per browse request, and then only when needed.
14
2021-12-17
jrmu
15
2021-12-17
jrmu
Script maintained by Petko YOTOV www.pmwiki.org/petko
16
2021-12-17
jrmu
*/
17
2021-12-17
jrmu
18
2021-12-17
jrmu
SDV($VarPagesFmt,array('$[PmWiki.Variables]'));
19
2021-12-17
jrmu
Markup('vardef','<links',"/^:\\$($WikiWordPattern|Author|Skin|pagename|Version) *:/",
20
2021-12-17
jrmu
':%apply=item id=$1%$$1:');
21
2021-12-17
jrmu
Markup('varlink','<wikilink',"/\\$($WikiWordPattern|Author|Skin|pagename|Version)\\b/",
22
2021-12-17
jrmu
"MarkupVarLinkIndex");
23
2021-12-17
jrmu
Markup('varindex', 'directives',
24
2021-12-17
jrmu
'/\\(:varindex:\\)/i', "MarkupVarLinkIndex");
25
2021-12-17
jrmu
26
2021-12-17
jrmu
function MarkupVarLinkIndex($m) {
27
2021-12-17
jrmu
extract($GLOBALS["MarkupToHTML"]); # get $pagename, $markupid
28
2021-12-17
jrmu
switch ($markupid) {
29
2021-12-17
jrmu
case 'varlink':
30
2021-12-17
jrmu
return Keep(VarLink($pagename,$m[1],'$'.$m[1]));
31
2021-12-17
jrmu
case 'varindex':
32
2021-12-17
jrmu
return Keep(VarIndexList($pagename));
33
2021-12-17
jrmu
}
34
2021-12-17
jrmu
}
35
2021-12-17
jrmu
36
2021-12-17
jrmu
SDVA($HTMLStylesFmt, array('vardoc' => "a.varlink { text-decoration:none;}\n"));
37
2021-12-17
jrmu
38
2021-12-17
jrmu
function VarLink($pagename,$tgt,$txt) {
39
2021-12-17
jrmu
global $VarIndex,$FmtV,$VarLinkMissingFmt,$VarLinkExistsFmt;
40
2021-12-17
jrmu
SDV($VarLinkMissingFmt,'$LinkText');
41
2021-12-17
jrmu
SDV($VarLinkExistsFmt,"<a class='varlink' href='\$LinkUrl'><code class='varlink'>\$LinkText</code></a>");
42
2021-12-17
jrmu
VarIndexLoad($pagename);
43
2021-12-17
jrmu
$FmtV['$LinkText'] = str_replace('$', '&#36;', $txt);
44
2021-12-17
jrmu
if (@!$VarIndex[$tgt]['pagename'])
45
2021-12-17
jrmu
return FmtPageName($VarLinkMissingFmt,$pagename);
46
2021-12-17
jrmu
return MakeLink($pagename,"{$VarIndex[$tgt]['pagename']}#$tgt",$txt,null,$VarLinkExistsFmt);
47
2021-12-17
jrmu
}
48
2021-12-17
jrmu
49
2021-12-17
jrmu
function VarIndexLoad($pagename) {
50
2021-12-17
jrmu
global $VarPagesFmt,$VarIndex,$WikiWordPattern;
51
2021-12-17
jrmu
static $loaded;
52
2021-12-17
jrmu
$VarIndex = (array)@$VarIndex;
53
2021-12-17
jrmu
if ($loaded) return;
54
2021-12-17
jrmu
$tmp = array();
55
2021-12-17
jrmu
foreach($VarPagesFmt as $vf) {
56
2021-12-17
jrmu
$v = FmtPageName($vf, $pagename);
57
2021-12-17
jrmu
if (@$loaded[$v]) continue;
58
2021-12-17
jrmu
$vlist = array($v);
59
2021-12-17
jrmu
$t = ReadTrail($pagename,$v);
60
2021-12-17
jrmu
if ($t)
61
2021-12-17
jrmu
for($i=0;$i<count($t);$i++)
62
2021-12-17
jrmu
if (@!$loaded[$t[$i]['pagename']]) $vlist[]=$t[$i]['pagename'];
63
2021-12-17
jrmu
foreach($vlist as $vname) {
64
2021-12-17
jrmu
$vpage = ReadPage($vname, READPAGE_CURRENT); @$loaded[$vname]++;
65
2021-12-17
jrmu
if (!$vpage) continue;
66
2021-12-17
jrmu
if (!preg_match_all("/\n:\\$([[:upper:]]\\w+|pagename) *:/",@$vpage['text'],$match))
67
2021-12-17
jrmu
continue;
68
2021-12-17
jrmu
foreach($match[1] as $n) {
69
2021-12-17
jrmu
$tmp[$n]['pagename'] = $vname;
70
2021-12-17
jrmu
$tmp[$n]['url'] = FmtPageName("{\$PageUrl}#$n",$vname);
71
2021-12-17
jrmu
}
72
2021-12-17
jrmu
}
73
2021-12-17
jrmu
}
74
2021-12-17
jrmu
$keys = array_keys($tmp);
75
2021-12-17
jrmu
natcasesort($keys); # ksort requires PHP 5.4 for caseless sort
76
2021-12-17
jrmu
foreach($keys as $k) {
77
2021-12-17
jrmu
$VarIndex[$k] = $tmp[$k];
78
2021-12-17
jrmu
}
79
2021-12-17
jrmu
}
80
2021-12-17
jrmu
81
2021-12-17
jrmu
# VarIndexList() generates a table of all indexed variables.
82
2021-12-17
jrmu
function VarIndexList($pagename) {
83
2021-12-17
jrmu
global $VarIndex;
84
2021-12-17
jrmu
if (!isset($VarIndex)) VarIndexLoad($pagename);
85
2021-12-17
jrmu
$out = FmtPageName("<table><tr><th>$[Variable]</th><th>$[Documented in]</th></tr>\n", $pagename);
86
2021-12-17
jrmu
foreach($VarIndex as $v=>$a)
87
2021-12-17
jrmu
$out .= FmtPageName("<tr><td><a class='varlink'
88
2021-12-17
jrmu
href='{$a['url']}'><code>&#036;$v</code></a></td><td><a
89
2021-12-17
jrmu
href='{\$PageUrl}'>{\$Title}</a></td></tr>\n",$a['pagename']);
90
2021-12-17
jrmu
$out .= "</table>";
91
2021-12-17
jrmu
return $out;
92
2021-12-17
jrmu
}
93
2021-12-17
jrmu
IRCNow