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.
This commit is contained in:
Thomas Keller 2011-12-06 02:16:27 +01:00
parent 8fde1e4762
commit 3f0c7c23d2
6 changed files with 43 additions and 20 deletions

View File

@ -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'])) { if (isset($this->request->GET['rev']) and preg_match('/^[0-9]+$/', $this->request->GET['rev'])) {
$pageRevision = Pluf_Shortcuts_GetObjectOr404('IDF_Wiki_PageRevision', $pageRevision = Pluf_Shortcuts_GetObjectOr404('IDF_Wiki_PageRevision',
$this->request->GET['rev']); $this->request->GET['rev']);
if ($pageRevision->wikipage != $pages[0]->id) { // this is actually an invariant since we came so far looking at
return '<span title="'.__('This revision of the resource is no longer available.').'">'.$match.'</span>'; // 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( $resourceRevision = Pluf::factory('IDF_Wiki_ResourceRevision')->getOne(
array('filter' => $sql->gen(), 'view' => 'join_pagerevision')); array('filter' => $sql->gen(), 'view' => 'join_pagerevision'));
if ($resourceRevision == null) {
return '<span title="'.__('This revision of the resource is no longer available.').'">'.$match.'</span>';
}
} }
$validOpts = array( $validOpts = array(

View File

@ -297,12 +297,13 @@ class IDF_Views_Wiki
return new Pluf_HTTP_Response_NotFound($request); return new Pluf_HTTP_Response_NotFound($request);
} }
$page = $pages[0]; $page = $pages[0];
$oldrev = false; $revision = $page->get_current_revision();
// We grab the old revision if requested. // We grab the old revision if requested.
if (isset($request->GET['rev']) and preg_match('/^[0-9]+$/', $request->GET['rev'])) { 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']); $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); return new Pluf_HTTP_Response_NotFound($request);
} }
} }
@ -311,7 +312,6 @@ class IDF_Views_Wiki
$tags = $page->get_tags_list(); $tags = $page->get_tags_list();
$dep = Pluf_Model_InArray($dtag, $tags); $dep = Pluf_Model_InArray($dtag, $tags);
$title = $page->title; $title = $page->title;
$revision = $page->get_current_revision();
$false = Pluf_DB_BooleanToDb(false, $page->getDbConnection()); $false = Pluf_DB_BooleanToDb(false, $page->getDbConnection());
$revs = $page->get_revisions_list(array('order' => 'creation_dtime DESC', $revs = $page->get_revisions_list(array('order' => 'creation_dtime DESC',
'filter' => 'is_head='.$false)); 'filter' => 'is_head='.$false));
@ -319,7 +319,6 @@ class IDF_Views_Wiki
array( array(
'page_title' => $title, 'page_title' => $title,
'page' => $page, 'page' => $page,
'oldrev' => $oldrev,
'rev' => $revision, 'rev' => $revision,
'revs' => $revs, 'revs' => $revs,
'tags' => $tags, 'tags' => $tags,
@ -348,7 +347,7 @@ class IDF_Views_Wiki
if (isset($request->GET['rev']) and preg_match('/^[0-9]+$/', $request->GET['rev'])) { if (isset($request->GET['rev']) and preg_match('/^[0-9]+$/', $request->GET['rev'])) {
$revision = Pluf_Shortcuts_GetObjectOr404('IDF_Wiki_ResourceRevision', $revision = Pluf_Shortcuts_GetObjectOr404('IDF_Wiki_ResourceRevision',
$request->GET['rev']); $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); return new Pluf_HTTP_Response_NotFound($request);
} }
} }

View File

