[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/wiki/ -> view.php (source)

   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * This file contains all necessary code to view a wiki page
  20   *
  21   * @package mod_wiki
  22   * @copyright 2009 Marc Alier, Jordi Piguillem marc.alier@upc.edu
  23   * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
  24   *
  25   * @author Jordi Piguillem
  26   * @author Marc Alier
  27   * @author David Jimenez
  28   * @author Josep Arus
  29   * @author Kenneth Riba
  30   *
  31   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32   */
  33  
  34  require_once('../../config.php');
  35  require_once($CFG->dirroot . '/mod/wiki/lib.php');
  36  require_once($CFG->dirroot . '/mod/wiki/locallib.php');
  37  require_once($CFG->dirroot . '/mod/wiki/pagelib.php');
  38  
  39  $id = optional_param('id', 0, PARAM_INT); // Course Module ID
  40  
  41  $pageid = optional_param('pageid', 0, PARAM_INT); // Page ID
  42  
  43  $wid = optional_param('wid', 0, PARAM_INT); // Wiki ID
  44  $title = optional_param('title', '', PARAM_TEXT); // Page Title
  45  $currentgroup = optional_param('group', 0, PARAM_INT); // Group ID
  46  $userid = optional_param('uid', 0, PARAM_INT); // User ID
  47  $groupanduser = optional_param('groupanduser', 0, PARAM_TEXT);
  48  
  49  $edit = optional_param('edit', -1, PARAM_BOOL);
  50  
  51  $action = optional_param('action', '', PARAM_ALPHA);
  52  $swid = optional_param('swid', 0, PARAM_INT); // Subwiki ID
  53  
  54  /*
  55   * Case 0:
  56   *
  57   * User that comes from a course. First wiki page must be shown
  58   *
  59   * URL params: id -> course module id
  60   *
  61   */
  62  if ($id) {
  63      // Cheacking course module instance
  64      if (!$cm = get_coursemodule_from_id('wiki', $id)) {
  65          print_error('invalidcoursemodule');
  66      }
  67  
  68      // Checking course instance
  69      $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
  70  
  71      require_login($course, true, $cm);
  72  
  73      // Checking wiki instance
  74      if (!$wiki = wiki_get_wiki($cm->instance)) {
  75          print_error('incorrectwikiid', 'wiki');
  76      }
  77      $PAGE->set_cm($cm);
  78  
  79      // Getting the subwiki corresponding to that wiki, group and user.
  80      //
  81      // Also setting the page if it exists or getting the first page title form
  82      // that wiki
  83  
  84      // Getting current group id
  85      $currentgroup = groups_get_activity_group($cm);
  86  
  87      // Getting current user id
  88      if ($wiki->wikimode == 'individual') {
  89          $userid = $USER->id;
  90      } else {
  91          $userid = 0;
  92      }
  93  
  94      // Getting subwiki. If it does not exists, redirecting to create page
  95      if (!$subwiki = wiki_get_subwiki_by_group($wiki->id, $currentgroup, $userid)) {
  96          $params = array('wid' => $wiki->id, 'group' => $currentgroup, 'uid' => $userid, 'title' => $wiki->firstpagetitle);
  97          $url = new moodle_url('/mod/wiki/create.php', $params);
  98          redirect($url);
  99      }
 100  
 101      // Getting first page. If it does not exists, redirecting to create page
 102      if (!$page = wiki_get_first_page($subwiki->id, $wiki)) {
 103          $params = array('swid'=>$subwiki->id, 'title'=>$wiki->firstpagetitle);
 104          $url = new moodle_url('/mod/wiki/create.php', $params);
 105          redirect($url);
 106      }
 107  
 108      /*
 109       * Case 1:
 110       *
 111       * A user wants to see a page.
 112       *
 113       * URL Params: pageid -> page id
 114       *
 115       */
 116  } elseif ($pageid) {
 117  
 118      // Checking page instance
 119      if (!$page = wiki_get_page($pageid)) {
 120          print_error('incorrectpageid', 'wiki');
 121      }
 122  
 123      // Checking subwiki
 124      if (!$subwiki = wiki_get_subwiki($page->subwikiid)) {
 125          print_error('incorrectsubwikiid', 'wiki');
 126      }
 127  
 128      // Checking wiki instance of that subwiki
 129      if (!$wiki = wiki_get_wiki($subwiki->wikiid)) {
 130          print_error('incorrectwikiid', 'wiki');
 131      }
 132  
 133      // Checking course module instance
 134      if (!$cm = get_coursemodule_from_instance("wiki", $subwiki->wikiid)) {
 135          print_error('invalidcoursemodule');
 136      }
 137  
 138      $currentgroup = $subwiki->groupid;
 139  
 140      // Checking course instance
 141      $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
 142  
 143      require_login($course, true, $cm);
 144      /*
 145       * Case 2:
 146       *
 147       * Trying to read a page from another group or user
 148       *
 149       * Page can exists or not.
 150       *  * If it exists, page must be shown
 151       *  * If it does not exists, system must ask for its creation
 152       *
 153       * URL params: wid -> subwiki id (required)
 154       *             title -> a page title (required)
 155       *             group -> group id (optional)
 156       *             uid -> user id (optional)
 157       *             groupanduser -> (optional)
 158       */
 159  } elseif ($wid && $title) {
 160  
 161      // Setting wiki instance
 162      if (!$wiki = wiki_get_wiki($wid)) {
 163          print_error('incorrectwikiid', 'wiki');
 164      }
 165  
 166      // Checking course module
 167      if (!$cm = get_coursemodule_from_instance("wiki", $wiki->id)) {
 168          print_error('invalidcoursemodule');
 169      }
 170  
 171      // Checking course instance
 172      $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
 173  
 174      require_login($course, true, $cm);
 175  
 176      $groupmode = groups_get_activity_groupmode($cm);
 177  
 178      if ($wiki->wikimode == 'individual' && ($groupmode == SEPARATEGROUPS || $groupmode == VISIBLEGROUPS)) {
 179          list($gid, $uid) = explode('-', $groupanduser);
 180      } else if ($wiki->wikimode == 'individual') {
 181          $gid = 0;
 182          $uid = $userid;
 183      } else if ($groupmode == NOGROUPS) {
 184          $gid = 0;
 185          $uid = 0;
 186      } else {
 187          $gid = $currentgroup;
 188          $uid = 0;
 189      }
 190  
 191      // Getting subwiki instance. If it does not exists, redirect to create page
 192      if (!$subwiki = wiki_get_subwiki_by_group($wiki->id, $gid, $uid)) {
 193          $context = context_module::instance($cm->id);
 194  
 195          $modeanduser = $wiki->wikimode == 'individual' && $uid != $USER->id;
 196          $modeandgroupmember = $wiki->wikimode == 'collaborative' && !groups_is_member($gid);
 197  
 198          $manage = has_capability('mod/wiki:managewiki', $context);
 199          $edit = has_capability('mod/wiki:editpage', $context);
 200          $manageandedit = $manage && $edit;
 201  
 202          if ($groupmode == VISIBLEGROUPS and ($modeanduser || $modeandgroupmember) and !$manageandedit) {
 203              print_error('nocontent','wiki');
 204          }
 205  
 206          $params = array('wid' => $wiki->id, 'group' => $gid, 'uid' => $uid, 'title' => $title);
 207          $url = new moodle_url('/mod/wiki/create.php', $params);
 208          redirect($url);
 209      }
 210  
 211      // Checking is there is a page with this title. If it does not exists, redirect to first page
 212      if (!$page = wiki_get_page_by_title($subwiki->id, $title)) {
 213          $params = array('wid' => $wiki->id, 'group' => $gid, 'uid' => $uid, 'title' => $wiki->firstpagetitle);
 214          // Check to see if the first page has been created
 215          if (!wiki_get_page_by_title($subwiki->id, $wiki->firstpagetitle)) {
 216              $url = new moodle_url('/mod/wiki/create.php', $params);
 217          } else {
 218              $url = new moodle_url('/mod/wiki/view.php', $params);
 219          }
 220          redirect($url);
 221      }
 222  
 223      //    /*
 224      //     * Case 3:
 225      //     *
 226      //     * A user switches group when is 'reading' a non-existent page.
 227      //     *
 228      //     * URL Params: wid -> wiki id
 229      //     *             title -> page title
 230      //     *             currentgroup -> group id
 231      //     *
 232      //     */
 233      //} elseif ($wid && $title && $currentgroup) {
 234      //
 235      //    // Checking wiki instance
 236      //    if (!$wiki = wiki_get_wiki($wid)) {
 237      //        print_error('incorrectwikiid', 'wiki');
 238      //    }
 239      //
 240      //    // Checking subwiki instance
 241      //    // @TODO: Fix call to wiki_get_subwiki_by_group
 242      //    if (!$currentgroup = groups_get_activity_group($cm)){
 243      //        $currentgroup = 0;
 244      //    }
 245      //    if (!$subwiki = wiki_get_subwiki_by_group($wid, $currentgroup)) {
 246      //        print_error('incorrectsubwikiid', 'wiki');
 247      //    }
 248      //
 249      //    // Checking page instance
 250      //    if ($page = wiki_get_page_by_title($subwiki->id, $title)) {
 251      //        unset($title);
 252      //    }
 253      //
 254      //    // Checking course instance
 255      //    $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
 256      //
 257      //    // Checking course module instance
 258      //    if (!$cm = get_coursemodule_from_instance("wiki", $wiki->id, $course->id)) {
 259      //        print_error('invalidcoursemodule');
 260      //    }
 261      //
 262      //    $subwiki = null;
 263      //    $page = null;
 264      //
 265      //    /*
 266      //     * Case 4:
 267      //     *
 268      //     * Error. No more options
 269      //     */
 270  } else {
 271      print_error('invalidparameters', 'wiki');
 272  }
 273  
 274  if (!wiki_user_can_view($subwiki, $wiki)) {
 275      print_error('cannotviewpage', 'wiki');
 276  }
 277  
 278  if (($edit != - 1) and $PAGE->user_allowed_editing()) {
 279      $USER->editing = $edit;
 280  }
 281  
 282  $wikipage = new page_wiki_view($wiki, $subwiki, $cm);
 283  
 284  $wikipage->set_gid($currentgroup);
 285  $wikipage->set_page($page);
 286  
 287  $context = context_module::instance($cm->id);
 288  if ($pageid) {
 289      wiki_page_view($wiki, $page, $course, $cm, $context, null, null, $subwiki);
 290  } else if ($id) {
 291      wiki_view($wiki, $course, $cm, $context);
 292  } else if ($wid && $title) {
 293      $other = array(
 294          'title' => $title,
 295          'wid' => $wid,
 296          'group' => $gid,
 297          'groupanduser' => $groupanduser
 298      );
 299      wiki_page_view($wiki, $page, $course, $cm, $context, $uid, $other, $subwiki);
 300  }
 301  
 302  $wikipage->print_header();
 303  $wikipage->print_content();
 304  
 305  $wikipage->print_footer();


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1