From 82611d8d337ed1f67ae2c6ec0e6d4184549f619d Mon Sep 17 00:00:00 2001 From: tjhunt Date: Wed, 6 May 2009 08:48:13 +0000 Subject: [PATCH] moodle_page: MDL-12212 ->docspath --- admin/report/security/index.php | 3 +- admin/report/security/lib.php | 8 ++--- index.php | 3 +- lib/pagelib.php | 24 +++++++++++++++ lib/simpletest/testpagelib_moodlepage.php | 14 +++++++++ lib/weblib.php | 36 +++++++---------------- 6 files changed, 54 insertions(+), 34 deletions(-) diff --git a/admin/report/security/index.php b/admin/report/security/index.php index c2f64fe086..1e8d2d9212 100644 --- a/admin/report/security/index.php +++ b/admin/report/security/index.php @@ -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; diff --git a/admin/report/security/lib.php b/admin/report/security/lib.php index 4e267050cb..94480df9bb 100644 --- a/admin/report/security/lib.php +++ b/admin/report/security/lib.php @@ -74,12 +74,8 @@ function report_security_doc_link($issue, $name) { return $name; } - $lang = str_replace('_utf8', '', current_language()); - - $str = "docroot/$lang/report/security/$issue\">"; - $str .= "httpswwwroot/pix/docs.gif\" alt=\"\" />$name"; - - return $str; + return '' + . '' . $name . ''; } ///============================================= diff --git a/index.php b/index.php index cc146022ef..a0f35487b6 100644 --- a/index.php +++ b/index.php @@ -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]), diff --git a/lib/pagelib.php b/lib/pagelib.php index 35a5c48062..45377264d6 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -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. diff --git a/lib/simpletest/testpagelib_moodlepage.php b/lib/simpletest/testpagelib_moodlepage.php index 92581cc785..43313e288e 100644 --- a/lib/simpletest/testpagelib_moodlepage.php +++ b/lib/simpletest/testpagelib_moodlepage.php @@ -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); + } } /** diff --git a/lib/weblib.php b/lib/weblib.php index 59918aab1d..0ca5345227 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -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 (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); @@ -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; -- 2.39.5