Get help button to display on pages with status updates, attempt to fix bug with nulls in filepath of bplustree, a=chris

Chris Pollett [2022-08-11 16:Aug:th]
Get help button to display on pages with status updates, attempt to fix bug with nulls in filepath of bplustree, a=chris
Filename
src/library/BPlusTree.php
src/views/CrawlstatusView.php
src/views/MachinestatusView.php
src/views/helpers/HelpbuttonHelper.php
src/views/helpers/PagingtableHelper.php
diff --git a/src/library/BPlusTree.php b/src/library/BPlusTree.php
index 19ea997e3..24008c001 100644
--- a/src/library/BPlusTree.php
+++ b/src/library/BPlusTree.php
@@ -516,8 +516,13 @@ class BPlusTree
         $keys = array_keys($node);
         sort($keys);
         $half_key = $keys[$half_num];
-        $new_leaf_filename = "$parent_folder/$node_prefix$half_key";
-        $new_archive_filename = "$parent_folder/$archive_prefix$half_key";
+        /* the str_replaces are because I was getting hard to trace crashes
+           concerning nulls in file name.
+         */
+        $new_leaf_filename = str_replace("\x00", "0",
+            "$parent_folder/$node_prefix$half_key");
+        $new_archive_filename = str_replace("\x00", "0",
+            "$parent_folder/$archive_prefix$half_key");
         $table_tools = $this->table_tools;
         $out_archive_filename = $tmp_archive_filename;
         $out_node = [];
diff --git a/src/views/CrawlstatusView.php b/src/views/CrawlstatusView.php
index eee50e9f8..f2f18fa9b 100755
--- a/src/views/CrawlstatusView.php
+++ b/src/views/CrawlstatusView.php
@@ -79,8 +79,7 @@ class CrawlstatusView extends View
         $icon_helper = $this->helper('iconlink');
         ?>
         <h1  class="home-groups-container slim"><?=
-            tl('crawlstatus_view_crawl_status')?></h1>
-        <?php
+            tl('crawlstatus_view_crawl_status')?></h1><?php
         $icon_helper->renderButton($admin_url . $csrf_string .
             '&amp;a=manageMachines', 'machines');
         $this->renderActiveCrawls($data);
@@ -387,15 +386,18 @@ class CrawlstatusView extends View
     public function renderCrawlForm($data)
     {
         $target = (empty($_REQUEST['noscript'])) ? "" : " target='_parent' ";
+        $new_crawl_help = (empty($_GET['noscript'])) ?
+            $this->helper("helpbutton")->render("New Crawl",
+            $data[C\CSRF_TOKEN], true) : "";
         ?>
-        <h2><?= tl('managecrawls_element_new_crawl') ?></h2>
+        <h2><?= tl('managecrawls_element_new_crawl') ?><?=
+        "&nbsp;" . $new_crawl_help ?></h2>
         <form id="crawlStartForm" method="get" <?=$target?> >
         <input type="hidden" name="c" value="admin" />
         <input type="hidden" name="<?= C\CSRF_TOKEN ?>" value="<?=
             $data[C\CSRF_TOKEN] ?>" />
         <input type="hidden" name="a" value="manageCrawls" />
         <input type="hidden" name="arg" value="start" />
-
         <p><label for="description-name"><?=
             tl('crawlstatus_view_description') ?></label>
             <input type="text" id="description-name"
@@ -406,12 +408,11 @@ class CrawlstatusView extends View
                 } ?>" maxlength="<?=C\TITLE_LEN ?>" class="wide-field" />
             <button class="button-box" type="submit"><?=
                 tl('crawlstatus_view_start') ?></button>
+
             <a <?=$target ?> href="?c=admin&amp;a=manageCrawls<?php
                 ?>&amp;arg=options&amp;<?=
                 C\CSRF_TOKEN . "=" . $data[C\CSRF_TOKEN] ?>"><?=
-                tl('crawlstatus_view_options') ?></a><?=
-                "&nbsp;" .$this->helper("helpbutton")->render(
-                "New Crawl", $data[C\CSRF_TOKEN]) ?>
+                tl('crawlstatus_view_options') ?></a>
         </p>
         </form><?php
     }
