// Check permission - Allow anyone with edit capability to revert to a previous version
$canrevert = has_capability('mod/ouwiki:edit', $context);
if (!$canrevert) {
    print_error('reverterrorcapability', 'ouwiki');
}
// Check if reverting to previous version has been confirmed
$confirmed = optional_param('confirm', null, PARAM_RAW);
if ($confirmed) {
    // Lock something - but maybe this should be the current version
    list($lockok, $lock) = ouwiki_obtain_lock($ouwiki, $pageversion->pageid);
    // Revert to previous version
    ouwiki_save_new_version($course, $cm, $ouwiki, $subwiki, $pagename, $pageversion->xhtml);
    // Unlock whatever we locked
    ouwiki_release_lock($pageversion->pageid);
    // Redirect to view what is now the current version
    redirect('view.php?' . ouwiki_display_wiki_parameters($pagename, $subwiki, $cm, OUWIKI_PARAMS_URL));
    exit;
} else {
    // Display confirm form
    $nav = get_string('revertversion', 'ouwiki');
    ouwiki_print_start($ouwiki, $cm, $course, $subwiki, $pagename, $context, array(array('name' => $nav, 'type' => 'ouwiki')), true, true);
    print_box_start();
    $a = ouwiki_nice_date($pageversion->timecreated);
    print get_string('revertversionconfirm', 'ouwiki', $a);
    print '<form action="revert.php" method="post">';
    print ouwiki_display_wiki_parameters($pagename, $subwiki, $cm, OUWIKI_PARAMS_FORM);
    print '<input type="hidden" name="version" value="' . $versionid . '" />' . '<input type="submit" name="confirm" value="' . get_string('revertversion', 'ouwiki') . '"/> ' . '<input type="submit" name="cancel" value="' . get_string('cancel') . '"/>';
    print '</form>';
    print_box_end();
    ouwiki_print_footer($course, $cm, $subwiki, $pagename);
}
if ($subwiki->userid) {
    $userid = $subwiki->userid;
} else {
    $userid = required_param('userid', PARAM_INT);
}
require_capability('mod/ouwiki:viewcontributions', $context);
// Check for downloading to .csv file
$title = get_string('report_userreports', 'ouwiki');
$csv = false;
$format = optional_param('format', false, PARAM_ALPHA);
if ($format == 'csv' || $format == 'excelcsv') {
    $filename = substr($course->shortname . '_' . format_string(htmlspecialchars($ouwiki->name)), 0, 31 - strlen($title)) . '_' . $title;
    $csv = new csv_writer($filename, $format);
} else {
    // Do header
    ouwiki_print_start($ouwiki, $cm, $course, $subwiki, $title, $context, null, false);
    print '<div id="ouwiki_belowtabs_reports">';
}
// get header text for tables from language page
$header->user = get_string('report_user', 'ouwiki');
$header->username = get_string('report_username', 'ouwiki');
$header->startday = get_string('report_startday', 'ouwiki');
$header->lastday = get_string('report_lastday', 'ouwiki');
$header->timeonwiki = get_string('report_timeonwiki', 'ouwiki');
$header->createdpages = get_string('report_createdpages', 'ouwiki');
$header->editedpages = get_string('report_editedpages', 'ouwiki');
$header->edits = get_string('report_edits', 'ouwiki');
$header->comments = get_string('report_comments', 'ouwiki');
$header->additions = get_string('report_additions', 'ouwiki');
$header->deletes = get_string('report_deletes', 'ouwiki');
$header->otheredits = get_string('report_otheredits', 'ouwiki');
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package ouwiki
 */
