• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

blogger


Commit MetaInfo

Revisão7e5e27a58101507ecc3e43c2fb7bf76a0d8ae3d1 (tree)
Hora2017-09-30 15:34:42
Autorumorigu <umorigu@gmai...>
Commiterumorigu

Mensagem de Log

BugTrack/2433 Search Progress and Cancel with search2 plugin

Mudança Sumário

Diff

--- a/plugin/search2.inc.php
+++ b/plugin/search2.inc.php
@@ -9,6 +9,10 @@
99 define('PLUGIN_SEARCH2_MAX_LENGTH', 80);
1010 define('PLUGIN_SEARCH2_MAX_BASE', 16); // #search(1,2,3,...,15,16)
1111
12+define('PLUGIN_SEARCH2_RESULT_RECORD_LIMIT', 500);
13+define('PLUGIN_SEARCH2_RESULT_RECORD_LIMIT_START', 100);
14+define('PLUGIN_SEARCH2_SEARCH_WAIT_MILLISECONDS', 1000);
15+
1216 // Show a search box on a page
1317 function plugin_search2_convert()
1418 {
@@ -22,6 +26,8 @@ function plugin_search2_action()
2226
2327 $action = isset($vars['action']) ? $vars['action'] : '';
2428 $base = isset($vars['base']) ? $vars['base'] : '';
29+ $start_s = isset($vars['start']) ? $vars['start'] : '';
30+ $start_index = pkwk_ctype_digit($start_s) ? intval($start_s) : 0;
2531 $bases = array();
2632 if ($base !== '') {
2733 $bases[] = $base;
@@ -39,17 +45,19 @@ function plugin_search2_action()
3945 } else if ($action === 'query') {
4046 $text = isset($vars['q']) ? $vars['q'] : '';
4147 header('Content-Type: application/json; charset=UTF-8');
42- plugin_search2_do_search($text, $base);
48+ plugin_search2_do_search($text, $base, $start_index);
4349 exit;
4450 }
4551 }
4652
47-function plugin_search2_do_search($query_text, $base)
53+function plugin_search2_do_search($query_text, $base, $start_index)
4854 {
4955 global $whatsnew, $non_list, $search_non_list;
5056 global $_msg_andresult, $_msg_orresult, $_msg_notfoundresult;
5157 global $search_auth;
5258
59+ $result_record_limit = $start_index === 0 ?
60+ PLUGIN_SEARCH2_RESULT_RECORD_LIMIT_START : PLUGIN_SEARCH2_RESULT_RECORD_LIMIT;
5361 $retval = array();
5462
5563 $b_type_and = true; // AND:TRUE OR:FALSE
@@ -82,6 +90,7 @@ function plugin_search2_do_search($query_text, $base)
8290 $found_pages = array();
8391 $readable_page_index = -1;
8492 $scan_page_index = -1;
93+ $saved_scan_start_index = -1;
8594 $last_read_page_name = null;
8695 foreach ($page_names as $page) {
8796 $b_match = FALSE;
@@ -96,6 +105,13 @@ function plugin_search2_do_search($query_text, $base)
96105 $pagename_only = true;
97106 }
98107 $readable_page_index++;
108+ if ($readable_page_index < $start_index) {
109+ // Skip: It's not time to read
110+ continue;
111+ }
112+ if ($saved_scan_start_index === -1) {
113+ $saved_scan_start_index = $scan_page_index;
114+ }
99115 // Search for page name and contents
100116 $body = get_source($page, TRUE, TRUE, TRUE);
101117 $target = $page . "\n" . remove_author_header($body);
@@ -122,6 +138,10 @@ function plugin_search2_do_search($query_text, $base)
122138 }
123139 }
124140 $last_read_page_name = $page;
141+ if ($start_index + $result_record_limit <= $readable_page_index + 1) {
142+ // Read page limit
143+ break;
144+ }
125145 }
126146 $message = str_replace('$1', htmlsc($query_text), str_replace('$2', count($found_pages),
127147 str_replace('$3', count($page_names), $b_type_and ? $_msg_andresult : $_msg_orresult)));
@@ -129,10 +149,13 @@ function plugin_search2_do_search($query_text, $base)
129149 $result_obj = array(
130150 'message' => $message,
131151 'q' => $query_text,
132- 'read_page_count' => $readable_page_index + 1,
133- 'scan_page_count' => $scan_page_index + 1,
152+ 'start_index' => $start_index,
153+ 'limit' => $result_record_limit,
154+ 'read_page_count' => $readable_page_index - $start_index + 1,
155+ 'scan_page_count' => $scan_page_index - $saved_scan_start_index + 1,
134156 'page_count' => count($page_names),
135157 'last_read_page_name' => $last_read_page_name,
158+ 'next_start_index' => $readable_page_index + 1,
136159 'search_done' => $search_done,
137160 'results' => $found_pages);
138161 $obj = $result_obj;
@@ -186,8 +209,6 @@ EOD;
186209 $_search2_result_found = htmlsc($_msg_andresult);
187210 $_search2_search_wait_milliseconds = PLUGIN_SEARCH2_SEARCH_WAIT_MILLISECONDS;
188211 $result_page_panel =<<<EOD
189-<div id="_plugin_search2_search_status"></div>
190-<div id="_plugin_search2_message"></div>
191212 <input type="checkbox" id="_plugin_search2_detail" checked><label for="_plugin_search2_detail">$_search_detail</label>
192213 <input type="hidden" id="_plugin_search2_msg_searching" value="$_search_searching">
193214 <input type="hidden" id="_plugin_search2_msg_result_notfound" value="$_search2_result_notfound">
@@ -200,13 +221,7 @@ EOD;
200221
201222 $plain_search_link = '<a href="' . $script . '?cmd=search' . '">' . htmlsc($_btn_search) . '</a>';
202223 $alt_msg = str_replace('$1', $plain_search_link, $_msg_use_alternative_link);
203- return <<<EOD
204-<noscript>
205- <p>$_msg_unsupported_webbrowser $alt_msg</p>
206-</noscript>
207-<p class="_plugin_search2_nosupport_message" style="display:none;">
208- $_msg_unsupported_webbrowser $alt_msg
209-</p>
224+ $form =<<<EOD
210225 <form action="$script" method="GET" class="_plugin_search2_form">
211226 <div>
212227 <input type="hidden" name="cmd" value="search2">
@@ -215,8 +230,29 @@ EOD;
215230 </div>
216231 $base_option
217232 </form>
233+EOD;
234+ $second_form =<<<EOD
235+<div class="_plugin_search2_second_form" style="display:none;">
236+<div class="_plugin_search2_search_status"></div>
237+<div class="_plugin_search2_message"></div>
238+$form
239+</div>
240+EOD;
241+
242+
243+ return <<<EOD
244+<noscript>
245+ <p>$_msg_unsupported_webbrowser $alt_msg</p>
246+</noscript>
247+<p class="_plugin_search2_nosupport_message" style="display:none;">
248+ $_msg_unsupported_webbrowser $alt_msg
249+</p>
250+$form
251+<div class="_plugin_search2_search_status"></div>
252+<div class="_plugin_search2_message"></div>
218253 $result_page_panel
219254 <ul id="result-list">
220255 </ul>
256+$second_form
221257 EOD;
222258 }
--- a/skin/search2.js
+++ b/skin/search2.js
@@ -93,15 +93,23 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
9393 var searchRegex = textToRegex(removeSearchOperators(searchText));
9494 var ul = document.querySelector('#result-list');
9595 if (!ul) return;
96- ul.innerHTML = '';
96+ if (obj.start_index === 0) {
97+ ul.innerHTML = '';
98+ }
9799 if (! session.scan_page_count) session.scan_page_count = 0;
98100 if (! session.read_page_count) session.read_page_count = 0;
99101 if (! session.hit_page_count) session.hit_page_count = 0;
102+ var prevHitPageCount = session.hit_page_count;
100103 session.scan_page_count += obj.scan_page_count;
101104 session.read_page_count += obj.read_page_count;
102105 session.hit_page_count += obj.results.length;
103106 session.page_count = obj.page_count;
104-
107+ if (prevHitPageCount === 0 && session.hit_page_count > 0) {
108+ var div = document.querySelector('._plugin_search2_second_form');
109+ if (div) {
110+ div.style.display = 'block';
111+ }
112+ }
105113 var msg = obj.message;
106114 var notFoundMessageTemplate = getMessageTemplate('_plugin_search2_msg_result_notfound',
107115 'No page which contains $1 has been found.');
@@ -110,7 +118,7 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
110118 var searchTextDecorated = findAndDecorateText(searchText, searchRegex);
111119 if (searchTextDecorated === null) searchTextDecorated = escapeHTML(searchText);
112120 var messageTemplate = foundMessageTemplate;
113- if (session.hit_page_count === 0) {
121+ if (obj.search_done && session.hit_page_count === 0) {
114122 messageTemplate = notFoundMessageTemplate;
115123 }
116124 msg = messageTemplate.replace(/\$1|\$2|\$3/g, function(m){
@@ -120,9 +128,17 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
120128 '$3': session.read_page_count
121129 }[m];
122130 });
123- document.querySelector('#_plugin_search2_message').innerHTML = msg;
124-
125- setSearchStatus('');
131+ setSearchMessage(msg);
132+ var progress = ' (read:' + session.read_page_count + ', scanned:' +
133+ session.scan_page_count + ', all:' + session.page_count + ')';
134+ var e = document.querySelector('#_plugin_search2_msg_searching');
135+ var msg = e && e.value || 'Searching...';
136+ setSearchStatus(msg + progress);
137+ if (obj.search_done) {
138+ setTimeout(function(){
139+ setSearchStatus('');
140+ }, 5000);
141+ }
126142 var results = obj.results;
127143 var now = new Date();
128144 results.forEach(function(val, index) {
@@ -167,6 +183,21 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
167183 fragment.appendChild(div);
168184 ul.appendChild(fragment);
169185 });
186+ if (!obj.search_done && obj.next_start_index) {
187+ var waitE = document.querySelector('#_search2_search_wait_milliseconds');
188+ var interval = minSearchWaitMilliseconds;
189+ try {
190+ interval = parseInt(waitE.value);
191+ } catch (e) {
192+ interval = minSearchWaitMilliseconds;
193+ }
194+ if (interval < minSearchWaitMilliseconds) {
195+ interval = minSearchWaitMilliseconds;
196+ }
197+ setTimeout(function(){
198+ doSearch(searchText, session, obj.next_start_index);
199+ }, interval);
200+ }
170201 }
171202 function prepareKanaMap() {
172203 if (kanaMap !== null) return;
@@ -396,10 +427,16 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
396427 }
397428 }
398429 function setSearchStatus(statusText) {
399- var statusObj = document.querySelector('#_plugin_search2_search_status');
400- if (statusObj) {
430+ var statusList = document.querySelectorAll('._plugin_search2_search_status');
431+ forEach(statusList, function(statusObj){
401432 statusObj.textContent = statusText;
402- }
433+ });
434+ }
435+ function setSearchMessage(msgHTML) {
436+ var objList = document.querySelectorAll('._plugin_search2_message');
437+ forEach(objList, function(obj){
438+ obj.innerHTML = msgHTML;
439+ });
403440 }
404441 function forEach(nodeList, func) {
405442 if (nodeList.forEach) {