diff --git a/src/views/MachinestatusView.php b/src/views/MachinestatusView.php
index 914a1373d..7be260356 100644
--- a/src/views/MachinestatusView.php
+++ b/src/views/MachinestatusView.php
@@ -85,10 +85,13 @@ class MachinestatusView extends View
         tl('machinestatus_view_machine_statuses')?></h1>
         <?=
         $icon_helper->renderButton($admin_url . $csrf_token .
-            '&amp;a=manageCrawls', "crawls");?>
-        <h2><?=tl('machinestatus_view_media_updater'). "&nbsp;" .
+            '&amp;a=manageCrawls', "crawls");
+        $media_updater_help = (empty($_GET['noscript'])) ?
             $this->helper("helpbutton")->render(
-            "Media Updater", $data[C\CSRF_TOKEN]) ?></h2>
+            "Media Updater", $data[C\CSRF_TOKEN], true) : "";
+        ?>
+        <h2><?=tl('machinestatus_view_media_updater'). "&nbsp;" .
+            $media_updater_help ?></h2>
         <div class="no-margin">&nbsp;[<a <?=$target
             ?> href="<?=$base_url . 'mediajobs'
             ?>"><?= tl('machinestatus_view_media_jobs'); ?>]</a>
@@ -118,10 +121,15 @@ class MachinestatusView extends View
         </form>
         </div>
         <?php
+        $machine_info_help = (empty($_GET['noscript'])) ?
+            $this->helper("helpbutton")->render(
+            "Machine Information", $data[C\CSRF_TOKEN], true) : "";
+        $manage_machines_help = (empty($_GET['noscript'])) ?
+            $this->helper("helpbutton")->render(
+            "Manage Machines", $data[C\CSRF_TOKEN], true) : "";
         if (count($data['MACHINES']) >= 1) {
-        $data['TABLE_TITLE'] = tl('machinestatus_view_machines') .
-             $this->helper("helpbutton")->render(
-                 "Machine Information", $data[C\CSRF_TOKEN]);
+            $data['TABLE_TITLE'] = tl('machinestatus_view_machines');
+            $data['TABLE_TITLE_HELP'] = $machine_info_help;
             $data['ACTIVITY'] = 'manageMachines';
             $data['VIEW'] = $this;
             $data['TOGGLE_ID'] = 'add-machine-form';
@@ -132,8 +140,7 @@ class MachinestatusView extends View
         } ?>
         <div id='add-machine-form' class='box'>
         <h2><?= tl('machinestatus_view_add_machine') . "&nbsp;" .
-            $this->helper("helpbutton")->render(
-                "Manage Machines", $data[C\CSRF_TOKEN]) ?></h2>
+            $manage_machines_help ?></h2>
         <form <?=$target ?> id="name-form" method="post">
         <input type="hidden" name="c" value="admin" />
         <input type="hidden" name="<?= C\CSRF_TOKEN ?>" value="<?=
diff --git a/src/views/helpers/HelpbuttonHelper.php b/src/views/helpers/HelpbuttonHelper.php
index d846e7bdc..fbd2bd044 100644
--- a/src/views/helpers/HelpbuttonHelper.php
+++ b/src/views/helpers/HelpbuttonHelper.php
@@ -81,7 +81,7 @@ class HelpbuttonHelper extends Helper
      * @param  $csrf_token_value  CSRF token to make api call/open edit link
      * @return String button html.
      */
-    public function render($help_point_id, $csrf_token_value)
+    public function render($help_point_id, $csrf_token_value, $as_html=false)
     {
         if ($this->is_help_initialized == false) {
             $this->setupHelpParams();
@@ -91,22 +91,32 @@ class HelpbuttonHelper extends Helper
         $api_controller = "api";
         $api_wiki_action = "wiki";
         $api_wiki_mode = "read";
+        $activity = $this->clean($_REQUEST['a'], 'string');
+        if ($activity == 'machineStatus') {
+            $activity = 'manageMachines';
+        } else if ($activity == 'crawlStatus') {
+            $activity = 'manageCrawls';
+        }
         $button_string = '<button type="button"
             class="help-button default"
             data-tl=\'' . $this->localization_data . '\'
             data-back-params=\'' . $this->back_params . '\'
             onclick="javascript:displayHelpForId(this,'
             . $is_mobile . ',\''
-            . $this->clean($_REQUEST['c']) . '\',\''
-            . $this->clean($_REQUEST['a']) . '\',\''
+            . $this->clean($_REQUEST['c'], 'string') . '\',\''
+            . $activity . '\',\''
             . C\CSRF_TOKEN . '\',\''
             . $csrf_token_value . "','$wiki_group_id','$api_controller',"
             . "'$api_wiki_action','$api_wiki_mode" . '\')" '
             . 'data-pagename="' . $help_point_id . '"> '
             . tl('helpbutton_helper_question_mark') . '</button>';
-        $button_string = "<script>\n" .
-            "document.write(" .json_encode($button_string) .");\n" .
-            "</script>";
+        if ($as_html) {
+            return $button_string;
+        } else {
+            $button_string = "<script>\n" .
+                "document.write(" .json_encode($button_string) .");\n" .
+                "</script>";
+        }
         return $button_string;
     }
     /**
@@ -158,6 +168,7 @@ class HelpbuttonHelper extends Helper
          * this ensures that the user can come back to the exact same url
          * he originated from.
          */
+
         $back_params_array = array_diff_key($_GET, array_flip(
             ["a", "c", C\CSRF_TOKEN, "open_help_page", "KWIKI_PAGE",
                 "modify_add"]
diff --git a/src/views/helpers/PagingtableHelper.php b/src/views/helpers/PagingtableHelper.php
index e88070c14..93bbf8ddf 100644
--- a/src/views/helpers/PagingtableHelper.php
+++ b/src/views/helpers/PagingtableHelper.php
@@ -336,6 +336,9 @@ class PagingtableHelper extends Helper
             </script>
             <?php
         }
+        if (!empty($data['TABLE_TITLE_HELP'])) {
+            e("&nbsp;".$data['TABLE_TITLE_HELP']);
+        }
         ?>
         </h2><?php
     }
ViewGit