diff --git a/admin/settings/plugins.php b/admin/settings/plugins.php index 6ee66089391fb..599aa088cb352 100644 --- a/admin/settings/plugins.php +++ b/admin/settings/plugins.php @@ -344,6 +344,8 @@ $temp = new admin_settingpage('webservicesoverview', get_string('webservicesoverview', 'webservice')); $temp->add(new admin_setting_webservicesoverview()); $ADMIN->add('webservicesettings', $temp); + //API documentation + $ADMIN->add('webservicesettings', new admin_externalpage('webservicedocumentation', get_string('wsdocapi', 'webservice'), "$CFG->wwwroot/$CFG->admin/webservice/documentation.php", 'moodle/site:config', false)); /// manage service $temp = new admin_settingpage('externalservices', get_string('externalservices', 'webservice')); $enablemobiledocurl = new moodle_url(get_docs_url('Enable_mobile_web_services')); diff --git a/admin/webservice/documentation.php b/admin/webservice/documentation.php new file mode 100644 index 0000000000000..92a4dd87c1528 --- /dev/null +++ b/admin/webservice/documentation.php @@ -0,0 +1,61 @@ +. + +/** + * Web services API documentation + * + * @package webservice + * @copyright 2011 Moodle Pty Ltd (http://moodle.com) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @author Jerome Mouneyrac + */ +require_once('../../config.php'); +require_once($CFG->libdir . '/adminlib.php'); +require($CFG->dirroot . '/webservice/lib.php'); + +admin_externalpage_setup('webservicedocumentation'); + +// get all the function descriptions +$functions = $DB->get_records('external_functions', array(), 'name'); +$functiondescs = array(); +foreach ($functions as $function) { + $functiondescs[$function->name] = external_function_info($function); +} + +//display the documentation for all documented protocols, +//regardless if they are activated or not +$protocols = array(); +$protocols['rest'] = true; +$protocols['xmlrpc'] = true; + +/// Check if we are in printable mode +$printableformat = optional_param('print', false, PARAM_BOOL); + +/// OUTPUT +echo $OUTPUT->header(); + +$renderer = $PAGE->get_renderer('core', 'webservice'); +echo $renderer->documentation_html($functiondescs, + $printableformat, $protocols, array(), $PAGE->url); + +/// trigger browser print operation +if (!empty($printableformat)) { + $PAGE->requires->js_function_call('window.print', array()); +} + +echo $OUTPUT->footer(); + diff --git a/lang/en/webservice.php b/lang/en/webservice.php index 5d0690e082d95..0bba546ee5a94 100644 --- a/lang/en/webservice.php +++ b/lang/en/webservice.php @@ -195,6 +195,7 @@ $string['wsauthmissing'] = 'The web service authentication plugin is missing.'; $string['wsauthnotenabled'] = 'The web service authentication plugin is disabled.'; $string['wsclientdoc'] = 'Moodle web service client documentation'; +$string['wsdocapi'] = 'API Documentation'; $string['wsdocumentation'] = 'Web service documentation'; $string['wsdocumentationdisable'] = 'Web service documentation is disabled.'; $string['wsdocumentationintro'] = 'To create a client we advise you to read the {$a->doclink}'; diff --git a/webservice/renderer.php b/webservice/renderer.php index 211663902f9a1..b6e32464b47d0 100644 --- a/webservice/renderer.php +++ b/webservice/renderer.php @@ -598,11 +598,14 @@ public function rest_param_description_html($paramdescription, $paramstring) { * @param array $authparam keys contains 'tokenid' * @param boolean $printableformat true if we want to display the documentation in a printable format * @param array $activatedprotocol + * @param string $parenturl url of the calling page - needed for the print button url: + * '/admin/documentation.php' or '/webservice/wsdoc.php' (default) * @return string the html to diplay */ - public function documentation_html($functions, $printableformat, $activatedprotocol, $authparams) { + public function documentation_html($functions, $printableformat, $activatedprotocol, + $authparams, $parenturl = '/webservice/wsdoc.php') { - $documentationhtml = $this->output->heading(get_string('documentation', 'webservice')); + $documentationhtml = $this->output->heading(get_string('wsdocapi', 'webservice')); $br = html_writer::empty_tag('br', array()); $brakeline = << $token, 'wsusername' => $username, 'wspassword' => $password, 'print' => true); - $url = new moodle_url('/webservice/wsdoc.php', $authparams); // Required + $url = new moodle_url($parenturl, $authparams); // Required $documentationhtml .= $this->output->single_button($url, get_string('print', 'webservice')); $documentationhtml .= $br; diff --git a/webservice/wsdoc.php b/webservice/wsdoc.php index db80f7a9456f1..60114edf377a0 100644 --- a/webservice/wsdoc.php +++ b/webservice/wsdoc.php @@ -73,10 +73,7 @@ $activatedprotocol['xmlrpc'] = webservice_protocol_is_enabled('xmlrpc'); /// Check if we are in printable mode -$printableformat = false; -if (isset($_REQUEST['print'])) { - $printableformat = $_REQUEST['print']; -} +$printableformat = optional_param('print', false, PARAM_BOOL); /// OUTPUT echo $OUTPUT->header();