diff --git a/blocks/global_navigation_tree/block_global_navigation_tree.php b/blocks/global_navigation_tree/block_global_navigation_tree.php index af206d289ce..9a7ff86f9aa 100644 --- a/blocks/global_navigation_tree/block_global_navigation_tree.php +++ b/blocks/global_navigation_tree/block_global_navigation_tree.php @@ -270,7 +270,7 @@ class block_global_navigation_tree extends block_tree { if ($node->key == $child->key && $node->type == $child->type) { if ($node->action instanceof moodle_url && $child->action instanceof moodle_url && $node->action->compare($child->action)) { unset($history[$key]); - } else if ($child->action instanceof moodle_url && $child->action->out(true) == $node->action) { + } else if ($child->action instanceof moodle_url && $child->action->out_omit_querystring() == $node->action) { unset($history[$key]); } else if ($child->action == $node->action) { unset($history[$key]); diff --git a/lib/blocklib.php b/lib/blocklib.php index 3931dbeed9f..386cd91e9aa 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -286,7 +286,7 @@ class block_manager { * @return string URL for moving block $this->movingblock to this position. */ protected function get_move_target_url($region, $weight) { - return $this->page->url->out(false, array('bui_moveid' => $this->movingblock, + return $this->page->url->out(array('bui_moveid' => $this->movingblock, 'bui_newregion' => $region, 'bui_newweight' => $weight, 'sesskey' => sesskey()), false); } @@ -889,7 +889,7 @@ class block_manager { } $controls = array(); - $actionurl = $this->page->url->out(false, array('sesskey'=> sesskey()), false); + $actionurl = $this->page->url->out(array('sesskey'=> sesskey()), false); // Assign roles icon. if (has_capability('moodle/role:assign', $block->context)) { @@ -1066,7 +1066,7 @@ class block_manager { $editpage->set_pagelayout('base'); $editpage->set_course($this->page->course); $editpage->set_context($block->context); - $editurlbase = str_replace($CFG->wwwroot . '/', '', $this->page->url->out(true)); + $editurlbase = str_replace($CFG->wwwroot . '/', '', $this->page->url->out_omit_querystring()); $editurlparams = $this->page->url->params(); $editurlparams['bui_editid'] = $blockid; $editpage->set_url($editurlbase, $editurlparams); diff --git a/lib/formslib.php b/lib/formslib.php index 8c26ccd2a5d..0b62cef7edb 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -1073,7 +1073,7 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless { $this->_formName = $formName; if (is_a($action, 'moodle_url')){ $this->_pageparams = html_writer::input_hidden_params($action); - $action = $action->out(true); + $action = $action->out_omit_querystring(); } else { $this->_pageparams = ''; } diff --git a/lib/listlib.php b/lib/listlib.php index 427b044b615..91166b5e08d 100644 --- a/lib/listlib.php +++ b/lib/listlib.php @@ -267,7 +267,7 @@ class moodle_list { $html .= " $currentpage \n"; } else { - $html .= "pageurl->out(false, array($this->pageparamname => $currentpage))."\">"; + $html .= "pageurl->out(array($this->pageparamname => $currentpage))."\">"; $html .= " $currentpage \n"; } } diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index e5105e3b0fb..cca4492a0ed 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -1069,12 +1069,12 @@ class html_select extends labelled_html_component { } if (!empty($selected)) { - $selectedurl = $baseurl->out(false, array($name => $selected), false); + $selectedurl = $baseurl->out(array($name => $selected), false); } // Replace real value by formatted URLs foreach ($options as $value => $label) { - $options[$baseurl->out(false, array($name => $value), false)] = $label; + $options[$baseurl->out(array($name => $value), false)] = $label; unset($options[$value]); } diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 8ddf06d4e53..36f3a3ab618 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -1072,7 +1072,7 @@ class core_renderer extends renderer_base { $output = html_writer::tag('div', array(), $output); // now the form itself around it - $url = $button->url->out(true); // url without params + $url = $button->url->out_omit_querystring(); // url without params if ($url === '') { $url = '#'; // there has to be always some action } diff --git a/lib/pagelib.php b/lib/pagelib.php index 873ab466263..f75fea82487 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -832,7 +832,7 @@ class moodle_page { $this->_url = new moodle_url($url, $params); - $fullurl = $this->_url->out(true); + $fullurl = $this->_url->out_omit_querystring(); if (strpos($fullurl, "$CFG->httpswwwroot/") !== 0) { debugging('Most probably incorrect set_page() url argument, it does not match the httpswwwroot!'); } diff --git a/lib/simpletest/pdflibtestpage.php b/lib/simpletest/pdflibtestpage.php index 7b98f2400c9..92ebbfb2509 100644 --- a/lib/simpletest/pdflibtestpage.php +++ b/lib/simpletest/pdflibtestpage.php @@ -140,5 +140,5 @@ $PAGE->set_heading('PDF library test'); echo $OUTPUT->header(); echo $OUTPUT->heading('Press the button to generate test PDF', 2); -echo $OUTPUT->continue_button($PAGE->url->out(false, array('getpdf' => 1))); +echo $OUTPUT->continue_button(new moodle_url($PAGE->url, array('getpdf' => 1))); echo $OUTPUT->footer(); diff --git a/lib/weblib.php b/lib/weblib.php index 06c10521eb9..b3b0274e2a9 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -491,7 +491,7 @@ class moodle_url { * @return string */ public function __toString() { - return $this->out(false, null, true); + return $this->out(null, true); } /** @@ -500,26 +500,19 @@ class moodle_url { * If you use the returned URL in HTML code, you want the escaped ampersands. If you use * the returned URL in HTTP headers, you want $escaped=false. * - * @param boolean $omitquerystring whether to output page params as a query string in the url. * @param array $overrideparams params to add to the output url, these override existing ones with the same name. * @param boolean $escaped Use & as params separator instead of plain & * @return string Resulting URL */ - public function out($omitquerystring = false, array $overrideparams = null, $escaped = true) { - $uri = $this->scheme ? $this->scheme.':'.((strtolower($this->scheme) == 'mailto') ? '':'//'): ''; - $uri .= $this->user ? $this->user.($this->pass? ':'.$this->pass:'').'@':''; - $uri .= $this->host ? $this->host : ''; - $uri .= $this->port ? ':'.$this->port : ''; - $uri .= $this->path ? $this->path : ''; + public function out(array $overrideparams = null, $escaped = true) { + $uri = $this->out_omit_querystring(); - if (!$omitquerystring) { - $querystring = $this->get_query_string($overrideparams, $escaped); - if ($querystring) { - $uri .= '?' . $querystring; - } - if (!is_null($this->anchor)) { - $uri .= '#'.$this->anchor; - } + $querystring = $this->get_query_string($overrideparams, $escaped); + if ($querystring) { + $uri .= '?' . $querystring; + } + if (!is_null($this->anchor)) { + $uri .= '#'.$this->anchor; } return $uri; @@ -531,7 +524,20 @@ class moodle_url { * @return string */ public function out_raw() { - return $this->out(false, null, false); + return $this->out(null, false); + } + + /** + * Returns url without parameters, everything before '?'. + * @return string + */ + public function out_omit_querystring() { + $uri = $this->scheme ? $this->scheme.':'.((strtolower($this->scheme) == 'mailto') ? '':'//'): ''; + $uri .= $this->user ? $this->user.($this->pass? ':'.$this->pass:'').'@':''; + $uri .= $this->host ? $this->host : ''; + $uri .= $this->port ? ':'.$this->port : ''; + $uri .= $this->path ? $this->path : ''; + return $uri; } /** @@ -546,7 +552,7 @@ class moodle_url { public function out_action(array $overrideparams = null) { $overrideparams = (array)$overrideparams; $overrideparams = array('sesskey'=> sesskey()) + $overrideparams; - return $this->out(false, $overrideparams); + return $this->out($overrideparams); } /** @@ -558,8 +564,8 @@ class moodle_url { */ public function compare(moodle_url $url, $matchtype = URL_MATCH_EXACT) { - $baseself = $this->out(true); - $baseother = $url->out(true); + $baseself = $this->out_omit_querystring(); + $baseother = $url->out_omit_querystring(); // Append index.php if there is no specific file if (substr($baseself,-1)=='/') { @@ -639,12 +645,16 @@ function prepare_url($url, $stripformparams=false) { $output = $url; if ($url instanceof moodle_url) { - $output = $url->out($stripformparams, array(), false); + if ($stripformparams) { + $output = $url->out_omit_querystring(); + } else { + $output = $url->out_raw(); + } } // Handle relative URLs if (substr($output, 0, 4) != 'http' && substr($output, 0, 1) != '/') { - if (preg_match('/(.*)\/([A-Za-z0-9-_]*\.php)$/', $PAGE->url->out(true), $matches)) { + if (preg_match('/(.*)\/([A-Za-z0-9-_]*\.php)$/', $PAGE->url->out_omit_querystring(), $matches)) { return $matches[1] . "/$output"; } else if ($output == '') { return $PAGE->url->out_raw() . '#'; diff --git a/mod/quiz/edit.php b/mod/quiz/edit.php index 76842a262a4..b783def4f0b 100644 --- a/mod/quiz/edit.php +++ b/mod/quiz/edit.php @@ -449,7 +449,7 @@ echo $OUTPUT->header(); // Initialise the JavaScript. $quizeditconfig = new stdClass; -$quizeditconfig->url = $thispageurl->out(false, array('qbanktool' => '0')); +$quizeditconfig->url = $thispageurl->out(array('qbanktool' => '0')); $quizeditconfig->dialoglisteners = array(); $numberoflisteners = max(quiz_number_of_pages($quiz->questions), 1); for ($pageiter = 1; $pageiter <= $numberoflisteners; $pageiter++) { @@ -477,10 +477,10 @@ if ($quiz_qbanktool) { echo '