]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Allow pages revisions to be reverted or deleted
authorJeff Tilson <jrtilson@gmail.com>
Fri, 5 Apr 2013 17:35:13 +0000 (13:35 -0400)
committerJeff Tilson <jrtilson@gmail.com>
Fri, 5 Apr 2013 17:35:13 +0000 (13:35 -0400)
mod/pages/actions/annotations/page/delete.php [new file with mode: 0644]
mod/pages/languages/en.php
mod/pages/lib/pages.php
mod/pages/pages/pages/edit.php
mod/pages/start.php
mod/pages/views/default/annotation/page.php
mod/pages/views/default/object/page_top.php
mod/pages/views/default/pages/sidebar/history.php

diff --git a/mod/pages/actions/annotations/page/delete.php b/mod/pages/actions/annotations/page/delete.php
new file mode 100644 (file)
index 0000000..792b7c0
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+/**
+ * Remove a page (revision) annotation
+ *
+ * @package ElggPages
+ */
+
+// Ensure we're logged in
+if (!elgg_is_logged_in()) {
+       forward();
+}
+
+// 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
index 930676b3ebd2e8efb4c4c79949f7c70af0de23dc..13b6ece2a8d9be06b8b852ab2bd0d474bca89c52 100644 (file)
@@ -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
index afe42b68f4200a3b324791aa44eda70cc2a3badf..7f90d53d8023c641916cc75ff27768544bc8a0e2 100644 (file)
@@ -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;
 }
 
index 1f411b94d7189aa2e2c447d651b354f6f6c9b199..a925cdc55cca383d521ca38ef9ff44266a31a583 100644 (file)
@@ -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");
index 8debeef24e203af9ef12ae6301d948b660e2480f..780d3d9a7296eaf2391cbbd50d2bb8f7b7d9e214 100644 (file)
@@ -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');
@@ -82,6 +83,9 @@ function pages_init() {
 
        // register ecml views to parse
        elgg_register_plugin_hook_handler('get_views', 'ecml', 'pages_ecml_views_hook');
+
+       // hook into annotation menu
+       elgg_register_plugin_hook_handler('register', 'menu:annotation', 'pages_annotation_menu_setup');
 }
 
 /**
@@ -362,3 +366,72 @@ function pages_ecml_views_hook($hook, $entity_type, $return_value, $params) {
 
        return $return_value;
 }
+
+/**
+ * Adds items to "page" annotations menu
+ *
+ * @param unknown_type $hook
+ * @param unknown_type $entity_type
+ * @param unknown_type $return_value
+ * @param unknown_type $params
+ */
+function pages_annotation_menu_setup($hook, $type, $return, $params) {
+       $annotation = $params['annotation'];
+       /* @var ElggAnnotation $annotation */
+
+       $entity = get_entity($annotation->entity_guid);
+
+       if ($annotation->name == 'page' && $entity->canEdit() && $annotation->canEdit()) {
+               // Get last revision
+               $revisions = elgg_get_annotations(array(
+                       'annotation_name' => 'page', 
+                       'limit' => 1, 
+                       'guid' => $annotation->entity_guid,
+                       'reverse_order_by' => true,
+               ));
+
+               // Check if this annotation is the last revision
+               if ($revisions) {
+                       $current_revision = $revisions[0];
+                       if ($current_revision == $annotation) {
+                               // Don't allow any actions on last revision, just display 'current revision'
+                               $options = array(
+                                       'name' => 'current',
+                                       'href' => false,
+                                       'text' => elgg_echo('pages:current_revision'),
+                                       'encode_text' => false
+                               );
+                               $return[] = ElggMenuItem::factory($options);
+                               return $return;
+                       }
+               }
+
+               // Revert
+               $options = array(
+                       'name' => 'revert',
+                       'href' => elgg_http_add_url_query_elements("pages/edit/{$annotation->entity_guid}", array(
+                               'annotation_id' => $annotation->id
+                       )),
+                       'text' => elgg_echo('pages:revert'),
+                       'encode_text' => false
+               );
+               $return[] = ElggMenuItem::factory($options);
+
+
+               // Delete
+               $url = elgg_http_add_url_query_elements('action/annotations/page/delete', array(
+                       'annotation_id' => $annotation->id,
+               ));
+
+               $options = array(
+                       'name' => 'delete',
+                       'href' => $url,
+                       'text' => "<span class=\"elgg-icon elgg-icon-delete\"></span>",
+                       'confirm' => elgg_echo('deleteconfirm'),
+                       'encode_text' => false
+               );
+               $return[] = ElggMenuItem::factory($options);
+       }
+
+       return $return;
+}
index a621b9281096a923abc7280be3d94fc3f9082d49..ecb28909202e6fceffcd286d4bdb2e890c0eda06 100644 (file)
@@ -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
index 945a22eed9b95f2aac07cff33b43a858410e658b..f352029934f5728079e0c6c2d73d660eacb5f61a 100644 (file)
@@ -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) {
index 7077edb9abdbdd5474aee2d3de087ab41922cddf..e0e8ed11a72e12b35159d24c2f34d923ce466006 100644 (file)
@@ -14,6 +14,7 @@ if ($vars['page']) {
                'limit' => 20,
                'reverse_order_by' => true
        );
+       elgg_push_context('widgets');
        $content = elgg_list_annotations($options);
 }