mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
moodle_page: MDL-12212 ->docspath
This commit is contained in:
parent
d7ab887938
commit
82611d8d33
@ -88,8 +88,7 @@ if ($issue and ($result = $issue(true))) {
|
||||
$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;
|
||||
|
||||
|
@ -74,12 +74,8 @@ function report_security_doc_link($issue, $name) {
|
||||
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>';
|
||||
}
|
||||
|
||||
///=============================================
|
||||
|
@ -87,7 +87,8 @@
|
||||
$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]),
|
||||
|
@ -71,6 +71,8 @@ class moodle_page {
|
||||
|
||||
protected $_pagetype = null;
|
||||
|
||||
protected $_docspath = null;
|
||||
|
||||
protected $_legacyclass = null;
|
||||
|
||||
/// Getter methods =============================================================
|
||||
@ -160,6 +162,17 @@ class moodle_page {
|
||||
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.
|
||||
*/
|
||||
@ -295,6 +308,17 @@ class moodle_page {
|
||||
$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.
|
||||
|
||||
|
@ -257,6 +257,20 @@ class moodle_page_test extends UnitTestCase {
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6664,33 +6664,21 @@ function convert_tabrows_to_tree($tabrows, $selected, $inactive, $activated) {
|
||||
* 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 (!has_capability('moodle/site:doclinks', $PAGE->context)) {
|
||||
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)) {
|
||||
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);
|
||||
@ -6698,8 +6686,7 @@ function page_doc_link($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;
|
||||
@ -6710,10 +6697,9 @@ function get_docs_url($path) {
|
||||
* 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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user