From 7352d26311775f7203673f0200844cc03b38a1ac Mon Sep 17 00:00:00 2001 From: Pavel Kulbakin Date: Fri, 27 Dec 2013 19:44:33 +0200 Subject: [PATCH] fix: page revisions [...] make revision listing, add & edit pages to show 404 error (instead of empty page or 500 error); fix view revision header margin; --- .../com_pages/controllers/revision.php | 103 +++++---- .../com_pages/domains/entities/page.php | 215 ++++++++---------- .../com_pages/domains/entities/revision.php | 78 +++---- .../com_pages/views/page/html/default.php | 14 +- .../com_pages/views/page/html/page.php | 62 ++--- .../views/revision/html/revision.php | 21 +- .../anahita/domain/entity/abstract.php | 2 +- .../anahita/domain/entity/default.php | 22 +- .../templates/base/css/components/pages.less | 10 - 9 files changed, 233 insertions(+), 294 deletions(-) delete mode 100644 src/site/templates/base/css/components/pages.less diff --git a/packages/Pages/src/site/components/com_pages/controllers/revision.php b/packages/Pages/src/site/components/com_pages/controllers/revision.php index 4c8954efc..cd89ee912 100644 --- a/packages/Pages/src/site/components/com_pages/controllers/revision.php +++ b/packages/Pages/src/site/components/com_pages/controllers/revision.php @@ -1,74 +1,79 @@ - * @author Rastin Mehr - * @copyright 2008 - 2010 rmdStudio Inc./Peerglobe Technology Inc - * @license GNU GPLv3 - * @version SVN: $Id: resource.php 11985 2012-01-12 10:53:20Z asanieyan $ - * @link http://www.anahitapolis.com - */ - /** * Revision Controller - * + * * @category Anahita * @package Com_pages * @subpackage Controller * @author Arash Sanieyan * @author Rastin Mehr * @license GNU GPLv3 - * @link http://www.anahitapolis.com + * @copyright 2008 - 2010 rmdStudio Inc./Peerglobe Technology Inc */ class ComPagesControllerRevision extends ComMediumControllerDefault { /** * Initializes the options for the object - * + * * Called from {@link __construct()} as a first step of object instantiation. - * - * @param object An optional KConfig object with configuration options. - * @return void + * + * @param object An optional KConfig object with configuration options. + * @return void */ protected function _initialize(KConfig $config) { $config->append(array( 'behaviors' => array('parentable') )); - + parent::_initialize($config); + } + + /** + * {@inheritdoc}} + */ + protected function _actionBrowse($context) + { + // revision listing is not allowed + throw new KHttpException('Not Found', KHttpResponse::NOT_FOUND); + } + + /** + * {@inheritdoc}} + */ + protected function _actionRead($context) + { + if ($context->request->layout) { + // only default revision view is allowed (i.e. forbid edit/add form access) + throw new KHttpException('Not Found', KHttpResponse::NOT_FOUND); + } + return parent::_actionRead($context); } + + /** + * Restores a page back to a revision + * + * @param KCommandContext $context Context paramter + * @return void + */ + protected function _actionRestore($context) + { + $revision = $this->getItem(); + $page = $revision->page; + $page->restore($revision); - /** - * Restores a page back to a revision - * - * @param KCommandContext $context Context paramter - * - * @return void - */ - protected function _actionRestore($context) - { - $revision = $this->getItem(); - $page = $revision->page; - $page->restore($revision); - - $msg = JText::sprintf('COM-PAGES-PAGE-REVISIONS-RESTORATION-CONFIRMATION', $revision->revisionNum); - $context->response->setRedirect($page->getURL().'&layout=edit', $msg); - } - - /** - * Prevents deletion of a revision - * - * @return boolean - */ - public function canDelete() - { - return false; - } -} \ No newline at end of file + $msg = JText::sprintf('COM-PAGES-PAGE-REVISIONS-RESTORATION-CONFIRMATION', $revision->revisionNum); + $context->response->setRedirect($page->getURL().'&layout=edit', $msg); + } + + /** + * Prevents deletion of a revision + * + * @return boolean + */ + public function canDelete() + { + return false; + } +} diff --git a/packages/Pages/src/site/components/com_pages/domains/entities/page.php b/packages/Pages/src/site/components/com_pages/domains/entities/page.php index 84912a48b..a73417b84 100644 --- a/packages/Pages/src/site/components/com_pages/domains/entities/page.php +++ b/packages/Pages/src/site/components/com_pages/domains/entities/page.php @@ -1,135 +1,116 @@ - * @author Rastin Mehr - * @copyright 2008 - 2010 rmdStudio Inc./Peerglobe Technology Inc - * @license GNU GPLv3 - * @version SVN: $Id: resource.php 11985 2012-01-12 10:53:20Z asanieyan $ - * @link http://www.anahitapolis.com - */ - /** * Page Entity - * + * * @category Anahita * @package Com_pages * @subpackage Domain_Entity * @author Arash Sanieyan * @author Rastin Mehr * @license GNU GPLv3 - * @link http://www.anahitapolis.com + * @copyright 2008 - 2010 rmdStudio Inc./Peerglobe Technology Inc */ class ComPagesDomainEntityPage extends ComMediumDomainEntityMedium -{ - /** - * Initializes the default configuration for the object - * - * Called from {@link __construct()} as a first step of object instantiation. - * - * @param KConfig $config An optional KConfig object with configuration options. - * - * @return void - */ - protected function _initialize(KConfig $config) - { - $config->append(array( - 'behaviors' => array( - 'enableable' - ), - - 'attributes' => array( - 'name' => array('required'=>true), - 'excerpt' => array('required'=>true,'format'=>'string') - ), - - 'relationships' => array( - 'revisions' - ), - 'aliases' => array( - 'published' => 'enabled', - 'title' => 'name' - ) - )); - +{ + /** + * Initializes the default configuration for the object + * + * Called from {@link __construct()} as a first step of object instantiation. + * + * @param KConfig $config An optional KConfig object with configuration options. + * @return void + */ + protected function _initialize(KConfig $config) + { + $config->append(array( + 'behaviors' => array( + 'enableable' + ), + + 'attributes' => array( + 'name' => array('required' => true), + 'excerpt' => array('required' => true, 'format' => 'string') + ), + + 'relationships' => array( + 'revisions' + ), + 'aliases' => array( + 'published' => 'enabled', + 'title' => 'name', + ) + )); + $config->append(array( 'behaviors' => array( 'modifiable' => array( - 'modifiable_properties' => array('excerpt','name','body') + 'modifiable_properties' => array('excerpt', 'name', 'body') ), //h2-h6 not allowed in the comments - 'commentable' => array('comment'=>array('format'=>'com://site/medium.filter.post')) - ) + 'commentable' => array('comment' => array('format' => 'com://site/medium.filter.post')) + ) )); - parent::_initialize($config); - } - - /** - * Creates a new revision before updating - * - * @return void - */ - protected function _beforeEntityUpdate(KCommandContext $context) - { - $modifications = $this->getModifiedData(); - - if ( isset($this->__restored) ) - return; - - if ( $modifications->name || $modifications->body || $modifications->excerpt ) - { - $revision = $this->addNewRevision(); - - foreach($modifications as $property => $change) { - $revision->$property = $change->old; - } - } - } - - /** - * Restore a page back to one of it's revision num - * - * @param int $revision - * @return void - */ - public function restore($revision) - { - $revision = $this->revisions->find(array('revisionNum'=>$revision->revisionNum)); - - if ( $revision ) - { - $this->__restored = true; - $this->setData(array( - 'name' => $revision->title, - 'body' => $revision->description, - 'exceprt' => $revision->excerpt - ), AnDomain::ACCESS_PROTECTED); - } - } - - /** - * Creates new revision - * - * @return ComPagesDomainEntityRevision - */ - public function addNewRevision() - { - return $this->revisions->addNew(array( - 'component' => $this->component, - 'author' => get_viewer(), - 'owner' => $this->owner, - 'title' => $this->title, - 'description' => $this->description, - 'excerpt' => $this->excerpt, - 'revisionNum' => (int)$this->revisions->fetchValue('MAX(@col(revisionNum))') + 1 - )); - } - -//end class -} \ No newline at end of file + parent::_initialize($config); + } + + /** + * Creates a new revision before updating + * + * @return void + */ + protected function _beforeEntityUpdate(KCommandContext $context) + { + $modifications = $this->getModifiedData(); + + if (isset($this->__restored)) { + return; + } + + if ($modifications->name || $modifications->body || $modifications->excerpt) { + $revision = $this->addNewRevision(); + + foreach ($modifications as $property => $change) { + $revision->$property = $change->old; + } + } + } + + /** + * Restore a page back to one of it's revision num + * + * @param int $revision + * @return void + */ + public function restore($revision) + { + $revision = $this->revisions->find(array('revisionNum' => $revision->revisionNum)); + + if ($revision) { + $this->__restored = true; + $this->setData(array( + 'name' => $revision->title, + 'body' => $revision->description, + 'exceprt' => $revision->excerpt + ), AnDomain::ACCESS_PROTECTED); + } + } + + /** + * Creates new revision + * + * @return ComPagesDomainEntityRevision + */ + public function addNewRevision() + { + return $this->revisions->addNew(array( + 'component' => $this->component, + 'author' => get_viewer(), + 'owner' => $this->owner, + 'title' => $this->title, + 'description' => $this->description, + 'excerpt' => $this->excerpt, + 'revisionNum' => (int)$this->revisions->fetchValue('MAX(@col(revisionNum))') + 1, + )); + } +} diff --git a/packages/Pages/src/site/components/com_pages/domains/entities/revision.php b/packages/Pages/src/site/components/com_pages/domains/entities/revision.php index 511af196b..a9d348cb4 100644 --- a/packages/Pages/src/site/components/com_pages/domains/entities/revision.php +++ b/packages/Pages/src/site/components/com_pages/domains/entities/revision.php @@ -1,60 +1,42 @@ - * @author Rastin Mehr - * @copyright 2008 - 2010 rmdStudio Inc./Peerglobe Technology Inc - * @license GNU GPLv3 - * @version SVN: $Id: resource.php 11985 2012-01-12 10:53:20Z asanieyan $ - * @link http://www.anahitapolis.com - */ - /** * Revision Entity - * + * * @category Anahita * @package Com_pages * @subpackage Domain_Entity * @author Arash Sanieyan * @author Rastin Mehr * @license GNU GPLv3 - * @link http://www.anahitapolis.com + * @copyright 2008 - 2010 rmdStudio Inc./Peerglobe Technology Inc */ class ComPagesDomainEntityRevision extends ComMediumDomainEntityMedium { - /** - * Initializes the default configuration for the object - * - * Called from {@link __construct()} as a first step of object instantiation. - * - * @param KConfig $config An optional KConfig object with configuration options. - * - * @return void - */ - protected function _initialize(KConfig $config) - { - $config->append(array( - 'behaviors' => array( - 'parentable'=>array('parent'=>'page'), - ), - 'attributes' => array( - 'excerpt' => 'excerpt', - 'revisionNum' => 'ordering' - ), - 'aliases' => array( - 'title' => 'name' - ) - )); - - parent::_initialize($config); - - AnHelperArray::unsetValues($config->behaviors, array('commentable', 'subscribable')); - } - -//end class -} \ No newline at end of file + /** + * Initializes the default configuration for the object + * + * Called from {@link __construct()} as a first step of object instantiation. + * + * @param KConfig $config An optional KConfig object with configuration options. + * @return void + */ + protected function _initialize(KConfig $config) + { + $config->append(array( + 'behaviors' => array( + 'parentable' => array('parent' => 'page'), + ), + 'attributes' => array( + 'excerpt' => 'excerpt', + 'revisionNum' => 'ordering', + ), + 'aliases' => array( + 'title' => 'name', + ) + )); + + parent::_initialize($config); + + AnHelperArray::unsetValues($config->behaviors, array('commentable', 'subscribable')); + } +} diff --git a/packages/Pages/src/site/components/com_pages/views/page/html/default.php b/packages/Pages/src/site/components/com_pages/views/page/html/default.php index 54e6d2fc2..f326c0cb3 100644 --- a/packages/Pages/src/site/components/com_pages/views/page/html/default.php +++ b/packages/Pages/src/site/components/com_pages/views/page/html/default.php @@ -2,18 +2,18 @@ authorize('administration')) : ?> - + -
    -
  • -
  • updateTime), @name($page->editor)) ?>
  • -
  • numOfComments), $page->numOfComments) ?>
  • -
