_binary From c0d44457b1ec3b8774039484312bcf0d776abf42 Mon Sep 17 00:00:00 2001
From: epinapala <epinapala@ebay.com>
Date: Fri, 19 Dec 2014 12:02:03 -0800
Subject: [PATCH] - Add "Edit" functionality to new articles not existing but
 added to help buttons. - More changes to access control. - refactor createdb
 for easy insertions of doc urls.

---
 configs/createdb.php                | 71 ++++++++++++++++---------------------
 scripts/help.js                     | 30 +++++++++++++---
 views/elements/api_element.php      |  6 ++--
 views/helpers/helpbutton_helper.php |  4 +++
 4 files changed, 63 insertions(+), 48 deletions(-)

diff --git a/configs/createdb.php b/configs/createdb.php
index 04648de..acbf323 100755
--- a/configs/createdb.php
+++ b/configs/createdb.php
@@ -549,6 +549,7 @@ foreach($public_pages as $page_name => $page_content) {
         "$page_name Wiki Page Created!", "Discuss the page in this thread!");
 }
 $help_pages = array();
+$docUrl = "https://www.seekquarry.com/?c=static&p=Documentation";
 $help_pages["Add_Locale"] = <<<EOD
 page_type=standard
 
@@ -652,61 +653,51 @@ text direction of a locale.
 * Finally, clicking the Delete link let&amp;#039;s one delete a locale and all
 its strings.
 EOD;
+$docLink = "#Managing%20Users,%20Roles,%20and%20Groups";
 $help_pages["Browse_Groups"] = <<<EOD
 page_type=standard
-
 page_border=solid-border
-
 toc=true
-
 title=Browse Groups
-
 END_HEAD_VARS==Creating or Joining a group==
-You can create or Join a Group all in one place using this Text field. Simply
-enter the Group Name You want to create or Join. If the Group Name already 
-exists, you will simply join the group. If the group name doesn't exist, you
-will be presented with more options to customize and create your new Group.
+You can create or Join a Group all in one place using this Text field.
+Simply enter the Group Name You want to create or Join. If the Group Name
+already exists, you will simply join the group. If the group name doesn't
+exist, you will be presented with more options to customize and create your
+new Group.
 ==Browse Existing Groups==
