$row[2] = $result->info;
$row[3] = is_null($result->link) ? ' ' : $result->link;
- $PAGE->set_pagetype('admin-report-security-' . $issue); // help link in footer
- // TODO, that should probably be changed to $PAGE->set_docs_link().
+ $PAGE->set_docs_path('admin/report/security/' . $issue);
$table->data[] = $row;
return $name;
}
- $lang = str_replace('_utf8', '', current_language());
-
- $str = "<a onclick=\"this.target='docspopup'\" href=\"$CFG->docroot/$lang/report/security/$issue\">";
- $str .= "<img class=\"iconhelp\" src=\"$CFG->httpswwwroot/pix/docs.gif\" alt=\"\" />$name</a>";
-
- return $str;
+ return '<a onclick="this.target=\'docspopup\'" href="' . get_docs_url('report/security/') . $issue . '">'
+ . '<img class="iconhelp" src="' . $CFG->httpswwwroot . '/pix/docs.gif" alt="" />' . $name . '</a>';
}
///=============================================
$langmenu = popup_form($CFG->wwwroot .'/index.php?lang=', $langs, 'chooselang', $currlang, '', '', '', true, 'self', $langlabel);
}
- $PAGE = page_create_object(PAGE_COURSE_VIEW, SITEID);
+ $PAGE = page_create_object(PAGE_COURSE_VIEW, SITEID);
+ $PAGE->set_docs_path('');
$pageblocks = blocks_setup($PAGE);
$editing = $PAGE->user_is_editing();
$preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
protected $_pagetype = null;
+ protected $_docspath = null;
+
protected $_legacyclass = null;
/// Getter methods =============================================================
return implode(' ', array_keys($this->_bodyclasses));
}
+ /**
+ * @return string the class names to put on the body element in the HTML.
+ */
+ public function get_docspath() {
+ if (is_string($this->_docspath)) {
+ return $this->_docspath;
+ } else {
+ return str_replace('-', '/', $this->pagetype);
+ }
+ }
+
/**
* PHP overloading magic to make the $PAGE->course syntax work.
*/
$this->set_context(get_context_instance(CONTEXT_COURSECAT, $categoryid));
}
+ /**
+ * Set a different path to use for the 'Moodle docs for this page' link.
+ * By default, it uses the pagetype, which is normally the same as the
+ * script name. So, for example, for mod/quiz/attempt.php, pagetype is
+ * mod-quiz-attempt, and so docspath is mod/quiz/attempt.
+ * @param string $path the path to use at the end of the moodle docs URL.
+ */
+ public function set_docs_path($path) {
+ $this->_docspath = $path;
+ }
+
/// Initialisation methods =====================================================
/// These set various things up in a default way.
$this->assertEqual('example-com--moodle', $this->testpage->url_to_class_name('https://example.com/moodle'));
$this->assertEqual('example-com--8080--nested-moodle', $this->testpage->url_to_class_name('https://example.com:8080/nested/moodle'));
}
+
+ public function test_set_docs_path() {
+ // Exercise SUT
+ $this->testpage->set_docs_path('a/file/path');
+ // Validate
+ $this->assertEqual('a/file/path', $this->testpage->docspath);
+ }
+
+ public function test_docs_path_defaults_from_pagetype() {
+ // Exercise SUT
+ $this->testpage->set_pagetype('a-page-type');
+ // Validate
+ $this->assertEqual('a/page/type', $this->testpage->docspath);
+ }
}
/**
* Returns a string containing a link to the user documentation for the current
* page. Also contains an icon by default. Shown to teachers and admin only.
*
- * @param string $text The text to be displayed for the link
- * @param string $iconpath The path to the icon to be displayed
+ * @param string $text The text to be displayed for the link
+ * @param string $iconpath The path to the icon to be displayed
*/
function page_doc_link($text='', $iconpath='') {
- global $SCRIPT, $COURSE, $CFG;
+ global $CFG, $PAGE;
- if (empty($CFG->docroot) or empty($CFG->rolesactive)) {
+ if (empty($CFG->docroot) || empty($CFG->rolesactive)) {
return '';
}
-
- if (empty($COURSE->id)) {
- $context = get_context_instance(CONTEXT_SYSTEM);
- } else {
- $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
- }
-
- if (!has_capability('moodle/site:doclinks', $context)) {
+ if (!has_capability('moodle/site:doclinks', $PAGE->context)) {
return '';
}
- if (empty($CFG->pagepath)) {
- $CFG->pagepath = ltrim($SCRIPT, '/');
- }
-
- $path = str_replace('.php', '', $CFG->pagepath);
-
- if (empty($path)) { // Not for home page
+ $path = $PAGE->docspath;
+ if (!$path) {
return '';
}
return doc_link($path, $text, $iconpath);
/**
* @param string $path the end of the URL.
- * @return The start of a MoodleDocs URL in the user's language.
- * E.g. http://docs.moodle.org/en/
+ * @return The MoodleDocs URL in the user's language. for example http://docs.moodle.org/en/$path
*/
function get_docs_url($path) {
global $CFG;
* Returns a string containing a link to the user documentation.
* Also contains an icon by default. Shown to teachers and admin only.
*
- * @param string $path The page link after doc root and language, no
- * leading slash.
- * @param string $text The text to be displayed for the link
- * @param string $iconpath The path to the icon to be displayed
+ * @param string $path The page link after doc root and language, no leading slash.
+ * @param string $text The text to be displayed for the link
+ * @param string $iconpath The path to the icon to be displayed
*/
function doc_link($path='', $text='', $iconpath='') {
global $CFG;