]> git.mjollnir.org Git - moodle.git/commitdiff
moodle_page: MDL-12212 ->docspath
authortjhunt <tjhunt>
Wed, 6 May 2009 08:48:13 +0000 (08:48 +0000)
committertjhunt <tjhunt>
Wed, 6 May 2009 08:48:13 +0000 (08:48 +0000)
admin/report/security/index.php
admin/report/security/lib.php
index.php
lib/pagelib.php
lib/simpletest/testpagelib_moodlepage.php
lib/weblib.php

index c2f64fe08673e7a82870e41b277027ac39fbdf94..1e8d2d921223617debd246d5a91fad61718fc0cb 100644 (file)
@@ -88,8 +88,7 @@ if ($issue and ($result = $issue(true))) {
     $row[2] = $result->info;
     $row[3] = is_null($result->link) ? '&nbsp;' : $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;
 
index 4e267050cb1f53bf29f464df66219b8d38d33600..94480df9bb991dce02ac2821e5359ae1561fd6b3 100644 (file)
@@ -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>';
 }
 
 ///=============================================
index cc146022efc5b1cdb2af5df521be0173ebaf3b40..a0f35487b68fdc75fe1c154ef28f1f9cea75df47 100644 (file)
--- 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]),
index 35a5c480620cc59580ca39eda6cc714fd0532e44..45377264d64eda830922796bb18a9eef80fd8b5f 100644 (file)
@@ -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.
 
index 92581cc78585a15f0606ece6c24a395efe8ac564..43313e288e02519d4dec8dc3dadc09ceeef99c45 100644 (file)
@@ -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);
+    }
 }
 
 /**
index 59918aab1d70c9fe5c73c4a665ca24261aebb607..0ca53452278cc556662b85d79287ba7c5edf1b79 100644 (file)
@@ -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;