Permalink
Browse files

[MDL-22112]

Finishing some todos and fixing some bugs
  • Loading branch information...
1 parent 7ff7f70 commit 74c6a62c737d230969530d4e1ca3f5258669efc2 Jordi Piguillem committed May 21, 2010
Showing with 225 additions and 188 deletions.
  1. +24 −21 mod/wiki/create.php
  2. +0 −8 mod/wiki/locallib.php
  3. +21 −5 mod/wiki/pagelib.php
  4. +65 −20 mod/wiki/renderer.php
  5. +115 −134 mod/wiki/view.php
View
@@ -15,9 +15,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
-
require_once('../../config.php');
-require_once(dirname(__FILE__).'/create_form.php');
+require_once(dirname(__FILE__) . '/create_form.php');
require_once($CFG->dirroot . '/mod/wiki/lib.php');
require_once($CFG->dirroot . '/mod/wiki/locallib.php');
require_once($CFG->dirroot . '/mod/wiki/pagelib.php');
@@ -29,11 +28,11 @@
// page editing page.
$action = optional_param('action', 'new', PARAM_TEXT);
// The title of the new page, can be empty
-$title = optional_param('title', '', PARAM_TEXT);
-$swid = optional_param('swid', 0, PARAM_INT);
-$wid = optional_param('wid', 0, PARAM_INT);
-$gid = optional_param('gid', 0, PARAM_INT);
-$uid = optional_param('uid', 0, PARAM_INT);
+$title = optional_param('title', '', PARAM_TEXT);
+$wid = optional_param('wid', 0, PARAM_INT);
+$swid = optional_param('swid', 0, PARAM_INT);
+$gid = optional_param('gid', 0, PARAM_INT);
+$uid = optional_param('uid', 0, PARAM_INT);
// 'create' action must be submitted by moodle form
// so sesskey must be checked
@@ -43,22 +42,20 @@
}
}
-$swiki = null;
+if (!empty($swid)) {
+ $subwiki = wiki_get_subwiki($swid);
-if (!empty($wid)) {
- // @TODO: Check for capabilities
- if (!$swid = wiki_add_subwiki($wid, $gid, $uid)) {
- print_error('invalidwikiid');
+ if (!$wiki = wiki_get_wiki($subwiki->wikiid)) {
+ print_error('invalidwikiid', 'wiki');
}
-}
+} else {
+ $subwiki = wiki_get_subwiki_by_group($wid, $gid, $uid);
-if (!$subwiki = wiki_get_subwiki($swid)) {
- print_error('invalidswid', 'wiki');
-}
+ if (!$wiki = wiki_get_wiki($wid)) {
+ print_error('invalidwikiid', 'wiki');
+ }
-if (!$wiki = wiki_get_wiki($subwiki->wikiid)) {
- print_error('invalidwikiid', 'wiki');
}
if (!$cm = get_coursemodule_from_instance('wiki', $wiki->id)) {
@@ -71,12 +68,18 @@
require_course_login($course->id, true, $cm);
-add_to_log($course->id, 'createpage', 'createpage', 'view.php?id='.$cm->id, $wiki->id);
+add_to_log($course->id, 'createpage', 'createpage', 'view.php?id=' . $cm->id, $wiki->id);
$wikipage = new page_wiki_create($wiki, $subwiki, $cm);
-$wikipage->set_gid($gid);
-$wikipage->set_swid($swid);
+if (!empty($swid)) {
+ $wikipage->set_gid($subwiki->groupid);
+ $wikipage->set_uid($subwiki->userid);
+} else {
+ $wikipage->set_gid($gid);
+ $wikipage->set_uid($uid);
+}
+
if (!empty($title)) {
$wikipage->set_title($title);
} else {
View
@@ -197,21 +197,13 @@ function wiki_get_version($versionid) {
*/
function wiki_get_first_page($subwikid, $module = null) {
global $DB, $USER;
- // TODO:
- // not sure if we should use current userid
-
- $extra = '';
- if ($module && $module->wikimode == 'individual') {
- $extra = ' AND p.userid=' . $USER->id;
- }
$sql = 'SELECT p.* ' .
'FROM {wiki} w, {wiki_subwikis} s, {wiki_pages} p ' .
'WHERE s.id = ? AND ' .
's.wikiid = w.id AND ' .
'w.firstpagetitle = p.title AND ' .
'p.subwikiid = s.id';
- $sql .= $extra;
return $DB->get_record_sql($sql, array($subwikid));
}
View
@@ -65,6 +65,10 @@
protected $gid;
/**
+ * @var int Current user ID
+ */
+ protected $uid;
+ /**
* @var array The tabs set used in wiki module
*/
protected $tabs = array('view', 'edit', 'comments', 'history', 'map');
@@ -195,6 +199,14 @@ function set_gid($gid) {
}
/**
+ * Method to set current user id
+ * @param int $uid Current user id
+ */
+ function set_uid($uid) {
+ $this->uid = $uid;
+ }
+
+ /**
* Method to set the URL of the page.
* This method must be overwritten by every type of page.
*/
@@ -346,7 +358,7 @@ function __construct($wiki, $subwiki, $cm) {
global $CFG, $PAGE;
parent::__construct($wiki, $subwiki, $cm);
self::$attachmentoptions = array(
- 'subdirs' => false,
+ 'subdirs' => false,
'maxfiles' => -1,
'maxbytes' => $CFG->maxbytes,
'accepted_types'=>'*'
@@ -522,7 +534,7 @@ protected function print_edit($content = null) {
$data->newcontentformat = FORMAT_HTML;
$data = file_prepare_standard_editor($data, 'newcontent', page_wiki_edit::$attachmentoptions, $context, 'wiki_attachments', $this->subwiki->id);
break;
- default:
+ default:
//$draftitemid = file_get_submitted_draft_itemid('attachments');
//file_prepare_draft_area($draftitemid, $context->id, 'wiki_attachments', $this->subwiki->id);
//$data->attachments = $draftitemid;
@@ -872,10 +884,11 @@ function set_swid($swid) {
}
function set_action($action) {
+ global $PAGE;
$this->action = $action;
require_once(dirname(__FILE__) . '/create_form.php');
- $url = new moodle_url('/mod/wiki/create.php', array('action' => 'create', 'swid' => $this->swid));
+ $url = new moodle_url('/mod/wiki/create.php', array('action' => 'create', 'wid' => $PAGE->activityrecord->id, 'gid' => $this->gid, 'uid' => $this->uid));
$formats = wiki_get_formats();
$options = array('formats' => $formats);
if ($this->title != get_string('newpage', 'wiki')) {
@@ -894,7 +907,6 @@ function print_content($pagetitle = '') {
global $PAGE;
$context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
- $wiki = wiki_get_wiki($this->swid);
// @TODO: Change this to has_capability and show an alternative interface.
require_capability('mod/wiki:createpage', $context, NULL, true, 'nocreatepermission', 'wiki');
@@ -909,8 +921,12 @@ function print_content($pagetitle = '') {
}
function create_page() {
- global $USER, $CFG;
+ global $USER, $CFG, $PAGE;
$data = $this->mform->get_data();
+ if (empty($this->subwiki)){
+ $swid = wiki_add_subwiki($PAGE->activityrecord->id, $this->gid, $this->uid);
+ $this->subwiki = wiki_get_subwiki($swid);
+ }
$id = wiki_create_page($this->subwiki->id, $data->pagetitle, $data->pageformat, $USER->id);
redirect($CFG->wwwroot . '/mod/wiki/edit.php?pageid=' . $id);
}
View
@@ -36,7 +36,7 @@ public function page_index() {
// @TODO: Fix call to wiki_get_subwiki_by_group
$gid = groups_get_activity_group($this->page->cm);
- $gid = !empty($gid)?$gid:0;
+ $gid = !empty($gid) ? $gid : 0;
if (!$subwiki = wiki_get_subwiki_by_group($this->page->cm->instance, $gid)) {
return false;
}
@@ -314,20 +314,17 @@ public function wiki_print_subwiki_selector($wiki, $subwiki, $page) {
// Only people with these capabilities can view all wikis
if ($view && $manage) {
// @TODO: Print here a combo that contains all users.
- $subwikis = wiki_get_subwikis($wiki->id);
+ $users = get_enrolled_users($context);
$options = array();
- foreach ($subwikis as $subwiki) {
- if ($subwiki->userid == 0) {
- continue;
- }
- $user = user_get_users_by_id(array($subwiki->userid));
- $options[$subwiki->id] = fullname($user[$subwiki->userid]);
+ foreach ($users as $user) {
+ $options[$user->id] = fullname($user);
}
echo $this->output->container_start('wiki_right');
- $url = $CFG->wwwroot . '/mod/wiki/view.php?pageid=' . $page->id;
- $name = 'swid';
- $selected = $page->subwikiid;
+ $params = array('wid' => $wiki->id, 'title' => $page->title);
+ $url = new moodle_url('/mod/wiki/view.php', $params);
+ $name = 'uid';
+ $selected = $subwiki->userid;
echo $this->output->single_select($url, $name, $options, $selected);
echo $this->output->container_end();
}
@@ -340,38 +337,86 @@ public function wiki_print_subwiki_selector($wiki, $subwiki, $page) {
if ($wiki->wikimode == 'collaborative') {
// We need to print a select to choose a course group
- $params = 'pageid=' . $page->id;
+ $params = 'wid=' . $wiki->id . '&amp;title=' . urlencode($page->title);
echo $this->output->container_start('wiki_right');
groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/wiki/view.php?' . $params);
echo $this->output->container_end();
return;
} else if ($wiki->wikimode == 'individual') {
// @TODO: Print here a combo that contains all users of that subwiki.
+ $view = has_capability('mod/wiki:viewpage', $context, $USER);
+ $manage = has_capability('mod/wiki:managewiki', $context, $USER);
+
+ // Only people with these capabilities can view all wikis
+ if ($view && $manage) {
+ $users = get_enrolled_users($context);
+ $options = array();
+ foreach ($users as $user) {
+ $groups = groups_get_all_groups($cm->course, $user->id);
+ if (!empty($groups)) {
+ foreach ($groups as $group) {
+ $options[$group->id][$group->name][$group->id . '-' . $user->id] = fullname($user);
+ }
+ } else {
+ $name = get_string('notingroup', 'wiki');
+ $options[0][$name]['0' . '-' . $user->id] = fullname($user);
+ }
+ }
+ } else {
+ $group = groups_get_group($subwiki->groupid);
+ $users = groups_get_members($subwiki->groupid);
+ foreach ($users as $user) {
+ $options[$group->id][$group->name][$group->id . '-' . $user->id] = fullname($user);
+ }
+ }
echo $this->output->container_start('wiki_right');
- echo "TODO: Print here a combo to choose user wiki from that subwiki";
+ $params = array('wid' => $wiki->id, 'title' => $page->title);
+ $url = new moodle_url('/mod/wiki/view.php', $params);
+ $name = 'groupanduser';
+ $selected = $subwiki->groupid . '-' . $subwiki->userid;
+ echo $this->output->single_select($url, $name, $options, $selected);
echo $this->output->container_end();
+
return;
+
} else {
// error
return;
}
CASE VISIBLEGROUPS:
if ($wiki->wikimode == 'collaborative') {
// We need to print a select to choose a course group
-
- $params = 'pageid=' . $page->id;
+ $params = 'wid=' . $wiki->id . '&amp;title=' . urlencode($page->title);
echo $this->output->container_start('wiki_right');
groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/wiki/view.php?' . $params);
echo $this->output->container_end();
return;
} else if ($wiki->wikimode == 'individual') {
- // @TODO: Print here a combo that contains all users of that wiki grouped by group.
+ $users = get_enrolled_users($context);
+ $options = array();
+ foreach ($users as $user) {
+ $groups = groups_get_all_groups($cm->course, $user->id);
+ if (!empty($groups)) {
+ foreach ($groups as $group) {
+ $options[$group->id][$group->name][$group->id . '-' . $user->id] = fullname($user);
+ }
+ } else {
+ $name = get_string('notingroup', 'wiki');
+ $options[0][$name]['0' . '-' . $user->id] = fullname($user);
+ }
+ }
+
echo $this->output->container_start('wiki_right');
- echo "TODO: Print here a combo to choose user wiki from that wiki";
+ $params = array('wid' => $wiki->id, 'title' => $page->title);
+ $url = new moodle_url('/mod/wiki/view.php', $params);
+ $name = 'groupanduser';
+ $selected = $subwiki->groupid . '-' . $subwiki->userid;
+ echo $this->output->single_select($url, $name, $options, $selected);
echo $this->output->container_end();
+
return;
} else {
@@ -393,10 +438,10 @@ function menu_map($pageid, $currentselect) {
$items[] = get_string($opt, 'wiki');
}
$selectoptions = array();
- foreach ($items as $key=>$item) {
- $selectoptions[$key+1] = $item;
+ foreach ($items as $key => $item) {
+ $selectoptions[$key + 1] = $item;
}
- $select = new single_select(new moodle_url('/mod/wiki/map.php', array('pageid'=>$pageid)), 'option', $selectoptions, $currentselect);
+ $select = new single_select(new moodle_url('/mod/wiki/map.php', array('pageid' => $pageid)), 'option', $selectoptions, $currentselect);
$select->label = get_string('mapmenu', 'wiki') . ': ';
return $this->output->container($this->output->render($select), 'midpad');
}
Oops, something went wrong.

0 comments on commit 74c6a62

Please sign in to comment.