_binary From 5da1695d0a53cee5e700bbc3e04eaa049e043554 Mon Sep 17 00:00:00 2001
From: epinapala <epinapala@ebay.com>
Date: Tue, 11 Nov 2014 19:22:31 -0800
Subject: [PATCH 1/3] * Database upgrade to V26 * Fixes Helppages in database
 to work with recent changes of using %20 <-> _ . * Also updated createdb.php
 & default.db with new articles * Tested on versions <=24 & 25

Signed-off-by: epinapala <epinapala@ebay.com>
---
 configs/config.php        |   2 +-
 configs/createdb.php      |  85 ++++++++++++++++++++++++++++++++++++++++++++++
 data/default.db           | Bin 128000 -> 142336 bytes
 lib/upgrade_functions.php |  46 ++++++++++++++++++++++++-
 4 files changed, 131 insertions(+), 2 deletions(-)

diff --git a/configs/config.php b/configs/config.php
index 91a3e7a..37f5def 100755
--- a/configs/config.php
+++ b/configs/config.php
@@ -37,7 +37,7 @@ if(!defined('BASE_DIR') ||
 /** Version number for upgrade function
  * @var int
  */
-define('YIOOP_VERSION', 25);
+define('YIOOP_VERSION', 26);
 /*
     pcre is an external library to php which can cause Yioop
     to seg fault if given instances of reg expressions with
diff --git a/configs/createdb.php b/configs/createdb.php
index 442670a..b4d2410 100755
--- a/configs/createdb.php
+++ b/configs/createdb.php
@@ -699,6 +699,91 @@ The access to a group can be changed by the owner after a group is created.
 * <u>Read</u> and <u>Read Comment</u> groups are often suitable if someone wants to use a Yioop Group as a blog.
 * <u>Read</u> Write makes sense for a more traditional bulletin board.
 EOD;
+$help_pages["Create_Group"] = <<<EOD
+page_type=standard
+
+page_border=solid-border
+
+title=Create Group
+
+END_HEAD_VARS''You will get to this form when the Group Name is available to create a new Group. ''
+----
+
+'''Name''' Field is used to specify the name of the new Group.
+<br />
+'''Register''' dropdown says how other users are allowed to join the group:
+* <u>No One</u> means no other user can join the group (you can still invite other users).
+* <u>By Request</u> means that other users can request the group owner to join the group.
+* <u>Anyone</u> means all users are allowed to join the group.
+<br />
+The '''Access''' dropdown controls how users who belong/subscribe to a group other than the owner can access that group.
+* <u>No Read</u> means that a non-owner member of the group cannot read or write the group news feed and cannot read the group wiki.
+* <u>Read</u> means that a non-owner member of the group can read the group news feed and the groups wiki page.
+* <u>Read</u> Comment means that a non-owner member of the group can read the group feed and wikis and can comment on any existing threads, but cannot start new ones.
+* <u>Read Write</u>, means that a non-owner member of the group can start new threads and comment on existing ones in the group feed and can edit and create wiki pages for the group's wiki.
+'''Voting'''
+* Specify the kind of voting allowed in the new group. + Voting allows users to vote up, -Voting allows users to vote down. +/- allows Voting up and down.
+'''Post Life time''' - Specifies How long the posts should be kept.
+EOD;
+$help_pages["Captcha_Type"] = <<<EOD
+page_type=standard
+
+page_border=solid-border
+
+title=Captcha Type
+
+END_HEAD_VARSThe Captcha Type field set controls what kind of [[https://en.wikipedia.org/wiki/CAPTCHA|captcha]] will be used during account registration, password recovery, and if a user wants to suggest a url.
+
+* The choices for captcha are:
+** '''Text Captcha''', the user has to select from a series of dropdown answers to questions of the form: ''Which in the following list is the most/largest/etc? or Which is the following list is the least/smallest/etc?; ''
+** '''Graphic Captcha''', the user needs to enter a sequence of characters from a distorted image;
+** '''Hash captcha''', the user's browser (the user doesn't need to do anything) needs to extend a random string with additional characters to get a string whose hash begins with a certain lead set of characters.
+
+- Of these, Hash Captcha is probably the least intrusive but requires Javascript and might run slowly on older browsers. A text captcha might be used to test domain expertise of the people who are registering for an account. Finally, the graphic captcha is probably the one people are most familiar with.
+EOD;
+$help_pages["Authentication_Type"] = <<<EOD
+page_type=standard
+
+page_border=solid-border
+
+title=Authentication Type
+
+END_HEAD_VARSThe Authentication Type field-set is used to control the protocol used to log people into Yioop.
+
+* Below is a list of Authentication types supported.
+** '''Normal Authentication''', passwords are checked against stored as salted hashes of the password; or
+** '''ZKP (zero knowledge protocol) authentication''', the server picks challenges at random and send these to the browser the person is logging in from, the browser computes based on the password an appropriate response according to the Fiat Shamir protocol.cThe password is never sent over the internet and is not stored on the server. These are the main advantages of ZKP, its drawback is that it is slower than Normal Authentication as to prove who you are with a low probability of error requires several browser-server exchanges.
+
+* You should choose which authentication scheme you want before you create many users as if you switch everyone will need to get a new password.
+EOD;
+$help_pages["Account_Registration"] = <<<EOD
+page_type=standard
+
+page_border=solid-border
+
+title=Account Registration
+
+END_HEAD_VARSThe Account Registration field-set is used to control how user's can obtain accounts on a Yioop installation.
+
+* The dropdown at the start of this fieldset allows you to select one of four possibilities:
+** '''Disable Registration''', users cannot register themselves, only the root account can add users.
+*** When Disable Registration is selected, the Suggest A Url form and link on the tool.php page is disabled as well, for all other registration type this link is enabled.
+** '''No Activation''', user accounts are immediately activated once a user signs up.
+** '''Email Activation''', after registering, users must click on a link which comes in a separate email to activate their accounts.
+*** If Email Activation is chosen, then the reset of this field-set can be used to specify the email address that the email comes to the user. The checkbox Use PHP mail() function controls whether to use the mail function in PHP to send the mail, this only works if mail can be sent from the local machine. Alternatively, if this is not checked like in the image above, one can configure an outgoing SMTP server to send the email through.
+** '''Admin Activation''', after registering, an admin account must activate the user before the user is allowed to use their account.
+EOD;
+$help_pages["Proxy_server"] = <<<EOD
+page_type=standard
+
+page_border=solid-border
+
+title=Proxy server
+
+END_HEAD_VARS* The Proxy Server field-set is used to control which proxies to use while crawling. By default Yioop does not use any proxies while crawling. A Tor Proxy can serve as a gateway to the Tor Network. Yioop can use this proxy to download .onion URLs on the [[https://en.wikipedia.org/wiki/Tor_%28anonymity_network%29|Tor network]].
+
+* Obviously, this proxy needs to be running though for Yioop to make use of it. Beneath the Tor Proxy input field is a checkbox labelled '''Crawl via Proxies'''. Checking this box, will reveal a text-area labelled Proxy Servers. You can enter the '''''address:port or address:port:proxytype''''' of proxy servers you would like to crawl through. If proxy servers are used, Yioop will make any requests to download pages to a randomly chosen server on the list which will proxy the request to the site which has the page to download. To some degree this can make the download site think the request is coming from a different ip (and potentially location) than it actually is. In practice, servers can often use HTTP headers to guess that a proxy is being used.
+EOD;
 //Insert Help pages
 foreach($help_pages as $page_name => $page_content) {
     $page_content = str_replace("&amp;", "&", $page_content);
diff --git a/data/default.db b/data/default.db
index c4042b8e736d53a2511af7b97bc085902d4ec24d..ee2f8a628da9a05b9fecb2292362fd8b8bbc792f 100644
GIT binary patch
diff --git a/lib/upgrade_functions.php b/lib/upgrade_functions.php
index 68ddd9f..fd72626 100644
--- a/lib/upgrade_functions.php
+++ b/lib/upgrade_functions.php
@@ -919,7 +919,51 @@ function upgradeDatabaseVersion25(&$db)
             . "Help Page Created!", "Discuss the page in this thread!");
     }
 }
-
+/**
+ * Upgrades a Version 25 version of the Yioop! database to a Version 26 version
+ * This version upgrade includes updation fo the Help pages in the database to
+ * work with the changes to the way Hyperlinks are specified in wiki markup.
+ * The changes were implemented to point all articles with page names
+ * containing %20 to be able to work with '_' and vice versa.
+ * @param object $db data source to use to upgrade
+ */
+function upgradeDatabaseVersion26(&$db){
+    /** For reading HELP_GROUP_ID**/
+    require_once BASE_DIR . "/configs/config.php";
+    /** For GroupModel::setPageName method */
+    require_once BASE_DIR . "/models/group_model.php";
+    $db->execute("DELETE FROM VERSION WHERE ID < 25");
+    $db->execute("UPDATE VERSION SET ID=26 WHERE ID=25");
+    //Delete all existing pages in Help group
+    $params = array(HELP_GROUP_ID);
+    $sql = "DELETE FROM GROUP_PAGE WHERE GROUP_ID=?";
+    $db->execute($sql, $params);
+    $sql = "DELETE FROM GROUP_PAGE_HISTORY WHERE GROUP_ID=?";
+    $db->execute($sql, $params);
+    //Insert the Help Group pages with corrected titles
+    $creation_time = microTimestamp();
+    $sql = "INSERT INTO GROUPS VALUES(" . HELP_GROUP_ID . ",'Help','"
+        . $creation_time . "','" . ROOT_ID . "',
+        '" . PUBLIC_BROWSE_REQUEST_JOIN . "', '" . GROUP_READ_WIKI . "',
+        " . UP_DOWN_VOTING_GROUP . ", " . FOREVER . ")";
+    $db->execute($sql);
+    $now = time();
+    $db->execute("INSERT INTO USER_GROUP VALUES (" . ROOT_ID . ", " .
+        HELP_GROUP_ID . ", " . ACTIVE_STATUS . ", $now)");
+    $db->execute("INSERT INTO USER_GROUP VALUES (" . PUBLIC_USER_ID . ", " .
+        HELP_GROUP_ID . ", " . ACTIVE_STATUS . ", $now)");
+    //Insert into Groups
+    $help_pages = getWikiHelpPages();
+    foreach($help_pages as $page_name => $page_content) {
+        $page_content = str_replace("&amp;", "&", $page_content);
+        $page_content = @htmlentities($page_content, ENT_QUOTES, "UTF-8");
+        $group_model = new GroupModel(DB_NAME, false);
+        $group_model->db = $db;
+        $group_model->setPageName(ROOT_ID, HELP_GROUP_ID, $page_name,
+            $page_content, "en-US", "Creating Default Pages", "$page_name "
+            . "Help Page Created!", "Discuss the page in this thread!");
+    }
+}
 /**
  * Reads the Help articles from default db and returns the array of pages.
  */
