Merge branch 'wip-MDL-33486-master' of git://github.com/marinaglancy/moodle

This commit is contained in:
Dan Poltawski
2014-04-07 13:10:41 +08:00
5 changed files with 248 additions and 41 deletions
+4 -1
View File
@@ -443,7 +443,7 @@ function wiki_pluginfile($course, $cm, $context, $filearea, $args, $forcedownloa
}
}
function wiki_search_form($cm, $search = '') {
function wiki_search_form($cm, $search = '', $subwiki = null) {
global $CFG, $OUTPUT;
$output = '<div class="wikisearch">';
@@ -454,6 +454,9 @@ function wiki_search_form($cm, $search = '') {
$output .= '<input id="searchwiki" name="searchstring" type="text" size="18" value="' . s($search, true) . '" alt="search" />';
$output .= '<input name="courseid" type="hidden" value="' . $cm->course . '" />';
$output .= '<input name="cmid" type="hidden" value="' . $cm->id . '" />';
if (!empty($subwiki->id)) {
$output .= '<input name="subwikiid" type="hidden" value="' . $subwiki->id . '" />';
}
$output .= '<input name="searchwikicontent" type="hidden" value="1" />';
$output .= '<input value="' . get_string('searchwikis', 'wiki') . '" type="submit" />';
$output .= '</fieldset>';
+15 -1
View File
@@ -110,7 +110,10 @@ abstract class page_wiki {
$PAGE->set_cm($cm);
$PAGE->set_activity_record($wiki);
// the search box
$PAGE->set_button(wiki_search_form($cm));
if (!empty($subwiki->id)) {
$search = optional_param('searchstring', null, PARAM_ALPHANUMEXT);
$PAGE->set_button(wiki_search_form($cm, $search, $subwiki));
}
}
/**
@@ -828,6 +831,17 @@ class page_wiki_search extends page_wiki {
global $PAGE, $CFG;
$PAGE->set_url($CFG->wwwroot . '/mod/wiki/search.php');
}
function print_header() {
global $PAGE;
parent::print_header();
$wiki = $PAGE->activityrecord;
$page = (object)array('title' => $wiki->firstpagetitle);
$this->wikioutput->wiki_print_subwiki_selector($wiki, $this->subwiki, $page, 'search');
}
function print_content() {
global $PAGE;
+13 -29
View File
@@ -302,17 +302,27 @@ class mod_wiki_renderer extends plugin_renderer_base {
public function wiki_print_subwiki_selector($wiki, $subwiki, $page, $pagetype = 'view') {
global $CFG, $USER;
require_once($CFG->dirroot . '/user/lib.php');
$cm = get_coursemodule_from_instance('wiki', $wiki->id);
switch ($pagetype) {
case 'files':
$baseurl = new moodle_url('/mod/wiki/files.php');
$baseurl = new moodle_url('/mod/wiki/files.php',
array('wid' => $wiki->id, 'title' => $page->title, 'pageid' => $page->id));
break;
case 'search':
$search = optional_param('searchstring', null, PARAM_ALPHANUMEXT);
$searchcontent = optional_param('searchwikicontent', 0, PARAM_INT);
$baseurl = new moodle_url('/mod/wiki/search.php',
array('cmid' => $cm->id, 'courseid' => $cm->course,
'searchstring' => $search, 'searchwikicontent' => $searchcontent));
break;
case 'view':
default:
$baseurl = new moodle_url('/mod/wiki/view.php');
$baseurl = new moodle_url('/mod/wiki/view.php',
array('wid' => $wiki->id, 'title' => $page->title));
break;
}
$cm = get_coursemodule_from_instance('wiki', $wiki->id);
$context = context_module::instance($cm->id);
// @TODO: A plenty of duplicated code below this lines.
// Create private functions.
@@ -337,11 +347,6 @@ class mod_wiki_renderer extends plugin_renderer_base {
}
echo $this->output->container_start('wiki_right');
$params = array('wid' => $wiki->id, 'title' => $page->title);
if ($pagetype == 'files') {
$params['pageid'] = $page->id;
}
$baseurl->params($params);
$name = 'uid';
$selected = $subwiki->userid;
echo $this->output->single_select($baseurl, $name, $options, $selected, null);
@@ -356,12 +361,6 @@ class mod_wiki_renderer extends plugin_renderer_base {
if ($wiki->wikimode == 'collaborative') {
// We need to print a select to choose a course group
$params = array('wid'=>$wiki->id, 'title'=>$page->title);
if ($pagetype == 'files') {
$params['pageid'] = $page->id;
}
$baseurl->params($params);
echo $this->output->container_start('wiki_right');
groups_print_activity_menu($cm, $baseurl);
echo $this->output->container_end();
@@ -397,11 +396,6 @@ class mod_wiki_renderer extends plugin_renderer_base {
}
}
echo $this->output->container_start('wiki_right');
$params = array('wid' => $wiki->id, 'title' => $page->title);
if ($pagetype == 'files') {
$params['pageid'] = $page->id;
}
$baseurl->params($params);
$name = 'groupanduser';
$selected = $subwiki->groupid . '-' . $subwiki->userid;
echo $this->output->single_select($baseurl, $name, $options, $selected, null);
@@ -417,11 +411,6 @@ class mod_wiki_renderer extends plugin_renderer_base {
if ($wiki->wikimode == 'collaborative') {
// We need to print a select to choose a course group
// moodle_url will take care of encoding for us
$params = array('wid'=>$wiki->id, 'title'=>$page->title);
if ($pagetype == 'files') {
$params['pageid'] = $page->id;
}
$baseurl->params($params);
echo $this->output->container_start('wiki_right');
groups_print_activity_menu($cm, $baseurl);
@@ -444,11 +433,6 @@ class mod_wiki_renderer extends plugin_renderer_base {
}
echo $this->output->container_start('wiki_right');
$params = array('wid' => $wiki->id, 'title' => $page->title);
if ($pagetype == 'files') {
$params['pageid'] = $page->id;
}
$baseurl->params($params);
$name = 'groupanduser';
$selected = $subwiki->groupid . '-' . $subwiki->userid;
echo $this->output->single_select($baseurl, $name, $options, $selected, null);
+30 -10
View File
@@ -30,6 +30,8 @@ $search = optional_param('searchstring', null, PARAM_ALPHANUMEXT);
$courseid = optional_param('courseid', 0, PARAM_INT);
$searchcontent = optional_param('searchwikicontent', 0, PARAM_INT);
$cmid = optional_param('cmid', 0, PARAM_INT);
$subwikiid = optional_param('subwikiid', 0, PARAM_INT);
$userid = optional_param('uid', 0, PARAM_INT);
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('invalidcourseid');
@@ -40,19 +42,37 @@ if (!$cm = get_coursemodule_from_id('wiki', $cmid)) {
require_login($course, true, $cm);
// @TODO: Fix call to wiki_get_subwiki_by_group
if (!$gid = groups_get_activity_group($cm)) {
$gid = 0;
}
if (!$subwiki = wiki_get_subwiki_by_group($cm->instance, $gid)) {
print_error('incorrectsubwikiid', 'wiki');
}
if (!$wiki = wiki_get_wiki($subwiki->wikiid)) {
// Checking wiki instance
if (!$wiki = wiki_get_wiki($cm->instance)) {
print_error('incorrectwikiid', 'wiki');
}
if (!wiki_user_can_view($subwiki, $wiki)) {
print_error('cannotviewfiles', 'wiki');
if ($subwikiid) {
// Subwiki id is specified.
$subwiki = wiki_get_subwiki($subwikiid);
if (!$subwiki || $subwiki->wikiid != $wiki->id) {
print_error('incorrectsubwikiid', 'wiki');
}
} else {
// Getting current group id
$gid = groups_get_activity_group($cm);
// Getting current user id
if ($wiki->wikimode == 'individual') {
$userid = $userid ? $userid : $USER->id;
} else {
$userid = 0;
}
if (!$subwiki = wiki_get_subwiki_by_group($cm->instance, $gid, $userid)) {
// Subwiki does not exist yet, redirect to the view page (which will redirect to create page if allowed).
$params = array('wid' => $wiki->id, 'group' => $gid, 'uid' => $userid, 'title' => $wiki->firstpagetitle);
$url = new moodle_url('/mod/wiki/view.php', $params);
redirect($url);
}
}
if ($subwiki && !wiki_user_can_view($subwiki, $wiki)) {
print_error('cannotviewpage', 'wiki');
}
$wikipage = new page_wiki_search($wiki, $subwiki, $cm);
+186
View File
@@ -0,0 +1,186 @@
@mod @mod_wiki
Feature: Users can search wikis
In order to find information in wiki
As a user
I need to be able to search individual and collaborative wikis
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@asd.com |
| student1 | Student | 1 | student1@asd.com |
| student2 | Student | 2 | student2@asd.com |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
| student2 | C1 | student |
@javascript
Scenario: Searching collaborative wiki
Given I log in as "teacher1"
And I follow "Course 1"
And I turn editing mode on
And I add a "Wiki" to section "1" and I fill the form with:
| Wiki name | Collaborative wiki name |
| Description | Collaborative wiki description |
| First page name | Collaborative index |
| Wiki mode | Collaborative wiki |
And I follow "Collaborative wiki name"
And I press "Create page"
And I set the following fields to these values:
| HTML format | Collaborative teacher1 page [[new page]] |
And I press "Save"
And I follow "Course 1"
And I log out
And I log in as "student1"
And I follow "Course 1"
And I follow "Collaborative wiki name"
And I follow "new page"
And I press "Create page"
And I set the following fields to these values:
| HTML format | New page created by student1 |
And I press "Save"
When I set the field "searchstring" to "page"
And I press "Search wikis"
Then I should see "New page created by student1"
And I should see "Collaborative teacher1 page"
And I set the field "searchstring" to "teacher1"
And I press "Search wikis"
And I should not see "New page created by student1"
And I should see "Collaborative teacher1 page"
And I log out
@javascript
Scenario: Searching individual wiki
Given I log in as "teacher1"
And I follow "Course 1"
And I turn editing mode on
And I add a "Wiki" to section "1" and I fill the form with:
| Wiki name | Individual wiki name |
| Description | Individual wiki description |
| First page name | Individual index |
| Wiki mode | Individual wiki |
And I follow "Individual wiki name"
And I press "Create page"
And I set the following fields to these values:
| HTML format | Individual teacher1 page |
And I press "Save"
And I log out
And I log in as "student1"
And I follow "Course 1"
And I follow "Individual wiki name"
And I press "Create page"
And I set the following fields to these values:
| HTML format | Individual student1 page |
And I press "Save"
When I set the field "searchstring" to "page"
And I press "Search wikis"
Then I should see "Individual student1 page"
And I should not see "Individual teacher1 page"
And I log out
And I log in as "student2"
And I follow "Course 1"
And I follow "Individual wiki name"
And I press "Create page"
And I set the following fields to these values:
| HTML format | Individual student2 page |
And I press "Save"
And I set the field "searchstring" to "page"
And I press "Search wikis"
And I should see "Individual student2 page"
And I should not see "Individual student1 page"
And I should not see "Individual teacher1 page"
And I log out
And I log in as "teacher1"
And I follow "Course 1"
And I follow "Individual wiki name"
And I set the field "searchstring" to "page"
And I press "Search wikis"
And I should see "Individual teacher1 page"
And I should not see "Individual student1 page"
And I should not see "Individual student2 page"
And I set the field "uid" to "Student 1"
And I should not see "Individual teacher1 page"
And I should see "Individual student1 page"
And I should not see "Individual student2 page"
And I set the field "uid" to "Student 2"
And I should not see "Individual teacher1 page"
And I should not see "Individual student1 page"
And I should see "Individual student2 page"
And I log out
@javascript
Scenario: Searching group wiki
Given the following "groups" exist:
| name | course | idnumber |
| Group1 | C1 | G1 |
| Group2 | C1 | G2 |
And the following "group members" exist:
| user | group |
| student1 | G1 |
| student2 | G2 |
And I log in as "teacher1"
And I follow "Course 1"
And I turn editing mode on
And I add a "Wiki" to section "1" and I fill the form with:
| Wiki name | Group wiki name |
| Description | Wiki description |
| First page name | Groups index |
| Wiki mode | Collaborative wiki |
| Group mode | Separate groups |
And I follow "Group wiki name"
And I set the field "Group" to "All participants"
And I press "Create page"
And I set the following fields to these values:
| HTML format | All participants teacher1 page |
And I press "Save"
And I set the field "group" to "Group1"
And I press "Create page"
And I set the following fields to these values:
| HTML format | Group1 teacher1 page [[new page1]] |
And I press "Save"
And I set the field "group" to "Group2"
And I press "Create page"
And I set the following fields to these values:
| HTML format | Group2 teacher1 page [[new page2]] |
And I press "Save"
And I log out
And I log in as "student1"
And I follow "Course 1"
And I follow "Group wiki name"
And I follow "new page1"
And I press "Create page"
And I set the following fields to these values:
| HTML format | Group1 student1 new page |
And I press "Save"
When I set the field "searchstring" to "page"
And I press "Search wikis"
Then I should see "Group1 teacher1 page"
And I should not see "Group2 teacher1 page"
And I should see "Group1 student1 new page"
And I should not see "All participants teacher1 page"
And I log out
And I log in as "student2"
And I follow "Course 1"
And I follow "Group wiki name"
And I follow "new page2"
And I press "Create page"
And I set the following fields to these values:
| HTML format | Group2 student2 new page |
And I press "Save"
And I set the field "searchstring" to "page"
And I press "Search wikis"
And I should not see "Group1 teacher1 page"
And I should see "Group2 teacher1 page"
And I should not see "Group1 student1 new page"
And I should see "Group2 student2 new page"
And I should not see "All participants teacher1 page"
And I log out
And I log in as "teacher1"
And I follow "Course 1"
And I follow "Group wiki name"