Commit MetaInfo

修订版acb25a8e90673626f1d8bbe69f8fe6b69b932925 (tree)
时间2018-03-28 02:54:20
作者umorigu <umorigu@gmai...>
Commiterumorigu

Log Message

BugTrack/2431 Topicpath title by JavaScript

pukiwiki.ini.php


$topicpath_title = 1; // (1: Enabled(default), 0: Disabled)

更改概述

差异

--- a/lib/html.php
+++ b/lib/html.php
@@ -186,7 +186,7 @@ function catbody($title, $page, $body)
186186 }
187187 }
188188 // Embed Scripting data
189- $html_scripting_data = get_html_scripting_data();
189+ $html_scripting_data = get_html_scripting_data($_page);
190190
191191 // Compat: 'HTML convert time' without time about MenuBar and skin
192192 $taketime = elapsedtime();
@@ -217,10 +217,11 @@ function _decorate_Nth_word($matches)
217217 /**
218218 * Get data used by JavaScript modules
219219 */
220-function get_html_scripting_data()
220+function get_html_scripting_data($page)
221221 {
222222 global $ticket_link_sites, $plugin;
223223 global $external_link_cushion_page, $external_link_cushion;
224+ global $topicpath_title;
224225 if (!isset($ticket_link_sites) || !is_array($ticket_link_sites)) {
225226 return '';
226227 }
@@ -272,12 +273,23 @@ EOS;
272273 <input type="hidden" class="external-link-cushion" value="$h_cushion" />
273274 EOS;
274275 }
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+ }
275286 $data = <<<EOS
276287 <div id="pukiwiki-site-properties" style="display:none;">
277288 $site_props
278289 $plugin_prop
279290 $ticketlink_data
280291 $external_link_cushion_data
292+$topicpath_data
281293 </div>
282294 EOS;
283295 return $data;
--- a/plugin/topicpath.inc.php
+++ b/plugin/topicpath.inc.php
@@ -2,7 +2,7 @@
22 // PukiWiki - Yet another WikiWikiWeb clone
33 // topicpath.inc.php
44 // Copyright
5-// 2004-2017 PukiWiki Development Team
5+// 2004-2018 PukiWiki Development Team
66 // 2003 reimy (Some bug fix)
77 // 2003 t.m (Migrate to 1.3)
88 // 2003 Nibun-no-ni (Originally written for PukiWiki 1.4.x)
@@ -30,40 +30,49 @@ function plugin_topicpath_convert()
3030 return '<div>' . plugin_topicpath_inline() . '</div>';
3131 }
3232
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+
3348 function plugin_topicpath_inline()
3449 {
3550 global $vars, $defaultpage;
36-
3751 $page = isset($vars['page']) ? $vars['page'] : '';
3852 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);
4954 $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'])) {
5857 // Page not exists
59- $topic_path[] = $element;
58+ $topic_path[] = htmlsc($p['leaf']);
6059 } else {
6160 // 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);
6473 }
6574 }
66- $s = join(PLUGIN_TOPICPATH_TOP_SEPARATOR, array_reverse($topic_path));
75+ $s = join(PLUGIN_TOPICPATH_TOP_SEPARATOR, $topic_path);
6776 if (PLUGIN_TOPICPATH_TOP_DISPLAY) {
6877 $s = '<span class="topicpath-top">' .
6978 make_pagelink($defaultpage, PLUGIN_TOPICPATH_TOP_LABEL) .
--- a/pukiwiki.ini.php
+++ b/pukiwiki.ini.php
@@ -334,6 +334,12 @@ $external_link_cushion = array(
334334 );
335335
336336 /////////////////////////////////////////////////
337+// Show Topicpath title
338+// 0: Disabled
339+// 1: Enabled
340+$topicpath_title = 1;
341+
342+/////////////////////////////////////////////////
337343 // Output HTML meta Referrer Policy
338344 // Value: '' (default), no-referrer, origin, same-origin, ...
339345 // Reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy
--- a/skin/main.js
+++ b/skin/main.js
@@ -452,7 +452,7 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
452452 link.classList.add('internal-link');
453453 } else {
454454 if (domainMatch(host, silentExternalDomainsR) ||
455- link.innerText.replace(/\s+/g, '') === '') {
455+ link.textContent.replace(/\s+/g, '') === '') {
456456 // Don't show extenal link icons on these domains
457457 link.classList.add('external-link-silent');
458458 }
@@ -466,9 +466,41 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
466466 }
467467 });
468468 }
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+ }
469500 setYourName();
470501 autoTicketLink();
471502 confirmEditFormLeaving();
472503 showPagePassage();
473504 convertExternalLinkToCushionPageLink();
505+ makeTopicpathTitle();
474506 });
--- a/skin/pukiwiki.css
+++ b/skin/pukiwiki.css
@@ -625,7 +625,7 @@ td.vote_td2 {
625625
626626 /* topicpath.inc.php */
627627 span.topicpath-slash {
628- margin: 0 0.4em;
628+ margin: 0 0.2em;
629629 }
630630 span.topicpath-top {
631631 user-select: none;
Show on old repository browser