aboutsummaryrefslogtreecommitdiff
path: root/mod/pages
diff options
context:
space:
mode:
Diffstat (limited to 'mod/pages')
-rw-r--r--mod/pages/actions/annotations/page/delete.php20
-rw-r--r--mod/pages/actions/pages/delete.php26
-rw-r--r--mod/pages/languages/en.php7
-rw-r--r--mod/pages/lib/pages.php7
-rw-r--r--mod/pages/pages/pages/edit.php13
-rw-r--r--mod/pages/pages/pages/friends.php2
-rw-r--r--mod/pages/pages/pages/history.php4
-rw-r--r--mod/pages/pages/pages/owner.php6
-rw-r--r--mod/pages/pages/pages/world.php4
-rw-r--r--mod/pages/start.php48
-rw-r--r--mod/pages/upgrades/2012061800.php49
-rw-r--r--mod/pages/views/default/annotation/page.php18
-rw-r--r--mod/pages/views/default/object/page_top.php26
-rw-r--r--mod/pages/views/default/pages/sidebar/history.php1
14 files changed, 194 insertions, 37 deletions
diff --git a/mod/pages/actions/annotations/page/delete.php b/mod/pages/actions/annotations/page/delete.php
new file mode 100644
index 000000000..156b516d2
--- /dev/null
+++ b/mod/pages/actions/annotations/page/delete.php
@@ -0,0 +1,20 @@
+<?php
+/**
+ * Remove a page (revision) annotation
+ *
+ * @package ElggPages
+ */
+
+// Make sure we can get the annotations and entity in question
+$annotation_id = (int) get_input('annotation_id');
+$annotation = elgg_get_annotation_from_id($annotation_id);
+$entity = get_entity($annotation->entity_guid);
+
+if ($annotation && $entity->canEdit() && $annotation->canEdit()) {
+ $annotation->delete();
+ system_message(elgg_echo("pages:revision:delete:success"));
+} else {
+ register_error(elgg_echo("pages:revision:delete:failure"));
+}
+
+forward("pages/history/{$annotation->entity_guid}"); \ No newline at end of file
diff --git a/mod/pages/actions/pages/delete.php b/mod/pages/actions/pages/delete.php
index 7a314a280..fd5791e4d 100644
--- a/mod/pages/actions/pages/delete.php
+++ b/mod/pages/actions/pages/delete.php
@@ -21,11 +21,33 @@ if (elgg_instanceof($page, 'object', 'page') || elgg_instanceof($page, 'object',
'metadata_value' => $page->getGUID()
));
if ($children) {
+ $db_prefix = elgg_get_config('dbprefix');
+ $subtype_id = (int)get_subtype_id('object', 'page_top');
+ $newentity_cache = is_memcache_available() ? new ElggMemcache('new_entity_cache') : null;
+
foreach ($children as $child) {
- $child->parent_guid = $parent;
+ if ($parent) {
+ $child->parent_guid = $parent;
+ } else {
+ // If no parent, we need to transform $child to a page_top
+ $child_guid = (int)$child->guid;
+
+ update_data("UPDATE {$db_prefix}entities
+ SET subtype = $subtype_id WHERE guid = $child_guid");
+
+ elgg_delete_metadata(array(
+ 'guid' => $child_guid,
+ 'metadata_name' => 'parent_guid',
+ ));
+
+ _elgg_invalidate_cache_for_entity($child_guid);
+ if ($newentity_cache) {
+ $newentity_cache->delete($child_guid);
+ }
+ }
}
}
-
+
if ($page->delete()) {
system_message(elgg_echo('pages:delete:success'));
if ($parent) {
diff --git a/mod/pages/languages/en.php b/mod/pages/languages/en.php
index 930676b3e..c204c1901 100644
--- a/mod/pages/languages/en.php
+++ b/mod/pages/languages/en.php
@@ -15,7 +15,7 @@ $english = array(
'pages:owner' => "%s's pages",
'pages:friends' => "Friends' pages",
'pages:all' => "All site pages",
- 'pages:add' => "Add page",
+ 'pages:add' => "Add a page",
'pages:group' => "Group pages",
'groups:enablepages' => 'Enable group pages',
@@ -25,6 +25,8 @@ $english = array(
'pages:history' => "History",
'pages:view' => "View page",
'pages:revision' => "Revision",
+ 'pages:current_revision' => "Current Revision",
+ 'pages:revert' => "Revert",
'pages:navigation' => "Navigation",
'pages:new' => "A new page",
@@ -75,6 +77,9 @@ View and comment on the new page:
'pages:error:no_title' => 'You must specify a title for this page.',
'pages:delete:success' => 'The page was successfully deleted.',
'pages:delete:failure' => 'The page could not be deleted.',
+ 'pages:revision:delete:success' => 'The page revision was successfully deleted.',
+ 'pages:revision:delete:failure' => 'The page revision could not be deleted.',
+ 'pages:revision:not_found' => 'Cannot find this revision.',
/**
* Page
diff --git a/mod/pages/lib/pages.php b/mod/pages/lib/pages.php
index afe42b68f..7f90d53d8 100644
--- a/mod/pages/lib/pages.php
+++ b/mod/pages/lib/pages.php
@@ -9,7 +9,7 @@
* @param ElggObject $page
* @return array
*/
-function pages_prepare_form_vars($page = null, $parent_guid = 0) {
+function pages_prepare_form_vars($page = null, $parent_guid = 0, $revision = null) {
// input names => defaults
$values = array(
@@ -41,6 +41,11 @@ function pages_prepare_form_vars($page = null, $parent_guid = 0) {
elgg_clear_sticky_form('page');
+ // load the revision annotation if requested
+ if ($revision instanceof ElggAnnotation && $revision->entity_guid == $page->getGUID()) {
+ $values['description'] = $revision->value;
+ }
+
return $values;
}
diff --git a/mod/pages/pages/pages/edit.php b/mod/pages/pages/pages/edit.php
index 1f411b94d..a925cdc55 100644
--- a/mod/pages/pages/pages/edit.php
+++ b/mod/pages/pages/pages/edit.php
@@ -8,6 +8,7 @@
gatekeeper();
$page_guid = (int)get_input('guid');
+$revision = (int)get_input('annotation_id');
$page = get_entity($page_guid);
if (!$page) {
register_error(elgg_echo('noaccess'));
@@ -28,7 +29,17 @@ elgg_push_breadcrumb(elgg_echo('edit'));
$title = elgg_echo("pages:edit");
if ($page->canEdit()) {
- $vars = pages_prepare_form_vars($page);
+
+ if ($revision) {
+ $revision = elgg_get_annotation_from_id($revision);
+ if (!$revision || !($revision->entity_guid == $page_guid)) {
+ register_error(elgg_echo('pages:revision:not_found'));
+ forward(REFERER);
+ }
+ }
+
+ $vars = pages_prepare_form_vars($page, $page->parent_guid, $revision);
+
$content = elgg_view_form('pages/edit', array(), $vars);
} else {
$content = elgg_echo("pages:noaccess");
diff --git a/mod/pages/pages/pages/friends.php b/mod/pages/pages/pages/friends.php
index 87ac631c2..cecc4053b 100644
--- a/mod/pages/pages/pages/friends.php
+++ b/mod/pages/pages/pages/friends.php
@@ -7,7 +7,7 @@
$owner = elgg_get_page_owner_entity();
if (!$owner) {
- forward('pages/all');
+ forward('', '404');
}
elgg_push_breadcrumb($owner->name, "pages/owner/$owner->username");
diff --git a/mod/pages/pages/pages/history.php b/mod/pages/pages/pages/history.php
index 872596179..7f5fa4f4f 100644
--- a/mod/pages/pages/pages/history.php
+++ b/mod/pages/pages/pages/history.php
@@ -9,12 +9,12 @@ $page_guid = get_input('guid');
$page = get_entity($page_guid);
if (!$page) {
-
+ forward('', '404');
}
$container = $page->getContainerEntity();
if (!$container) {
-
+ forward('', '404');
}
elgg_set_page_owner_guid($container->getGUID());
diff --git a/mod/pages/pages/pages/owner.php b/mod/pages/pages/pages/owner.php
index b29332ee1..7de74a3b4 100644
--- a/mod/pages/pages/pages/owner.php
+++ b/mod/pages/pages/pages/owner.php
@@ -7,7 +7,7 @@
$owner = elgg_get_page_owner_entity();
if (!$owner) {
- forward('pages/all');
+ forward('', '404');
}
// access check for closed groups
@@ -20,8 +20,8 @@ elgg_push_breadcrumb($owner->name);
elgg_register_title_button();
$content = elgg_list_entities(array(
- 'types' => 'object',
- 'subtypes' => 'page_top',
+ 'type' => 'object',
+ 'subtype' => 'page_top',
'container_guid' => elgg_get_page_owner_guid(),
'full_view' => false,
));
diff --git a/mod/pages/pages/pages/world.php b/mod/pages/pages/pages/world.php
index e6a705b6b..c130a6bd6 100644
--- a/mod/pages/pages/pages/world.php
+++ b/mod/pages/pages/pages/world.php
@@ -13,8 +13,8 @@ elgg_push_breadcrumb(elgg_echo('pages'));
elgg_register_title_button();
$content = elgg_list_entities(array(
- 'types' => 'object',
- 'subtypes' => 'page_top',
+ 'type' => 'object',
+ 'subtype' => 'page_top',
'full_view' => false,
));
if (!$content) {
diff --git a/mod/pages/start.php b/mod/pages/start.php
index 6d974f122..f9c34cd85 100644
--- a/mod/pages/start.php
+++ b/mod/pages/start.php
@@ -28,9 +28,10 @@ function pages_init() {
elgg_register_annotation_url_handler('page', 'pages_revision_url');
// Register some actions
- $action_base = elgg_get_plugins_path() . 'pages/actions/pages';
- elgg_register_action("pages/edit", "$action_base/edit.php");
- elgg_register_action("pages/delete", "$action_base/delete.php");
+ $action_base = elgg_get_plugins_path() . 'pages/actions';
+ elgg_register_action("pages/edit", "$action_base/pages/edit.php");
+ elgg_register_action("pages/delete", "$action_base/pages/delete.php");
+ elgg_register_action("annotations/page/delete", "$action_base/annotations/page/delete.php");
// Extend the main css view
elgg_extend_view('css/elgg', 'pages/css');
@@ -80,8 +81,13 @@ function pages_init() {
// entity menu
elgg_register_plugin_hook_handler('register', 'menu:entity', 'pages_entity_menu_setup');
+ // hook into annotation menu
+ elgg_register_plugin_hook_handler('register', 'menu:annotation', 'pages_annotation_menu_setup');
+
// register ecml views to parse
elgg_register_plugin_hook_handler('get_views', 'ecml', 'pages_ecml_views_hook');
+
+ elgg_register_event_handler('upgrade', 'system', 'pages_run_upgrades');
}
/**
@@ -281,25 +287,37 @@ function page_notify_message($hook, $entity_type, $returnvalue, $params) {
/**
* Extend permissions checking to extend can-edit for write users.
*
- * @param unknown_type $hook
- * @param unknown_type $entity_type
- * @param unknown_type $returnvalue
- * @param unknown_type $params
+ * @param string $hook
+ * @param string $entity_type
+ * @param bool $returnvalue
+ * @param array $params
*/
-function pages_write_permission_check($hook, $entity_type, $returnvalue, $params)
-{
+function pages_write_permission_check($hook, $entity_type, $returnvalue, $params) {
if ($params['entity']->getSubtype() == 'page'
|| $params['entity']->getSubtype() == 'page_top') {
$write_permission = $params['entity']->write_access_id;
$user = $params['user'];
- if (($write_permission) && ($user)) {
- // $list = get_write_access_array($user->guid);
- $list = get_access_array($user->guid); // get_access_list($user->guid);
-
- if (($write_permission!=0) && (in_array($write_permission,$list))) {
- return true;
+ if ($write_permission && $user) {
+ switch ($write_permission) {
+ case ACCESS_PRIVATE:
+ // Elgg's default decision is what we want
+ return;
+ break;
+ case ACCESS_FRIENDS:
+ $owner = $params['entity']->getOwnerEntity();
+ if ($owner && $owner->isFriendsWith($user->guid)) {
+ return true;
+ }
+ break;
+ default:
+ $list = get_access_array($user->guid);
+ if (in_array($write_permission, $list)) {
+ // user in the access collection
+ return true;
+ }
+ break;
}
}
}
diff --git a/mod/pages/upgrades/2012061800.php b/mod/pages/upgrades/2012061800.php
new file mode 100644
index 000000000..c21ccae3b
--- /dev/null
+++ b/mod/pages/upgrades/2012061800.php
@@ -0,0 +1,49 @@
+<?php
+/**
+ * Restore disappeared subpages. This is caused by its parent page being deleted
+ * when the parent page is a top level page. We take advantage of the fact that
+ * the parent_guid was deleted for the subpages.
+ *
+ * This upgrade script will no longer work once we have converted all pages to
+ * have the same entity subtype.
+ */
+
+
+/**
+ * Update subtype
+ *
+ * @param ElggObject $page
+ */
+function pages_2012061800($page) {
+ $dbprefix = elgg_get_config('dbprefix');
+ $subtype_id = (int)get_subtype_id('object', 'page_top');
+ $page_guid = (int)$page->guid;
+ update_data("UPDATE {$dbprefix}entities
+ SET subtype = $subtype_id WHERE guid = $page_guid");
+ error_log("called");
+ return true;
+}
+
+$previous_access = elgg_set_ignore_access(true);
+
+$dbprefix = elgg_get_config('dbprefix');
+$name_metastring_id = get_metastring_id('parent_guid');
+if (!$name_metastring_id) {
+ return;
+}
+
+// Looking for pages without metadata
+$options = array(
+ 'type' => 'object',
+ 'subtype' => 'page',
+ 'wheres' => "NOT EXISTS (
+ SELECT 1 FROM {$dbprefix}metadata md
+ WHERE md.entity_guid = e.guid
+ AND md.name_id = $name_metastring_id)"
+);
+$batch = new ElggBatch('elgg_get_entities_from_metadata', $options, 'pages_2012061800', 50, false);
+elgg_set_ignore_access($previous_access);
+
+if ($batch->callbackResult) {
+ error_log("Elgg Pages upgrade (2012061800) succeeded");
+}
diff --git a/mod/pages/views/default/annotation/page.php b/mod/pages/views/default/annotation/page.php
index a621b9281..ecb289092 100644
--- a/mod/pages/views/default/annotation/page.php
+++ b/mod/pages/views/default/annotation/page.php
@@ -39,4 +39,22 @@ $body = <<< HTML
<p class="elgg-subtext">$subtitle</p>
HTML;
+if (!elgg_in_context('widgets')) {
+ $menu = elgg_view_menu('annotation', array(
+ 'annotation' => $annotation,
+ 'sort_by' => 'priority',
+ 'class' => 'elgg-menu-hz float-alt',
+ ));
+}
+
+$body = <<<HTML
+<div class="mbn">
+ $menu
+ <h3>$title_link</h3>
+ <span class="elgg-subtext">
+ $subtitle
+ </span>
+</div>
+HTML;
+
echo elgg_view_image_block($icon, $body); \ No newline at end of file
diff --git a/mod/pages/views/default/object/page_top.php b/mod/pages/views/default/object/page_top.php
index 945a22eed..f35202993 100644
--- a/mod/pages/views/default/object/page_top.php
+++ b/mod/pages/views/default/object/page_top.php
@@ -60,18 +60,26 @@ if ($comments_count != 0 && !$revision) {
$comments_link = '';
}
-$metadata = elgg_view_menu('entity', array(
- 'entity' => $vars['entity'],
- 'handler' => 'pages',
- 'sort_by' => 'priority',
- 'class' => 'elgg-menu-hz',
-));
-
$subtitle = "$editor_text $comments_link $categories";
// do not show the metadata and controls in widget view
-if (elgg_in_context('widgets') || $revision) {
- $metadata = '';
+if (!elgg_in_context('widgets')) {
+ // If we're looking at a revision, display annotation menu
+ if ($revision) {
+ $metadata = elgg_view_menu('annotation', array(
+ 'annotation' => $annotation,
+ 'sort_by' => 'priority',
+ 'class' => 'elgg-menu-hz float-alt',
+ ));
+ } else {
+ // Regular entity menu
+ $metadata = elgg_view_menu('entity', array(
+ 'entity' => $vars['entity'],
+ 'handler' => 'pages',
+ 'sort_by' => 'priority',
+ 'class' => 'elgg-menu-hz',
+ ));
+ }
}
if ($full) {
diff --git a/mod/pages/views/default/pages/sidebar/history.php b/mod/pages/views/default/pages/sidebar/history.php
index 7077edb9a..e0e8ed11a 100644
--- a/mod/pages/views/default/pages/sidebar/history.php
+++ b/mod/pages/views/default/pages/sidebar/history.php
@@ -14,6 +14,7 @@ if ($vars['page']) {
'limit' => 20,
'reverse_order_by' => true
);
+ elgg_push_context('widgets');
$content = elgg_list_annotations($options);
}