diff options
author | Ineiev <ineiev@gnu.org> | 2024-10-29 09:22:10 +0000 |
---|---|---|
committer | Ineiev <ineiev@gnu.org> | 2024-11-06 15:51:59 +0000 |
commit | 8dc73e738b1ae9485b289df6117715eae2f1fa2c (patch) | |
tree | 09b6aaae4343d4e7d44c67f56fa13a902afdde9c | |
parent | 491e81ecfdc7632409c61e7bdaa0e87375310106 (diff) | |
download | savane-8dc73e738b1ae9485b289df6117715eae2f1fa2c.tar.gz |
add input for offset, Savannah sr #109559
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | frontend/php/bugs/dependencies.php | 12 | ||||
-rw-r--r-- | frontend/php/include/html.php | 69 | ||||
-rw-r--r-- | frontend/php/include/trackers/general.php | 7 | ||||
-rw-r--r-- | frontend/php/include/trackers/show.php | 10 | ||||
-rw-r--r-- | frontend/php/include/trackers/view-dependencies.php | 2 | ||||
-rw-r--r-- | frontend/php/include/trackers_run/browse.php | 55 | ||||
-rw-r--r-- | frontend/php/search/index.php | 12 | ||||
-rw-r--r-- | frontend/php/siteadmin/grouplist.php | 4 | ||||
-rw-r--r-- | frontend/php/siteadmin/spamlist.php | 9 | ||||
-rw-r--r-- | frontend/php/siteadmin/usergroup.php | 10 | ||||
-rw-r--r-- | frontend/php/siteadmin/userlist.php | 7 | ||||
-rw-r--r-- | frontend/php/testing/sane.php | 39 |
13 files changed, 114 insertions, 124 deletions
@@ -7,7 +7,7 @@ * The headers are omitted when serving tracker attachments when the respective fields are empty. -* More controls are added to navigate search results. +* More controls are added to navigate search results, see Savannah sr #109559. * Bugs fixes: diff --git a/frontend/php/bugs/dependencies.php b/frontend/php/bugs/dependencies.php index 4aa3e2d4..250447e5 100644 --- a/frontend/php/bugs/dependencies.php +++ b/frontend/php/bugs/dependencies.php @@ -56,16 +56,8 @@ $includes = ['init', 'http', 'trackers/general', 'trackers/view-dependencies']; foreach ($includes as $i) require_once ("../include/$i.php"); -extract (sane_import ('request', - [ - 'true' => 'include_closed', - 'digits' => ['max_rows', ['offset', [0, 410338673]]] - ] -)); - -if (empty ($max_rows)) - $max_rows = 10; -$max_rows = intval ($max_rows); +extract (sane_import ('request', ['true' => 'include_closed'])); +html_nextprev_extract_params (10); trackers_view_dependencies ($list_format); ?> diff --git a/frontend/php/include/html.php b/frontend/php/include/html.php index b3c21b3b..95cbc504 100644 --- a/frontend/php/include/html.php +++ b/frontend/php/include/html.php @@ -170,8 +170,8 @@ function html_nextprev_separator () function html_nextprev_link ($url, $offset, $max_rows) { - return "<a href=\"$url&offset=" - . "$offset&max_rows=" . utils_specialchars ($max_rows) . "#results\">"; + $start = $offset + 1; + return "<a href=\"$url&start=$start&max_rows=$max_rows#results\">"; } function html_medium_link ($url, $offset, $max_rows) @@ -223,7 +223,7 @@ function html_prev ($url, $offset, $max_rows, $total_rows) if ($offset < 0) $offset = 0; $ret .= html_nextprev_link ($url, $offset, $max_rows); - return $ret . html_image ('arrows/previous.png') . " $prev_msg</a>"; + return $ret . html_image ('arrows/previous.png') . " $prev_msg</a>$sep"; } function html_next ($url, $offset, $max_rows, $total_rows) @@ -233,10 +233,10 @@ function html_next ($url, $offset, $max_rows, $total_rows) $next_msg = _("Next"); $end_msg = _("End"); $sep = html_nextprev_separator (); $rows = min ($max_rows, $total_rows - $offset); - if ($offset + $max_rows >= $total_rows) - return "<i>$next_msg</i> " . html_image ("arrows/nextgrey.png") + if ($offset + $max_rows > $total_rows) + return "$sep<i>$next_msg</i> " . html_image ("arrows/nextgrey.png") . "$sep<i>$end_msg</i> " . html_image ('arrows/lastgrey.png'); - $ret = html_nextprev_link ($url, $offset + $rows, $max_rows); + $ret = $sep . html_nextprev_link ($url, $offset + $rows, $max_rows); $ret .= "$next_msg " . html_image ("arrows/next.png") . "</a>$sep"; $ret .= html_more ($url, $offset, $max_rows, $total_rows); $last_page = $total_rows - ($total_rows % $max_rows); @@ -246,6 +246,43 @@ function html_next ($url, $offset, $max_rows, $total_rows) return "$ret$end_msg " . html_image ("arrows/last.png") . "</a>"; } +function html_nextprev_extract_params ($default_max_rows = 50) +{ + extract (sane_import ('request', + [ + 'digits' => [ + ['max_rows', [1, 4913]], + ['offset', [0, 410338672]], ['start', [1, 410338673]] + ] + ] + )); + if (empty ($max_rows) + || !intval ($max_rows) # Values like '00' aren't empty, but intval is zero. + ) + $max_rows = $default_max_rows; + if (empty ($offset)) + $offset = 0; + if (!empty ($start)) + $offset = $start - 1; + foreach (['max_rows', 'offset'] as $v) + $GLOBALS[$v] = intval ($$v); +} + +function html_nextprev_item_count ($offset, $max_rows, $total_rows, $have_form) +{ + $first_item = $offset; + if ($have_form) + $first_item = form_hidden (['max_rows' => $max_rows]) + . form_input ('text', 'start', $offset + 1, 'size="3"'); + $latest_item = min ($offset + $max_rows, $total_rows); + return sprintf ( + # TRANSLATORS: The first argument is the number of the first item shown, + # the second argument is the number of the last item shown, + # the third argument is the total number of items. + _('%1$s–%2$s / %3$s'), $first_item, $latest_item, $total_rows + ); +} + function html_nextprev_str ($url, $offset, $max_rows, $total_rows) { $ret = "<p class=\"nextprev\">\n"; @@ -254,17 +291,17 @@ function html_nextprev_str ($url, $offset, $max_rows, $total_rows) $msg = ngettext ( "%d matching item", "%d matching items", $total_rows); return $ret . sprintf ($msg, $total_rows); } - $sep = html_nextprev_separator (); - $ret .= html_prev ($url, $offset, $max_rows, $total_rows) . $sep; - $latest_item = min ($offset + $max_rows, $total_rows); - $ret .= sprintf ( - # TRANSLATORS: The first argument is the number of the first item shown, - # the second argument is the number of the last item shown, - # the third argument is the total number of items. - _('%1$s–%2$s / %3$s'), $offset + 1, $latest_item, $total_rows + $have_form = $total_rows > $max_rows; + if ($have_form) + $ret = form_tag (['action' => "$url#results"]) . $ret; + $ret .= html_prev ($url, $offset, $max_rows, $total_rows); + $ret .= html_nextprev_item_count ( + $offset, $max_rows, $total_rows, $have_form ); - $ret .= $sep . html_next ($url, $offset, $max_rows, $total_rows); - return "$ret</p>\n"; + $ret .= html_next ($url, $offset, $max_rows, $total_rows) . "</p>\n"; + if ($have_form) + $ret .= "</form>\n"; + return $ret; } function html_nextprev ($url, $offset, $max_rows, $total_rows) diff --git a/frontend/php/include/trackers/general.php b/frontend/php/include/trackers/general.php index 31b17742..7279b451 100644 --- a/frontend/php/include/trackers/general.php +++ b/frontend/php/include/trackers/general.php @@ -355,10 +355,11 @@ function trackers_field_date_operator ($field_name, $value = '', $ro = false) . "\" name=\"{$field_name}_op\">$options</select>\n"; } -function trackers_chunksz_control ($var = 'chunksz') +function trackers_max_rows_control () { - return html_label ($var, _("Items to show at once:")) . ' ' - . form_input ('text', $var, $GLOBALS[$var], 'size="3" maxlength="5"'); + global $max_rows; + return html_label ('max_rows', _("Items to show at once:")) . ' ' + . form_input ('text', 'max_rows', $max_rows, 'size="3" maxlength="5"'); } function trackers_field_text ( diff --git a/frontend/php/include/trackers/show.php b/frontend/php/include/trackers/show.php index 7e9045c9..6b49a3c7 100644 --- a/frontend/php/include/trackers/show.php +++ b/frontend/php/include/trackers/show.php @@ -126,23 +126,17 @@ function show_item_in_list ($row, $fields, $widths, $field_num) print "</tr>\n"; } -function show_item_list ( - $items, $offset, $total_rows, $fields, $titles, $widths, $url -) +function show_item_list ($items, $fields, $titles, $widths, $url) { - global $chunksz; $links = []; foreach ($fields as $field) $links[] = "$url&order=$field#results"; - $nav_bar = html_nextprev_str ($url, $offset, $chunksz, $total_rows); - - print "<div id='results'>$nav_bar</div>\n"; print html_build_list_table_top ($titles, $links); $field_num = count ($fields); foreach ($items as $row) show_item_in_list ($row, $fields, $widths, $field_num); - print "</table>\n$nav_bar"; + print "</table>\n"; } # Show the changes of the tracker data we have for this item, diff --git a/frontend/php/include/trackers/view-dependencies.php b/frontend/php/include/trackers/view-dependencies.php index fbe558e4..9851f8b9 100644 --- a/frontend/php/include/trackers/view-dependencies.php +++ b/frontend/php/include/trackers/view-dependencies.php @@ -253,7 +253,7 @@ function trackers_print_view_deps_controls () global $include_closed, $group; print form_tag (['method' => 'get']); print form_hidden (['func' => 'view-dependencies', 'group' => $group]); - print trackers_chunksz_control ('max_rows'); + print trackers_max_rows_control ('max_rows'); print " \n"; print form_checkbox ('include_closed', !empty ($include_closed), ['label' => _('Include closed items')]); diff --git a/frontend/php/include/trackers_run/browse.php b/frontend/php/include/trackers_run/browse.php index 334fcfe0..b2c0a410 100644 --- a/frontend/php/include/trackers_run/browse.php +++ b/frontend/php/include/trackers_run/browse.php @@ -52,7 +52,7 @@ extract (sane_import ('get', [ 'digits' => [ - 'chunksz', 'offset', 'report_id', + 'report_id', ['msort', 'sumORdet', 'advsrch', 'history_search', [0, 1]], ['spamscore', [1, null]], ['history_date_yearfd', [1900, null]], @@ -75,22 +75,13 @@ extract (sane_import ('get', ] )); +html_nextprev_extract_params (); # Number of search criteria (boxes) displayed in one row. $fields_per_line = 5; # Avoid undesired user input. $browse_preamble = ''; -$default_chunksz = 50; - -# Number of bugs displayed on screen in one chunk. -# Default 50. -if (empty ($chunksz)) - $chunksz = $default_chunksz; -$chunksz = intval ($chunksz); -if ($chunksz <= 0) # Catch values like "00" (non-empty, but intval is zero). - $chunksz = $default_chunksz; - # Digest mode? Set the digest variable to one. $digest = $func == 'digest'; @@ -292,11 +283,11 @@ if (!$set) || $field == 'sumORdet' ) $$field = $value_id; - elseif ($field == 'chunksz') + elseif (in_array ($field, ['chunksz', 'max_rows'])) { - $chunksz = intval ($value_id); - if ($chunksz <= 0) - $chunksz = $default_chunksz; + $max_rows = intval ($value_id); + if ($max_rows <= 0) + $max_rows = 50; } elseif ($field == 'history') { @@ -344,7 +335,7 @@ elseif ($set == 'custom') if (is_scalar ($value_id)) $pref_stg .= "&{$field}[]=$value_id"; } - $pref_stg .= "&advsrch=$advsrch&msort=$msort&chunksz=$chunksz"; + $pref_stg .= "&advsrch=$advsrch&msort=$msort&max_rows=$max_rows"; $pref_stg .= "&spamscore=$spamscore&report_id=$report_id"; $pref_stg .= "&sumORdet=$sumORdet"; @@ -410,13 +401,13 @@ $where .= ")"; # It would be too heavy on the database if this was done very frequently # and we already found some project giving direct links to 500 the browse # item page with 500 items shown by default. -# Save the wanted number of chunksz, for later. -$wanted_chunksz = $chunksz; -if ($chunksz > 150 && !$digest) - $chunksz = 150; +# Save the wanted number of max_rows for later use. +$wanted_max_rows = $max_rows; +if ($max_rows > 150 && !$digest) + $max_rows = 150; $limit = "LIMIT ?, ?"; -$limit_params = [$offset, $chunksz]; +$limit_params = [$offset, $max_rows]; # Prepare for summary and original submission as 'special' criteria. $summary_search = 0; @@ -1087,7 +1078,7 @@ if ($history_search) . "&history_date=$history_date"; $form .= '<p class="smaller">'; -$form .= trackers_chunksz_control () . ' '; +$form .= trackers_max_rows_control () . ' '; if ($is_trackeradmin) $form .= sprintf ( @@ -1096,9 +1087,9 @@ if ($is_trackeradmin) 'size="3" maxlength="2" title="' . _("Spam level of items to hide") . '"') ); -if ($wanted_chunksz != $chunksz) +if ($wanted_max_rows != $max_rows) { - # No use of ngettext as $chunksz will never be below 10, otherwise + # No use of ngettext as $max_rows will never be below 10, otherwise # it would mean that Savane would be modified to never list more # than 10 items at once, which is almost nothing. $form .= ' <span class="warn">' @@ -1107,7 +1098,7 @@ if ($wanted_chunksz != $chunksz) . "Printer Version.", "Warning: only %s items can be shown at once, unless using " . "Printer Version.", - $chunksz), $chunksz + $max_rows), $max_rows ) . '</span>'; } @@ -1152,17 +1143,17 @@ if ($totalrows > 0) } print html_show_displayoptions ($form, $form_opening, $form_submit); - -if ($digest) - print form_tag (['method' => 'get']) - . form_hidden (['group' => $group, 'func' => "digestselectfield"]); - if ($totalrows > 0) { - show_item_list ($result_array, $offset, $totalrows, $col_list, - $lbl_list, $width_list, $url); + $nav_bar = html_nextprev_str ($url, $offset, $max_rows, $totalrows); + print "<div id='results'>$nav_bar</div>\n"; + if ($digest) + print form_tag (['method' => 'get']) + . form_hidden (['group' => $group, 'func' => "digestselectfield"]); + show_item_list ($result_array, $col_list, $lbl_list, $width_list, $url); if ($digest) print form_footer (_("Proceed to Digest next step")); + print $nav_bar; show_priority_colors_key (); } else diff --git a/frontend/php/search/index.php b/frontend/php/search/index.php index e00fb6df..471ec63f 100644 --- a/frontend/php/search/index.php +++ b/frontend/php/search/index.php @@ -46,21 +46,13 @@ require_once ('../include/init.php'); $tos_values = array_merge (['soft', 'people'], utils_get_tracker_list ()); extract (sane_import ('request', [ - 'digits' => - [ 'type', 'only_group_id', ['offset', [0, 410338673]], - ['max_rows', [1, 4913]], ['exact', [0, 1]] - ], + 'digits' => ['type', 'only_group_id', ['exact', [0, 1]]], 'strings' => [['type_of_search', $tos_values]], 'pass' => ['words0', 'words1', 'words'], ] )); -if (empty ($offset)) - $offset = 0; - -if (empty ($max_rows)) - $max_rows = 25; - +html_nextprev_extract_params (25); foreach ([0, 1] as $n) if (!empty (${"words$n"})) $words = ${"words$n"}; diff --git a/frontend/php/siteadmin/grouplist.php b/frontend/php/siteadmin/grouplist.php index 83ae1a72..7a93c8c1 100644 --- a/frontend/php/siteadmin/grouplist.php +++ b/frontend/php/siteadmin/grouplist.php @@ -52,7 +52,6 @@ site_admin_header ( extract (sane_import ('get', [ - 'digits' => ['offset', 'max_rows'], 'name' => 'group_name_search', 'preg' => [['status', '/^[A-Z]$/']], 'pass' => 'search', @@ -65,6 +64,7 @@ extract (sane_import ('post', )); form_check (['assign_gid']); +html_nextprev_extract_params (100); function fetch_member_data ($data) { @@ -172,8 +172,6 @@ print '<td><a href="grouplist.php?status=D">' print "</tr>\n"; print "</table>\n"; -$max_rows = !empty ($max_rows)? $max_rows: 100; - $abc_array = [ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', diff --git a/frontend/php/siteadmin/spamlist.php b/frontend/php/siteadmin/spamlist.php index 719a596f..da5c2b54 100644 --- a/frontend/php/siteadmin/spamlist.php +++ b/frontend/php/siteadmin/spamlist.php @@ -48,7 +48,7 @@ session_require (['group' => '1', 'admin_flags' => 'A']); # We don't internationalize messages in this file because they are # for Savannah admins who use English. -extract (sane_import ('get', ['digits' => ['max_rows', 'offset']])); +html_nextprev_extract_params (100); function wash_user () { @@ -144,13 +144,6 @@ $title_arr = [ no_i18n ("Incriminated posts"), no_i18n ("Flagged by") ]; -if (empty ($max_rows)) - $max_rows = 50; - -if (empty ($offset)) - $offset = 0; -$offset = intval ($offset); - $sql = "FROM user WHERE status = 'A' AND spamscore > 0"; $result = db_execute ("SELECT count(DISTINCT(user_id)) AS cnt $sql"); $cnt = 0; diff --git a/frontend/php/siteadmin/usergroup.php b/frontend/php/siteadmin/usergroup.php index 745fee47..bc975935 100644 --- a/frontend/php/siteadmin/usergroup.php +++ b/frontend/php/siteadmin/usergroup.php @@ -57,9 +57,7 @@ $actions = ['remove_user_from_group', 'update_user_group', 'update_user', 'add_user_to_group', 'rename', 'delete', 'activate' ]; -extract (sane_import ('request', - ['digits' => ['user_id', 'max_rows', 'offset']] -)); +extract (sane_import ('request', ['digits' => 'user_id'])); extract (sane_import ('post', [ 'strings' => [['action', $actions]], @@ -75,11 +73,7 @@ form_check ('update'); if (empty ($update)) $action = null; -if (empty ($max_rows)) - $max_rows = 50; - -$max_rows = intval ($max_rows); -$offset = intval ($offset); +html_nextprev_extract_params (); function contribution_nextprev ($uid, $offset, $max_rows, $total_rows) { diff --git a/frontend/php/siteadmin/userlist.php b/frontend/php/siteadmin/userlist.php index 18a0d8d8..0949f990 100644 --- a/frontend/php/siteadmin/userlist.php +++ b/frontend/php/siteadmin/userlist.php @@ -50,11 +50,12 @@ site_admin_header (['title' => no_i18n("User List"), 'context' => 'admuser']); extract (sane_import ('get', [ - 'digits' => ['offset', 'user_id', 'max_rows'], - 'specialchars' => 'text_search', 'name' => 'user_name_search' + 'digits' => 'user_id', 'specialchars' => 'text_search', + 'name' => 'user_name_search' ] )); extract (sane_import ('request', ['pass' => 'search'])); +html_nextprev_extract_params (100); $abc_array = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', @@ -76,8 +77,6 @@ print form_tag (['method' => 'get', 'name' => 'usersrch']) . form_hidden (['usersearch' => '1']) . form_submit (no_i18n ("Search")) . "\n</form>\n</p>\n"; -if (empty ($max_rows)) - $max_rows = 100; $offset = intval ($offset); $sql_fields = diff --git a/frontend/php/testing/sane.php b/frontend/php/testing/sane.php index 221d442b..9581ab86 100644 --- a/frontend/php/testing/sane.php +++ b/frontend/php/testing/sane.php @@ -291,6 +291,18 @@ $reference = 'cookbook/index.php'; test_sane_import ($in, $names, $out); } +$reference = 'bugs/dependencies.php'; +{ + $names = [ + 'strings' => [['list_format', ['default' => 'html', 'text', 'svg']]] + ]; + $in = ['include_closed' => 1, 'list_format' => 'png']; + $out = ['list_format' => 'html']; + test_sane_import ($in, $names, $out); + $in = ['include_closed' => 1, 'list_format' => 'png']; + $out = ['include_closed' => true]; +} + $reference = 'css/graph-widths.php'; { $names = ['preg' => [['widths', '/^[.,\d]+$/']]]; @@ -1106,7 +1118,7 @@ $reference = 'include/trackers_run/browse.php'; $names = [ 'digits' => [ - 'chunksz', 'offset', 'report_id', + 'report_id', ['msort', 'sumORdet', 'advsrch', 'history_search', [0, 1]], ['spamscore', [1, null]], ['history_date_yearfd', [1900, null]], @@ -1128,8 +1140,6 @@ $reference = 'include/trackers_run/browse.php'; ], ]; $in = [ - 'chunksz' => 40, - 'offset' => 83521, 'report_id' => 5, 'history_field' => 0, 'msort' => 0, @@ -2038,22 +2048,15 @@ $reference = 'search/index.php'; { $tos_values = array_merge (['soft', 'people'], utils_get_tracker_list ()); $names = [ - 'digits' => - [ 'type', 'only_group_id', ['offset', [0, 410338673]], - ['max_rows', [1, 4913]], ['exact', [0, 1]] - ], + 'digits' => ['type', 'only_group_id', ['exact', [0, 1]]], 'strings' => [['type_of_search', $tos_values]], 'pass' => 'words', ]; $in = $out = [ - 'type' => 1, 'exact' => 0, 'offset' => 2, 'max_rows' => 3, + 'type' => 1, 'exact' => 0, 'only_group_id' => 4, 'type_of_search' => 'soft', 'words' => 'w', ]; test_sane_import ($in, $names, $out); - $in['offset'] = -1; $out['offset'] = 1; - test_sane_import ($in, $names, $out); - $in['max_rows'] = 0; $out['max_rows'] = null; - test_sane_import ($in, $names, $out); } $reference = 'sendmessage.php'; @@ -2214,7 +2217,7 @@ $reference = 'siteadmin/user_changepw.php'; $reference = 'siteadmin/usergroup.php'; { $names = [ - 'digits' => ['user_id', 'max_rows', 'offset'], + 'digits' => 'user_id', 'strings' => [ [ 'action', @@ -2225,10 +2228,7 @@ $reference = 'siteadmin/usergroup.php'; ], ], ]; - $in = $out = [ - 'user_id' => 83521, 'max_rows' => 51, 'offset' => 119, - 'action' => 'delete' - ]; + $in = $out = ['user_id' => 83521, 'action' => 'delete']; test_sane_import ($in, $names, $out); $names = [ 'name' => 'new_name', @@ -2246,15 +2246,14 @@ $reference = 'siteadmin/usergroup.php'; $reference = 'siteadmin/userlist.php'; { $names = [ - 'digits' => ['offset', 'user_id'], - 'specialchars' => 'text_search', + 'digits' => 'user_id', 'specialchars' => 'text_search', 'strings' => [ ['action', ['delete', 'suspend', 'activate']], ], 'name' => 'user_name_search', ]; $in = $out = [ - 'offset' => 1, 'user_id' => 289, 'text_search' => 'text', + 'user_id' => 289, 'text_search' => 'text', 'action' => 'delete', 'user_name_search' => 'agn' ]; test_sane_import ($in, $names, $out); |