-You can use the [Browse] hyper link to browse the existing Groups. You will
-then be presented with a web form to narrow your search followed by a list of
-all visible groups to you beneath.
-{{right|
-[[https://www.seekquarry.com/?c=static&p=Documentation#Managing%20Users,%20Roles,%20and%20Groups|Learn More...]]}}
+You can use the [Browse] hyper link to browse the existing Groups.
+You will then be presented with a web form to narrow your search followed by
+a list of all visible groups to you beneath.
+{{right|[[$docUrl$docLink| Learn More..]]}}
 EOD;
+$docLink = "#GUI%20for%20Managing%20Machines%20and%20Servers";
 $help_pages["Machine_Information"] = <<<EOD
 page_type=standard
-
 page_border=solid-border
-
 toc=true
-
 title=Machine Information
-
-END_HEAD_VARS<br />
-'''Machine Information listings:'''
+END_HEAD_VARS'''Machine Information listings:'''
 <br />
-This shows the currently known about machines. This list always begins 
-with the '''Name Server''' itself and a toggle to control whether or not
-the News Updater process is running on the Name Server. This allows you to
-control whether or not Yioop attempts to update its RSS (or Atom) search
-sources on an hourly basis.
-<br />There is also a link to the log file of the News Updater process. Under
-the Name Server information is a dropdown that can be used to control the
-number of current machine statuses that are displayed for all other machines
-that have been added. It also might have next and previous arrow links to go
-through the currently available machines.
- <br />
-{{right|[[https://www.seekquarry.com/?c=static&p=Documentation#GUI%20for%20Managing%20Machines%20and%20Servers|Learn More...]]}}
+This shows the currently known about machines. This list always begins with
+ the '''Name Server''' itself and a toggle to control whether or not the
+  News Updater process is running on the Name Server. This allows you to
+   control whether or not Yioop attempts to update its RSS (or Atom) search
+    sources on an hourly basis.
+<br />There is also a link to the log file of the News Updater process.
+ Under the Name Server information is a dropdown that can be used to control
+  the number of current machine statuses that are displayed for all other
+   machines that have been added. It also might have next and previous arrow
+    links to go through the currently available machines.
+<br />
+{{right|[[$docUrl$docLink| Learn More.]]}}
 EOD;
+$docLink = "#GUI%20for%20Managing%20Machines%20and%20Servers";
 $help_pages["Manage_Machines"] = <<<EOD
 page_type=standard
-
 page_border=solid-border
-
 toc=true
-
 title=Manage Machines
-
 END_HEAD_VARS'''Add Machine:'''
 <br /><br />
 The Add machine form allows you to add a new machine to be controlled by this
@@ -716,16 +707,14 @@ installed Yioop instance.
 <br />
 The '''Mirror''' check-box says whether you want the given Yioop installation
 to act as a mirror for another Yioop installation. Checking it will reveal a
-drop-down menu that allows you to choose which installation amongst the
+drop-down menu that allows you to choose which installation among-st the
 previously entered machines you want to mirror. The '''Has Queue Server'''
-check-box is used to say whether the given Yioop installation will be running
-a queue server or not.
+check-box is used to say whether the given Yioop installation will be running a
+queue server or not.
 <br />
 Finally, the '''Number of Fetchers''' drop down allows you to say how many
 fetcher instances you want to be able to manage for that machine.
-
-{{right|[[https://www.seekquarry.com/?c=static&p=Documentation#GUI%20for%20Managing%20Machines%20and%20Servers|Learn More...]]}}
-
+{{right|[[$docUrl$docLink|Learn More..]]}}
 EOD;
 $help_pages["Discover_Groups"] = <<<EOD
 page_type=standard
diff --git a/scripts/help.js b/scripts/help.js
index 0d90a83..a641fef 100644
--- a/scripts/help.js
+++ b/scripts/help.js
@@ -266,7 +266,8 @@ function getPageWithCallback(url, response_type, success_call_back,
             success_call_back && success_call_back(
                 JSON.parse(request.responseText));
         } else {
-            error_handler && error_handler(status);
+            error_handler && error_handler(status,
+                JSON.parse(request.responseText));
         }
     };
     request.send();
@@ -329,11 +330,30 @@ function displayHelpForId(help_point, is_mobile, target_controller,
             }
             toggleHelp('help-frame', is_mobile, target_controller);
         },
-        function(status)
+        function(status, response)
         {
-            doMessage("<h2 class='red'>" + tl["wiki_view_not_available"] +
-            "</h2>");
-            //toggleHelp('help-frame', is_mobile, target_controller);
+            if(status === 404 && response && response.can_edit) {
+                elt('page_name').innerHTML = help_point
+                    .getAttribute("data-pagename");
+                elt('page_name').innerHTML += ' [<a href="' +
+                getEditLink(
+                    target_controller,
+                    current_action,
+                    csrf_token_key,
+                    csrf_token_value,
+                    help_group_id,
+                    help_point.getAttribute("data-pagename"),
+                    back_params) + '">' +
+                tl["wiki_view_edit"] + '</a>]';
+                elt("help-frame-body").innerHTML =
+                    (tl["wiki_view_page_no_exist"]).replace("%s", "'" +
+                    help_point.getAttribute("data-pagename") + "'") +
+                    tl["wiki_view_create_edit"];
+                toggleHelp('help-frame', is_mobile, target_controller);
+            } else {
+                doMessage("<h2 class='red'>" + tl["wiki_view_not_available"] +
+                "</h2>");
+            }
         });
 }
 /*
diff --git a/views/elements/api_element.php b/views/elements/api_element.php
index f0875db..b42965c 100644
--- a/views/elements/api_element.php
+++ b/views/elements/api_element.php
@@ -92,15 +92,17 @@ class ApiElement extends Element implements CrawlConstants
             if(!$logged_in) {
                 $out_array["logged_in"] = false;
                 $http_code = "401 Unauthorized";
+            }else{
+                $http_code = "404 Not Found";
             }
         }
-        if($can_edit && $data['PAGE']) {
+        if($can_edit) {
             $out_array["can_edit"] = true;
         }
         if(isset($data['errors']) && count($data['errors']) > 0) {
             $out_array['errors'] = json_encode(
                 array_map(
-                    function ($string) {
+                    function ($string){
                         return html_entity_decode($string, ENT_QUOTES,
                             'UTF-8');
                     }, $data['errors']));
diff --git a/views/helpers/helpbutton_helper.php b/views/helpers/helpbutton_helper.php
index 44d600e..a6afaaa 100644
--- a/views/helpers/helpbutton_helper.php
+++ b/views/helpers/helpbutton_helper.php
@@ -125,6 +125,10 @@ class HelpbuttonHelper extends Helper
             'wiki_view_edit :"' . tl('wiki_view_edit') . '",' .
             'wiki_view_not_available :"' . tl('wiki_view_not_available') .
             '",' .
+            'wiki_view_create_edit :"' . tl('wiki_view_create_edit') .
+            '",' .
+            'wiki_view_page_no_exist :"' . tl('wiki_view_page_no_exist','%s') .
+            '",' .
             'wiki_view_read :"' . tl('wiki_view_read') . '"' .
             "}";
         $this->back_params = "{";
-- 
2.1.2

