Fossil SCM

Add the /intermap page for adjusting the interwiki mapping using a Web interface.

drh 2020-08-23 15:52 interwiki
Commit dab94dda308cf6b3dbc8be0f9dab26380d5eb7502fa0aad12bd7469449a567fb
2 files changed +117 +5
--- src/interwiki.c
+++ src/interwiki.c
@@ -263,5 +263,122 @@
263263
blob_appendf(out,"</table></blockquote>\n");
264264
}else{
265265
blob_appendf(out,"<i>None</i></blockquote>\n");
266266
}
267267
}
268
+
269
+/*
270
+** WEBPAGE: /intermap
271
+**
272
+** View and modify the interwiki tag map or "intermap".
273
+** This page is visible to administrators only.
274
+*/
275
+void interwiki_page(void){
276
+ Stmt q;
277
+ int n = 0;
278
+ const char *z;
279
+ const char *zTag = "";
280
+ const char *zBase = "";
281
+ const char *zHash = "";
282
+ const char *zWiki = "";
283
+ char *zErr = 0;
284
+
285
+ login_check_credentials();
286
+ if( !g.perm.Setup ){
287
+ login_needed(0);
288
+ return;
289
+ }
290
+ if( P("submit")!=0 && cgi_csrf_safe(1) ){
291
+ zTag = PT("tag");
292
+ zBase = PT("base");
293
+ zHash = PT("hash");
294
+ zWiki = PT("wiki");
295
+ if( zTag==0 || zTag[0]==0 || !interwiki_valid_name(zTag) ){
296
+ zErr = mprintf("Not a valid interwiki tag name: \"%s\"", zTag ? zTag : "");
297
+ }else if( zBase==0 || zBase[0]==0 ){
298
+ db_multi_exec("DELETE FROM config WHERE name='interwiki:%q';", zTag);
299
+ }else{
300
+ if( zHash && zHash[0]==0 ) zHash = 0;
301
+ if( zWiki && zWiki[0]==0 ) zWiki = 0;
302
+ db_multi_exec(
303
+ "REPLACE INTO config(name,value,mtime)"
304
+ "VALUES('interwiki:'||lower(%Q),"
305
+ " json_object('base',%Q,'hash',%Q,'wiki',%Q),"
306
+ " now());",
307
+ zTag, zBase, zHash, zWiki);
308
+ }
309
+ }
310
+
311
+ style_header("Interwiki Map Configuration");
312
+ @ <p>Interwiki links are hyperlink targets of the form
313
+ @ <blockquote><i>Tag</i><b>:</b><i>PageName</i></blockquote>
314
+ @ <p>Such links resolve to links to <i>PageName</i> on a separate server
315
+ @ identified by <i>Tag</i>. The Interwiki Map or "intermap" is a mapping
316
+ @ from <i>Tags</i> to complete Server URLs.
317
+ db_prepare(&q,
318
+ "SELECT substr(name,11),"
319
+ " json_extract(value,'$.base'),"
320
+ " json_extract(value,'$.hash'),"
321
+ " json_extract(value,'$.wiki')"
322
+ " FROM config WHERE name glob 'interwiki:*'"
323
+ );
324
+ while( db_step(&q)==SQLITE_ROW ){
325
+ if( n==0 ){
326
+ @ The current mapping is as follows:
327
+ @ <ol>
328
+ }
329
+ @ <li><p> %h(db_column_text(&q,0))
330
+ @ <ul>
331
+ @ <li> Base-URL: <tt>%h(db_column_text(&q,1))</tt>
332
+ z = db_column_text(&q,2);
333
+ if( z==0 ){
334
+ @ <li> Hash-path: <i>NULL</i>
335
+ }else{
336
+ @ <li> Hash-path: <tt>%h(z)</tt>
337
+ }
338
+ z = db_column_text(&q,3);
339
+ if( z==0 ){
340
+ @ <li> Wiki-path: <i>NULL</i>
341
+ }else{
342
+ @ <li> Wiki-path: <tt>%h(z)</tt>
343
+ }
344
+ @ </ul>
345
+ n++;
346
+ }
347
+ db_finalize(&q);
348
+ if( n ){
349
+ @ </ol>
350
+ }else{
351
+ @ No mappings are currently defined.
352
+ }
353
+
354
+ @ <p>To add a new mapping, fill out the form below providing a unique name
355
+ @ for the tag. To edit an exist mapping, fill out the form and use the
356
+ @ existing name as the tag. To delete an existing mapping, fill in the
357
+ @ tag field but leave the "Base URL" field blank.</p>
358
+ if( zErr ){
359
+ @ <p class="error">%h(zErr)</p>
360
+ }
361
+ @ <form method="POST" action="%R/intermap">
362
+ login_insert_csrf_secret();
363
+ @ <table border="0">
364
+ @ <tr><td class="form_label" id="imtag">Tag:</td>
365
+ @ <td><input type="text" id="tag" aria-labeledby="imtag" name="tag" \
366
+ @ size="15" value="%h(zTag)"></td></tr>
367
+ @ <tr><td class="form_label" id="imbase">Base&nbsp;URL:</td>
368
+ @ <td><input type="text" id="base" aria-labeledby="imbase" name="base" \
369
+ @ size="70" value="%h(zBase)"></td></tr>
370
+ @ <tr><td class="form_label" id="imhash">Hash-path:</td>
371
+ @ <td><input type="text" id="hash" aria-labeledby="imhash" name="hash" \
372
+ @ size="20" value="%h(zHash)">
373
+ @ (use "<tt>/info/</tt>" when the target is Fossil)</td></tr>
374
+ @ <tr><td class="form_label" id="imwiki">Wiki-path:</td>
375
+ @ <td><input type="text" id="wiki" aria-labeledby="imwiki" name="wiki" \
376
+ @ size="20" value="%h(zWiki)">
377
+ @ (use "<tt>/wiki?name=</tt>" when the target is Fossil)</td></tr>
378
+ @ <tr><td></td>
379
+ @ <td><input type="submit" name="submit" value="Apply Changes"></td></tr>
380
+ @ </table>
381
+ @ </form>
382
+
383
+ style_footer();
384
+}
268385
--- src/interwiki.c
+++ src/interwiki.c
@@ -263,5 +263,122 @@
263 blob_appendf(out,"</table></blockquote>\n");
264 }else{
265 blob_appendf(out,"<i>None</i></blockquote>\n");
266 }
267 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
268
--- src/interwiki.c
+++ src/interwiki.c
@@ -263,5 +263,122 @@
263 blob_appendf(out,"</table></blockquote>\n");
264 }else{
265 blob_appendf(out,"<i>None</i></blockquote>\n");
266 }
267 }
268
269 /*
270 ** WEBPAGE: /intermap
271 **
272 ** View and modify the interwiki tag map or "intermap".
273 ** This page is visible to administrators only.
274 */
275 void interwiki_page(void){
276 Stmt q;
277 int n = 0;
278 const char *z;
279 const char *zTag = "";
280 const char *zBase = "";
281 const char *zHash = "";
282 const char *zWiki = "";
283 char *zErr = 0;
284
285 login_check_credentials();
286 if( !g.perm.Setup ){
287 login_needed(0);
288 return;
289 }
290 if( P("submit")!=0 && cgi_csrf_safe(1) ){
291 zTag = PT("tag");
292 zBase = PT("base");
293 zHash = PT("hash");
294 zWiki = PT("wiki");
295 if( zTag==0 || zTag[0]==0 || !interwiki_valid_name(zTag) ){
296 zErr = mprintf("Not a valid interwiki tag name: \"%s\"", zTag ? zTag : "");
297 }else if( zBase==0 || zBase[0]==0 ){
298 db_multi_exec("DELETE FROM config WHERE name='interwiki:%q';", zTag);
299 }else{
300 if( zHash && zHash[0]==0 ) zHash = 0;
301 if( zWiki && zWiki[0]==0 ) zWiki = 0;
302 db_multi_exec(
303 "REPLACE INTO config(name,value,mtime)"
304 "VALUES('interwiki:'||lower(%Q),"
305 " json_object('base',%Q,'hash',%Q,'wiki',%Q),"
306 " now());",
307 zTag, zBase, zHash, zWiki);
308 }
309 }
310
311 style_header("Interwiki Map Configuration");
312 @ <p>Interwiki links are hyperlink targets of the form
313 @ <blockquote><i>Tag</i><b>:</b><i>PageName</i></blockquote>
314 @ <p>Such links resolve to links to <i>PageName</i> on a separate server
315 @ identified by <i>Tag</i>. The Interwiki Map or "intermap" is a mapping
316 @ from <i>Tags</i> to complete Server URLs.
317 db_prepare(&q,
318 "SELECT substr(name,11),"
319 " json_extract(value,'$.base'),"
320 " json_extract(value,'$.hash'),"
321 " json_extract(value,'$.wiki')"
322 " FROM config WHERE name glob 'interwiki:*'"
323 );
324 while( db_step(&q)==SQLITE_ROW ){
325 if( n==0 ){
326 @ The current mapping is as follows:
327 @ <ol>
328 }
329 @ <li><p> %h(db_column_text(&q,0))
330 @ <ul>
331 @ <li> Base-URL: <tt>%h(db_column_text(&q,1))</tt>
332 z = db_column_text(&q,2);
333 if( z==0 ){
334 @ <li> Hash-path: <i>NULL</i>
335 }else{
336 @ <li> Hash-path: <tt>%h(z)</tt>
337 }
338 z = db_column_text(&q,3);
339 if( z==0 ){
340 @ <li> Wiki-path: <i>NULL</i>
341 }else{
342 @ <li> Wiki-path: <tt>%h(z)</tt>
343 }
344 @ </ul>
345 n++;
346 }
347 db_finalize(&q);
348 if( n ){
349 @ </ol>
350 }else{
351 @ No mappings are currently defined.
352 }
353
354 @ <p>To add a new mapping, fill out the form below providing a unique name
355 @ for the tag. To edit an exist mapping, fill out the form and use the
356 @ existing name as the tag. To delete an existing mapping, fill in the
357 @ tag field but leave the "Base URL" field blank.</p>
358 if( zErr ){
359 @ <p class="error">%h(zErr)</p>
360 }
361 @ <form method="POST" action="%R/intermap">
362 login_insert_csrf_secret();
363 @ <table border="0">
364 @ <tr><td class="form_label" id="imtag">Tag:</td>
365 @ <td><input type="text" id="tag" aria-labeledby="imtag" name="tag" \
366 @ size="15" value="%h(zTag)"></td></tr>
367 @ <tr><td class="form_label" id="imbase">Base&nbsp;URL:</td>
368 @ <td><input type="text" id="base" aria-labeledby="imbase" name="base" \
369 @ size="70" value="%h(zBase)"></td></tr>
370 @ <tr><td class="form_label" id="imhash">Hash-path:</td>
371 @ <td><input type="text" id="hash" aria-labeledby="imhash" name="hash" \
372 @ size="20" value="%h(zHash)">
373 @ (use "<tt>/info/</tt>" when the target is Fossil)</td></tr>
374 @ <tr><td class="form_label" id="imwiki">Wiki-path:</td>
375 @ <td><input type="text" id="wiki" aria-labeledby="imwiki" name="wiki" \
376 @ size="20" value="%h(zWiki)">
377 @ (use "<tt>/wiki?name=</tt>" when the target is Fossil)</td></tr>
378 @ <tr><td></td>
379 @ <td><input type="submit" name="submit" value="Apply Changes"></td></tr>
380 @ </table>
381 @ </form>
382
383 style_footer();
384 }
385
--- src/setup.c
+++ src/setup.c
@@ -1076,10 +1076,15 @@
10761076
@ make this setting be just "<b>b</b>". To allow unsafe HTML anywhere except
10771077
@ in forum posts, make this setting be "<b>btw</b>". The default is an
10781078
@ empty string which means that Fossil never allows Markdown documents
10791079
@ to generate unsafe HTML.
10801080
@ (Property: "safe-html")</p>
1081
+ @ <hr />
1082
+ @ The current interwiki tag map is as follows:
1083
+ interwiki_append_map_table(cgi_output_blob());
1084
+ @ <p>Visit <a href="./intermap">%R/intermap</a> for details or to
1085
+ @ modify the interwiki tag map.
10811086
@ <hr />
10821087
onoff_attribute("Use HTML as wiki markup language",
10831088
"wiki-use-html", "wiki-use-html", 0, 0);
10841089
@ <p>Use HTML as the wiki markup language. Wiki links will still be parsed
10851090
@ but all other wiki formatting will be ignored.</p>
10861091
--- src/setup.c
+++ src/setup.c
@@ -1076,10 +1076,15 @@
1076 @ make this setting be just "<b>b</b>". To allow unsafe HTML anywhere except
1077 @ in forum posts, make this setting be "<b>btw</b>". The default is an
1078 @ empty string which means that Fossil never allows Markdown documents
1079 @ to generate unsafe HTML.
1080 @ (Property: "safe-html")</p>
 
 
 
 
 
