Revision | acb25a8e90673626f1d8bbe69f8fe6b69b932925 (tree) |
---|---|
Time | 2018-03-28 02:54:20 |
Author | umorigu <umorigu@gmai...> |
Commiter | umorigu |
BugTrack/2431 Topicpath title by JavaScript
pukiwiki.ini.php
$topicpath_title = 1; // (1: Enabled(default), 0: Disabled)
@@ -186,7 +186,7 @@ function catbody($title, $page, $body) | ||
186 | 186 | } |
187 | 187 | } |
188 | 188 | // Embed Scripting data |
189 | - $html_scripting_data = get_html_scripting_data(); | |
189 | + $html_scripting_data = get_html_scripting_data($_page); | |
190 | 190 | |
191 | 191 | // Compat: 'HTML convert time' without time about MenuBar and skin |
192 | 192 | $taketime = elapsedtime(); |
@@ -217,10 +217,11 @@ function _decorate_Nth_word($matches) | ||
217 | 217 | /** |
218 | 218 | * Get data used by JavaScript modules |
219 | 219 | */ |
220 | -function get_html_scripting_data() | |
220 | +function get_html_scripting_data($page) | |
221 | 221 | { |
222 | 222 | global $ticket_link_sites, $plugin; |
223 | 223 | global $external_link_cushion_page, $external_link_cushion; |
224 | + global $topicpath_title; | |
224 | 225 | if (!isset($ticket_link_sites) || !is_array($ticket_link_sites)) { |
225 | 226 | return ''; |
226 | 227 | } |
@@ -272,12 +273,23 @@ EOS; | ||
272 | 273 | <input type="hidden" class="external-link-cushion" value="$h_cushion" /> |
273 | 274 | EOS; |
274 | 275 | } |
276 | + // Topicpath title | |
277 | + $topicpath_data = ''; | |
278 | + if ($topicpath_title && exist_plugin('topicpath')) { | |
279 | + $parents = plugin_topicpath_parent_links($page); | |
280 | + $h_topicpath = htmlsc(json_encode($parents, | |
281 | + JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); | |
282 | + $topicpath_data = <<<EOS | |
283 | +<input type="hidden" class="topicpath-links" value="$h_topicpath" /> | |
284 | +EOS; | |
285 | + } | |
275 | 286 | $data = <<<EOS |
276 | 287 | <div id="pukiwiki-site-properties" style="display:none;"> |
277 | 288 | $site_props |
278 | 289 | $plugin_prop |
279 | 290 | $ticketlink_data |
280 | 291 | $external_link_cushion_data |
292 | +$topicpath_data | |
281 | 293 | </div> |
282 | 294 | EOS; |
283 | 295 | return $data; |
@@ -2,7 +2,7 @@ | ||
2 | 2 | // PukiWiki - Yet another WikiWikiWeb clone |
3 | 3 | // topicpath.inc.php |
4 | 4 | // Copyright |
5 | -// 2004-2017 PukiWiki Development Team | |
5 | +// 2004-2018 PukiWiki Development Team | |
6 | 6 | // 2003 reimy (Some bug fix) |
7 | 7 | // 2003 t.m (Migrate to 1.3) |
8 | 8 | // 2003 Nibun-no-ni (Originally written for PukiWiki 1.4.x) |
@@ -30,40 +30,49 @@ function plugin_topicpath_convert() | ||
30 | 30 | return '<div>' . plugin_topicpath_inline() . '</div>'; |
31 | 31 | } |
32 | 32 | |
33 | +function plugin_topicpath_parent_links($page) | |
34 | +{ | |
35 | + $parts = explode('/', $page); | |
36 | + $parents = array(); | |
37 | + for ($i = 0, $pos = 0; $pos = strpos($page, '/', $i); $i = $pos + 1) { | |
38 | + $p = substr($page, 0, $pos); | |
39 | + $parents[] = array( | |
40 | + 'page' => $p, | |
41 | + 'leaf' => substr($p, $i), | |
42 | + 'uri' => get_page_uri($p), | |
43 | + ); | |
44 | + } | |
45 | + return $parents; | |
46 | +} | |
47 | + | |
33 | 48 | function plugin_topicpath_inline() |
34 | 49 | { |
35 | 50 | global $vars, $defaultpage; |
36 | - | |
37 | 51 | $page = isset($vars['page']) ? $vars['page'] : ''; |
38 | 52 | if ($page == '' || $page == $defaultpage) return ''; |
39 | - | |
40 | - $parts = explode('/', $page); | |
41 | - | |
42 | - $b_link = TRUE; | |
43 | - if (PLUGIN_TOPICPATH_THIS_PAGE_DISPLAY) { | |
44 | - $b_link = PLUGIN_TOPICPATH_THIS_PAGE_LINK; | |
45 | - } else { | |
46 | - array_pop($parts); // Remove the page itself | |
47 | - } | |
48 | - | |
53 | + $parents = plugin_topicpath_parent_links($page); | |
49 | 54 | $topic_path = array(); |
50 | - while (! empty($parts)) { | |
51 | - $_landing = join('/', $parts); | |
52 | - $element = htmlsc(array_pop($parts)); | |
53 | - if (! $b_link) { | |
54 | - // This page ($_landing == $page) | |
55 | - $b_link = TRUE; | |
56 | - $topic_path[] = $element; | |
57 | - } else if (PKWK_READONLY && ! is_page($_landing)) { | |
55 | + foreach ($parents as $p) { | |
56 | + if (PKWK_READONLY && !is_page($p['page'])) { | |
58 | 57 | // Page not exists |
59 | - $topic_path[] = $element; | |
58 | + $topic_path[] = htmlsc($p['leaf']); | |
60 | 59 | } else { |
61 | 60 | // Page exists or not exists |
62 | - $topic_path[] = '<a href="' . get_page_uri($_landing) . '">' . | |
63 | - $element . '</a>'; | |
61 | + $topic_path[] = '<a href="' . $p['uri'] . '">' . | |
62 | + $p['leaf'] . '</a>'; | |
63 | + } | |
64 | + } | |
65 | + // This page | |
66 | + if (PLUGIN_TOPICPATH_THIS_PAGE_DISPLAY) { | |
67 | + $leaf_name = preg_replace('#^.*/#', '', $page); | |
68 | + if (PLUGIN_TOPICPATH_THIS_PAGE_LINK) { | |
69 | + $topic_path[] = '<a href="' . get_page_uri($page) . '">' . | |
70 | + $leaf_name . '</a>'; | |
71 | + } else { | |
72 | + $topic_path[] = htmlsc($leaf_name); | |
64 | 73 | } |
65 | 74 | } |
66 | - $s = join(PLUGIN_TOPICPATH_TOP_SEPARATOR, array_reverse($topic_path)); | |
75 | + $s = join(PLUGIN_TOPICPATH_TOP_SEPARATOR, $topic_path); | |
67 | 76 | if (PLUGIN_TOPICPATH_TOP_DISPLAY) { |
68 | 77 | $s = '<span class="topicpath-top">' . |
69 | 78 | make_pagelink($defaultpage, PLUGIN_TOPICPATH_TOP_LABEL) . |
@@ -334,6 +334,12 @@ $external_link_cushion = array( | ||
334 | 334 | ); |
335 | 335 | |
336 | 336 | ///////////////////////////////////////////////// |
337 | +// Show Topicpath title | |
338 | +// 0: Disabled | |
339 | +// 1: Enabled | |
340 | +$topicpath_title = 1; | |
341 | + | |
342 | +///////////////////////////////////////////////// | |
337 | 343 | // Output HTML meta Referrer Policy |
338 | 344 | // Value: '' (default), no-referrer, origin, same-origin, ... |
339 | 345 | // Reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy |
@@ -452,7 +452,7 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function( | ||
452 | 452 | link.classList.add('internal-link'); |
453 | 453 | } else { |
454 | 454 | if (domainMatch(host, silentExternalDomainsR) || |
455 | - link.innerText.replace(/\s+/g, '') === '') { | |
455 | + link.textContent.replace(/\s+/g, '') === '') { | |
456 | 456 | // Don't show extenal link icons on these domains |
457 | 457 | link.classList.add('external-link-silent'); |
458 | 458 | } |
@@ -466,9 +466,41 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function( | ||
466 | 466 | } |
467 | 467 | }); |
468 | 468 | } |
469 | + function makeTopicpathTitle() { | |
470 | + var topicpathE = document.querySelector('#pukiwiki-site-properties .topicpath-links'); | |
471 | + if (!topicpathE || !topicpathE.value) return; | |
472 | + var topicpathLinks = JSON.parse(topicpathE.value); | |
473 | + if (!topicpathLinks) return; | |
474 | + var titleH1 = document.querySelector('h1.title'); | |
475 | + if (!titleH1) return; | |
476 | + var aList = titleH1.querySelectorAll('a'); | |
477 | + if (!aList || aList.length > 1) return; | |
478 | + var a = titleH1.querySelector('a'); | |
479 | + if (!a) return; | |
480 | + var fragment = document.createDocumentFragment(); | |
481 | + for (var i = 0, n = topicpathLinks.length; i < n; i++) { | |
482 | + var path = topicpathLinks[i]; | |
483 | + var a1 = document.createElement('a'); | |
484 | + a1.setAttribute('href', path.uri); | |
485 | + a1.setAttribute('title', path.page); | |
486 | + a1.textContent = path.leaf; | |
487 | + fragment.appendChild(a1); | |
488 | + var span = document.createElement('span'); | |
489 | + span.className = 'topicpath-slash'; | |
490 | + span.textContent = '/'; | |
491 | + fragment.appendChild(span); | |
492 | + } | |
493 | + var a2 = document.createElement('a'); | |
494 | + a2.setAttribute('href', a.getAttribute('href')); | |
495 | + a2.setAttribute('title', 'Backlinks'); | |
496 | + a2.textContent = a.textContent.replace(/^.+\//, ''); | |
497 | + fragment.appendChild(a2); | |
498 | + titleH1.replaceChild(fragment, a); | |
499 | + } | |
469 | 500 | setYourName(); |
470 | 501 | autoTicketLink(); |
471 | 502 | confirmEditFormLeaving(); |
472 | 503 | showPagePassage(); |
473 | 504 | convertExternalLinkToCushionPageLink(); |
505 | + makeTopicpathTitle(); | |
474 | 506 | }); |
@@ -625,7 +625,7 @@ td.vote_td2 { | ||
625 | 625 | |
626 | 626 | /* topicpath.inc.php */ |
627 | 627 | span.topicpath-slash { |
628 | - margin: 0 0.4em; | |
628 | + margin: 0 0.2em; | |
629 | 629 | } |
630 | 630 | span.topicpath-top { |
631 | 631 | user-select: none; |