-- 
1.9.3 (Apple Git-50)


From 7a7a2e37b33275a5da4bf2860500ff4e1280f933 Mon Sep 17 00:00:00 2001
From: epinapala <epinapala@ebay.com>
Date: Tue, 11 Nov 2014 19:33:01 -0800
Subject: [PATCH 2/3] * Add Help Elements for newly added help. * Remove param
 'c' where its not needed for rendering help button.

Signed-off-by: epinapala <epinapala@ebay.com>
---
 views/elements/managegroups_element.php   |  6 +++++-
 views/elements/managelocales_element.php  |  4 +++-
 views/elements/security_element.php       |  4 ++++
 views/elements/serversettings_element.php | 14 +++++++++++---
 views/helpers/searchform_helper.php       |  2 --
 5 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/views/elements/managegroups_element.php b/views/elements/managegroups_element.php
index f2810c1..ec88481 100755
--- a/views/elements/managegroups_element.php
+++ b/views/elements/managegroups_element.php
@@ -291,7 +291,9 @@ class ManagegroupsElement extends Element
                 tl('managegroups_element_addgroup_form')."</a></div>");
             e("<h2>".tl('managegroups_element_group_info'). "</h2>");
         } else if($creategroup) {
-            e("<h2>".tl('managegroups_element_create_group'). "</h2>");
+            e("<h2>".tl('managegroups_element_create_group'));
+            e("&nbsp;" . $this->view->helper("helpbutton")->render(
+            "Create Group", $data[CSRF_TOKEN]). "</h2>");
         } else {
             e("<h2>".tl('managegroups_element_add_group'). "</h2>");
         }
