Initial commit
[vector.git] / vector.php
blobde0e7a9daad5d803c4896eec6c2cd10ff605dda8
1 <?php if (!defined('PmWiki')) exit();
3 function SA_log($x)
5 echo "<pre>";
6 print_r($x);
7 echo "</pre>";
10 global $PageLogoAltUrl;
11 SDV($PageLogoAltUrl, "$PubDirUrl/skins/pmwiki/pmwiki-32.gif");
13 global $HTMLStylesFmt;
14 $HTMLStylesFmt['pmwiki'] = preg_replace("/ code.escaped \{ white-space: nowrap; \}\n/", '', $HTMLStylesFmt['pmwiki']);
16 # Skin Parts handling
17 global $SkinPartFmt, $WikiTitle;
18 SDVA($SkinPartFmt, array(
19 'wikititle' => "{\$VectorTitlePrefix}{\$Titlespaced} — $WikiTitle",
20 'title' => '{$VectorTitlePrefix}{$Titlespaced}',
21 'footer' => '
22 %lastmod%$[This page was last edited on {$LastModified}]
23 * %item rel=nofollow% %navbox% [[&#9650; $[Top] &#9650; -> #top]]
24 * %item rel=nofollow% [[$[Search] -> $[{$SiteGroup}/Search]]]
25 * %item rel=nofollow% [[$[Recent Changes] -> $[{$Group}/RecentChanges]]]
26 * %item rel=nofollow% [[$[All Recent Changes] -> $[{$SiteGroup}/AllRecentChanges]]]
28 'pageactions' => '
29 * %item rel=nofollow% [[$[View] -> {$FullName}?action=browse]] %comment%[[{$Groupspaced}/&hellip; -> {$Group}]]%%
30 * %item rel=nofollow% [[$[Edit Page] -> {$FullName}?action=edit]]
31 * %item rel=nofollow% [[$[Page Attributes] -> {$FullName}?action=attr]]
32 * %item rel=nofollow% [[$[Page History] -> {$FullName}?action=diff]]
33 * %item rel=nofollow% [[$[Upload] -> {$FullName}?action=upload]]
35 'attachalias' => 'AttachClip:',
36 ));
38 function RenderPart($pagename, $part, $strip = '') {
39 global $SkinPartFmt, $PCache, $VectorTitlePrefix;
40 $n = "skin_$part";
41 if(!isset($PCache[$pagename][$n])) {
42 $t = '';
43 if($SkinPartFmt[$part]) {
44 $t = htmlspecialchars($SkinPartFmt[$part], ENT_NOQUOTES);
45 if($part == "title" || $part == "wikititle") {
46 $basepagename = PageVar($pagename, '$BaseName');
47 $t = MarkupToHTML($basepagename, "<:block>$t", array('escape' => 0));
48 } else {
49 $t = MarkupToHTML($pagename, "<:block>$t", array('escape' => 0));
52 $PCache[$pagename][$n] = $strip ? preg_replace($strip, '', $t) : $t;
54 print $PCache[$pagename][$n];
57 function RenderTitle($pagename) {
58 RenderPart($pagename, 'wikititle', "/(<[^>]+>|\r\n?|\n\r?)/");
61 function RetrievePageMarkup($pagelist) {
62 foreach($pagelist as $p) {
63 if (PageExists($p)) {
64 $page = RetrieveAuthPage($p, 'read', false, READPAGE_CURRENT);
65 return array($page['text'], $page['title']);
66 break;
69 return null;
72 function RenderActions($pagename, $actionslist) {
73 global $action, $SkinPartFmt;
74 $pagelist = preg_split('/\s+/', $actionslist, -1, PREG_SPLIT_NO_EMPTY);
75 list($text,) = RetrievePageMarkup($pagelist);
76 SDV($text, preg_replace("/(\r\n|\n?\r)/", "\n", $SkinPartFmt['pageactions']));
77 preg_match('/(<([uo])l.*>(?:.*)<\\/\\2l>)/si', MarkupToHTML($pagename, $text), $m);
78 $ls = explode("</li>", str_replace("\n", "", $m[1]));
79 $lRe = "/(.*?)<a.*?href='(.*?)'.*?>(.*?)<\\/a>(.*)/i";
80 foreach($ls as $i => $l) {
81 if(preg_match($lRe, $l, $l1)) {
82 $laction = preg_match("/action=(.*)/i", $l1[2], $a) ? $a[1] : 'browse';
83 if($action == $laction) {
84 $ls[$i] = $l1[1];
85 if($l1[4] && preg_match($lRe, $l1[4], $l2))
86 $ls[$i] .= "<a class='active' href='" . $l2[2] . "'>" . $l2[3] . "</a>";
87 else
88 $ls[$i] .= "<p class='active'>" . $l1[3] . "</p>";
92 print implode("\n</li>", $ls);
95 function RenderTalkSelector($pagename) {
96 $out = " <ul id='article-talk-selector'>\n";
97 if (preg_match('/-Talk$/', $pagename)) {
98 $basename = PageVar($pagename, '$BaseName');
99 $out .= " <li><a href='{$ScriptUrl}/{$basename}'>Article</a>\n";
100 $out .= " <li><p class='active'>Talk</p>";
102 else {
103 $out .= " <li><p class='active'>Article</p>\n";
104 $out .= " <li><a href='{$ScriptUrl}/{$pagename}-Talk'>Talk</a>\n";
106 $out .= " </ul>";
108 print $out;
111 # links decoration
112 global $EnableSkinLinkDecoration;
113 if(IsEnabled($EnableSkinLinkDecoration, 1)) {
114 global $SkinPartFmt, $IMapLinkFmt, $LinkFunctions, $IMap;
115 global $LinkPageCreateFmt, $LinkUploadCreateFmt, $UrlLinkFmt;
117 $intermap = $SkinPartFmt['attachalias'];
119 $IMapLinkFmt['Attach:'] = "<a class='attachlink' href='\$LinkUrl' rel='nofollow'>\$LinkText</a>";
120 $IMapLinkFmt[$intermap] = "<a class='attachlink' href='\$LinkUrl' rel='nofollow'>\$LinkText</a><a class='createlink' href='\$LinkUpload'><img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAANCAMAAABSF4SHAAAAB3RJTUUH1gEeFxAvfW/GcwAAAAlwSFlzAAAewQAAHsEBw2lUUwAAAARnQU1BAACxjwv8YQUAAAAJUExURf///wBmzABm/0odWaIAAAABdFJOUwBA5thmAAAAJklEQVR42mNgYGBgYmJiAFFYMTpkhJJYaKAGEA0CjGAE4TAyAikADqwAQusNffkAAAAASUVORK5CYII=' alt='' /></a>";
121 $LinkFunctions[$intermap] = 'LinkUpload';
122 $IMap[$intermap] = '$1';
124 $LinkPageCreateFmt = "<a class='createlinktext' href='\$PageUrl?action=edit'>\$LinkText</a>";
125 $LinkUploadCreateFmt = "<a class='createlinktext' href='\$LinkUpload'>\$LinkText</a><a class='createlink' href='\$LinkUpload'><img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAANCAMAAABSF4SHAAAAB3RJTUUH1gEeFwEtwLiETwAAAAlwSFlzAAAewQAAHsEBw2lUUwAAAARnQU1BAACxjwv8YQUAAAAGUExURf////8LC59859AAAAABdFJOUwBA5thmAAAAHklEQVR42mNgYGBgZGRkAFFYMQmQEaIeahbMCIjxAAhQACm+UQJbAAAAAElFTkSuQmCC' alt='' /></a>";
128 /******************************/
129 /* Automatic change summaries */
130 /******************************/
132 global $EditFunctions, $AutomaticChangeSummaries;
133 SDV($AutomaticChangeSummaries,1);
134 if($AutomaticChangeSummaries) {
135 array_unshift($EditFunctions, 'ProvideDefaultSummary');
136 function ProvideDefaultSummary($pagename,&$page,&$new)
138 global $ChangeSummary, $DiffFunction;
139 if ($ChangeSummary || !function_exists(@$DiffFunction)) return;
140 $diff = $DiffFunction($new['text'],@$page['text']);
141 $difflines = explode("\n",$diff."\n");
142 $in=array(); $out=array();
143 foreach ($difflines as $d)
144 { if ($d=='' || $d[0]=='-' || $d[0]=='\\') continue;
145 if ($d[0]=='<' && count($out)<10) {$out[]=substr($d,2); continue;}
146 if ($d[0]=='>' && count($in)<10) {$in[]=substr($d,2); continue;}
148 $diff2=''; if (count($out)==0) {$out=$in; $diff2="[deleted] ";}
149 foreach ($out as $s) {$diff2 .= $s." ";}
150 $ChangeSummary=str_replace(array("<",">","\n"),array("&lt;","&gt;"," "),$diff2);
151 $new['csum']=$ChangeSummary;
155 /*************/
156 /* DictIndex */
157 /*************/
159 global $FPLDictIndexStartFmt, $FPLDictIndexEndFmt, $FPLDictIndexLFmt, $FPLDictIndexLEndFmt, $FPLDictIndexIFmt, $FPLDictIndexHeaderLink;
160 $FPLDictIndexLFmt = "<div class='fplindex_letter_block' id='\$IndexLetter'><dt>\$IndexLetter</dt>\n<dd><ul>\n";
161 $FPLDictIndexLEndFmt = "</dd></ul>\n</div>\n";
162 $FPLDictIndexIFmt = "<li><a href='\$PageUrl' title='\$Group : \$Title'>\$Titlespaced</a>\n";
164 /*******************/
165 /* MediaCategories */
166 /*******************/
168 global $McatLabelS, $McatLabelP;
169 $McatLabelS = '<a href="{$ScriptUrl}/Category/Category">Category</a>:';
170 $McatLabelP = '<a href="{$ScriptUrl}/Category/Category">Categories</a>:';
172 /****************/
173 /* Title prefix */
174 /****************/
176 global $action, $FmtPV, $VectorTitlePrefix;
177 $VectorTitlePrefix = ($action == "edit") ? "%font-style=normal%Editing%% " : "";
178 if(preg_match("/-Talk/", $pagename)) { $VectorTitlePrefix .= "Talk: "; }
179 $FmtPV['$VectorTitlePrefix'] = '$GLOBALS["VectorTitlePrefix"]';
181 /*****************/
182 /* Custom search */
183 /*****************/
185 ## redefine searchbox format:
186 Markup_e('searchbox', '>links', '/\\(:searchbox(\\s.*?)?:\\)/', "SearchBox2");
187 function SearchBox2($m)
189 global $SearchBoxOpt, $SearchQuery, $EnablePathInfo;
190 extract($GLOBALS['MarkupToHTML']);
192 SDVA($SearchBoxOpt, array(
193 'size' => '20',
194 'label' => FmtPageName('$[Search]', $pagename),
195 'value' => str_replace("'", "&#039;", $SearchQuery)));
197 $opt = array_merge((array)$SearchBoxOpt, ParseArgs($m[1]));
198 $focus = $opt['focus'];
199 $opt['action'] = 'search';
201 if($opt['target'])
202 $target = MakePageName($pagename, $opt['target']);
203 else
204 $target = $pagename;
206 $out = FmtPageName(" class='wikisearch' action='\$PageUrl' method='get'>", $target);
207 $opt['n'] = IsEnabled($EnablePathInfo, 0) ? '' : $target;
208 $out .= "<input type='search' name='q' value='{$opt['value']}' class='inputbox searchbox' autofocus autocomplete='off' size='{$opt['size']}' ";
209 if ($focus)
210 $out .= " onfocus=\"if(this.value=='{$opt['value']}') this.value=''\" onblur=\"if(this.value=='') this.value='{$opt['value']}'\" ";
211 $out .= " /><input type='submit' class='inputbutton searchbutton' value='{$opt['label']}' />";
213 foreach($opt as $k => $v)
215 if ($v == '' || is_array($v)) continue;
216 if ($k=='q' || $k=='label' || $k=='value' || $k=='size') continue;
217 $k = str_replace("'", "&#039;", $k);
218 $v = str_replace("'", "&#039;", $v);
219 $out .= "<input type='hidden' name='$k' value='$v' />";
221 return "<form ".Keep($out)." </form>";
224 if (($_GET['pagename'] == "Site/Search" && isset($_GET['q'])) || $action == "search")
226 global $SearchResultsFmt;
227 $SearchQuery = str_replace('$', '&#036;', PHSC(stripmagic(@$_REQUEST['q']), ENT_NOQUOTES));
228 if (preg_match("/^link=/", $SearchQuery)) {
229 $target_page = preg_replace("/^link=/",'',$SearchQuery);
230 $SearchResultsFmt = "<div class='wikisearch'><p>Pages that link to <code>$target_page</code>:</p>
231 \$MatchList
232 <p>\$[SearchFound]</p><hr /></div>";
233 } else {
234 $SearchResultsFmt = "<div class='wikisearch'><p>Pages containing the text <code>\$SearchQuery</code>:</p>
235 \$MatchList
236 <p>\$[SearchFound]</p></div>";
240 if ($action == "search" && $pagename != "Site.Search") {
241 $params = $_GET;
242 unset($params['n']);
243 Redirect("Site/Search?" . http_build_query($params));
246 /************/
247 /* Jump-box */
248 /************/
250 global $VectorJumpBoxEnabled;
251 SDV($VectorJumpBoxEnabled, true);
252 if ($VectorJumpBoxEnabled && $_GET['pagename'] == "Site/Search" && isset($_GET['q'])) {
253 global $DefaultGroup;
254 $text = stripmagic($_GET['q']);
255 if (PageExists($text))
256 Redirect($text);
257 else if (PageExists("{$DefaultGroup}.{$text}"))
258 Redirect("{$DefaultGroup}.{$text}");
261 /**************/
262 /* Talk pages */
263 /**************/
265 # Automatically create a talk page when a non-talk page is edited
266 global $AutoCreateTalkPages, $TalkPageTemplate;
267 SDV($AutoCreateTalkPages, true);
268 SDV($TalkPageTemplate, '$SiteGroup.TalkTemplate');
269 $FmtPV['$TalkPageTemplate'] = "'" . FmtPageName($TalkPageTemplate, $pagename) . "'";
270 function CreateTalkPage($pagename, &$page, &$new) {
271 global $IsPagePosted, $TalkPageTemplate;
272 $talkpagename = $pagename . "-Talk";
273 if (!$IsPagePosted)
274 return;
275 if (preg_match('/-Talk$/', $pagename) || PageExists($talkpagename))
276 return;
277 if (RetrieveAuthPage($talkpagename, 'edit', false, READPAGE_CURRENT) == false)
278 return;
280 $talkpageparameters = array('ctime' => $Now);
281 $templatepage = RetrieveAuthPage(FmtPageName($TalkPageTemplate, $pagename), 'read', false, READPAGE_CURRENT);
282 $talkpageparameters['text'] = (@$templatepage['text'] > '') ? $templatepage['text'] : "This is the Talk page for {$Basename}.\n";
283 WritePage($talkpagename, $talkpageparameters);
286 if($AutoCreateTalkPages == true) {
287 $EditFunctions[] = 'CreateTalkPage';
290 # Prevent talk pages from showing up in pagelists
291 # (either default or with list=normal
292 global $SearchPatterns;
293 $SearchPatterns['default'][] = '!.*-Talk$!';
294 $SearchPatterns['normal'][] = '!.*-Talk$!';
296 # Make {$BaseName} of talk pages refer to the article page (not the talk page)
297 global $BaseNamePatterns;
298 $BaseNamePatterns['/-Talk$/'] = '';
300 /**************************/
301 /* Searchbox Autocomplete */
302 /**************************/
304 // Disabled for now, until I figure out a lower-overhead way to do this.
305 // (jQuery is too bloated)
307 // global $HTMLHeaderFmt, $HTMLFooterFmt;
308 // $HTMLHeaderFmt['autocomplete'][0] =
309 // "<script src='{$SkinDirUrl}/jquery.js'></script>
310 // <link rel='stylesheet' href='{$SkinDirUrl}/vector_searchbox.css' />
311 // <script src='{$SkinDirUrl}/jquery-ui.js'></script>";
312 // $HTMLFooterFmt['autocomplete'][0] =
313 // "<script language='javascript' type='text/javascript'>$(\".searchbox\").autocomplete({
314 // source: function(request, response) {
315 // $.ajax({
316 // url: \"{\$ScriptUrl}\",
317 // dataType: \"jsonp\",
318 // data: {
319 // 'action': \"suggest\",
320 // 'q': request.term
321 // },
322 // success: function(data) {
323 // response(data[1]);
324 // }
325 // });
326 // }
327 // });</script>";