@ -137,6 +137,8 @@ class IDF_Wiki_PageRevision extends Pluf_Model
function postSave($create=false) function postSave($create=false)
{ {
$prj = $this->get_wikipage()->get_project();
if ($create) { if ($create) {
// Check if more than one revision for this page. We do // Check if more than one revision for this page. We do
// not want to insert the first revision in the timeline // 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)); $sql = new Pluf_SQL('wikipage=%s', array($this->wikipage));
$rev = Pluf::factory('IDF_Wiki_PageRevision')->getList(array('filter'=>$sql->gen())); $rev = Pluf::factory('IDF_Wiki_PageRevision')->getList(array('filter'=>$sql->gen()));
if ($rev->count() > 1) { if ($rev->count() > 1) {
IDF_Timeline::insert($this, $this->get_wikipage()->get_project(), IDF_Timeline::insert($this, $prj, $this->get_submitter());
$this->get_submitter());
foreach ($rev as $r) { foreach ($rev as $r) {
if ($r->id != $this->id and $r->is_head) { if ($r->id != $this->id and $r->is_head) {
$r->is_head = false; $r->is_head = false;
@ -159,6 +160,24 @@ class IDF_Wiki_PageRevision extends Pluf_Model
$page->update(); // Will update the modification timestamp. $page->update(); // Will update the modification timestamp.
IDF_Search::index($page); 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) public function timelineFragment($request)

View File

@ -332,7 +332,7 @@ $ctl[] = array('regex' => '#^/p/([\-\w]+)/page/(.*)/$#',
'model' => 'IDF_Views_Wiki', 'model' => 'IDF_Views_Wiki',
'method' => 'viewPage'); 'method' => 'viewPage');
$ctl[] = array('regex' => '#^/p/([\-\w]+)/resouce/(.*)/$#', $ctl[] = array('regex' => '#^/p/([\-\w]+)/resource/(.*)/$#',
'base' => $base, 'base' => $base,
'model' => 'IDF_Views_Wiki', 'model' => 'IDF_Views_Wiki',
'method' => 'viewResource'); 'method' => 'viewResource');

View File

@ -1,7 +1,7 @@
{extends "idf/wiki/base.html"} {extends "idf/wiki/base.html"}
{block extraheader} {block extraheader}
{if $oldrev}<meta name="ROBOTS" content="NOINDEX" />{/if} {if !$rev.is_head}<meta name="ROBOTS" content="NOINDEX" />{/if}
<link rel="stylesheet" type="text/css" media="print" href="{media '/idf/css/print-wiki.css'}" /> <link rel="stylesheet" type="text/css" media="print" href="{media '/idf/css/print-wiki.css'}" />
{/block} {/block}
@ -14,8 +14,8 @@
use it as reference only if you are sure you need these specific information.{/blocktrans}</p> use it as reference only if you are sure you need these specific information.{/blocktrans}</p>
</div> </div>
{/if} {/if}
{if $oldrev} {if !$rev.is_head}
{ashowuser 'submitter', $oldrev.get_submitter(), $request}{aurl 'url', 'IDF_Views_Wiki::viewPage', array($project.shortname, $page.title)} {ashowuser 'submitter', $rev.get_submitter(), $request}{aurl 'url', 'IDF_Views_Wiki::viewPage', array($project.shortname, $page.title)}
<div class="old-rev"> <div class="old-rev">
<p>{blocktrans}You are looking at an old revision of the page <p>{blocktrans}You are looking at an old revision of the page
<a href="{$url}">{$page.title}</a>. This revision was created <a href="{$url}">{$page.title}</a>. This revision was created
@ -28,14 +28,12 @@ by {$submitter}.{/blocktrans}</p>
<script type="text/javascript" src="{media '/idf/js/wiki-toc.js'}"></script> <script type="text/javascript" src="{media '/idf/js/wiki-toc.js'}"></script>
<p class="desc">{$page.summary}</p> <p class="desc">{$page.summary}</p>
{if !$oldrev}
{markdown $rev.content, $request} {markdown $rev.content, $request}
{else}
{markdown $oldrev.content, $request} {if !$rev.is_head and ($isOwner or $isAdmin)}
{if $isOwner or $isAdmin}{aurl 'url', 'IDF_Views_Wiki::deletePageRev', array($project.shortname, $oldrev.id)} {aurl 'url', 'IDF_Views_Wiki::deletePageRev', array($project.shortname, $rev.id)}
<p class="delp"><a href="{$url}" title="{trans 'Delete this revision'}"><img src="{media '/idf/img/trash.png'}" style="vertical-align: text-bottom;" alt="{trans 'Trash'}" /></a> <a href="{$url}">{trans 'Delete this revision'}</a></p> <p class="delp"><a href="{$url}" title="{trans 'Delete this revision'}"><img src="{media '/idf/img/trash.png'}" style="vertical-align: text-bottom;" alt="{trans 'Trash'}" /></a> <a href="{$url}">{trans 'Delete this revision'}</a></p>
{/if} {/if}
{/if}
</div> </div>
{/block} {/block}

View File

@ -30,7 +30,9 @@ by {$submitter}.{/blocktrans}</p>
<li>{trans 'MIME type'}: {$resource.mime_type}</li> <li>{trans 'MIME type'}: {$resource.mime_type}</li>
<li><a href="{$rev.getRawURL(true)}">{trans 'Download this file'}</a></li> <li><a href="{$rev.getRawURL(true)}">{trans 'Download this file'}</a></li>
</ul> </ul>
{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)}
<p class="delp"><a href="{$url}" title="{trans 'Delete this revision'}"><img src="{media '/idf/img/trash.png'}" style="vertical-align: text-bottom;" alt="{trans 'Trash'}" /></a> <a href="{$url}">{trans 'Delete this revision'}</a></p> <p class="delp"><a href="{$url}" title="{trans 'Delete this revision'}"><img src="{media '/idf/img/trash.png'}" style="vertical-align: text-bottom;" alt="{trans 'Trash'}" /></a> <a href="{$url}">{trans 'Delete this revision'}</a></p>
{/if} {/if}