@@ -612,6 +614,8 @@ class ManagegroupsElement extends Element
         $view = $this->view;
         if(isset($data['browse'])) {
             $title = tl('managegroups_element_discover_groups');
+            $title .= "&nbsp;" . $view->helper("helpbutton")->render(
+            "Discover Groups", $data[CSRF_TOKEN]);
         } else {
             $title = tl('managegroups_element_search_group');
         }
diff --git a/views/elements/managelocales_element.php b/views/elements/managelocales_element.php
index 01952a3..91aec8b 100644
--- a/views/elements/managelocales_element.php
+++ b/views/elements/managelocales_element.php
@@ -135,7 +135,7 @@ class ManagelocalesElement extends Element
             e("<h2>".tl('managelocales_element_add_locale'). "&nbsp;");
         }
         e($this->view->helper("helpbutton")->render(
-            "Add Locale", $data[CSRF_TOKEN],$_REQUEST['c']));
+            "Add Locale", $data[CSRF_TOKEN]));
         e("</h2>");
         ?>
         <form id="addLocaleForm" method="post">
@@ -178,6 +178,8 @@ class ManagelocalesElement extends Element
                         "writing-mode", "writingmode",
                         $data['WRITING_MODES'],
                         $data['CURRENT_LOCALE']['writingmode']); ?>