+
    +
  • +
  • updateTime), @name($page->editor)) ?>
  • +
  • numOfComments), $page->numOfComments) ?>
  • +
-true)) ?> \ No newline at end of file + true)) ?> \ No newline at end of file diff --git a/packages/Pages/src/site/components/com_pages/views/page/html/page.php b/packages/Pages/src/site/components/com_pages/views/page/html/page.php index 22f761c65..4aacfbe80 100644 --- a/packages/Pages/src/site/components/com_pages/views/page/html/page.php +++ b/packages/Pages/src/site/components/com_pages/views/page/html/page.php @@ -2,37 +2,37 @@ -published): ?> -'warning')) ?> - +published): ?> + 'warning')) ?> +
-
-
- author) ?> -
- -
-

author) ?>

-
- creationTime) ?> -
-
-
- -

- title) ?> -

- - description): ?> -
- description ) ?> -
- - -
-
- -
-
+
+
+ author) ?> +
+ +
+

author) ?>

+
+ creationTime) ?> +
+
+
+ +

+ title) ?> +

+ + description): ?> +
+ description ) ?> +
+ + +
+
+ +
+
diff --git a/packages/Pages/src/site/components/com_pages/views/revision/html/revision.php b/packages/Pages/src/site/components/com_pages/views/revision/html/revision.php index 00a966a58..ccbda57ad 100644 --- a/packages/Pages/src/site/components/com_pages/views/revision/html/revision.php +++ b/packages/Pages/src/site/components/com_pages/views/revision/html/revision.php @@ -2,15 +2,14 @@ -
-

