Skip to content

Commit

Permalink
MDL-21695 help files replaced by standard strings - basic infrastruct…
Browse files Browse the repository at this point in the history
…ure in place, no strings converted yet
  • Loading branch information
skodak committed Apr 10, 2010
1 parent 3a915b0 commit 53a78ce
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 24 deletions.
27 changes: 19 additions & 8 deletions help.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<strong>Old 1.9 style help files need to be converted to standard strings with "_hlp" suffix: '.$component.'/'.$identifier.'</strong>';
die;
}

die('TODO: help files will be soon reimplemented by using normal get_string().');
echo get_string($identifier, $component);
19 changes: 19 additions & 0 deletions lib/formslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,25 @@ function setHelpButton($elementname, $buttonargs, $suppresscheck=false, $functio
}
}

/**
* 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 [] :-(
Expand Down
18 changes: 9 additions & 9 deletions lib/outputcomponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ public static function fields($tableprefix = '', $idalias = '') {
*/
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
*/
Expand All @@ -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;
}
}

Expand Down
14 changes: 7 additions & 7 deletions lib/outputrenderers.php
Original file line number Diff line number Diff line change
Expand Up @@ -1343,19 +1343,19 @@ function render_rating(rating $rating) {
* 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');
}
Expand All @@ -1369,8 +1369,8 @@ public function heading_with_help($text, $helppage, $component='moodle', $icon='
* @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)) {
Expand Down Expand Up @@ -1405,8 +1405,8 @@ protected function render_help_icon(help_icon $helpicon) {
$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"));
Expand Down

0 comments on commit 53a78ce

Please sign in to comment.