コミットメタ情報

リビジョンa3190c9e66568f0ca7fbc5125f770789c13c09fe (tree)
日時2017-09-12 02:09:11
作者umorigu <umorigu@gmai...>
コミッターumorigu

ログメッセージ

BugTrack/2292 Improve do_search() and links_update()

* Simplify page name search by new links_do_search_page()
* Remove redundant searching in do_search()

変更サマリ

差分

--- a/lib/func.php
+++ b/lib/func.php
@@ -341,6 +341,7 @@ function do_search($word, $type = 'AND', $non_format = FALSE, $base = '')
341341 if ($search_auth && ! check_readable($page, false, false)) {
342342 unset($pages[$page]);
343343 --$count;
344+ continue;
344345 }
345346
346347 // Search for page contents
--- a/lib/link.php
+++ b/lib/link.php
@@ -99,15 +99,14 @@ function links_update($page)
9999 links_add($page, array_diff($rel_new, $rel_old), $rel_auto);
100100 links_delete($page, array_diff($rel_old, $rel_new));
101101
102- global $WikiName, $autolink, $nowikiname, $search_non_list;
102+ global $WikiName, $autolink, $nowikiname;
103103
104104 // $pageが新規作成されたページで、AutoLinkの対象となり得る場合
105105 if ($time && ! $rel_file_exist && $autolink
106106 && (preg_match("/^$WikiName$/", $page) ? $nowikiname : strlen($page) >= $autolink))
107107 {
108108 // $pageを参照していそうなページを一斉更新する(おい)
109- $search_non_list = 1;
110- $pages = do_search($page, 'AND', TRUE);
109+ $pages = links_do_search_page($page);
111110 foreach ($pages as $_page) {
112111 if ($_page !== $page)
113112 links_update($_page);
@@ -245,3 +244,34 @@ function & links_get_objects($page, $refresh = FALSE)
245244 $result = $obj->get_objects(join('', preg_grep('/^(?!\/\/|\s)./', get_source($page))), $page);
246245 return $result;
247246 }
247+
248+/**
249+ * Search function for AutoLink updating
250+ *
251+ * @param $word page name
252+ * @return list of page name that contains $word
253+ */
254+function links_do_search_page($word)
255+{
256+ global $whatsnew;
257+
258+ $keys = get_search_words(preg_split('/\s+/', $word, -1, PREG_SPLIT_NO_EMPTY));
259+ foreach ($keys as $key=>$value)
260+ $keys[$key] = '/' . $value . '/S';
261+ $pages = get_existpages();
262+ $pages = array_flip($pages);
263+ unset($pages[$whatsnew]);
264+ $count = count($pages);
265+ foreach (array_keys($pages) as $page) {
266+ $b_match = FALSE;
267+ // Search for page contents
268+ foreach ($keys as $key) {
269+ $lines = remove_author_lines(get_source($page, TRUE, FALSE));
270+ $b_match = preg_match($key, join('', $lines));
271+ if (! $b_match) break; // OR
272+ }
273+ if ($b_match) continue;
274+ unset($pages[$page]); // Miss
275+ }
276+ return array_keys($pages);
277+}
旧リポジトリブラウザで表示