/** */
$countasview = true;
require 'basicpage.php';
if (class_exists('ouflags')) {
    require_once '../../local/mobile/ou_lib.php';
    global $OUMOBILESUPPORT;
    $OUMOBILESUPPORT = true;
    ou_set_is_mobile(ou_get_is_mobile_from_cookies());
    if (ou_get_is_mobile()) {
        ou_mobile_configure_theme();
    }
}
ouwiki_print_start($ouwiki, $cm, $course, $subwiki, $pagename, $context);
global $CFG;
//cheeck consistency in setting Sub-wikis and group mode;
$urllink = $CFG->wwwroot . '/course/view.php?id=' . $cm->course;
if ($cm->groupmode == 0 && isset($subwiki->groupid)) {
    error("Sub-wikis is set to 'One wiki per group'. \n        Please change Group mode to 'Separate groups' or 'Visible groups'.", $urllink);
}
if ($cm->groupmode > 0 && !isset($subwiki->groupid)) {
    error("Sub-wikis is NOT set to 'One wiki per group'. \n        Please change Group mode to 'No groups'.", $urllink);
}
if (ajaxenabled() || class_exists('ouflags')) {
    // YUI and basic script
    require_js(array('yui_yahoo', 'yui_event', 'yui_connection', 'yui_dom', 'yui_animation'));
    // Print javascript
    print '<script type="text/javascript" src="ouwiki.js"></script><script type="text/javascript">
    strCloseComments="' . addslashes_js(get_string('closecomments', 'ouwiki')) . '";
$countasview = true;
require 'basicpage.php';
if (class_exists('ouflags')) {
    require_once '../../local/mobile/ou_lib.php';
    global $OUMOBILESUPPORT;
    $OUMOBILESUPPORT = true;
    ou_set_is_mobile(ou_get_is_mobile_from_cookies());
}
$treemode = optional_param('type', '', PARAM_ALPHA) == 'tree';
// Get basic wiki parameters
$wikiparams = ouwiki_display_wiki_parameters(null, $subwiki, $cm);
// Do header
if (class_exists('ouflags') && ou_get_is_mobile()) {
    ou_mobile_configure_theme();
}
ouwiki_print_start($ouwiki, $cm, $course, $subwiki, get_string('index', 'ouwiki'), $context, null, false);
// Print tabs for selecting index type
$tabrow = array();
$tabrow[] = new tabobject('alpha', 'wikiindex.php?' . $wikiparams, get_string('tab_index_alpha', 'ouwiki'));
$tabrow[] = new tabobject('tree', 'wikiindex.php?' . $wikiparams . '&amp;type=tree', get_string('tab_index_tree', 'ouwiki'));
$tabs = array();
$tabs[] = $tabrow;
print_tabs($tabs, $treemode ? 'tree' : 'alpha');
print '<div id="ouwiki_belowtabs">';
global $orphans;
function ouwiki_display_page_in_index($indexitem, $subwiki, $cm)
{
    if ($startpage = is_null($indexitem->title)) {
        $title = get_string('startpage', 'ouwiki');
        $output = '<div class="ouw_index_startpage">';
    } else {
require 'basicpage.php';
$v1 = required_param('v1', PARAM_INT);
$v2 = required_param('v2', PARAM_INT);
// Check permission - Allow anyone with delete page capability to compare with a deleted page version
$candelete = has_capability('mod/ouwiki:deletepage', $context);
// Get the current page [and current version, which we ignore]
$pageversion1 = ouwiki_get_page_version($subwiki, $pagename, $v1);
$pageversion2 = ouwiki_get_page_version($subwiki, $pagename, $v2);
if (!$pageversion1 || !$pageversion2 || (!empty($pageversion1->deletedat) || !empty($pageversion2->deletedat)) && !$candelete) {
    error('Specified version does not exist');
}
if ($pageversion1 >= $pageversion2) {
    error('Versions out of order');
}
// Print header
ouwiki_print_start($ouwiki, $cm, $course, $subwiki, $pagename, $context, array(array('name' => get_string('tab_history', 'ouwiki'), 'link' => 'history.php?' . ouwiki_display_wiki_parameters($pagename, $subwiki, $cm), 'type' => 'ouwiki'), array('name' => get_string('changesnav', 'ouwiki'), 'type' => 'ouwiki')), true, true);
// Obtain difference between two versions
list($diff1, $diff2, $numchanges) = ouwiki_diff_html($pageversion1->xhtml, $pageversion2->xhtml);
// if there are no changes then check if there are any annotations in the new version
if ($numchanges == 0) {
    $annotations = ouwiki_get_annotations($pageversion2);
    if (count($annotations) === 0) {
        $advice = get_string('diff_nochanges', 'ouwiki');
    } else {
        $advice = get_string('diff_someannotations', 'ouwiki');
    }
} else {
    $advice = get_string('advice_diff', 'ouwiki');
}
print '<p class="ouw_advice">' . $advice . ' ' . get_string('returntohistory', 'ouwiki', 'history.php?' . ouwiki_display_wiki_parameters($pagename, $subwiki, $cm)) . '</p>';
// Obtain difference between two versions
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 ? '&amp;type=pages' : '') . '&amp;magic=' . $subwiki->magic;
$rssurl = $CFG->wwwroot . '/mod/ouwiki/feed-wikihistory.php?' . $wikiparams . ($newpages ? '&amp;type=pages' : '') . '&amp;magic=' . $subwiki->magic . '&amp;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'));
$tabrow[] = new tabobject('pages', 'wikihistory.php?' . $wikiparams . '&amp;type=pages', get_string('tab_index_pages', 'ouwiki'));
$tabs = array();
$tabs[] = $tabrow;
print_tabs($tabs, $newpages ? 'pages' : 'changes');
print '<div id="ouwiki_belowtabs">';
// On first page, show information
if (!$from) {
    print get_string('advice_wikirecentchanges_' . ($newpages ? 'pages' : 'changes' . (!empty($CFG->ouwikienablecurrentpagehighlight) ? '' : '_nohighlight')), 'ouwiki') . '</p>';
}
$strdate = get_string('date');
$strtime = get_string('time');
$strpage = get_string('page', 'ouwiki');
 * @author s.marshall@open.ac.uk
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package ouwiki
 */
