リビジョン | f17bc09a8167e9f11cb2250e74c1651c6c4ee67a (tree) |
---|---|
日時 | 2017-10-28 00:50:11 |
作者 | umorigu <umorigu@gmai...> |
コミッター | umorigu |
BugTrack/2283 ls2 plugin: Improve include loop handling
* Fix infinite loop on 'include' and no-'title' condition
* Trace including tree on each page
@@ -117,12 +117,13 @@ function plugin_ls2_show_lists($prefix, & $params) | ||
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | -function plugin_ls2_get_headings($page, & $params, $level, $include = FALSE) | |
120 | +function plugin_ls2_get_headings($page, & $params, $level, $include = FALSE, | |
121 | + &$read_pages = array()) | |
121 | 122 | { |
122 | 123 | static $_ls2_anchor = 0; |
123 | 124 | |
124 | 125 | // ページが未表示のとき |
125 | - $is_done = (isset($params["page_$page"]) && $params["page_$page"] > 0); | |
126 | + $is_done = isset($read_pages[$page]); | |
126 | 127 | if (! $is_done) $params["page_$page"] = ++$_ls2_anchor; |
127 | 128 | |
128 | 129 | $s_page = htmlsc($page); |
@@ -132,7 +133,7 @@ function plugin_ls2_get_headings($page, & $params, $level, $include = FALSE) | ||
132 | 133 | plugin_ls2_list_push($params, $level); |
133 | 134 | $ret = $include ? '<li>include ' : '<li>'; |
134 | 135 | |
135 | - if ($params['title'] && $is_done) { | |
136 | + if ($is_done) { | |
136 | 137 | $ret .= '<a href="' . $href . '" title="' . $title . '">' . $s_page . '</a> '; |
137 | 138 | $ret .= '<a href="#list_' . $params["page_$page"] . '"><sup>↑</sup></a>'; |
138 | 139 | array_push($params['result'], $ret); |
@@ -162,7 +163,11 @@ function plugin_ls2_get_headings($page, & $params, $level, $include = FALSE) | ||
162 | 163 | preg_match('/^#include\((.+)\)/', $line, $matches) && |
163 | 164 | is_page($matches[1])) |
164 | 165 | { |
165 | - plugin_ls2_get_headings($matches[1], $params, $level + 1, TRUE); | |
166 | + $read_pages[$page] = 1; | |
167 | + $sub_page = $matches[1]; | |
168 | + if (!isset($read_pages[$sub_page])) { | |
169 | + plugin_ls2_get_headings($sub_page, $params, $level + 1, TRUE, $read_pages); | |
170 | + } | |
166 | 171 | } |
167 | 172 | } |
168 | 173 | } |