Ejemplo n.º 1
0
$ouwiki_nologin = true;
require_once dirname(__FILE__) . '/../../config.php';
require $CFG->dirroot . '/mod/ouwiki/basicpage.php';
$magic = required_param('magic', PARAM_RAW);
if ($magic != $subwiki->magic) {
    print_error('Incorrect magic number');
}
$newpages = optional_param('type', '', PARAM_ALPHA) == 'pages';
$rss = optional_param('format', '', PARAM_RAW) === 'rss';
// Get basic wiki parameters
$wikiparams = ouwiki_display_wiki_parameters('', $subwiki, $cm);
// Get changes
if ($newpages) {
    $changes = ouwiki_get_subwiki_recentpages($subwiki->id, 0, OUWIKI_FEEDSIZE);
} else {
    $changes = ouwiki_get_subwiki_recentchanges($subwiki->id, 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');
    }
}
$a = new StdClass();
$a->course = htmlspecialchars($course->shortname);
$a->name = htmlspecialchars($ouwiki->name);
Ejemplo n.º 2
0
 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
 }
    require_once '../../local/mobile/ou_lib.php';
    global $OUMOBILESUPPORT;
    $OUMOBILESUPPORT = true;
    ou_set_is_mobile(ou_get_is_mobile_from_cookies());
}
define('OUWIKI_PAGESIZE', 50);
$newpages = optional_param('type', '', PARAM_ALPHA) == 'pages';
$from = optional_param('from', '', PARAM_INT);
// Get basic wiki parameters
$wikiparams = ouwiki_display_wiki_parameters(null, $subwiki, $cm);
$tabparams = $newpages ? $wikiparams . '&type=pages' : $wikiparams;
// Get changes
if ($newpages) {
    $changes = ouwiki_get_subwiki_recentpages($subwiki->id, $from, OUWIKI_PAGESIZE + 1);
} else {
    $changes = ouwiki_get_subwiki_recentchanges($subwiki->id, $from, OUWIKI_PAGESIZE + 1);
}
// Do header
$atomurl = $CFG->wwwroot . '/mod/ouwiki/feed-wikihistory.php?' . $wikiparams . ($newpages ? '&type=pages' : '') . '&magic=' . $subwiki->magic;
$rssurl = $CFG->wwwroot . '/mod/ouwiki/feed-wikihistory.php?' . $wikiparams . ($newpages ? '&type=pages' : '') . '&magic=' . $subwiki->magic . '&format=rss';
$meta = '<link rel="alternate" type="application/atom+xml" title="Atom feed" ' . 'href="' . $atomurl . '" />';
// bug #3542
$wikiname = format_string(htmlspecialchars($ouwiki->name));
$title = $wikiname . ' - ' . get_string('wikirecentchanges', 'ouwiki');
if (class_exists('ouflags') && ou_get_is_mobile()) {
    ou_mobile_configure_theme();
}
ouwiki_print_start($ouwiki, $cm, $course, $subwiki, $from > 0 ? get_string('wikirecentchanges_from', 'ouwiki', (int) ($from / OUWIKI_PAGESIZE) + 1) : get_string('wikirecentchanges', 'ouwiki'), $context, null, false, false, $meta, $title);
// Print tabs for selecting all changes/new pages
$tabrow = array();
$tabrow[] = new tabobject('changes', 'wikihistory.php?' . $wikiparams, get_string('tab_index_changes', 'ouwiki'));
Ejemplo n.º 4
0
 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);
 }