$wiki->groupingid = $cm->groupingid; $wiki->groupmembersonly = $cm->groupmembersonly; $wiki->cmid = $cm->id; /// Default format: $moodle_format = FORMAT_MOODLE; ### SAVE ID from Moodle $moodleID = @$_REQUEST["id"]; /// Globally disable CamelCase, if the option is selected for this wiki. $moodle_disable_camel_case = $wiki->disablecamelcase == 1; if ($wiki_entry = wiki_get_default_entry($wiki, $course, $userid, $groupid)) { // OK, now we know the entry ID, we can do lock etc. // If true, we are 'really' on an editing page, not just on edit/something $reallyedit = $actions[0] == 'edit' && !$canceledit && !$editsave; // Remove lock when we go to another wiki page (such as the cancel page) if (!$reallyedit) { wiki_release_lock($wiki_entry->id, $pagename); } else { if (array_key_exists('content', $_POST)) { // Do not allow blank content because it causes problems (the wiki decides // the page should automatically go into edit mode, but Moodle doesn't realise // this and filters out the JS) if ($_POST['content'] == '') { $_POST['content'] = "\n"; $_REQUEST['content'] = "\n"; } // We must have the edit lock in order to be permitted to save list($ok, $lock) = wiki_obtain_lock($wiki_entry->id, $pagename); if (!$ok) { $strsavenolock = get_string('savenolock', 'wiki'); error($strsavenolock, $CFG->wwwroot . '/mod/wiki/view.php?id=' . $cm->id . '&page=view/' . urlencode($pagename)); }
/** * Returns a string which contains the information about * why a section is locked: because the page that contains it * is beeing edited, because it's part of a section that's beeing * edited, because it itself is already beeing edited or * because someone is editing one or more subsections of it. * If it's not locked returns the empty string. * * @param Object $WS WikiStorage * @param Integer $wikiid Id of current wiki * @param String $page PageName * @param String $sectionhash md5sum of the section * @param String $text Content text of the page * @return String Lock information */ function wiki_is_section_locked($WS, $wikiid, $page, $sectionhash, $text) { global $USER; $locks = array(); $lock = null; $lockstatus = null; $mypage = $page . '#' . $sectionhash; // check if page is locked $lock = wiki_is_locked($WS, $wikiid, $page); if ($lock) { $locks[] = $lock; $lockstatus = get_string('lockedsectionbypage_header', 'wiki'); $lockstatus .= wiki_get_locks_table($WS, $locks, $page, 'page'); $lockstatus .= get_string('lockedsection_footer', 'wiki'); $lockstatus .= wiki_get_override_info($WS, $page, $locks); return $lockstatus; } // check if the section it's already locked $lock = wiki_is_locked($WS, $wikiid, $mypage); if ($lock) { if (wiki_is_locked_by_userid($WS, $WS->dfwiki->id, $mypage, $USER->id)) { // if it's our lock allow to edit anyway wiki_release_lock($WS, $WS->dfwiki->id, $mypage); return null; } $locks[] = $lock; $lockstatus = get_string('lockedsection_header', 'wiki'); $lockstatus .= wiki_get_locks_table($WS, $locks, $mypage, 'page'); $lockstatus .= get_string('lockedsection_footer', 'wiki'); $lockstatus .= wiki_get_override_info($WS, $mypage, $locks); return $lockstatus; } // check if relative sections (parents/subsections) are locked $relative_hashes = wiki_get_relative_sections($text, $sectionhash); //// check parents foreach ($relative_hashes[0] as $parent_hash) { $mypage = $page . '#' . $parent_hash; $lock = wiki_is_locked($WS, $wikiid, $mypage); if ($lock) { $locks[] = $lock; } } $parents_locked = count($locks); if ($parents_locked > 0) { $lockstatus = get_string('lockedsectionbyparent_header', 'wiki'); $lockstatus .= wiki_get_locks_table($WS, $locks, $mypage, 'sections'); $lockstatus .= get_string('lockedsectionbyparent_footer', 'wiki'); $lockstatus .= wiki_get_override_info($WS, $mypage, $locks); return $lockstatus; } //// check subsections $locks = array(); foreach ($relative_hashes[1] as $subsection_hash) { $mypage = $page . '#' . $subsection_hash; $lock = wiki_is_locked($WS, $wikiid, $mypage); if ($lock) { $locks[] = $lock; } } $subsections_locked = count($locks); if ($subsections_locked > 0) { $a = null; $a->n = $subsections_locked; $lockstatus = get_string('lockedsectionbysubsections_header', 'wiki', $a); $lockstatus .= wiki_get_locks_table($WS, $locks, $mypage, 'sections'); $lockstatus .= get_string('lockedsection_footer', 'wiki'); $lockstatus .= wiki_get_override_info($WS, $mypage, $locks); return $lockstatus; } return $lockstatus; }