From 7886efc41ec10fea2614ffb1ffb33af24accda6d Mon Sep 17 00:00:00 2001 From: jerome mouneyrac Date: Mon, 21 Dec 2009 04:01:02 +0000 Subject: [PATCH] webservice MDL-20803 add switch to disable documentation, fix renderer call on login page, fix xhtml strict, add css file. TODO: use output render function to display tag, move all css style into the css file --- admin/settings/plugins.php | 1 + lang/en_utf8/admin.php | 2 ++ lang/en_utf8/webservice.php | 1 + webservice/renderer.php | 42 +++++++++++++------------------------ webservice/wsdoc.css | 26 +++++++++++++++++++++++ webservice/wsdoc.php | 18 +++++++++++++--- 6 files changed, 60 insertions(+), 30 deletions(-) create mode 100644 webservice/wsdoc.css diff --git a/admin/settings/plugins.php b/admin/settings/plugins.php index f5d6f09a60..11e44b42f1 100644 --- a/admin/settings/plugins.php +++ b/admin/settings/plugins.php @@ -249,6 +249,7 @@ if ($hassiteconfig) { if (empty($CFG->enablewebservices)) { $temp->add(new admin_setting_heading('webservicesaredisabled', '', get_string('disabledwarning', 'webservice'))); } + $temp->add(new admin_setting_configcheckbox('enablewsdocumentation', get_string('enablewsdocumentation', 'admin'), get_string('configenablewsdocumentation', 'admin'), false)); $ADMIN->add('webservicesettings', $temp); $webservices_available = get_plugin_list('webservice'); $active_webservices = empty($CFG->webserviceprotocols) ? array() : explode(',', $CFG->webserviceprotocols); diff --git a/lang/en_utf8/admin.php b/lang/en_utf8/admin.php index a31d5e3a8a..b7026a98a4 100644 --- a/lang/en_utf8/admin.php +++ b/lang/en_utf8/admin.php @@ -161,6 +161,7 @@ $string['configenablesafebrowserintegration'] = 'This adds the choice \'Require $string['configenablestats'] = 'If you choose \'yes\' here, Moodle\'s cronjob will process the logs and gather some statistics. Depending on the amount of traffic on your site, this can take awhile. If you enable this, you will be able to see some interesting graphs and statistics about each of your courses, or on a sitewide basis.'; $string['configenabletrusttext'] = 'By default Moodle will always thoroughly clean text that comes from users to remove any possible bad scripts, media etc that could be a security risk. The Trusted Content system is a way of giving particular users that you trust the ability to include these advanced features in their content without interference. To enable this system, you need to first enable this setting, and then grant the Trusted Content permission to a specific Moodle role. Texts created or uploaded by such users will be marked as trusted and will not be cleaned before display.'; $string['configenablewebservices'] = 'Web services enable other systems to log in to this Moodle and perform operations. For extra security this feature should be disabled unless you are really using it.'; +$string['configenablewsdocumentation'] = 'Enable auto-generation of web services documentation. A web service user can access to his own documentation without login into Moodle. It display the documentation for the enabled protocols only.'; $string['configenrolmentplugins'] = 'Please choose the enrolment plugins you wish to use. Don\'t forget to configure the settings properly.

You have to indicate which plugins are enabled, and one plugin can be set as the default plugin for interactive enrolment. To disable interactive enrolment, set \"enrollable\" to \"No\" in required courses.'; $string['configerrorlevel'] = 'Choose the amount of PHP warnings that you want to be displayed. Normal is usually the best choice.'; $string['configexperimentalsplitrestore'] = 'If enabled, course backup files will be checked for XML errors and split into smaller parts for use in the restore process. This will result in improvements to restore robustness and execution times, particularly for medium to large course backups.'; @@ -427,6 +428,7 @@ $string['enablesafebrowserintegration'] = 'Enable Safe Exam Browser integration' $string['enablestats'] = 'Enable statistics'; $string['enabletrusttext'] = 'Enable Trusted Content'; $string['enablewebservices'] = 'Enable web services'; +$string['enablewsdocumentation'] = 'Web services documentation'; $string['allowbeforeblock'] = 'Allowed list will be processed first'; $string['allowbeforeblockdesc'] = 'By Default, blocked list will be processed first, if this option enabled, allowed IPs list will be processed before blocked list.'; $string['encoding'] = 'Encoding'; diff --git a/lang/en_utf8/webservice.php b/lang/en_utf8/webservice.php index dfc031cf14..e1ba2b8521 100644 --- a/lang/en_utf8/webservice.php +++ b/lang/en_utf8/webservice.php @@ -58,6 +58,7 @@ $string['testclient'] = 'Web service test client'; $string['validuntil'] = 'Valid until'; $string['webservices'] = 'Web services'; $string['wsdocumentation'] = 'Web service documentation'; +$string['wsdocumentationdisable'] = 'Web service documentation is disabled.'; $string['wsdocumentationintro'] = 'Following a listing of web service functions available for the username $a.
In order to create a client we advice you to read the Moodle documentation'; $string['wsdocumentationlogin'] = 'Enter your web service username and password.'; $string['wspassword'] = 'Web service password'; diff --git a/webservice/renderer.php b/webservice/renderer.php index fa0f074057..a17d2fd806 100644 --- a/webservice/renderer.php +++ b/webservice/renderer.php @@ -170,8 +170,8 @@ EOF; $restresponsehtml = ""; + $restresponsehtml .= "
"; $restresponsehtml .= "
";
-        $restresponsehtml .= "
"; $restresponsehtml .= ''.get_string('restcode', 'webservice').'
'; $brakeline = <<description_in_indented_xml_format($returndescription); $content .="".$brakeline; $restresponsehtml .= $brakeline.htmlentities($content).$brakeline; - $restresponsehtml .= "
"; - $restresponsehtml .= "
"; + $restresponsehtml .= "
"; return $restresponsehtml; } @@ -262,29 +261,24 @@ EOF; $required = $paramdesc->required?get_string('required', 'webservice'):get_string('optional', 'webservice'); $documentationhtml .= "".$paramname . " (" .$required. ")
"; $documentationhtml .= "        ".$paramdesc->desc."

"; + $documentationhtml .= "
"; $documentationhtml .= "
";
-                $documentationhtml .= "
"; - //$documentationhtml .= print_collapsible_region_start('', 'aera_'.$functionname."_".$paramname,''.get_string('generalstructure', 'webservice').'',false,true,true); $documentationhtml .= ''.get_string('generalstructure', 'webservice').'
'; $documentationhtml .= $brakeline.$this->detailed_description_html($paramdesc); - //$documentationhtml .= print_collapsible_region_end(true); - $documentationhtml .= "
"; - $documentationhtml .= "

"; + $documentationhtml .= "

"; if (!empty($activatedprotocol['xmlrpc'])) { + $documentationhtml .= "
"; $documentationhtml .= "
";
-                    $documentationhtml .= "
"; $documentationhtml .= ''.get_string('phpparam', 'webservice').'
'; $documentationhtml .= $brakeline.'['.$paramname.'] =>'.htmlentities($this->xmlrpc_param_description_html($paramdesc)). $brakeline. $brakeline; - $documentationhtml .= "

"; - $documentationhtml .= "
"; + $documentationhtml .= "

"; } if (!empty($activatedprotocol['rest'])) { + $documentationhtml .= "
"; $documentationhtml .= "
";
-                    $documentationhtml .= "
"; $documentationhtml .= ''.get_string('restparam', 'webservice').'
'; $documentationhtml .= $brakeline.htmlentities($this->rest_param_description_html($paramdesc,$paramname)). $brakeline. $brakeline; - $documentationhtml .= "
"; - $documentationhtml .= "
"; + $documentationhtml .= "
"; } $documentationhtml .= ""; } @@ -297,21 +291,17 @@ EOF; } if (!empty($description->returns_desc)) { + $documentationhtml .= "
"; $documentationhtml .= "
";
-                $documentationhtml .= "
"; - //$documentationhtml .= print_collapsible_region_start('', 'aera_'.$functionname."_xmlrpc_return",''.get_string('generalstructure', 'webservice').'',false,true,true); $documentationhtml .= ''.get_string('generalstructure', 'webservice').'
'; $documentationhtml .= $brakeline.$this->detailed_description_html($description->returns_desc); - //$documentationhtml .= print_collapsible_region_end(true); - $documentationhtml .= "
"; - $documentationhtml .= "

"; + $documentationhtml .= "

"; if (!empty($activatedprotocol['xmlrpc'])) { + $documentationhtml .= "
"; $documentationhtml .= "
";
-                    $documentationhtml .= "
"; $documentationhtml .= ''.get_string('phpresponse', 'webservice').'
'; $documentationhtml .= htmlentities($this->xmlrpc_param_description_html($description->returns_desc)).$brakeline.$brakeline; - $documentationhtml .= "
"; - $documentationhtml .= "

"; + $documentationhtml .= "

"; } if (!empty($activatedprotocol['rest'])) { $documentationhtml .= $this->rest_response_html($functionname, $description->returns_desc); @@ -323,10 +313,9 @@ EOF; if (!empty($activatedprotocol['rest'])) { $documentationhtml .= "".get_string('errorcodes', 'webservice')."
"; - $documentationhtml .= ""; + $documentationhtml .= "
"; + $documentationhtml .= "
"; $documentationhtml .= "
";
-                $documentationhtml .= "
"; - $documentationhtml .= ''.get_string('restexception', 'webservice').'
'; $errormessage = get_string('invalidparameter', 'debug'); $restexceptiontext =<< EOF; $documentationhtml .= $brakeline.htmlentities($restexceptiontext); - $documentationhtml .= "
"; - $documentationhtml .= "

"; + $documentationhtml .= "

"; $documentationhtml .= "
"; } $documentationhtml .= "

"; diff --git a/webservice/wsdoc.css b/webservice/wsdoc.css new file mode 100644 index 0000000000..e181acc28c --- /dev/null +++ b/webservice/wsdoc.css @@ -0,0 +1,26 @@ +/*////////////////////////////////////////////////////////////////////////// +// // +// This file is part of Moodle - http://moodle.org/ // +// Moodle - Modular Object-Oriented Dynamic Learning Environment // +// // +// Moodle is free software: you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation, either version 3 of the License, or // +// (at your option) any later version. // +// // +// Moodle is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with Moodle. If not, see . // +// // +//////////////////////////////////////////////////////////////////////////*/ + +table, td +{ + text-align: left; + border: 0px solid black; +} + diff --git a/webservice/wsdoc.php b/webservice/wsdoc.php index 33471e5b44..e94053cca9 100644 --- a/webservice/wsdoc.php +++ b/webservice/wsdoc.php @@ -59,7 +59,6 @@ class webservice_documentation_generator { /** * Run the documentation generation - * @param bool $simple use simple authentication * @return void */ public function run() { @@ -222,14 +221,17 @@ class webservice_documentation_generator { * Generate and display the documentation */ protected function display_documentation_html() { - global $PAGE, $OUTPUT, $SITE; + global $PAGE, $OUTPUT, $SITE, $CFG; $PAGE->set_url('/webservice/wsdoc'); $PAGE->set_docs_path(''); $PAGE->set_title($SITE->fullname." ".get_string('wsdocumentation', 'webservice')); $PAGE->set_heading($SITE->fullname." ".get_string('wsdocumentation', 'webservice')); $PAGE->set_pagelayout('popup'); + $PAGE->set_pagetype('webservice-doc-generator'); + $PAGE->requires->css('webservice/wsdoc.css'); + echo $OUTPUT->header(); $activatedprotocol = array(); @@ -258,10 +260,15 @@ class webservice_documentation_generator { $PAGE->set_title($SITE->fullname." ".get_string('wsdocumentation', 'webservice')); $PAGE->set_heading($SITE->fullname." ".get_string('wsdocumentation', 'webservice')); $PAGE->set_pagelayout('popup'); + $PAGE->set_pagetype('webservice-doc-generator-login'); + + $PAGE->requires->css('webservice/wsdoc.css'); echo $OUTPUT->header(); - $renderer = $PAGE->get_renderer('core', 'wsdoc'); + + $renderer = $PAGE->get_renderer('core', 'webservice'); echo $renderer->login_page_html($errormessage); + echo $OUTPUT->footer(); } @@ -273,6 +280,11 @@ class webservice_documentation_generator { /////// RUN THE SCRIPT //// /////////////////////////// +if (empty($CFG->enablewsdocumentation)) { + echo get_string('wsdocumentationdisable', 'webservice'); + die; +} + //run the documentation generator $generator = new webservice_documentation_generator(); $generator->run(); -- 2.39.5