### Eclipse Workspace Patch 1.0
#P 19stable
Index: admin/roles/tabs.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/roles/tabs.php,v
retrieving revision 1.27.2.6
diff -u -r1.27.2.6 tabs.php
--- admin/roles/tabs.php	1 Jan 2009 14:29:37 -0000	1.27.2.6
+++ admin/roles/tabs.php	23 Mar 2009 17:08:07 -0000
@@ -154,6 +154,12 @@
                 }
             }
             break;
+        
+        case CONTEXT_PAGE:
+            if ($page = $DB->get_record('page', array('id' => $context->instanceid))) {
+                print_header($page->fullname, $page->fullname, build_navigation(array()));
+            }
+            break;
 
         default:
             error ('This is an unknown context (' . $context->contextlevel . ') in admin/roles/tabs.php!');
Index: admin/settings/top.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/settings/top.php,v
retrieving revision 1.15.2.8
diff -u -r1.15.2.8 top.php
--- admin/settings/top.php	28 Nov 2008 08:12:52 -0000	1.15.2.8
+++ admin/settings/top.php	23 Mar 2009 17:08:07 -0000
@@ -20,6 +20,8 @@
 
 $ADMIN->add('root', new admin_category('users', get_string('users','admin')));
 $ADMIN->add('root', new admin_category('courses', get_string('courses','admin')));
+$ADMIN->add('root', new admin_category('pages', get_string('pages','block_page')));
+$ADMIN->add('root', new admin_externalpage('pagemgmt', get_string('pagemgmt', 'block_page'), "$CFG->wwwroot/blocks/page/index.php", 'block/page:update'));
 $ADMIN->add('root', new admin_category('grades', get_string('grades')));
 $ADMIN->add('root', new admin_category('location', get_string('location','admin')));
 $ADMIN->add('root', new admin_category('language', get_string('language')));
Index: lib/accesslib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/accesslib.php,v
retrieving revision 1.421.2.99
diff -u -r1.421.2.99 accesslib.php
--- lib/accesslib.php	20 Mar 2009 12:01:38 -0000	1.421.2.99
+++ lib/accesslib.php	23 Mar 2009 17:08:08 -0000
@@ -144,6 +144,7 @@
 define('CONTEXT_GROUP', 60);
 define('CONTEXT_MODULE', 70);
 define('CONTEXT_BLOCK', 80);
+define('CONTEXT_PAGE', 90);
 
 // capability risks - see http://docs.moodle.org/en/Development:Hardening_new_Roles_system
 define('RISK_MANAGETRUST', 0x0001);
@@ -2170,6 +2171,9 @@
         case CONTEXT_USER:
             // default to basepath
             break;
+        case CONTEXT_PAGE:
+            // default to basepath
+            break;            
     }
 
     // if grandparents unknown, maybe rebuild_context_path() will solve it later
@@ -2349,6 +2353,18 @@
         execute_sql($sql, $feedback);
 
     }
