} else { // No page version found, reset page current version id $DB->set_field('ouwiki_pages', 'currentversionid', null, array('id' => $pageversion->pageid)); } } // Update completion status for user $completion = new completion_info($course); if ($completion->is_enabled($cm) && ($ouwiki->completionpages || $ouwiki->completionedits)) { $completion->update_state($cm, COMPLETION_INCOMPLETE); } } else { // Flag page version as no longer deleted $action = 'undelete'; $DB->set_field('ouwiki_versions', 'deletedat', null, array('id' => $versionid)); // Get first undeleted (current) page version (there must be one) $pageversions = ouwiki_get_page_history($pageversion->pageid, false, 0, 1); $currentpageversion = reset($pageversions); if (!$currentpageversion) { throw new Exception('Error deleting/undeleting ouwiki page version'); } // Check if version that has been undeleted should be the new current version if ($pageversion->currentversionid != $currentpageversion->versionid) { // Set new current version id $DB->set_field('ouwiki_pages', 'currentversionid', $currentpageversion->versionid, array('id' => $pageversion->pageid)); } // Update completion status for user $completion = new completion_info($course); if ($completion->is_enabled($cm) && ($ouwiki->completionedits || $ouwiki->completionpages)) { $completion->update_state($cm, COMPLETION_COMPLETE, $pageversion->userid); } }
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @package ouwiki */ global $ouwiki_nologin; $ouwiki_nologin = true; require_once dirname(__FILE__) . '/../../config.php'; require $CFG->dirroot . '/mod/ouwiki/basicpage.php'; // Get information about page $pageversion = ouwiki_get_current_page($subwiki, $pagename, OUWIKI_GETPAGE_CREATE); $magic = required_param('magic', PARAM_RAW); if ($magic != $subwiki->magic) { print_error('Incorrect magic number'); } $rss = optional_param('format', '', PARAM_RAW) === 'rss'; // Get history $changes = ouwiki_get_page_history($pageversion->pageid, false, 0, OUWIKI_FEEDSIZE); $useragent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $oldbrowser = !preg_match('/Opera/', $useragent) && preg_match('/MSIE [456]/', $useragent) || preg_match('/Firefox\\/1\\./', $useragent); if ($oldbrowser) { header('Content-Type: text/xml; charset=UTF-8'); } else { if ($rss) { header('Content-Type: application/rss+xml; charset=UTF-8'); } else { header('Content-Type: application/atom+xml; charset=UTF-8'); } } $pagetitle = $pageversion->title === '' ? get_string('startpage', 'ouwiki') : htmlspecialchars($pageversion->title); $a = new StdClass(); $a->course = htmlspecialchars($course->shortname); $a->name = htmlspecialchars($ouwiki->name);
function test_ouwiki_pages_and_versions() { $user = $this->get_new_user(); $course = $this->get_new_course(); // setup a wiki to use $ouwiki = $this->get_new_ouwiki($course->id, OUWIKI_SUBWIKIS_SINGLE); $cm = $this->get_new_course_module($course->id, $ouwiki->id, NOGROUPS); $context = get_context_instance(CONTEXT_MODULE, $cm->instance); $groupid = 0; $subwiki = ouwiki_get_subwiki($course, $ouwiki, $cm, $context, $groupid, $user->id, true); // create the start page $startpagename = 'startpage'; $formdata = null; $startpageversion = ouwiki_get_current_page($subwiki, $startpagename, OUWIKI_GETPAGE_CREATE); ouwiki_save_new_version($course, $cm, $ouwiki, $subwiki, $startpagename, $startpagename, -1, -1, -1, null, $formdata); $this->assertIsA($subwiki, "stdClass"); // create a page $pagename1 = 'testpage1'; $content1 = 'testcontent'; // we don't get anything returned for this ouwiki_create_new_page($course, $cm, $ouwiki, $subwiki, $startpagename, $pagename1, $content1, $formdata); // try get that page $pageversion = ouwiki_get_current_page($subwiki, $pagename1); $this->assertIsA($subwiki, "stdClass"); $this->assertEqual($pageversion->title, $pagename1); // make some more version $content2 = "testcontent2"; $content3 = "testcontent3"; ouwiki_save_new_version($course, $cm, $ouwiki, $subwiki, $pagename1, $content2, -1, -1, -1, null, $formdata); ouwiki_save_new_version($course, $cm, $ouwiki, $subwiki, $pagename1, $content3, -1, -1, -1, null, $formdata); // get the history $history = ouwiki_get_page_history($pageversion->pageid, true); $this->assertIsA($history, "array"); // last version should match $content3 $lastversion = array_shift($history); $pageversion = ouwiki_get_page_version($subwiki, $pagename1, $lastversion->versionid); $this->assertEqual($pageversion->xhtml, $content3); // add another page $pagename2 = 'testpage2'; $content4 = 'testcontent4'; // we don't get anything returned for this ouwiki_create_new_page($course, $cm, $ouwiki, $subwiki, $startpagename, $pagename2, $content4, $formdata); // test recent pages $changes = ouwiki_get_subwiki_recentpages($subwiki->id); $this->assertIsA($changes, "array"); // first page should be startpage $this->assertEqual($changes[1]->title, $startpagename); // 3rd page should be pagename2 $this->assertEqual($changes[3]->title, $pagename2); // test recent wiki changes $changes = ouwiki_get_subwiki_recentchanges($subwiki->id); $this->assertEqual($changes[1]->title, $startpagename); // sixth change should be to testpage2 - when we created testpage2 $this->assertEqual($changes[6]->title, $pagename2); // seventh change shouldbe start page again - when we linked to testpage2 to startpage $this->assertEqual($changes[7]->title, $startpagename); // test deleting a version }
$wikiname = format_string(htmlspecialchars($ouwiki->name)); $name = ''; if ($pagename) { $name = $pagename; } else { $name = get_string('startpage', 'ouwiki'); } $title = $wikiname . ' - ' . $title . ' : ' . $name; ouwiki_print_start($ouwiki, $cm, $course, $subwiki, $pagename, $context, null, false, false, $meta, $title); // get delete capability for wiki page versions and associated delete strings $candelete = has_capability('mod/ouwiki:deletepage', $context); $strdelete = get_string('delete'); $strdeleted = get_string('deleted'); $strundelete = get_string('undelete', 'ouwiki'); // Get history $changes = ouwiki_get_page_history($pageversion->pageid, $candelete); ouwiki_print_tabs('history', $pagename, $subwiki, $cm, $context, true, $pageversion->locked); print_string('advice_history', 'ouwiki', "view.php?{$wikiparams}"); // Print message about deleted things being invisible to students so admins // don't get confused if ($candelete) { $found = false; foreach ($changes as $change) { if (!empty($change->deletedat)) { $found = true; break; } } if ($found) { print '<p class="ouw_deletedpageinfo">' . get_string('pagedeletedinfo', 'ouwiki') . '</p>'; }
public function test_ouwiki_pages_and_versions() { global $DB; $this->resetAfterTest(true); $user = $this->get_new_user(); $course = $this->get_new_course(); // Setup a wiki to use. $ouwiki = $this->get_new_ouwiki($course->id, OUWIKI_SUBWIKIS_SINGLE); $cm = get_coursemodule_from_instance('ouwiki', $ouwiki->id); $this->assertNotEmpty($cm); $context = context_module::instance($cm->id); $groupid = 0; $this->setUser($user); $subwiki = ouwiki_get_subwiki($course, $ouwiki, $cm, $context, $groupid, $user->id, true); // Create the start page. $startpagename = 'startpage'; $formdata = null; $startpageversion = ouwiki_get_current_page($subwiki, $startpagename, OUWIKI_GETPAGE_CREATE); $verid = ouwiki_save_new_version($course, $cm, $ouwiki, $subwiki, $startpagename, $startpagename, -1, -1, -1, null, $formdata); // Create a page. $pagename1 = 'testpage1'; $content1 = 'testcontent'; ouwiki_create_new_page($course, $cm, $ouwiki, $subwiki, $startpagename, $pagename1, $content1, $formdata); // Try get that page. $pageversion = ouwiki_get_current_page($subwiki, $pagename1); $this->assertEquals($pageversion->title, $pagename1); // Test fullname info from ouwiki_get_current_page. $this->assertEquals(fullname($user), fullname($pageversion)); // Make some more versions. $content2 = 'testcontent2'; $content3 = 'testcontent3'; ouwiki_save_new_version($course, $cm, $ouwiki, $subwiki, $pagename1, $content2, -1, -1, -1, null, $formdata); $verid = ouwiki_save_new_version($course, $cm, $ouwiki, $subwiki, $pagename1, $content3, -1, -1, -1, null, $formdata); $versions = $DB->get_records('ouwiki_versions'); $versionids = array(); foreach ($versions as $version) { $versionids[] = $version->id; } $this->assertEquals(max($versionids), $verid); $pageversion = ouwiki_get_current_page($subwiki, $pagename1); $this->assertEquals($content3, $pageversion->xhtml); // Get the history. $history = ouwiki_get_page_history($pageversion->pageid, true); $this->assertEquals('array', gettype($history)); // Last version should match $content3. $version = array_shift($history); $this->assertEquals(max($versionids), $version->versionid); $this->assertEquals($user->id, $version->id); $this->assertEquals(1, $version->wordcount); $this->assertEquals($pageversion->previousversionid, $version->previousversionid); $this->assertNull($version->importversionid); // Add another page. $pagename2 = 'testpage2'; $content4 = 'testcontent4'; // We don't get anything returned for this. ouwiki_create_new_page($course, $cm, $ouwiki, $subwiki, $startpagename, $pagename2, $content4, $formdata); // Test recent pages. $changes = ouwiki_get_subwiki_recentpages($subwiki->id); $this->assertEquals('array', gettype($changes)); $this->assertEquals(fullname($user), fullname(current($changes))); // First page should be startpage. $this->assertEquals(end($changes)->title, $startpagename); // 3rd page should be pagename2. $this->assertEquals(reset($changes)->title, $pagename2); $testfullname = fullname(current($changes)); $this->assertEquals(fullname($user), $testfullname); // Test recent wiki changes. $changes = ouwiki_get_subwiki_recentchanges($subwiki->id); $testfullname = fullname(reset($changes)); $this->assertEquals(fullname($user), $testfullname); $this->assertEquals(reset($changes)->title, $startpagename); // Sixth change should be to testpage2 - when we created testpage2. $this->assertEquals(next($changes)->title, $pagename2); // Seventh change shouldbe start page again - when we linked to testpage2 to startpage. $this->assertEquals(end($changes)->title, $startpagename); }