function ouwiki_print_tabs($selected, $pagename, $subwiki, $cm, $context, $pageexists = true, $pagelocked = false)
{
    global $CFG;
    $tabrow = array();
    if (class_exists('ouflags')) {
        //  OpenLearn insitu editing
        //  Now we have to check if we are in an insitu edited course and display
        //  the extra tabs for versions and the main mod settings (tidyer this way)
        //  means you don't need to go back to the course homepage to edit the other
        //  mod settings
        if (has_capability('local/course:revisioneditor', get_context_instance(CONTEXT_COURSE, $cm->course), null, false)) {
            if (!empty($revisionedit)) {
                //  We don't need a URL as the current tab is always empty, and this tab
                //  will only display while you are viewing a revision
                $tabrow[] = new tabobject('viewrevision', '', 'View Revision');
                $current_tab = 'viewrevision';
            }
            $tabrow[] = new tabobject('edit_settings', $CFG->wwwroot . '/course/modedit.php?update=' . $cm->id . '&return=1', 'Edit Settings');
            $tabrow[] = new tabobject('revisions', $CFG->wwwroot . '/local/insitu/activity_revisions.php?id=' . $cm->id, get_string('revisions', 'course'));
        }
    }
    $params = ouwiki_display_wiki_parameters($pagename, $subwiki, $cm);
    $tabrow[] = new tabobject('view', 'view.php?' . $params, get_string('tab_view', 'ouwiki'));
    if ($subwiki->canedit && !$pagelocked) {
        $tabrow[] = new tabobject('edit', 'edit.php?' . $params, get_string('tab_edit', 'ouwiki'));
    }
    if (ouwiki_get_commenting($subwiki->commenting) == OUWIKI_COMMENTS_ANNOTATION || ouwiki_get_commenting($subwiki->commenting) == OUWIKI_COMMENTS_BOTH) {
        if ($subwiki->canannotate) {
            $tabrow[] = new tabobject('annotate', 'annotate.php?' . $params, get_string('tab_annotate', 'ouwiki'));
        }
    }
    if (!class_exists('ouflags') && $pageexists || class_exists('ouflags') && !ou_get_is_mobile() && $pageexists) {
        $tabrow[] = new tabobject('history', 'history.php?' . $params, get_string('tab_history', 'ouwiki'));
    }
    $tabs = array();
    $tabs[] = $tabrow;
    print_tabs($tabs, $selected, $pageexists ? '' : array('edit', 'annotate'));
    print '<div id="ouwiki_belowtabs">';
}
$actioncancel = array_key_exists('cancel', $_POST);
if ($actionsave && class_exists('ouflags')) {
    $DASHBOARD_COUNTER = DASHBOARD_WIKI_EDIT;
}
if (!empty($_POST) && !confirm_sesskey()) {
    print_error('invalidrequest');
}
// We even display header etc. for preview posts (default is to hide for post)
require 'basicpage.php';
require_once dirname(__FILE__) . '/../../lib/ajax/ajaxlib.php';
// Get the current page version, creating page if needed
$pageversion = ouwiki_get_current_page($subwiki, $pagename, OUWIKI_GETPAGE_ACCEPTNOVERSION);
$wikiformfields = ouwiki_display_wiki_parameters($pagename, $subwiki, $cm, OUWIKI_PARAMS_FORM);
// Check permission
require_capability('mod/ouwiki:annotate', $context);
if (!(ouwiki_get_commenting($subwiki->commenting) == OUWIKI_COMMENTS_ANNOTATION || ouwiki_get_commenting($subwiki->commenting) == OUWIKI_COMMENTS_BOTH)) {
    $redirect = 'view.php?' . ouwiki_display_wiki_parameters($pagename, $subwiki, $cm, OUWIKI_PARAMS_URL);
    print_error('You do not have permission to annotate this wiki page', 'error', $redirect);
}
// Need list of known sections on current version
//$knownsections=ouwiki_find_sections($pageversion->xhtml);
// For everything except cancel we need to obtain a lock.
if (!$actioncancel) {
    if (!$pageversion) {
        error(get_string('startpagedoesnotexist', 'ouwiki'));
    }
    // Get lock
    list($lockok, $lock) = ouwiki_obtain_lock($ouwiki, $pageversion->pageid);
}
// Handle save
if ($actionsave) {