From 53a78cef28cbd73679dbfc48f68b52726a125f80 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sat, 10 Apr 2010 09:10:08 +0000 Subject: [PATCH] MDL-21695 help files replaced by standard strings - basic infrastructure in place, no strings converted yet --- help.php | 27 +++++++++++++++++++-------- lib/formslib.php | 19 +++++++++++++++++++ lib/outputcomponents.php | 18 +++++++++--------- lib/outputrenderers.php | 14 +++++++------- 4 files changed, 54 insertions(+), 24 deletions(-) diff --git a/help.php b/help.php index f14bc7e5747..892fc665560 100644 --- a/help.php +++ b/help.php @@ -10,16 +10,27 @@ * @author Martin Dougiamas * @package moodlecore */ + +define('NO_MOODLE_COOKIES', true); + require_once('config.php'); +$identifier = required_param('identifier', PARAM_SAFEDIR); +$component = required_param('component', PARAM_SAFEDIR); +$lang = required_param('component', PARAM_LANG); + +if (!$lang) { + $lang = 'en'; +} + +$SESSION->lang = $lang; // does not actually modify session because we do not use cookies here -// Legacy url parameters - just dispaply error -$file = optional_param('file', '', PARAM_PATH); -$text = optional_param('text', 'No text to display', PARAM_CLEAN); -$module = optional_param('module', 'moodle', PARAM_ALPHAEXT); +// send basic headers only, we do not need full html page here +@header('Content-Type: text/plain; charset=utf-8'); -// New get_string() parameters -// $identifier = -// $component = +if (strpos('_hlp', $identifier) === false) { + echo 'Old 1.9 style help files need to be converted to standard strings with "_hlp" suffix: '.$component.'/'.$identifier.''; + die; +} -die('TODO: help files will be soon reimplemented by using normal get_string().'); +echo get_string($identifier, $component); diff --git a/lib/formslib.php b/lib/formslib.php index 0b62cef7edb..0e48c40b2c6 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -1358,6 +1358,25 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless { } } + /** + * Add a help button to element, + * only one button per element is allowed. + * + * @param string $elementname name of the element to add the item to + * @param string $identifier + * @param string $title + * @param string $component + * @param string $linktext + * @return void + */ + function addHelpButton($elementname, $identifier, $title, $component = 'moodle', $linktext = '') { + if (array_key_exists($elementname, $this->_elementIndex)) { + $element->_helpbutton = $OUTPUT->help_icon($identifier, $title, $component, $linktext); + } else if (!$suppresscheck) { + debugging(get_string('nonexistentformelements', 'form', $elementname)); + } + } + /** * Set constant value not overriden by _POST or _GET * note: this does not work for complex names with [] :-( diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index 5baf3303f87..67ebec29362 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -153,9 +153,9 @@ class user_picture implements renderable { */ class help_icon implements renderable { /** - * @var string $page name of help page + * @var string $helpidentifier lang pack identifier (should inlcude the "_hlp" suffix) */ - public $helppage; + public $helpidentifier; /** * @var string $title A descriptive text for title tooltip */ @@ -171,23 +171,23 @@ class help_icon implements renderable { /** * Constructor: sets up the other components in case they are needed - * @param string $page The keyword that defines a help page + * @param string $helpidentifier The keyword that defines a help page * @param string $title A descriptive text for accesibility only * @param string $component * @param bool $linktext add extra text to icon * @return void */ - public function __construct($helppage, $title, $component = 'moodle') { + public function __construct($helpidentifier, $title, $component = 'moodle') { if (empty($title)) { throw new coding_exception('A help_icon object requires a $text parameter'); } - if (empty($helppage)) { - throw new coding_exception('A help_icon object requires a $helppage parameter'); + if (empty($helpidentifier)) { + throw new coding_exception('A help_icon object requires a $helpidentifier parameter'); } - $this->helppage = $helppage; - $this->title = $title; - $this->component = $component; + $this->helpidentifier = $helpidentifier; + $this->title = $title; + $this->component = $component; } } diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 253412e2afb..2e66b8d2217 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -1343,19 +1343,19 @@ END; * Centered heading with attached help button (same title text) * and optional icon attached * @param string $text A heading text - * @param string $page The keyword that defines a help page + * @param string $helpidentifier The keyword that defines a help page * @param string $component component name * @param string|moodle_url $icon * @param string $iconalt icon alt text * @return string HTML fragment */ - public function heading_with_help($text, $helppage, $component='moodle', $icon='', $iconalt='') { + public function heading_with_help($text, $helpidentifier, $component='moodle', $icon='', $iconalt='') { $image = ''; if ($icon) { $image = $this->pix_icon($icon, $iconalt, $component, array('class'=>'icon')); } - $help = $this->help_icon($helppage, $text, $component); + $help = $this->help_icon($helpidentifier, $text, $component); return $this->heading($image.$text.$help, 2, 'main help'); } @@ -1369,8 +1369,8 @@ END; * @param string|bool $linktext true means use $title as link text, string means link text value * @return string HTML fragment */ - public function help_icon($helppage, $title, $component = 'moodle', $linktext='') { - $icon = new help_icon($helppage, $title, $component); + public function help_icon($helpidentifier, $title, $component = 'moodle', $linktext = '') { + $icon = new help_icon($helpidentifier, $title, $component); if ($linktext === true) { $icon->linktext = $title; } else if (!empty($linktext)) { @@ -1405,8 +1405,8 @@ END; $output .= $helpicon->linktext; } - // now create the link around it - TODO: this will be changed during the big lang cleanup in 2.0 - $url = new moodle_url('/help.php', array('module' => $helpicon->component, 'file' => $helpicon->helppage .'.html')); + // now create the link around it + $url = new moodle_url('/help.php', array('component' => $helpicon->component, 'identifier' => $helpicon->helpidentifier, 'lang'=>current_language())); // note: this title is displayed only if JS is disabled, otherwise the link will have the new ajax tooltip $title = get_string('helpprefix2', '', trim($helpicon->title, ". \t")); -- 2.43.0