From eb7880654f45f40fe762cd205620d88d6da74a2d Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sun, 17 Jan 2010 09:37:30 +0000 Subject: [PATCH] MDL-21233 finally removed the omitquerystring parameters from the out method because: 1/ the least used parameter should nto be first, 2/ it is colliding with the other two paramters, now we have separate funtion for that instead --- .../block_global_navigation_tree.php | 2 +- lib/blocklib.php | 6 +-- lib/formslib.php | 2 +- lib/listlib.php | 2 +- lib/outputcomponents.php | 4 +- lib/outputrenderers.php | 2 +- lib/pagelib.php | 2 +- lib/simpletest/pdflibtestpage.php | 2 +- lib/weblib.php | 54 +++++++++++-------- mod/quiz/edit.php | 6 +-- mod/quiz/editlib.php | 8 +-- mod/quiz/report/grading/report.php | 2 +- mod/quiz/report/overview/overview_table.php | 2 +- mod/quiz/report/overview/report.php | 8 +-- mod/quiz/report/responses/report.php | 4 +- mod/quiz/report/responses/responses_table.php | 2 +- mod/quiz/report/statistics/report.php | 2 +- mod/workshop/allocation/manual/lib.php | 4 +- question/category_class.php | 2 +- question/editlib.php | 8 +-- question/preview.php | 2 +- 21 files changed, 68 insertions(+), 58 deletions(-) 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 '
'; echo '
'; diff --git a/mod/quiz/editlib.php b/mod/quiz/editlib.php index 0b8194a64d3..3ab3fdc2962 100644 --- a/mod/quiz/editlib.php +++ b/mod/quiz/editlib.php @@ -603,7 +603,7 @@ function quiz_print_question_list($quiz, $pageurl, $allowdelete = true, if (!$reordertool && !$quiz->shufflequestions) { echo $OUTPUT->container_start('addpage'); - $url = new moodle_url($pageurl->out(true), array('cmid' => $quiz->cmid, 'courseid' => $quiz->course, 'addpage' => $count, 'sesskey' => sesskey())); + $url = new moodle_url($pageurl->out_omit_querystring(), array('cmid' => $quiz->cmid, 'courseid' => $quiz->course, 'addpage' => $count, 'sesskey' => sesskey())); echo $OUTPUT->single_button($url, get_string('addpagehere', 'quiz'), 'get', $hasattempts); echo $OUTPUT->container_end(); } @@ -644,7 +644,7 @@ function quiz_print_pagecontrols($quiz, $pageurl, $page, $hasattempts) { $defaultcategory = question_make_default_categories($contexts->all()); // Create the url the question page will return to - $returnurl_addtoquiz = new moodle_url($pageurl->out(true), array('addonpage' => $page)); + $returnurl_addtoquiz = new moodle_url($pageurl->out_omit_querystring(), array('addonpage' => $page)); // Print a button linking to the choose question type page. $newquestionparams = array('returnurl' => $returnurl_addtoquiz->out(), @@ -664,7 +664,7 @@ function quiz_print_pagecontrols($quiz, $pageurl, $page, $hasattempts) { - + />
@@ -758,7 +758,7 @@ function quiz_print_randomquestion(&$question, &$pageurl, &$quiz, $quiz_qbanktoo $a->arrow = $OUTPUT->rarrow(); $strshowcategorycontents = get_string('showcategorycontents', 'quiz', $a); - $openqbankurl = $pageurl->out(false, array('qbanktool' => 1, + $openqbankurl = $pageurl->out(array('qbanktool' => 1, 'cat' => $category->id . ',' . $category->contextid)); $linkcategorycontents = ' ' . $strshowcategorycontents . ''; diff --git a/mod/quiz/report/grading/report.php b/mod/quiz/report/grading/report.php index 04530b8a6fb..5eb7f38ea0b 100644 --- a/mod/quiz/report/grading/report.php +++ b/mod/quiz/report/grading/report.php @@ -158,7 +158,7 @@ class quiz_grading_report extends quiz_default_report { /// find out current groups mode if ($groupmode = groups_get_activity_groupmode($this->cm)) { // Groups are being used - groups_print_activity_menu($this->cm, $this->viewurl->out(false, array('userid'=>0, 'attemptid'=>0))); + groups_print_activity_menu($this->cm, $this->viewurl->out(array('userid'=>0, 'attemptid'=>0))); } if(empty($this->users)) { diff --git a/mod/quiz/report/overview/overview_table.php b/mod/quiz/report/overview/overview_table.php index d0427257e4b..67063c35442 100644 --- a/mod/quiz/report/overview/overview_table.php +++ b/mod/quiz/report/overview/overview_table.php @@ -76,7 +76,7 @@ class quiz_report_overview_table extends table_sql { // Start form $url = new moodle_url($this->reporturl, $this->displayoptions); echo '
'; - echo '
'; + echo ''; echo '
'; echo html_writer::input_hidden_params($url); echo '
'; diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php index 81956f4ad4d..dca4463fd69 100644 --- a/mod/quiz/report/overview/report.php +++ b/mod/quiz/report/overview/report.php @@ -170,12 +170,12 @@ class quiz_overview_report extends quiz_default_report { $this->regrade_all_needed($quiz, $groupstudents); } if ($regradeall || $regradealldry || $regradealldrydo){ - redirect($reporturl->out(false, $displayoptions, false), '', 5); + redirect($reporturl->out($displayoptions, false), '', 5); } if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used if (!$table->is_downloading()) { - groups_print_activity_menu($cm, $reporturl->out(false, $displayoptions)); + groups_print_activity_menu($cm, $reporturl->out($displayoptions)); } } @@ -294,7 +294,7 @@ class quiz_overview_report extends quiz_default_report { } $displayurl = new moodle_url($reporturl, $displayoptions); echo '
'; - echo ''; + echo ''; echo '
'; echo html_writer::input_hidden_params($displayurl); echo ''; @@ -379,7 +379,7 @@ class quiz_overview_report extends quiz_default_report { $table->sortable(true, 'uniqueid'); // Set up the table - $table->define_baseurl($reporturl->out(false, $displayoptions)); + $table->define_baseurl($reporturl->out($displayoptions)); $table->collapsible(false); diff --git a/mod/quiz/report/responses/report.php b/mod/quiz/report/responses/report.php index cbce7eabc0a..a76c4bb776a 100644 --- a/mod/quiz/report/responses/report.php +++ b/mod/quiz/report/responses/report.php @@ -138,7 +138,7 @@ class quiz_responses_report extends quiz_default_report { if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used if (!$table->is_downloading()) { - groups_print_activity_menu($cm, $reporturl->out(false, $displayoptions)); + groups_print_activity_menu($cm, $reporturl->out($displayoptions)); } } // Print information on the number of existing attempts @@ -306,7 +306,7 @@ class quiz_responses_report extends quiz_default_report { $table->sortable(true, 'concattedid'); // Set up the table - $table->define_baseurl($reporturl->out(false, $displayoptions)); + $table->define_baseurl($reporturl->out($displayoptions)); $table->collapsible(true); diff --git a/mod/quiz/report/responses/responses_table.php b/mod/quiz/report/responses/responses_table.php index f2ee4504486..470b0501f5b 100644 --- a/mod/quiz/report/responses/responses_table.php +++ b/mod/quiz/report/responses/responses_table.php @@ -34,7 +34,7 @@ class quiz_report_responses_table extends table_sql { $displayurl = new moodle_url($this->reporturl, $this->displayoptions); $strreallydel = addslashes_js(get_string('deleteattemptcheck','quiz')); echo '
'; - echo ''; echo '
'; echo html_writer::input_hidden_params($displayurl); diff --git a/mod/quiz/report/statistics/report.php b/mod/quiz/report/statistics/report.php index bca9fde74a0..a5ae560ec4e 100644 --- a/mod/quiz/report/statistics/report.php +++ b/mod/quiz/report/statistics/report.php @@ -409,7 +409,7 @@ class quiz_statistics_report extends quiz_default_report { } $quizinformationtablehtml .= $OUTPUT->box_start('boxaligncenter generalbox boxwidthnormal mdl-align'); $quizinformationtablehtml .= get_string('lastcalculated', 'quiz_statistics', $a); - $aurl = new moodle_url($reporturl->out(true), $reporturl->params()+array('recalculate'=>1)); + $aurl = new moodle_url($reporturl->out_omit_querystring(), $reporturl->params()+array('recalculate'=>1)); $quizinformationtablehtml .= $OUTPUT->single_button($aurl, get_string('recalculatenow', 'quiz_statistics')); $quizinformationtablehtml .= $OUTPUT->box_end(); } diff --git a/mod/workshop/allocation/manual/lib.php b/mod/workshop/allocation/manual/lib.php index ea81781937e..d8f2415aeb5 100644 --- a/mod/workshop/allocation/manual/lib.php +++ b/mod/workshop/allocation/manual/lib.php @@ -87,7 +87,7 @@ class workshop_manual_allocator implements workshop_allocator { } } $m = implode('-', $m); // serialize message object to be passed via URL - redirect($PAGE->url->out(false, array('m' => $m), false)); + redirect($PAGE->url->out(array('m' => $m), false)); break; case 'del': if (!confirm_sesskey()) { @@ -119,7 +119,7 @@ class workshop_manual_allocator implements workshop_allocator { } } $m = implode('-', $m); // serialize message object to be passed via URL - redirect($PAGE->url->out(false, array('m' => $m), false)); + redirect($PAGE->url->out(array('m' => $m), false)); } break; } diff --git a/question/category_class.php b/question/category_class.php index 33c3e53dff5..7976a37c9b2 100644 --- a/question/category_class.php +++ b/question/category_class.php @@ -93,7 +93,7 @@ class question_category_list_item extends list_item { /// Each section adds html to be displayed as part of this list item $questionbankurl = "{$CFG->wwwroot}/question/edit.php?". $this->parentlist->pageurl->get_query_string(array('category'=>"$category->id,$category->contextid")); - $catediturl = $this->parentlist->pageurl->out(false, array('edit'=>$this->id)); + $catediturl = $this->parentlist->pageurl->out(array('edit'=>$this->id)); $item = "edit}\" href=\"$catediturl\">".$category->name ." ".'('.$category->questioncount.')'; $item .= ' '. $category->info; diff --git a/question/editlib.php b/question/editlib.php index c6de2f0bbd0..242d134c08a 100644 --- a/question/editlib.php +++ b/question/editlib.php @@ -999,7 +999,7 @@ class question_bank_view { if (count($newsort) > question_bank_view::MAX_SORTS) { $newsort = array_slice($newsort, 0, question_bank_view::MAX_SORTS, true); } - return $this->baseurl->out(false, $this->sort_to_params($newsort)); + return $this->baseurl->out($this->sort_to_params($newsort)); } protected function build_query_sql($category, $recurse, $showhidden) { @@ -1078,11 +1078,11 @@ class question_bank_view { } public function edit_question_url($questionid) { - return $this->editquestionurl->out(false, array('id' => $questionid)); + return $this->editquestionurl->out(array('id' => $questionid)); } public function move_question_url($questionid) { - return $this->editquestionurl->out(false, array('id' => $questionid, 'movecontext' => 1)); + return $this->editquestionurl->out(array('id' => $questionid, 'movecontext' => 1)); } public function preview_question_url($questionid) { @@ -1422,7 +1422,7 @@ class question_bank_view { $checkforfiles = true; } } - $returnurl = $this->baseurl->out(false, array('category'=>"$tocategoryid,$contextid")); + $returnurl = $this->baseurl->out(array('category'=>"$tocategoryid,$contextid")); if (!$checkforfiles){ if (!question_move_questions_to_category(implode(',', $questionids), $tocategory->id)) { print_error('errormovingquestions', 'question', $returnurl, $questionids); diff --git a/question/preview.php b/question/preview.php index 94257c1d08d..0dddbabbac4 100644 --- a/question/preview.php +++ b/question/preview.php @@ -218,7 +218,7 @@ echo "

\n"; } $number = 1; - echo '', "\n"; + echo '', "\n"; print_question($questions[$id], $curstate, $number, $quiz, $options); echo '
';