From 3f0c7c23d2907fa3ed90659c7c62c8f8d0df5d5b Mon Sep 17 00:00:00 2001 From: Thomas Keller Date: Tue, 6 Dec 2011 02:16:27 +0100 Subject: [PATCH] Finally save pagerevision and resourcerevision relations when a new page revision is created; fix a couple of bugs and streamline the view logic for viewPage and viewResource. --- src/IDF/Template/Markdown.php | 9 ++++++-- src/IDF/Views/Wiki.php | 11 +++++----- src/IDF/Wiki/PageRevision.php | 23 ++++++++++++++++++-- src/IDF/conf/urls.php | 2 +- src/IDF/templates/idf/wiki/viewPage.html | 14 +++++------- src/IDF/templates/idf/wiki/viewResource.html | 4 +++- 6 files changed, 43 insertions(+), 20 deletions(-) diff --git a/src/IDF/Template/Markdown.php b/src/IDF/Template/Markdown.php index 82b12cd..4c05704 100644 --- a/src/IDF/Template/Markdown.php +++ b/src/IDF/Template/Markdown.php @@ -130,8 +130,10 @@ class IDF_Template_Markdown extends Pluf_Template_Tag if (isset($this->request->GET['rev']) and preg_match('/^[0-9]+$/', $this->request->GET['rev'])) { $pageRevision = Pluf_Shortcuts_GetObjectOr404('IDF_Wiki_PageRevision', $this->request->GET['rev']); - if ($pageRevision->wikipage != $pages[0]->id) { - return ''.$match.''; + // this is actually an invariant since we came so far looking at + // and rendering the old revision already + if ($pageRevision == null) { + throw new Exception('page revision with id '.$this->request->GET['rev'].' not found'); } } @@ -140,6 +142,9 @@ class IDF_Template_Markdown extends Pluf_Template_Tag $resourceRevision = Pluf::factory('IDF_Wiki_ResourceRevision')->getOne( array('filter' => $sql->gen(), 'view' => 'join_pagerevision')); + if ($resourceRevision == null) { + return ''.$match.''; + } } $validOpts = array( diff --git a/src/IDF/Views/Wiki.php b/src/IDF/Views/Wiki.php index ccf5fbe..dc51c12 100644 --- a/src/IDF/Views/Wiki.php +++ b/src/IDF/Views/Wiki.php @@ -297,12 +297,13 @@ class IDF_Views_Wiki return new Pluf_HTTP_Response_NotFound($request); } $page = $pages[0]; - $oldrev = false; + $revision = $page->get_current_revision(); + // We grab the old revision if requested. if (isset($request->GET['rev']) and preg_match('/^[0-9]+$/', $request->GET['rev'])) { - $oldrev = Pluf_Shortcuts_GetObjectOr404('IDF_Wiki_PageRevision', + $revision = Pluf_Shortcuts_GetObjectOr404('IDF_Wiki_PageRevision', $request->GET['rev']); - if ($oldrev->wikipage != $page->id or $oldrev->is_head == true) { + if ($revision->wikipage != $page->id) { return new Pluf_HTTP_Response_NotFound($request); } } @@ -311,7 +312,6 @@ class IDF_Views_Wiki $tags = $page->get_tags_list(); $dep = Pluf_Model_InArray($dtag, $tags); $title = $page->title; - $revision = $page->get_current_revision(); $false = Pluf_DB_BooleanToDb(false, $page->getDbConnection()); $revs = $page->get_revisions_list(array('order' => 'creation_dtime DESC', 'filter' => 'is_head='.$false)); @@ -319,7 +319,6 @@ class IDF_Views_Wiki array( 'page_title' => $title, 'page' => $page, - 'oldrev' => $oldrev, 'rev' => $revision, 'revs' => $revs, 'tags' => $tags, @@ -348,7 +347,7 @@ class IDF_Views_Wiki if (isset($request->GET['rev']) and preg_match('/^[0-9]+$/', $request->GET['rev'])) { $revision = Pluf_Shortcuts_GetObjectOr404('IDF_Wiki_ResourceRevision', $request->GET['rev']); - if ($revision->wikiresource != $resource->id or $revision->is_head == true) { + if ($revision->wikiresource != $resource->id) { return new Pluf_HTTP_Response_NotFound($request); } } diff --git a/src/IDF/Wiki/PageRevision.php b/src/IDF/Wiki/PageRevision.php index 2b4c848..ae05d5d 100644 --- a/src/IDF/Wiki/PageRevision.php +++ b/src/IDF/Wiki/PageRevision.php @@ -137,6 +137,8 @@ class IDF_Wiki_PageRevision extends Pluf_Model function postSave($create=false) { + $prj = $this->get_wikipage()->get_project(); + if ($create) { // Check if more than one revision for this page. We do // not want to insert the first revision in the timeline @@ -146,8 +148,7 @@ class IDF_Wiki_PageRevision extends Pluf_Model $sql = new Pluf_SQL('wikipage=%s', array($this->wikipage)); $rev = Pluf::factory('IDF_Wiki_PageRevision')->getList(array('filter'=>$sql->gen())); if ($rev->count() > 1) { - IDF_Timeline::insert($this, $this->get_wikipage()->get_project(), - $this->get_submitter()); + IDF_Timeline::insert($this, $prj, $this->get_submitter()); foreach ($rev as $r) { if ($r->id != $this->id and $r->is_head) { $r->is_head = false; @@ -159,6 +160,24 @@ class IDF_Wiki_PageRevision extends Pluf_Model $page->update(); // Will update the modification timestamp. IDF_Search::index($page); } + + // remember the resource revisions used in this page revision + if ($this->is_head) { + preg_match_all('#\[\[!([A-Za-z0-9\-]+)[^\]]*\]\]#im', $this->content, $matches, PREG_PATTERN_ORDER); + if (count($matches) > 1 && count($matches[1]) > 0) { + foreach ($matches[1] as $resourceName) { + $sql = new Pluf_SQL('project=%s AND title=%s', + array($prj->id, $resourceName)); + $resources = Pluf::factory('IDF_Wiki_Resource')->getList(array('filter'=>$sql->gen())); + if ($resources->count() == 0) + continue; + + $current_revision = $resources[0]->get_current_revision(); + $current_revision->setAssoc($this); + $this->setAssoc($current_revision); + } + } + } } public function timelineFragment($request) diff --git a/src/IDF/conf/urls.php b/src/IDF/conf/urls.php index 745a552..4550f32 100644 --- a/src/IDF/conf/urls.php +++ b/src/IDF/conf/urls.php @@ -332,7 +332,7 @@ $ctl[] = array('regex' => '#^/p/([\-\w]+)/page/(.*)/$#', 'model' => 'IDF_Views_Wiki', 'method' => 'viewPage'); -$ctl[] = array('regex' => '#^/p/([\-\w]+)/resouce/(.*)/$#', +$ctl[] = array('regex' => '#^/p/([\-\w]+)/resource/(.*)/$#', 'base' => $base, 'model' => 'IDF_Views_Wiki', 'method' => 'viewResource'); diff --git a/src/IDF/templates/idf/wiki/viewPage.html b/src/IDF/templates/idf/wiki/viewPage.html index 203fdf2..43a2cf4 100644 --- a/src/IDF/templates/idf/wiki/viewPage.html +++ b/src/IDF/templates/idf/wiki/viewPage.html @@ -1,7 +1,7 @@ {extends "idf/wiki/base.html"} {block extraheader} -{if $oldrev}{/if} +{if !$rev.is_head}{/if} {/block} @@ -14,8 +14,8 @@ use it as reference only if you are sure you need these specific information.{/blocktrans}

{/if} -{if $oldrev} -{ashowuser 'submitter', $oldrev.get_submitter(), $request}{aurl 'url', 'IDF_Views_Wiki::viewPage', array($project.shortname, $page.title)} +{if !$rev.is_head} +{ashowuser 'submitter', $rev.get_submitter(), $request}{aurl 'url', 'IDF_Views_Wiki::viewPage', array($project.shortname, $page.title)}

{blocktrans}You are looking at an old revision of the page {$page.title}. This revision was created @@ -28,14 +28,12 @@ by {$submitter}.{/blocktrans}

{$page.summary}

-{if !$oldrev} {markdown $rev.content, $request} -{else} -{markdown $oldrev.content, $request} -{if $isOwner or $isAdmin}{aurl 'url', 'IDF_Views_Wiki::deletePageRev', array($project.shortname, $oldrev.id)} + +{if !$rev.is_head and ($isOwner or $isAdmin)} +{aurl 'url', 'IDF_Views_Wiki::deletePageRev', array($project.shortname, $rev.id)}

{trans 'Trash'} {trans 'Delete this revision'}

{/if} -{/if}
{/block} diff --git a/src/IDF/templates/idf/wiki/viewResource.html b/src/IDF/templates/idf/wiki/viewResource.html index 726f69f..a41714e 100644 --- a/src/IDF/templates/idf/wiki/viewResource.html +++ b/src/IDF/templates/idf/wiki/viewResource.html @@ -30,7 +30,9 @@ by {$submitter}.{/blocktrans}

  • {trans 'MIME type'}: {$resource.mime_type}
  • {trans 'Download this file'}
  • -{if ($isOwner or $isAdmin) and !$rev.is_head}{aurl 'url', 'IDF_Views_Wiki::deleteResourceRev', array($project.shortname, $rev.id)} + +{if !$rev.is_head and ($isOwner or $isAdmin)} +{aurl 'url', 'IDF_Views_Wiki::deleteResourceRev', array($project.shortname, $rev.id)}

    {trans 'Trash'} {trans 'Delete this revision'}

    {/if}