+            <?php e($this->view->helper("helpbutton")->render(
+                "Locale Writing Mode", $data[CSRF_TOKEN])); ?>
             </td>
             </tr>
             <tr><th><label for="locale-active"><?php
diff --git a/views/elements/security_element.php b/views/elements/security_element.php
index 261696f..cd9dedb 100755
--- a/views/elements/security_element.php
+++ b/views/elements/security_element.php
@@ -67,6 +67,8 @@ class SecurityElement extends Element
                 <legend><label
                 for="authentication-mode"><b><?php
                 e(tl('security_element_authentication_type'));
+                e("&nbsp;" . $this->view->helper("helpbutton")->render(
+                            "Authentication Type", $data[CSRF_TOKEN]))
                 ?>
                 </label></b></legend>
                     <?php $this->view->helper("options")->render(
@@ -86,6 +88,8 @@ class SecurityElement extends Element
                 <legend><label
                 for="captcha-mode"><b><?php
                 e(tl('security_element_captcha_type'));
+                e("&nbsp;" . $this->view->helper("helpbutton")->render(
+                            "Captcha Type", $data[CSRF_TOKEN]))
                 ?></b>
                 </label></legend>
                 <?php
diff --git a/views/elements/serversettings_element.php b/views/elements/serversettings_element.php
index 5b9949e..9e5fdf7 100644
--- a/views/elements/serversettings_element.php
+++ b/views/elements/serversettings_element.php
@@ -107,7 +107,10 @@ class ServersettingsElement extends Element
             </div>
             <div class="top-margin">
             <fieldset><legend><?php
-                e(tl('configure_element_database_setup'))?></legend>
+                e(tl('configure_element_database_setup'));
+                e("&nbsp;" .$this->view->helper("helpbutton")->render(
+                        "Database Setup", $data[CSRF_TOKEN]));?>
+                </legend>
                 <div ><label for="database-system"><b><?php
                     e(tl('serversettings_element_database_system'));
                     ?></b></label>
@@ -150,6 +153,8 @@ class ServersettingsElement extends Element
                 <legend><label
                 for="account-registration"><?php
                 e(tl('serversettings_element_account_registration'));
+                e("&nbsp;" .$this->view->helper("helpbutton")->render(
+                        "Account Registration", $data[CSRF_TOKEN]));
                 ?>
                 </label></legend>
                     <?php $this->view->helper("options")->render(
@@ -208,9 +213,12 @@ class ServersettingsElement extends Element
             </div>
             <div class="top-margin">
             <fieldset><legend><?php
-                e(tl('serversettings_element_proxy_title'))?></legend>
+                e(tl('serversettings_element_proxy_title'));
+                e("&nbsp;" .$this->view->helper("helpbutton")->render(
+                        "Proxy server", $data[CSRF_TOKEN]));
+                ?></legend>
                 <div ><b><label for="tor-proxies"><?php
-                    e(tl('serversettings_element_tor_proxy'))?></label></b>
+                    e(tl('serversettings_element_tor_proxy'));?></label></b>
                     <input type="text" id="tor-proxies" name="TOR_PROXY"
                         value="<?php e($data['TOR_PROXY']); ?>"
                         class="wide-field" />
diff --git a/views/helpers/searchform_helper.php b/views/helpers/searchform_helper.php
index da96dd5..4b05cf2 100644
--- a/views/helpers/searchform_helper.php
+++ b/views/helpers/searchform_helper.php
@@ -77,8 +77,6 @@ class SearchformHelper extends Helper
         e("<div class='float-opposite'><a href='$old_base_url'>".
             $return_form_name."</a></div>");
         e("<h2>$title" . "&nbsp;");
-        e($view->helper("helpbutton")->render(
-            "Discover Groups", $data[CSRF_TOKEN]));
         e("</h2>");
         $item_sep = (MOBILE) ? "<br />" : "</td><td>";
         ?>
-- 
1.9.3 (Apple Git-50)


From 7f50583742fcce8362d25eecb16afc5b99a4c916 Mon Sep 17 00:00:00 2001
From: epinapala <epinapala@ebay.com>
Date: Tue, 11 Nov 2014 20:32:13 -0800
Subject: [PATCH 3/3] * WikiHelpBackLogic cleanup * This fix Removes
 setupWikiHelpBackLogic method from controller.php preventing the method to be
 executed every time controller is loaded. * The first part of the contents of
 setupWikiHelpBackLogic are now moved to SocialComponent::wiki(). This ensures
 that the back-params/Back_url is set only when wiki action is executed, and
 in-turn only for read/edit args. * The second part of the contents of
 setupWikiHelpBackLogic, which are responsible for opening the help article
 automatically when 'open_help_page' Request param is set, is now moved to a
 setupParams method in help-button helper. This ensures that this logic is
 executed only when a help-button is loaded on the page, and that too only
 once. * Other $_REQUEST cleanup fixes.

Signed-off-by: epinapala <epinapala@ebay.com>
---
 controllers/components/social_component.php | 47 ++++++++++++----
 controllers/controller.php                  | 49 ----------------
 views/helpers/helpbutton_helper.php         | 86 ++++++++++++++++++-----------
 views/layouts/web_layout.php                |  6 ++
 4 files changed, 95 insertions(+), 93 deletions(-)

diff --git a/controllers/components/social_component.php b/controllers/components/social_component.php
index 8a682b0..1e77be9 100644
--- a/controllers/components/social_component.php
+++ b/controllers/components/social_component.php
@@ -719,12 +719,14 @@ class SocialComponent extends Component implements CrawlConstants
         }
         $possible_arguments = array("addcomment", "deletepost", "addgroup",
             "newthread", "updatepost", "status", "upvote", "downvote");
-        if (isset($_REQUEST['v']) && $_REQUEST['v'] == 'grouped') {
-            $data['MODE'] = 'grouped';
-            if(isset($_REQUEST['just_group_id'])){
-            $data['JUST_GROUP_ID'] = $_REQUEST['just_group_id'];
-            }
-            if (isset($_REQUEST['limit'])) {
+        if (isset($_REQUEST['v'])) {
+            $view = $parent->clean($_REQUEST['v'], "string");
+            if ($view == 'grouped') {
+                $data['MODE'] = 'grouped';
+                if (isset($_REQUEST['just_group_id'])) {
+                    $data['JUST_GROUP_ID'] = $_REQUEST['just_group_id'];
+                }
+                if (isset($_REQUEST['limit'])) {
                 $limit = $parent->clean($_REQUEST['limit'], "int");
             } else {
                 $limit = 0;
@@ -763,12 +765,12 @@ class SocialComponent extends Component implements CrawlConstants
                 }
             }
             $data['NUM_SHOWN'] = $num_shown;
-            $data['LIMIT'] = $limit;
-            $data['RESULTS_PER_PAGE'] = $results_per_page;
-            $data['PAGING_QUERY'] = "./?c=$controller_name&amp;a=groupFeeds";
-            $data['OTHER_PAGING_QUERY'] =
-                "./?c=$other_controller_name&amp;a=groupFeeds";
-            return $data;
+                $data['LIMIT'] = $limit;
+                $data['RESULTS_PER_PAGE'] = $results_per_page;
+                $data['PAGING_QUERY'] = "./?c=$controller_name&amp;a=groupFeeds";
+                $data['OTHER_PAGING_QUERY'] = "./?c=$other_controller_name&amp;a=groupFeeds";
+                return $data;
+            }
         }
         if(isset($_REQUEST['arg']) &&
             in_array($_REQUEST['arg'], $possible_arguments)) {
@@ -1749,6 +1751,27 @@ EOD;
                 $this->initializeWikiEditor($data);
             }
         }
+       /** Check if back params need to be set. Set them if required.
+        * the back params are usually sent when the wiki action is initiated
+        * from within an open help article.
+        */
+        $data["OTHER_BACK_URL"] = "";
+            if(isset($_REQUEST['back_params']) &&
+                isset($_REQUEST['arg']) && in_array(
+                    $parent->clean($_REQUEST['arg'],"string"), array('edit',
+                    'read'))) {
+                $back_params_cleaned = $_REQUEST['back_params'];
+                array_walk($back_params_cleaned, array($parent, 'clean'));
+                foreach($back_params_cleaned as
+                        $back_param_key => $back_param_value) {
+                    $data['BACK_PARAMS']["back_params[$back_param_key]"]
+                        = $back_param_value;
+                    $data["OTHER_BACK_URL"] .=
+                        "&amp;back_params[$back_param_key]" . "=" .
+                        $back_param_value;
+                }
+                $data['BACK_URL'] = http_build_query($back_params_cleaned);
+            }
         return $data;
     }
     /**
diff --git a/controllers/controller.php b/controllers/controller.php
index 3a177cb..fb5e90d 100755
--- a/controllers/controller.php
+++ b/controllers/controller.php
@@ -259,7 +259,6 @@ abstract class Controller
             $data['DISPLAY_MESSAGE'] = $_SESSION['DISPLAY_MESSAGE'];
             unset($_SESSION['DISPLAY_MESSAGE']);
         }
-        $data = array_merge($data, $this->setupWikiHelpBackLogic());
         $this->view($view)->render($data);
     }
     /**
@@ -287,54 +286,6 @@ abstract class Controller
         exit();
     }
     /**
-     * This is a helper method that sets proper data vars required to perform
-     * Back page logic when the user is navigating from help article to edit
-     * page,and then back to help article.
-     *
-     * @param type $data to add data vars
-     * @return string $data
-     */
-    function setupWikiHelpBackLogic()
-    {
-        $data = array();
-        $data["OTHER_BACK_URL"] = "";
-        if(isset($_REQUEST['a'])) {
-            $action = $this->clean($_REQUEST['a'], "string");
-            if($action == 'wiki' && isset($_REQUEST['back_params']) &&
-                isset($_REQUEST['arg']) && in_array(
-                    $this->clean($_REQUEST['arg'],"string"), array('edit',
-                    'read'))) {
-                foreach($_REQUEST['back_params'] as
-                        $back_param_key => $back_param_value) {
-                    $back_param_key = $this->clean($back_param_key, "string");
-                    $back_param_value = $this->clean($back_param_value,
-                        "string");
-                    $data['BACK_PARAMS']["back_params[$back_param_key]"]
-                        = $back_param_value;
-                    $data["OTHER_BACK_URL"] .=
-                        "&amp;back_params[$back_param_key]" . "=" .
-                        $back_param_value;
-                }
-                $data['BACK_URL'] = http_build_query($_REQUEST["back_params"]);
-            }
-        }
-        if(isset($_REQUEST['open_help_page'])) {
-            $data['OPEN_HELP_PAGE'] = $this->clean($_REQUEST['open_help_page'],
-                "string");
-            if(!isset($data['SCRIPT'])) {
-                $data['SCRIPT'] = "";
-            }
-            $data['SCRIPT'] .= "\n" .
-                'var matches = '
-                . 'document.querySelectorAll(\'[data-pagename="'
-                . $data['OPEN_HELP_PAGE']
-                . '"]\');'
-                . "matches[0].click();"
-                . "\n";
-        }
-        return $data;
-    }
-    /**
      * When an activity involves displaying tabular data (such as rows of
      * users, groups, etc), this method might be called to set up $data
      * fields for next, prev, and page links, it also makes the call to the
diff --git a/views/helpers/helpbutton_helper.php b/views/helpers/helpbutton_helper.php
index 993606c..519f01e 100644
--- a/views/helpers/helpbutton_helper.php
+++ b/views/helpers/helpbutton_helper.php
@@ -55,6 +55,7 @@ class HelpbuttonHelper extends Helper
         $this->isHelpInitialized = false;
         $this->localizationdata = NULL;
         $this->backParams = NULL;
+        $this->script = NULL;
         parent::__construct();
     }
     /**
@@ -68,27 +69,8 @@ class HelpbuttonHelper extends Helper
      */
     public function render($help_point_id, $csrf_token_value)
     {
-        if ($this->isHelpInitialized == false) {
-            //Set only once.
-            $this->isHelpInitialized = true;
-            $this->localizationdata = "{" .
-                    'wiki_view_edit :"' . tl('wiki_view_edit') . '",' .
-                    'wiki_view_read :"' . tl('wiki_view_read') . '"' .
-                    "}";
-            $this->backParams = "{";
-            $back_params_array = array_diff_key($_REQUEST, array_flip(
-                array("a", "c", "u", "p", CSRF_TOKEN, "open_help_page")
-            ));
-            array_walk($back_params_array, array($this, 'clean'));
-            $back_params_only_keys = array_keys($back_params_array);
-            $last_key = end($back_params_only_keys);
-            foreach ($back_params_array as $key => $value) {
-                $this->backParams .= $key . ' : "' . $value . '"';
-                if ($key != $last_key) {
-                    $this->backParams .= ',';
-                }
-            }
-            $this->backParams .= "}";
+        if($this->isHelpInitialized == false) {
+            $this->setupHelpParams();
         }
         $is_mobile = MOBILE ? "true" : "false";
         $wiki_group_id = HELP_GROUP_ID;
@@ -100,14 +82,14 @@ class HelpbuttonHelper extends Helper
                     data-tl=\'' . $this->localizationdata . '\'
                     data-back-params=\'' . $this->backParams . '\'
                     onclick="javascript:displayHelpForId(this,'
-                . $is_mobile . ',\''
-                . $_REQUEST['c'] . '\',\''
-                . $_REQUEST['a'] . '\',\''
-                . CSRF_TOKEN . '\',\''
-                . $csrf_token_value . "','$wiki_group_id','$api_controller',"
-                . "'$api_wiki_action','$api_wiki_mode" . '\')" '
-                . 'data-pagename="' . $help_point_id . '"> '
-                . tl('wiki_question_mark') . '</button>';
+        . $is_mobile . ',\''
+        . $this->clean($_REQUEST['c']) . '\',\''
+        . $this->clean($_REQUEST['a']) . '\',\''
+        . CSRF_TOKEN . '\',\''
+        . $csrf_token_value . "','$wiki_group_id','$api_controller',"
+        . "'$api_wiki_action','$api_wiki_mode" . '\')" '
+        . 'data-pagename="' . $help_point_id . '"> '
+        . tl('wiki_question_mark') . '</button>';
     }
     /**
      * Used to clean strings that might be tainted as originate from the user
@@ -118,14 +100,54 @@ class HelpbuttonHelper extends Helper
      *     or -1 you would still get a Notice.
      * @return string the clean input matching the type provided
      */
-    private function clean($value, $default = NULL) {
-        if (isset($value)) {
+    private function clean($value, $default = NULL)
+    {
+        $clean_value = NULL;
+        if(isset($value)) {
             $value2 = str_replace("&amp;", "&", $value);
             $clean_value = @htmlentities($value2, ENT_QUOTES, "UTF-8");
         } else {
             $clean_value = $default;
         }
+        return $clean_value;
+    }
+    /**
+     * This Helper method is used to setup params needed for Context-Sensitive
+     * help to work. This gets executed if there is atleast one help button
+     * rendered on the page. This is executed only once with the help of
+     * "isHelpInitialized" variable.
+     *
+     */
+    private function setupHelpParams()
+    {
+        $this->isHelpInitialized = true;
+        $this->localizationdata = "{" .
+            'wiki_view_edit :"' . tl('wiki_view_edit') . '",' .
+            'wiki_view_read :"' . tl('wiki_view_read') . '"' .
+            "}";
+        $this->backParams = "{";
+        $back_params_array = array_diff_key($_REQUEST, array_flip(
+            array("a", "c", "u", "p", CSRF_TOKEN, "open_help_page")
+        ));
+        array_walk($back_params_array, array($this, 'clean'));
+        $back_params_only_keys = array_keys($back_params_array);
+        $last_key = end($back_params_only_keys);
+        foreach($back_params_array as $key => $value) {
+            $this->backParams .= $key . ' : "' . $value . '"';
+            if($key != $last_key) {
+                $this->backParams .= ',';
+            }
+        }
+        $this->backParams .= "}";
+        if(isset($_REQUEST['open_help_page'])) {
+            $help_page_to_open = $this->clean($_REQUEST['open_help_page']);
+            $this->script = 'var matches = '
+                . 'document.querySelectorAll(\'[data-pagename="'
+                . $help_page_to_open
+                . '"]\');' . "\n\t\t"
+                . "matches[0].click();"
+                . "\n";
+        }
     }
-
 }
 ?>
\ No newline at end of file
diff --git a/views/layouts/web_layout.php b/views/layouts/web_layout.php
index 1105cab..396860b 100755
--- a/views/layouts/web_layout.php
+++ b/views/layouts/web_layout.php
@@ -241,6 +241,12 @@ class WebLayout extends Layout
 
             $data["INCLUDE_SCRIPTS"][] = "help";
         }
+        if($this->view->helper('helpbutton')->script){
+            if(!isset($data['SCRIPT'])) {
+                $data['SCRIPT'] = "";
+            }
+            $data['SCRIPT'] .= $this->view->helper('helpbutton')->script;
+        }
         if(isset($data['INCLUDE_SCRIPTS'])) {
             foreach($data['INCLUDE_SCRIPTS'] as $script_name) {
                 if($script_name == "math") {
-- 
1.9.3 (Apple Git-50)