/** */
require 'basicpage.php';
if (class_exists('ouflags')) {
    require_once '../../local/mobile/ou_lib.php';
    global $OUMOBILESUPPORT;
    $OUMOBILESUPPORT = true;
    ou_set_is_mobile(ou_get_is_mobile_from_cookies());
    if (ou_get_is_mobile()) {
        ou_mobile_configure_theme();
    }
}
ouwiki_print_start($ouwiki, $cm, $course, $subwiki, get_string('searchresults'), $context);
require_once '../../blocks/ousearch/searchlib.php';
$querytext = stripslashes(required_param('query', PARAM_RAW));
$query = new ousearch_search($querytext);
$query->set_coursemodule($cm);
if ($subwiki->groupid) {
    $query->set_group_id($subwiki->groupid);
}
if ($subwiki->userid) {
    $query->set_user_id($subwiki->userid);
}
$foundsomething = ousearch_display_results($query, 'search.php?' . ouwiki_display_wiki_parameters(null, $subwiki, $cm));
// Footer
ouwiki_print_footer($course, $cm, $subwiki, null, 'search.php?query=' . urlencode($querytext), $foundsomething ? null : 'searchfailure', $querytext);
?>
$wikiparams = ouwiki_display_wiki_parameters($pagename, $subwiki, $cm);
$wikiinputs = ouwiki_display_wiki_parameters($pagename, $subwiki, $cm, OUWIKI_PARAMS_FORM);
// Do header
$atomurl = $CFG->wwwroot . '/mod/ouwiki/feed-history.php?' . $wikiparams . '&amp;magic=' . $subwiki->magic;
$rssurl = $CFG->wwwroot . '/mod/ouwiki/feed-history.php?' . $wikiparams . '&amp;magic=' . $subwiki->magic . '&amp;format=rss';
$meta = '<link rel="alternate" type="application/atom+xml" title="Atom feed" ' . 'href="' . $atomurl . '" />';
$title = get_string('historyfor', 'ouwiki');
$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)) {
    $overridebutton = $canoverride ? "\n<form class='ouwiki_overridelock' action='override.php' method='post'>\n  <input type='hidden' name='redirpage' value='annotate'>\n  {$wikiformfields}\n  <input type='submit' value='{$overridelock}' />\n</form>\n" : '';
    $cancel = get_string('cancel');
    $tryagain = get_string('tryagain', 'ouwiki');
    print "\n<div id='ouwiki_lockinfo'>\n  <h2>{$pagelockedtitle}</h2>\n  <p>{$pagelockeddetails} {$pagelockedtimeout}</p>\n  {$pagelockedoverride}\n  <div class='ouwiki_lockinfobuttons'>\n    <form action='edit.php' method='get'>\n      {$wikiformfields}\n      <input type='submit' value='{$tryagain}' />\n    </form>\n    <form action='view.php' method='get'>\n      {$wikiformfields}\n      <input type='submit' value='{$cancel}' />\n    </form>\n    {$overridebutton}\n  </div>\n</div>";
    print_footer($course);
    exit;
}
// The page is now locked to us! Go ahead and print edit form
// get title of the page
$title = get_string('annotatingpage', 'ouwiki');
$wikiname = format_string(htmlspecialchars($ouwiki->name));
$name = '';
$name = $pagename;
$title = $wikiname . ' - ' . $title . ' : ' . $name;
// Print header
ouwiki_print_start($ouwiki, $cm, $course, $subwiki, $pagename, $context, array(array('name' => get_string('annotatingpage', 'ouwiki'), 'type' => 'ouwiki')), false, false, '', $title);
if (ajaxenabled() || class_exists('ouflags')) {
    // YUI and basic script
    require_js(array('yui_yahoo', 'yui_connection', 'yui_dom', 'yui_dom-event', 'yui_animation', 'yui_container', 'yui_dragdrop', 'yui_element', 'yui_button'));
    // Print javascript
    print '<script type="text/javascript" src="annotate.js"></script><script type="text/javascript">
    strCloseComments="' . addslashes_js(get_string('closecomments', 'ouwiki')) . '";
    strCloseCommentForm="' . addslashes_js(get_string('closecommentform', 'ouwiki')) . '";
    ouwikiStrings = {save : "' . addslashes_js(get_string('add')) . '",
        cancel : "' . addslashes_js(get_string('cancel')) . '"};
    </script>';
}
// Tabs
ouwiki_print_tabs('annotate', $pagename, $subwiki, $cm, $context, $pageversion->versionid ? true : false, $pageversion->locked);
ouwiki_print_editlock($lock, $ouwiki);
if ($ouwiki->timeout && $js) {
switch ($format) {
    case OUWIKI_FORMAT_TEMPLATE:
        header('Content-Type: text/xml; encoding=UTF-8');
        header('Content-Disposition: attachment; filename="' . $filename . '.template.xml"');
        print '<wiki>';
        break;
    case OUWIKI_FORMAT_RTF:
        require_once '../../local/rtf.php';
        $html = '<root><p>' . get_string('savedat', 'ouwiki', userdate(time())) . '</p><hr />';
        break;
    case OUWIKI_FORMAT_HTML:
        // Do header
        if (class_exists('ouflags') && ou_get_is_mobile()) {
            ou_mobile_configure_theme();
        }
        ouwiki_print_start($ouwiki, $cm, $course, $subwiki, get_string('entirewiki', 'ouwiki'), $context, null, false, true);
        print '<div class="ouwiki_content">';
        break;
}
// Get list of all pages
$first = true;
$index = ouwiki_get_subwiki_index($subwiki->id);
foreach ($index as $pageinfo) {
    // Get page details
    $pageversion = ouwiki_get_current_page($subwiki, $pageinfo->title);
    // If the page hasn't really been created yet, skip it
    if (is_null($pageversion->xhtml)) {
        continue;
    }
    $visibletitle = is_null($pageversion->title) ? get_string('startpage', 'ouwiki') : $pageversion->title;
    switch ($format) {
    } else {
        if (!$section) {
            $name = get_string('startpage', 'ouwiki');
        } else {
            $title = get_string('editingsection', 'ouwiki');
            $name = htmlspecialchars($sectiontitle);
        }
    }
    // endif
}
$title = $wikiname . ' - ' . $title . ' : ' . $name;
// Print header
if (class_exists('ouflags') && ou_get_is_mobile()) {
    ou_mobile_configure_theme();
}
ouwiki_print_start($ouwiki, $cm, $course, $subwiki, $pagename, $context, array(array('name' => $section ? get_string('editingsection', 'ouwiki', htmlspecialchars($sectiontitle)) : get_string('editingpage', 'ouwiki'), 'type' => 'ouwiki')), false, false, '', $title);
if ($addnewsection) {
    $section = false;
}
// Tabs
ouwiki_print_tabs('edit', $pagename, $subwiki, $cm, $context, $pageversion->versionid ? true : false);
// setup the edit locking
ouwiki_print_editlock($lock, $ouwiki);
// Calculate initial text for html editor
if ($section) {
    $existing = $sectiondetails->content;
} else {
    if ($addnewsection) {
        $existing = $sectionheader;
    } else {
        if ($pageversion) {