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'])) {
$pageRevision = Pluf_Shortcuts_GetObjectOr404('IDF_Wiki_PageRevision',
$this->request->GET['rev']);
if ($pageRevision->wikipage != $pages[0]->id) {
return '<span title="'.__('This revision of the resource is no longer available.').'">'.$match.'</span>';
// 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 '<span title="'.__('This revision of the resource is no longer available.').'">'.$match.'</span>';
}
}
$validOpts = array(

View File

@ -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);
}
}

View File

@ -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)

View File

@ -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');

View File

@ -1,7 +1,7 @@
{extends "idf/wiki/base.html"}
{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'}" />
{/block}
@ -14,8 +14,8 @@
use it as reference only if you are sure you need these specific information.{/blocktrans}</p>
</div>
{/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)}
<div class="old-rev">
<p>{blocktrans}You are looking at an old revision of the page
<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>
<p class="desc">{$page.summary}</p>
{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)}
<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}
</div>
{/block}

View File

@ -30,7 +30,9 @@ by {$submitter}.{/blocktrans}</p>
<li>{trans 'MIME type'}: {$resource.mime_type}</li>
<li><a href="{$rev.getRawURL(true)}">{trans 'Download this file'}</a></li>
</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>
{/if}