- title) ?> -

- - body): ?> -
- body ) ?> -
- +
+

+ title) ?> +

+ + body): ?> +
+ body) ?> +
+
- diff --git a/src/libraries/anahita/domain/entity/abstract.php b/src/libraries/anahita/domain/entity/abstract.php index 2ee3f229d..cbe1e76c7 100644 --- a/src/libraries/anahita/domain/entity/abstract.php +++ b/src/libraries/anahita/domain/entity/abstract.php @@ -368,7 +368,7 @@ public function set($name, $value = null) $context['property'] = $property; $context['value'] = $value; $context['entity'] = $this; - + if ($this->getRepository()->getCommandChain()->run('before.setdata', $context) === false) { return $this; } diff --git a/src/libraries/anahita/domain/entity/default.php b/src/libraries/anahita/domain/entity/default.php index fb65ba8c2..7386efa7b 100644 --- a/src/libraries/anahita/domain/entity/default.php +++ b/src/libraries/anahita/domain/entity/default.php @@ -1,19 +1,4 @@ - * @author Rastin Mehr - * @copyright 2008 - 2010 rmdStudio Inc./Peerglobe Technology Inc - * @license GNU GPLv3 - * @version SVN: $Id$ - * @link http://www.anahitapolis.com - */ - /** * Default Domain Entity * @@ -23,11 +8,8 @@ * @author Arash Sanieyan * @author Rastin Mehr * @license GNU GPLv3 - * @link http://www.anahitapolis.com + * @copyright 2008 - 2010 rmdStudio Inc./Peerglobe Technology Inc */ class AnDomainEntityDefault extends AnDomainEntityAbstract -{ - +{ } - -?> \ No newline at end of file diff --git a/src/site/templates/base/css/components/pages.less b/src/site/templates/base/css/components/pages.less deleted file mode 100644 index 89d5288b7..000000000 --- a/src/site/templates/base/css/components/pages.less +++ /dev/null @@ -1,10 +0,0 @@ -@CHARSET "UTF-8"; - -.an-page-main, -.an-revision-main -{ - h1,h2,h3,h4 - { - margin: 20px 0; - } -} \ No newline at end of file