1081 @ <hr />
1082 onoff_attribute("Use HTML as wiki markup language",
1083 "wiki-use-html", "wiki-use-html", 0, 0);
1084 @ <p>Use HTML as the wiki markup language. Wiki links will still be parsed
1085 @ but all other wiki formatting will be ignored.</p>
1086
--- src/setup.c
+++ src/setup.c
@@ -1076,10 +1076,15 @@
1076 @ make this setting be just "<b>b</b>". To allow unsafe HTML anywhere except
1077 @ in forum posts, make this setting be "<b>btw</b>". The default is an
1078 @ empty string which means that Fossil never allows Markdown documents
1079 @ to generate unsafe HTML.
1080 @ (Property: "safe-html")</p>
1081 @ <hr />
1082 @ The current interwiki tag map is as follows:
1083 interwiki_append_map_table(cgi_output_blob());
1084 @ <p>Visit <a href="./intermap">%R/intermap</a> for details or to
1085 @ modify the interwiki tag map.
1086 @ <hr />
1087 onoff_attribute("Use HTML as wiki markup language",
1088 "wiki-use-html", "wiki-use-html", 0, 0);
1089 @ <p>Use HTML as the wiki markup language. Wiki links will still be parsed
1090 @ but all other wiki formatting will be ignored.</p>
1091

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button