+    
+    if (empty($contextlevel) or $contextlevel == CONTEXT_PAGE) {
+        $sql = "INSERT INTO {context} (contextlevel, instanceid)
+                SELECT ".CONTEXT_PAGE.", p.id
+                  FROM {page} p
+                 WHERE NOT EXISTS (SELECT 'x'
+                                     FROM {context} cx
+                                    WHERE p.id = cx.instanceid AND cx.contextlevel=".CONTEXT_PAGE.")";
+        execute_sql($sql,$feedback);
+
+    }
+    
 
     if ($buildpaths) {
         build_context_path(false, $feedback);
@@ -2394,6 +2410,14 @@
               SELECT c.contextlevel,
                      c.instanceid
               FROM {$CFG->prefix}context c
+              LEFT OUTER JOIN {$CFG->prefix}page t
+                   ON c.instanceid = t.id
+             WHERE t.id IS NULL AND c.contextlevel = ".CONTEXT_PAGE."
+            UNION
+              SELECT c.contextlevel,
+                     c.instanceid
+                FROM {context} c
+
               LEFT OUTER JOIN {$CFG->prefix}block_instance t
                 ON c.instanceid = t.id
               WHERE t.id IS NULL AND c.contextlevel = " . CONTEXT_BLOCK . "
@@ -2480,7 +2504,7 @@
 function get_context_instance($contextlevel, $instance=0) {
 
     global $context_cache, $context_cache_id, $CFG;
-    static $allowed_contexts = array(CONTEXT_SYSTEM, CONTEXT_USER, CONTEXT_COURSECAT, CONTEXT_COURSE, CONTEXT_GROUP, CONTEXT_MODULE, CONTEXT_BLOCK);
+    static $allowed_contexts = array(CONTEXT_SYSTEM, CONTEXT_USER, CONTEXT_COURSECAT, CONTEXT_COURSE, CONTEXT_GROUP, CONTEXT_MODULE, CONTEXT_BLOCK, CONTEXT_PAGE);
 
     if ($contextlevel === 'clearcache') {
         // TODO: Remove for v2.0
@@ -3493,6 +3517,20 @@
                 }
             }
             break;
+        
+        case CONTEXT_PAGE:
+            if ($page = get_record('page','id',$context->instanceid)) {
+                if ($withprefix){
+                    $name = get_string('page', 'block_page').': ';
+                }
+                if ($short){
+                    $name .= format_string($page->shortname);
+                } else {
+                    $name .= format_string($page->fullname);
+               }
+            }
+            break;
+            
 
         default:
             error ('This is an unknown context (' . $context->contextlevel . ') in print_context_name!');
@@ -3553,6 +3591,12 @@
                       FROM {$CFG->prefix}capabilities
                      WHERE contextlevel IN (".CONTEXT_COURSE.",".CONTEXT_MODULE.",".CONTEXT_BLOCK.")";
         break;
+        
+        case CONTEXT_PAGE: // course context and bellow
+            $SQL = "SELECT *
+                      FROM {capabilities}
+                     WHERE contextlevel IN (".CONTEXT_PAGE.",".CONTEXT_BLOCK.")";
+        break;
 
         case CONTEXT_MODULE: // mod caps
             $cm = get_record('course_modules', 'id', $context->instanceid);
@@ -3813,6 +3857,26 @@
 
             return get_records_sql($sql);
         break;
+        
+        case CONTEXT_PAGE:
+            // Find
+            // - blocks assigned to the page explicitly - easy
+            $params = "'{$context->path}/%'";
+            $sql = " SELECT ctx.*
+                       FROM {$CFG->prefix}context ctx
+                      WHERE ctx.path LIKE $params
+                            AND ctx.contextlevel IN (".CONTEXT_BLOCK.")";
+            $records = array();
+            if ($rs  = get_recordset_sql($sql)) {
+                foreach ($rs as $rec) {
+                    $records[$rec->id] = $rec;
+                    $context_cache[$rec->contextlevel][$rec->instanceid] = $rec;
+                }
+                rs_close($rs);
+            }
+            return $records;
+        break;
+        
 
         default:
             error('This is an unknown context (' . $context->contextlevel . ') in get_child_contexts!');
Index: lang/en_utf8/block_page.php
===================================================================
RCS file: lang/en_utf8/block_page.php
diff -N lang/en_utf8/block_page.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ lang/en_utf8/block_page.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,23 @@
+<?php
+
+$string['addnewpage'] = 'Add a new page';
+$string['blockeditoff'] = 'Turn block editing off';
+$string['blockediton'] = 'Turn block editing on';
+$string['blockname'] = 'Page Administration';
+$string['deletepage'] = 'Delete a page';
+$string['deletepagecheck'] = 'Are you absolutely sure you want to completely delete this page and all the data it contains?';
+$string['editpage'] = 'Edit page';
+$string['editpagesettings'] = 'Edit page settings';
+$string['fulllistofpages'] = 'All pages';
+$string['page'] = 'Page';
+$string['pagemgmt'] = 'Add/edit pages';
+$string['pages'] = 'Pages';
+
+//Capabilities
+$string['page:view'] = 'View pages';
+$string['page:create'] = 'Create pages';
+$string['page:delete'] = 'Delete pages';
+$string['page:update'] = 'Update pages';
+$string['page:visibility'] = 'Change page visibility';
+
+?>
Index: blocks/page/db/upgrade.php
===================================================================
RCS file: blocks/page/db/upgrade.php
diff -N blocks/page/db/upgrade.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ blocks/page/db/upgrade.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,34 @@
+<?php
+
+// This file keeps track of upgrades to 
+// the page block
+//
+// Sometimes, changes between versions involve
+// alterations to database structures and other
+// major things that may break installations.
+//
+// The upgrade function in this file will attempt
+// to perform all the necessary actions to upgrade
+// your older installtion to the current version.
+//
+// If there's something it cannot do itself, it
+// will tell you what you need to do.
+//
+// The commands in here will all be database-neutral,
+// using the functions defined in lib/ddllib.php
+
+function xmldb_block_page_upgrade($oldversion) {
+    global $CFG;
+
+    $dbman = get_manager();
+    $result = true;
+
+/// And upgrade begins here. For each one, you'll need one 
+/// block of code similar to the next one. Please, delete 
+/// this comment lines once this file start handling proper
+/// upgrade code.
+
+    return $result;
+}
+
+?>
Index: blocks/page/index.php
===================================================================
RCS file: blocks/page/index.php
diff -N blocks/page/index.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ blocks/page/index.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,77 @@
+<?php
+///////////////////////////////////////////////////////////////////////////
+//                                                                       //
+// NOTICE OF COPYRIGHT                                                   //
+//                                                                       //
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
+//          http://moodle.com                                            //
+//                                                                       //
+// Copyright (C) 1999 onwards Martin Dougiamas  http://dougiamas.com     //
+//                                                                       //
+// This program is free software; you can redistribute it and/or modify  //
+// it under the terms of the GNU General Public License as published by  //
+// the Free Software Foundation; either version 2 of the License, or     //
+// (at your option) any later version.                                   //
+//                                                                       //
+// This program is distributed in the hope that it will be useful,       //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
+// GNU General Public License for more details:                          //
+//                                                                       //
+//          http://www.gnu.org/copyleft/gpl.html                         //
+//                                                                       //
+///////////////////////////////////////////////////////////////////////////
+
+require_once("../../config.php");
+require_once("lib.php");
+
+$context = get_context_instance(CONTEXT_SYSTEM);
+
+require_login();
+
+if (!has_capability('block/page:update', $context)) {
+    redirect($CFG->wwwroot.'/');
+    exit;
+}
+
+$stradministration = get_string('administration');
+$strpages = get_string('pages', 'block_page');
+$stredit = get_string('edit');
+$strdelete = get_string('delete');
+$straction = get_string('action');
+
+
+/// From now on is all the admin/course creator functions
+
+/// Print headings
+
+if (has_capability('moodle/site:config', $context)) {
+    require_once($CFG->libdir.'/adminlib.php');
+    admin_externalpage_setup('pagemgmt');
+    admin_externalpage_print_header();
+} else {
+    print_header("$site->shortname: $strpages", $strpages,
+        build_navigation(array()), '', '', true);
+}
+
+print_heading($strpages);
+
+echo '<table class="generalbox editpage boxaligncenter"><tr class="header">';
+echo '<th class="header" scope="col">&nbsp;</th>';
+echo '<th class="header" scope="col">'.$stredit.'</th>';
+echo '</tr>';
+
+print_pages_edit();
+
+echo '</table>';
+
+echo '<div class="buttons">';
+
+
+if (has_capability('block/page:create', $context)) {
+    // print create course link to first category
+    print_single_button('edit.php', array(), get_string('addnewpage', 'block_page'), 'get');
+}
+
+print_footer();
+?>
Index: blocks/page/lib.php
===================================================================
RCS file: blocks/page/lib.php
diff -N blocks/page/lib.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ blocks/page/lib.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,209 @@
+<?php  
+///////////////////////////////////////////////////////////////////////////
+//                                                                       //
+// NOTICE OF COPYRIGHT                                                   //
+//                                                                       //
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
+//          http://moodle.com                                            //
+//                                                                       //
+// Copyright (C) 1999 onwards Martin Dougiamas  http://dougiamas.com     //
+//                                                                       //
+// This program is free software; you can redistribute it and/or modify  //
+// it under the terms of the GNU General Public License as published by  //
+// the Free Software Foundation; either version 2 of the License, or     //
+// (at your option) any later version.                                   //
+//                                                                       //
+// This program is distributed in the hope that it will be useful,       //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
+// GNU General Public License for more details:                          //
+//                                                                       //
+//          http://www.gnu.org/copyleft/gpl.html                         //
+//                                                                       //
+///////////////////////////////////////////////////////////////////////////
+
+require_once('../../config.php');
+require_once($CFG->dirroot.'/blocks/page/pagelib.php');
+
+/**
+ * Prints a table listing all pages
+ */
+function print_pages_edit() 
+{
+
+    global $CFG, $USER;
+
+    static $str = '';
+
+    if (empty($str)) {
+        $str->edit     = get_string('edit');
+        $str->delete   = get_string('delete');
+        $str->hide     = get_string('hide');
+        $str->show     = get_string('show');
+    }
+
+    if ($pages = get_records('page')) {
+
+    foreach ($pages as $page) {
+        $page->context = get_context_instance(CONTEXT_PAGE, $page->id);
+        
+        echo '<tr><td align="left" class="name">';
+        $linkcss = $page->visible ? '' : ' class="dimmed" ';
+        echo "<a {$linkcss} title=\"{$str->edit}\" href=\"{$CFG->wwwroot}/blocks/page/view.php?id={$page->id}\">".format_string($page->fullname)."</a>\r\n";
+        echo '</td>';
+        
+        echo '<td class="icons">';    /// Print little icons
+        
+        if (has_capability('block/page:update', $page->context)) {
+            echo "<a title=\"{$str->edit}\" href=\"edit.php?id={$page->id}\"><img src=\"{$CFG->pixpath}/i/edit.gif\" alt=\"{$str->edit}\" /></a>\r\n";
+        }
+
+        if (has_capability('block/page:delete', $page->context)) {
+            echo "<a title=\"{$str->delete}\" href=\"delete.php?id={$page->id}\"><img src=\"{$CFG->pixpath}/i/delete.png\" alt=\"{$str->delete}\" /></a>\r\n";
+        }
+
+        if (has_capability('block/page:visibility', $page->context)) {
+            if (!empty($page->visible)) {
+                echo "<a title=\"{$str->hide}\" href=\"view.php?hide=1&id={$page->id}&sesskey=".sesskey()."\"><img src=\"{$CFG->pixpath}/i/hide.gif\" alt=\"{$str->hide}\" /></a>\r\n";
+            } else {
+                echo "<a title=\"{$str->show}\" href=\"view.php?show=1&id={$page->id}&sesskey=".sesskey()."\"><img src=\"{$CFG->pixpath}/i/show.gif\" alt=\"{$str->show}\" /></a>\r\n";
+            }
+        }
+        
+        echo '</td>';
+        echo '</tr>';
+    }
+    }
+}
+
+/**
+ * Toggles a page visible/invisible
+ * @param int $pageid
+ * @param string $visibility
+ */
+function set_page_visible($pageid, $visibility) {
+    
+    
+    if (get_record('page', 'id', $pageid)) {
+        set_field('page', 'visible', $visibility, 'id', $pageid);
+    }
+}
+
+/* 
+ * Create a page and either return a $page object or false
+ *
+ * @param object $data  - all the data needed for an entry in the 'page' table
+ */
+function create_page($data) {
+    global $CFG, $USER;
+
+    $data->timecreated = time();
+
+    if ($newpageid = insert_record('page', $data)) {  // Set up new page
+
+        $page = get_record('page', 'id', $newpageid);
+
+        // Setup the blocks
+        $blocks = page_create_object(PAGE_STATIC_VIEW, $page->id);
+        blocks_repopulate_page($blocks); // Return value not checked because you can always edit later
+
+        return $page;
+    } 
+
+    return false;   // error
+}
+
+/* 
+ * Update a page and return true or false
+ *
+ * @param object $data  - all the data needed for an entry in the 'page' table
+ */
+function update_page($data) {
+    global $USER, $CFG;
+
+    // Update with the new data
+    if (update_record('page', $data)) {
+
+        $page = get_record('page', 'id',$data->id);
+
+        // Test for and remove blocks which aren't appropriate anymore
+        $blocks = page_create_object(PAGE_STATIC_VIEW, $page->id);
+        blocks_remove_inappropriate($blocks);
+
+        // put custom role names into db
+        $context = get_context_instance(CONTEXT_PAGE, $page->id);
+        
+        foreach ($data as $dname => $dvalue) {
+          
+            // is this the right param?
+            $dvalue = clean_param($dvalue, PARAM_NOTAGS);
+
+            if (!strstr($dname, 'role_')) {
+                continue;
+            }  
+            
+            $dt = explode('_', $dname);
+            $roleid = $dt[1];
+            // make up our mind whether we want to delete, update or insert
+            
+            if (empty($dvalue)) {
+                delete_records('role_names', 'contextid' , $context->id, 'roleid', $roleid);
+            } else if ($t = get_record('role_names', 'contextid', $context->id, 'roleid', $roleid)) {
+                $t->text = $dvalue;
+                update_record('role_names', $t);    
+            } else {
+                $t->contextid = $context->id;
+                $t->roleid = $roleid;
+                $t->text = $dvalue;
+                insert_record('role_names', $t);  
+            }
+        }
+
+        return true;
+    }
+
+    return false;
+}
+
+/* 
+ * Deletes a page
+ *
+ * @param int $pageid
+ */
+function delete_page($pageid) {
+    global $CFG, $USER;
+
+    $context = get_context_instance(CONTEXT_PAGE, $pageid);
+
+    if(has_capability('block/page:delete', $context))
+    {
+        delete_records('page', 'id', $pageid);
+
+    $sql = "SELECT * FROM ".$CFG->prefix."block_instance WHERE pagetype ='".PAGE_STATIC_VIEW."' AND pageid = ".$pageid;
+        if ($blocks = get_records_sql($sql)) {
+            if (delete_records('block_instance', 'pagetype', PAGE_STATIC_VIEW, 'pageid', $pageid)) {
+
+                require_once($CFG->libdir.'/blocklib.php');
+                foreach ($blocks as $block) {  /// Delete any associated contexts for this block
+
+                    delete_context(CONTEXT_BLOCK, $block->id);
+
+                    // fix for MDL-7164
+                    // Get the block object and call instance_delete()
+                    if (!$record = blocks_get_record($block->blockid)) {
+                        continue;
+                    }
+                    if (!$obj = block_instance($record->name, $block)) {
+                        continue;
+                    }
+                    // Return value ignored, in core mods this does not do anything, but just in case
+                    // third party blocks might have stuff to clean up
+                    // we execute this anyway
+                    $obj->instance_delete();
+
+                }
+            }
+        }
+    }
+}
+?>
Index: blocks/page/edit.php
===================================================================
RCS file: blocks/page/edit.php
diff -N blocks/page/edit.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ blocks/page/edit.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,119 @@
+<?php
+///////////////////////////////////////////////////////////////////////////
+//                                                                       //
+// NOTICE OF COPYRIGHT                                                   //
+//                                                                       //
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
+//          http://moodle.com                                            //
+//                                                                       //
+// Copyright (C) 1999 onwards Martin Dougiamas  http://dougiamas.com     //
+//                                                                       //
+// This program is free software; you can redistribute it and/or modify  //
+// it under the terms of the GNU General Public License as published by  //
+// the Free Software Foundation; either version 2 of the License, or     //
+// (at your option) any later version.                                   //
+//                                                                       //
+// This program is distributed in the hope that it will be useful,       //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
+// GNU General Public License for more details:                          //
+//                                                                       //
+//          http://www.gnu.org/copyleft/gpl.html                         //
+//                                                                       //
+///////////////////////////////////////////////////////////////////////////
+
+require_once('../../config.php');
+require_once($CFG->dirroot.'/enrol/enrol.class.php');
+require_once($CFG->libdir.'/blocklib.php');
+require_once('lib.php');
+require_once('pagelib.php');
+require_once('edit_form.php');
+
+$id = optional_param('id', 0, PARAM_INT); //Page ID
+
+if ($id) {
+    //We are editing a page
+    if (!$page = get_record('page', 'id', $id)) {
+        error('Page ID was incorrect');
+    }
+
+    require_capability('block/page:update', get_context_instance(CONTEXT_PAGE, $page->id));
+} else {
+    //We are creating a new page
+    $page = null;
+    require_login();
+
+    require_capability('block/page:create', get_context_instance(CONTEXT_SYSTEM));
+}
+
+
+// Page Editing Form
+$editform = new page_edit_form('edit.php');
+
+// Override defaults if page exists
+if (!empty($page)) {
+    $editform->set_data($page);
+}
+
+if ($editform->is_cancelled()) {
+    if (empty($page)) {
+        redirect($CFG->wwwroot);
+    } else {
+        redirect($CFG->wwwroot.'/blocks/page/view.php?id='.$page->id);
+    }
+} else if ($data = $editform->get_data()) {
+
+    $data->timemodified = time();
+
+    if (empty($page)) {
+        if (!$page = create_page($data)) {
+            print_error('coursenotcreated');
+        }
+        
+        redirect($CFG->wwwroot."/blocks/page/view.php?id=$page->id");
+
+    } else {
+        if (!update_page($data)) {
+            print_error('coursenotupdated');
+        }
+
+        redirect($CFG->wwwroot."/blocks/page/view.php?id=$page->id");
+    }
+}
+
+
+/// Print the form
+
+$site = get_site();
+
+$streditcoursesettings = get_string('editpagesettings', 'block_page');
+$straddnewcourse = get_string('addnewpage', 'block_page');
+$stradministration = get_string('blockname', 'block_page');
+$navlinks = array();
+
+if (!empty($page)) {
+    $navlinks[] = array('name' => $streditcoursesettings,
+                        'link' => null,
+                        'type' => 'misc');
+    $title = $streditcoursesettings;
+    $fullname = $page->fullname;
+} else {
+    $navlinks[] = array('name' => $stradministration,
+                        'link' => "$CFG->wwwroot/$CFG->admin/index.php",
+                        'type' => 'misc');
+    $navlinks[] = array('name' => $straddnewcourse,
+                        'link' => null,
+                        'type' => 'misc');
+    $title = "$site->shortname: $straddnewcourse";
+    $fullname = $site->fullname;
+}
+
+$navigation = build_navigation($navlinks);
+print_header($title, $fullname, $navigation, $editform->focus());
+print_heading($streditcoursesettings);
+
+$editform->display();
+
+print_footer();
+
+?>
Index: blocks/page/db/access.php
===================================================================
RCS file: blocks/page/db/access.php
diff -N blocks/page/db/access.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ blocks/page/db/access.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,95 @@
+<?php
+//
+// Capability definitions for the pages block and system.
+//
+// The capabilities are loaded into the database table when the block is
+// installed or updated. Whenever the capability definitions are updated,
+// the module version number should be bumped up.
+//
+// The system has four possible values for a capability:
+// CAP_ALLOW, CAP_PREVENT, CAP_PROHIBIT, and inherit (not set).
+//
+//
+// CAPABILITY NAMING CONVENTION
+//
+// It is important that capability names are unique. The naming convention
+// for capabilities that are specific to modules and blocks is as follows:
+//   [mod/block]/<component_name>:<capabilityname>
+//
+// component_name should be the same as the directory name of the mod or block.
+//
+// Core moodle capabilities are defined thus:
+//    moodle/<capabilityclass>:<capabilityname>
+//
+// Examples: mod/forum:viewpost
+//           block/recent_activity:view
+//           moodle/site:deleteuser
+//
+// The variable name for the capability definitions array follows the format
+//   $<componenttype>_<component_name>_capabilities
+//
+// For the core capabilities, the variable is $moodle_capabilities.
+
+
+$block_page_capabilities = array(
+
+    'block/page:view' => array(
+
+        'riskbitmask' => RISK_PERSONAL,
+
+        'captype' => 'read',
+        'contextlevel' => CONTEXT_SYSTEM,
+        'legacy' => array(
+            'guest' => CAP_ALLOW,
+            'user' => CAP_ALLOW,
+            'student' => CAP_ALLOW,
+            'teacher' => CAP_ALLOW,
+            'editingteacher' => CAP_ALLOW,
+            'coursecreator' => CAP_ALLOW,
+            'admin' => CAP_ALLOW
+        )
+    ),
+    
+    'block/page:create' => array(
+
+        'riskbitmask' => RISK_SPAM | RISK_XSS,
+
+        'captype' => 'write',
+        'contextlevel' => CONTEXT_SYSTEM,
+        'legacy' => array(
+            'admin' => CAP_ALLOW
+        )
+    ),
+
+    'block/page:delete' => array(
+        'captype' => 'write',
+        'contextlevel' => CONTEXT_SYSTEM,
+        'legacy' => array(
+            'admin' => CAP_ALLOW
+        )
+    ),
+
+    'block/page:update' => array(
+
+        'riskbitmask' => RISK_SPAM | RISK_XSS,
+
+        'captype' => 'write',
+        'contextlevel' => CONTEXT_SYSTEM,
+        'legacy' => array(
+            'admin' => CAP_ALLOW
+        )
+    ),
+    
+    'block/page:visibility' => array(
+
+        'riskbitmask' => RISK_SPAM | RISK_PERSONAL,
+
+        'captype' => 'write',
+        'contextlevel' => CONTEXT_SYSTEM,
+        'legacy' => array(
+            'admin' => CAP_ALLOW
+        )
+    )
+);
+
+?>
Index: blocks/page/view.php
===================================================================
RCS file: blocks/page/view.php
diff -N blocks/page/view.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ blocks/page/view.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,141 @@
+<?php
+///////////////////////////////////////////////////////////////////////////
+//                                                                       //
+// NOTICE OF COPYRIGHT                                                   //
+//                                                                       //
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
+//          http://moodle.com                                            //
+//                                                                       //
+// Copyright (C) 1999 onwards Martin Dougiamas  http://dougiamas.com     //
+//                                                                       //
+// This program is free software; you can redistribute it and/or modify  //
+// it under the terms of the GNU General Public License as published by  //
+// the Free Software Foundation; either version 2 of the License, or     //
+// (at your option) any later version.                                   //
+//                                                                       //
+// This program is distributed in the hope that it will be useful,       //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
+// GNU General Public License for more details:                          //
+//                                                                       //
+//          http://www.gnu.org/copyleft/gpl.html                         //
+//                                                                       //
+///////////////////////////////////////////////////////////////////////////
+
+require_once('../../config.php');
+require_once('lib.php');
+require_once('pagelib.php');
+require_once($CFG->libdir.'/blocklib.php');
+require_once($CFG->libdir.'/ajax/ajaxlib.php');
+require_once($CFG->dirroot.'/mod/forum/lib.php');
+
+$id          = optional_param('id', 0, PARAM_INT);
+$name        = optional_param('name', '', PARAM_RAW);
+$edit        = optional_param('edit', -1, PARAM_BOOL);
+$hide        = optional_param('hide', 0, PARAM_INT);
+$show        = optional_param('show', 0, PARAM_INT);
+$switchrole  = optional_param('switchrole',-1, PARAM_INT);
+
+if (empty($id)) {
+    error("Must specify id");
+}
+
+if (! ($page = get_record('page', 'id', $id)) ) {
+    error('Invalid page id');
+}
+
+if (!$context = get_context_instance(CONTEXT_PAGE, $page->id)) {
+    print_error('nocontext');
+}
+
+if (!has_capability('block/page:view', $context) or (!has_capability('block/page:visibility', $context) and $page->visible == 0)) {
+    redirect($CFG->wwwroot.'/index.php');
+}
+
+if(! empty($CFG->allowcoursethemes) ){
+    if(isset($page->theme)){
+        // specifying theme here saves us some dbqs
+        theme_setup($page->theme);
+    }
+}
+
+$PAGE = page_create_object(PAGE_STATIC_VIEW, $page->id);
+$pageblocks = blocks_setup($PAGE, BLOCKS_PINNED_BOTH);
+$editing    = $PAGE->user_is_editing();
+
+if (!isset($USER->editing)) {
+    $USER->editing = 0;
+}
+if ($PAGE->user_allowed_editing()) {
+    if (($edit == 1) and confirm_sesskey()) {
+        $USER->editing = 1;
+    } else if (($edit == 0) and confirm_sesskey()) {
+        $USER->editing = 0;
+        if(!empty($USER->activitycopy) && $USER->activitycopycourse == $course->id) {
+            $USER->activitycopy       = false;
+            $USER->activitycopycourse = NULL;
+        }
+    }
+
+    if ($hide && confirm_sesskey()) {
+        set_page_visible($page->id, '0');
+        redirect($CFG->wwwroot.'/blocks/page/index.php');
+    }
+
+    if ($show && confirm_sesskey()) {
+        set_page_visible($page->id, '1');
+        redirect($CFG->wwwroot.'/blocks/page/index.php');
+    }
+} else {
+    $USER->editing = 0;
+}
+
+$PAGE->print_header($SITE->fullname.': %fullname%', NULL, '', '');
+?>
+<table id="layout-table" summary="layout">
+  <tr>
+  <?php
+    $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
+    foreach ($lt as $column) {
+        switch ($column) {
+            case 'left':
+    if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
+        echo '<td id="left-column">';
+        print_container_start();
+        blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
+        print_container_end();
+        echo '</td>';
+    }
+            break;
+            case 'middle':
+    echo '<td id="middle-column">'. skip_main_destination();
+
+    print_container_start();
+    print_box_start('staticpage');
+    print_heading($page->fullname, 'left', 1);
+    print_heading("<i>Last Updated: ".userdate($page->timemodified, get_string('strftimedate'))."</i>", 'left', 4);
+    echo "<p>".$page->content."</p>";
+    print_box_end();
+    print_container_end();
+
+    echo '</td>';
+            break;
+            case 'right':
+    // The right column
+    if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing || $PAGE->user_allowed_editing()) {
+        echo '<td id="right-column">';
+        print_container_start();
+        blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
+        print_container_end();
+        echo '</td>';
+    }
+            break;
+        }
+    }
+?>
+  </tr>
+</table>
+<?php
+    print_footer('home');     // Please do not modify this line
+?>
+
Index: blocks/page/pagelib.php
===================================================================
RCS file: blocks/page/pagelib.php
diff -N blocks/page/pagelib.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ blocks/page/pagelib.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,171 @@
+<?php
+///////////////////////////////////////////////////////////////////////////
+//                                                                       //
+// NOTICE OF COPYRIGHT                                                   //
+//                                                                       //
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
+//          http://moodle.com                                            //
+//                                                                       //
+// Copyright (C) 1999 onwards Martin Dougiamas  http://dougiamas.com     //
+//                                                                       //
+// This program is free software; you can redistribute it and/or modify  //
+// it under the terms of the GNU General Public License as published by  //
+// the Free Software Foundation; either version 2 of the License, or     //
+// (at your option) any later version.                                   //
+//                                                                       //
+// This program is distributed in the hope that it will be useful,       //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
+// GNU General Public License for more details:                          //
+//                                                                       //
+//          http://www.gnu.org/copyleft/gpl.html                         //
+//                                                                       //
+///////////////////////////////////////////////////////////////////////////
+
+require_once($CFG->libdir.'/pagelib.php');
+require_once('lib.php');
+
+define('PAGE_STATIC_VIEW', 'page-view');
+define('PAGE_FORMAT', 'page');
+
+/**
+ * Class that allows for pages of content.
+ *
+ * @author Darryl Pogue
+ * @package pages
+ */
+class page_static extends page_base {
+    // Despite being named "static" the content is actually stored in the database
+
+    var $pagerecord = NULL;
+
+    function init_quick($data) {
+        parent::init_quick($data);
+    }
+
+    function init_full() {
+        
+        if($this->full_init_done) {
+            return;
+        }
+        if (empty($this->id)) {
+            $this->id = 0; // avoid db errors
+        }
+        
+        $this->pagerecord = get_record('page', 'id', $this->id);
+
+        if(empty($this->pagerecord)) {
+            error('Cannot fully initialize page: invalid page id '. $this->id);
+        }
+
+        $this->context = get_context_instance(CONTEXT_PAGE, $this->id);
+        // Preload - ensures that the context cache is populated
+        // in one DB query...
+        $this->childcontexts = get_child_contexts($this->context);
+        $this->full_init_done = true;
+    }
+
+    function user_allowed_editing() {
+        $this->init_full();
+
+        if (isset($this->_user_allowed_editing)) {
+            return $this->_user_allowed_editing;
+        }
+
+        if (has_capability('block/page:update', $this->context)) {
+            $this->_user_allowed_editing = true;
+            return true;
+        }
+
+        foreach ($this->childcontexts as $cc) {
+            if (($cc->contextlevel == CONTEXT_BLOCK &&
+                 has_capability('moodle/site:manageblocks', $cc))) {
+                $this->_user_allowed_editing = true;
+                return true;
+            }
+        }
+    }
+
+    function user_is_editing() {
+        return isediting();
+    }
+
+    function print_header($title, $morenavlinks=NULL, $meta='', $bodytags='', $extrabuttons='') {
+        global $USER, $CFG;
+
+        $this->init_full();
+        $replacements = array(
+            '%fullname%' => $this->pagerecord->fullname
+        );
+        foreach($replacements as $search => $replace) {
+            $title = str_replace($search, $replace, $title);
+        }
+    
+        $navlinks = array();
+        $navlinks[] = array('name' => $this->pagerecord->shortname, 'link' => '', 'type' => '');
+        
+        if(!empty($morenavlinks)) {
+            $navlinks = array_merge($navlinks, $morenavlinks);
+        }
+
+        $navigation = build_navigation($navlinks);
+
+        $buttons = empty($morenavlinks) ? '' : '&nbsp;';
+
+        if ($extrabuttons != '') {
+            $buttons = ($buttons == '&nbsp;') ? $extrabuttons : $buttons.$extrabuttons;
+        }
+
+        print_header($title, $this->pagerecord->fullname, $navigation,
+                     '', $meta, true, $buttons, user_login_string(1, $USER), false, $bodytags);
+    }
+
+    function get_type() {
+        return PAGE_STATIC_VIEW;
+    }
+
+    function get_format_name() {
+        return PAGE_STATIC_VIEW;
+    }
+
+    function url_get_path() {
+        global $CFG;
+
+        return $CFG->wwwroot .'/blocks/page/view.php';
+    }
+
+    function url_get_parameters() {
+        return array('id' => $this->id);
+    }
+
+    function blocks_get_positions() {
+        return array(BLOCK_POS_LEFT, BLOCK_POS_RIGHT);
+    }
+
+    function blocks_default_position() {
+        return BLOCK_POS_RIGHT;
+    }
+
+    function blocks_get_default() {
+        global $CFG;
+        
+        $this->init_full();
+
+        $blocknames = 'page:login,messages,calendar_month';
+        
+        return $blocknames;
+    }
+
+    function blocks_move_position(&$instance, $move) {
+        if($instance->position == BLOCK_POS_LEFT && $move == BLOCK_MOVE_RIGHT) {
+            return BLOCK_POS_RIGHT;
+        } else if ($instance->position == BLOCK_POS_RIGHT && $move == BLOCK_MOVE_LEFT) {
+            return BLOCK_POS_LEFT;
+        }
+        return $instance->position;
+    }
+}
+
+page_map_class(PAGE_STATIC_VIEW, 'page_static');
+
+?>
Index: blocks/page/db/install.xml
===================================================================
RCS file: blocks/page/db/install.xml
diff -N blocks/page/db/install.xml
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ blocks/page/db/install.xml	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<XMLDB PATH="blocks/page/db" VERSION="20090301" COMMENT="XMLDB file for Moodle pages"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
+>
+  <TABLES>
+    <TABLE NAME="page" COMMENT="Main Content Pages">
+      <FIELDS>
+        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="fullname"/>
+        <FIELD NAME="fullname" TYPE="char" LENGTH="254" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="shortname"/>
+        <FIELD NAME="shortname" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="fullname" NEXT="content"/>
+        <FIELD NAME="content" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="shortname" NEXT="visible"/>
+        <FIELD NAME="visible" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" ENUM="false" PREVIOUS="content" NEXT="lang"/>
+        <FIELD NAME="lang" TYPE="char" LENGTH="30" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="visible" NEXT="theme"/>
+        <FIELD NAME="theme" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="lang" NEXT="timecreated"/>
+        <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="theme" NEXT="timemodified"/>
+        <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="timecreated"/>
+      </FIELDS>
+      <KEYS>
+        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+      </KEYS>
+    </TABLE>
+  </TABLES>
+</XMLDB>
Index: blocks/page/edit_form.php
===================================================================
RCS file: blocks/page/edit_form.php
diff -N blocks/page/edit_form.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ blocks/page/edit_form.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,88 @@
+<?php
+///////////////////////////////////////////////////////////////////////////
+//                                                                       //
+// NOTICE OF COPYRIGHT                                                   //
+//                                                                       //
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
+//          http://moodle.com                                            //
+//                                                                       //
+// Copyright (C) 1999 onwards Martin Dougiamas  http://dougiamas.com     //
+//                                                                       //
+// This program is free software; you can redistribute it and/or modify  //
+// it under the terms of the GNU General Public License as published by  //
+// the Free Software Foundation; either version 2 of the License, or     //
+// (at your option) any later version.                                   //
+//                                                                       //
+// This program is distributed in the hope that it will be useful,       //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
+// GNU General Public License for more details:                          //
+//                                                                       //
+//          http://www.gnu.org/copyleft/gpl.html                         //
+//                                                                       //
+///////////////////////////////////////////////////////////////////////////
+
+require_once($CFG->libdir.'/formslib.php');
+
+class page_edit_form extends moodleform {
+
+    function definition() {
+        global $USER, $CFG;
+
+        $mform    =& $this->_form;
+
+/// form definition with new course defaults
+//--------------------------------------------------------------------------------
+        $mform->addElement('header','general', get_string('general', 'form'));
+
+        $mform->addElement('text','fullname', get_string('fullname'),'maxlength="254" size="50"');
+        $mform->setHelpButton('fullname', array('coursefullname', get_string('fullname')), true);
+        $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
+        $mform->setType('fullname', PARAM_MULTILANG);
+
+        $mform->addElement('text','shortname', get_string('shortname'),'maxlength="100" size="20"');
+        $mform->setHelpButton('shortname', array('courseshortname', get_string('shortname')), true);
+        $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
+        $mform->setType('shortname', PARAM_MULTILANG);
+
+        $mform->addElement('htmleditor','content', get_string('summary'), array('rows'=> '10', 'cols'=>'65'));
+        $mform->setHelpButton('content', array('text2', get_string('helptext')), true);
+        $mform->addRule('content', get_string('missingsummary'), 'required', null, 'client');
+        $mform->setType('content', PARAM_RAW);
+
+        if (!empty($CFG->allowcoursethemes)) {
+            $themes=array();
+            $themes[''] = get_string('forceno');
+            $themes += get_list_of_themes();
+            $mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
+        }
+
+//--------------------------------------------------------------------------------
+        $mform->addElement('header','', get_string('language'));
+
+        $languages=array();
+        $languages[''] = get_string('forceno');
+        $languages += get_list_of_languages();
+        $mform->addElement('select', 'lang', get_string('forcelanguage'), $languages);
+//--------------------------------------------------------------------------------
+        $this->add_action_buttons();
+//--------------------------------------------------------------------------------
+        $mform->addElement('hidden', 'id', null);
+        $mform->setType('id', PARAM_INT);
+    }
+
+    function definition_after_data() {
+        global $CFG;
+
+        $mform =& $this->_form;
+    }
+        
+
+/// perform some extra moodle validation
+    function validation($data, $files) {
+        $errors = parent::validation($data, $files);
+
+        return $errors;
+    }
+}
+?>
Index: blocks/page/block_page.php
===================================================================
RCS file: blocks/page/block_page.php
diff -N blocks/page/block_page.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ blocks/page/block_page.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,62 @@
+<?php
+
+class block_page extends block_list {
+    function init() {
+        $this->title = "Page Administration";
+        $this->version = 20090301;
+    }
+
+    function get_content() {
+
+        global $CFG, $USER, $SITE, $COURSE;
+
+        if ($this->content !== NULL) {
+            return $this->content;
+        }
+
+        $this->content = new stdClass;
+        $this->content->items = array();
+        $this->content->icons = array();
+        $this->content->footer = '';
+
+        if (empty($this->instance)) {
+            return $this->content = '';
+        }
+
+        $context = get_context_instance(CONTEXT_PAGE, $this->instance->pageid);
+        $course = get_record('page', 'id', $this->instance->pageid);
+
+        if (empty($CFG->loginhttps)) {
+            $securewwwroot = $CFG->wwwroot;
+        } else {
+            $securewwwroot = str_replace('http:','https:',$CFG->wwwroot);
+        }
+
+        if (has_capability('block/page:update', $context)) {
+            $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/edit.gif" class="icon" alt="" />';
+            if (isediting($this->instance->pageid)) {
+                $this->content->items[]='<a href="view.php?id='.$this->instance->pageid.'&amp;edit=off&amp;sesskey='.sesskey().'">'.get_string('blockeditoff', 'block_page').'</a>';
+            } else {
+                $this->content->items[]='<a href="view.php?id='.$this->instance->pageid.'&amp;edit=on&amp;sesskey='.sesskey().'">'.get_string('blockediton', 'block_page').'</a>';
+            }
+
+            $this->content->items[]='<a href="'.$CFG->wwwroot.'/blocks/page/edit.php?id='.$this->instance->pageid.'">'.get_string('editpage', 'block_page').'</a>';
+            $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/settings.gif" class="icon" alt="" />';
+        }
+
+
+        if (has_capability('moodle/role:assign', $context)) {
+            $this->content->items[]='<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id.'">'.get_string('assignroles', 'role').'</a>';
+            $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/roles.gif" class="icon" alt="" />';
+
+        }
+
+        return $this->content;
+    }
+
+    function applicable_formats() {
+        return array('page' => true);
+    }
+}
+
+?>
Index: blocks/page/delete.php
===================================================================
RCS file: blocks/page/delete.php
diff -N blocks/page/delete.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ blocks/page/delete.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,91 @@
+<?php
+///////////////////////////////////////////////////////////////////////////
+//                                                                       //
+// NOTICE OF COPYRIGHT                                                   //
+//                                                                       //
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
+//          http://moodle.com                                            //
+//                                                                       //
+// Copyright (C) 1999 onwards Martin Dougiamas  http://dougiamas.com     //
+//                                                                       //
+// This program is free software; you can redistribute it and/or modify  //
+// it under the terms of the GNU General Public License as published by  //
+// the Free Software Foundation; either version 2 of the License, or     //
+// (at your option) any later version.                                   //
+//                                                                       //
+// This program is distributed in the hope that it will be useful,       //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
+// GNU General Public License for more details:                          //
+//                                                                       //
+//          http://www.gnu.org/copyleft/gpl.html                         //
+//                                                                       //
+///////////////////////////////////////////////////////////////////////////
+
+require_once("../../config.php");
+require_once("lib.php");
+
+$pageid     = required_param('id', PARAM_INT); //Page ID
+$delete = optional_param('delete', '', PARAM_ALPHANUM); //Confirmation Hash
+
+$context = get_context_instance(CONTEXT_PAGE, $pageid);
+require_capability('block/page:delete', $context);
+
+$strdeletecourse = get_string('deletepage', 'block_page');
+$stradministration = get_string('blockname', 'block_page');
+$strpages = get_string('pages', 'block_page');
+
+if (!$page = get_record('page', 'id', $pageid)) {
+    error("Page ID was incorrect");
+}
+
+$navlinks = array();
+
+if (!$delete) {
+    $strdeletecheck = get_string('deletecheck', '', $page->shortname);
+    $strdeletecoursecheck = get_string('deletepagecheck', 'block_page');
+
+    $navlinks[] = array('name' => $stradministration, 'link' => "../$CFG->admin/index.php", 'type' => 'misc');
+    $navlinks[] = array('name' => $strpages, 'link' => "index.php", 'type' => 'misc');
+    $navlinks[] = array('name' => $strdeletecheck, 'link' => null, 'type' => 'misc');
+    $navigation = build_navigation($navlinks);
+
+    print_header("$SITE->shortname: $strdeletecheck", $SITE->fullname, $navigation);
+
+    notice_yesno("$strdeletecoursecheck<br /><br />" . format_string($page->fullname) .
+                 " (" . format_string($page->shortname) . ")",
+                 "delete.php?id=$page->id&amp;delete=".md5($page->timemodified)."&amp;sesskey=$USER->sesskey", "index.php");
+
+    print_footer();
+    exit;
+}
+
+if ($delete != md5($page->timemodified)) {
+    error("The check variable was wrong - try again");
+}
+
+if (!confirm_sesskey()) {
+    error(get_string('confirmsesskeybad', 'error'));
+}
+
+// OK checks done, delete the course now.
+$strdeletingcourse = get_string('deletingcourse', '', format_string($page->shortname));
+
+$navlinks[] = array('name' => $stradministration, 'link' => "../$CFG->admin/index.php", 'type' => 'misc');
+$navlinks[] = array('name' => $strpages, 'link' => "index.php", 'type' => 'misc');
+$navlinks[] = array('name' => $strdeletingcourse, 'link' => null, 'type' => 'misc');
+$navigation = build_navigation($navlinks);
+
+print_header("$SITE->shortname: $strdeletingcourse", $SITE->fullname, $navigation);
+
+print_heading($strdeletingcourse);
+
+delete_page($page->id);
+
+print_heading( get_string('deletedcourse', '', format_string($page->shortname)) );
+
+print_continue("index.php");
+
+print_footer();
+
+?>
