Indefero

Indefero Commit Details


Date:2011-11-26 16:25:46 (13 years 25 days ago)
Author:Thomas Keller
Branch:develop, release-1.3
Commit:58ccb93f2d1824f3f8225bed09481bd7911a62bf
Parents: ff2b19d58760980227e80676613949cdda91b786
Message:Render a resource preview view with more information about the resource, such as its summary, its mime type, a preview (available for some image/* and text/* mime types) and a list of pages where the specific resource revision is used.

Changes:

File differences

src/IDF/Views/Wiki.php
275275
276276
277277
278
278
279279
280280
281281
......
328328
329329
330330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
331389
332390
333391
}
return Pluf_Shortcuts_RenderToResponse('idf/wiki/createResource.html',
array(
'resource_title' => $title,
'page_title' => $title,
'form' => $form,
),
$request);
}
/**
* View a documentation resource.
*/
public $viewResource_precond = array('IDF_Precondition::accessWiki');
public function viewResource($request, $match)
{
$prj = $request->project;
$sql = new Pluf_SQL('project=%s AND title=%s',
array($prj->id, $match[2]));
$resources = Pluf::factory('IDF_Wiki_Resource')->getList(array('filter'=>$sql->gen()));
if ($resources->count() != 1) {
return new Pluf_HTTP_Response_NotFound($request);
}
$resource = $resources[0];
$revision = $resource->get_current_revision();
// grab the old revision if requested.
if (isset($request->GET['rev']) and preg_match('/^[0-9]+$/', $request->GET['rev'])) {
$revision = Pluf_Shortcuts_GetObjectOr404('IDF_Wiki_ResourceRevision',
$request->GET['rev']);
if ($oldrev->wikiresource != $resource->id or $oldrev->is_head == true) {
return new Pluf_HTTP_Response_NotFound($request);
}
}
$pagerevs = $revision->getPageRevisions();
$title = $resource->title;
$false = Pluf_DB_BooleanToDb(false, $resource->getDbConnection());
$revs = $resource->get_revisions_list(array('order' => 'creation_dtime DESC',
'filter' => 'is_head='.$false));
return Pluf_Shortcuts_RenderToResponse('idf/wiki/viewResource.html',
array(
'page_title' => $title,
'resource' => $resource,
'rev' => $revision,
'revs' => $revs,
'pagerevs' => $pagerevs,
),
$request);
}
/**
* Returns a bytestream to the given raw resource revision
*/
public $rawResource_precond = array('IDF_Precondition::accessWiki');
public function rawResource($request, $match)
{
$prj = $request->project;
$rev = Pluf_Shortcuts_GetObjectOr404('IDF_Wiki_ResourceRevision',
$match[2]);
$res = $rev->get_wikiresource();
if ($res->get_project()->id != $prj->id) {
return new Pluf_HTTP_Response_NotFound($request);
}
return new Pluf_HTTP_Response_File($rev->getFilePath(), $res->mime_type);
}
/**
* Remove a revision of a page.
*/
public $deletePageRev_precond = array('IDF_Precondition::accessWiki',
src/IDF/Wiki/ResourceRevision.php
138138
139139
140140
141
142
143
144
145
146
147
141148
142149
143150
144151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
145192
$this->get_wikiresource()->id, $this->id, $this->get_wikiresource()->orig_file_ext);
}
function getFileURL()
{
$prj = $this->get_wikiresource()->get_project();
return Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::rawResource',
array($prj->shortname, $this->id));
}
function preDelete()
{
@unlink($this->getFilePath());
}
/**
* Returns the page revisions which contain references to this resource revision
*/
function getPageRevisions()
{
$db =& Pluf::db();
$sql_results = $db->select(
'SELECT idf_wiki_pagerevision_id as id '.
'FROM '.Pluf::f('db_table_prefix', '').'idf_wiki_pagerevision_idf_wiki_resourcerevision_assoc '.
'WHERE idf_wiki_resourcerevision_id='.$this->id
);
$ids = array(0);
foreach ($sql_results as $id) {
$ids[] = $id['id'];
}
$ids = implode (',', $ids);
$sql = new Pluf_SQL('id IN ('.$ids.')');
return Pluf::factory('IDF_Wiki_PageRevision')
->getList(array('filter' => $sql->gen()));
}
/**
* Renders the resource
*/
function render()
{
$url = $this->getFileURL();
$resource = $this->get_wikiresource();
if (preg_match('#^image/(gif|jpeg|png|tiff)$#', $resource->mime_type)) {
return sprintf('<a href="%s"><img src="%s" alt="%s" /></a>', $url, $url, $resource->title);
}
if (preg_match('#^text/(xml|html|sgml|javascript|ecmascript|css)$#', $resource->mime_type)) {
return sprintf('<iframe src="%s" alt="%s"></iframe>', $url, $resource->title);
}
return __('Unable to render preview for this MIME type.');
}
}
src/IDF/conf/urls.php
322322
323323
324324
325
326
327
328
329
325330
326331
327332
'model' => 'IDF_Views_Wiki',
'method' => 'deleteResource');
$ctl[] = array('regex' => '#^/p/([\-\w]+)/res/raw/(.*)/$#',
'base' => $base,
'model' => 'IDF_Views_Wiki',
'method' => 'rawResource');
$ctl[] = array('regex' => '#^/p/([\-\w]+)/page/(.*)/$#',
'base' => $base,
'model' => 'IDF_Views_Wiki',
src/IDF/templates/idf/wiki/viewResource.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{extends "idf/wiki/base.html"}
{block extraheader}
{if !$rev.is_head}<meta name="ROBOTS" content="NOINDEX" />{/if}
{/block}
{block docclass}yui-t3{assign $inResourceView=true}{/block}
{block body}
{if !$rev.is_head}
{ashowuser 'submitter', $oldrev.get_submitter(), $request}{aurl 'url', 'IDF_Views_Wiki::viewResource', array($project.shortname, $resource.title)}
<div class="old-rev">
<p>{blocktrans}You are looking at an old revision of the resource
<a href="{$url}">{$resource.title}</a>. This revision was created
by {$submitter}.{/blocktrans}</p>
</div>
{/if}
<div id="wiki-resource">
<p class="desc">{$resource.summary}</p>
<p class="preview">{$rev.render()|unsafe}</p>
<ul>
<li>{trans 'File size'}: {$rev.filesize|size}</li>
<li>{trans 'MIME type'}: {$resource.mime_type}</li>
</ul>
{if ($isOwner or $isAdmin) and !$rev.is_head}{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}
<p><strong>{trans 'Page Usage'}</strong></p>
{if $pagerevs.count() == 0}
<p>{trans 'This resource is not used on any pages yet.'}</p>
{else}
<ul>{foreach $pagerevs as $pagerev}
{assign $css = ''}
{if !$pagerev.is_head}{assign $css=' class="old-rev"'}{/if}
<li{$css|unsafe}><a href="{url 'IDF_Views_Wiki::viewPage', array($project.shortname, $pagerev.get_wikipage().title), array('rev'=>$pagerev.id)}">{$pagerev.get_wikipage().title} ({$pagerev.summary})</a></li>
{/foreach}</ul>
{/if}
</div>
{/block}
{block context}
{ashowuser 'submitter', $resource.get_submitter(), $request}
<p><strong>{trans 'Created:'}</strong> <span class="nobrk">{$resource.creation_dtime|dateago}</span><br /><span class="nobrk">{blocktrans}by {$submitter}{/blocktrans}</span></p>
{if $rev.creation_dtime != $resource.creation_dtime}<p>{ashowuser 'submitter', $rev.get_submitter(), $request}
<strong>{trans 'Updated:'}</strong> <span class="nobrk">{$rev.creation_dtime|dateago}</span><br /><span class="nobrk">{blocktrans}by {$submitter}{/blocktrans}</span></p>{/if}
{if $revs.count() > 0}
<p><strong>{trans 'Old Revisions'}</strong></p>
<ul>{foreach $revs as $old}
<li><a href="{url 'IDF_Views_Wiki::viewResource', array($project.shortname, $resource.title), array('rev'=>$old.id)}">{$old.summary}</a></li>
{/foreach}</ul>
{/if}
{/block}
www/media/idf/css/style.css
802802
803803
804804
805
806
807
808
809
810
811
812
813
805814
806815
807816
......
824833
825834
826835
836
837
838
827839
828840
829841
width: 60%;
}
p.preview img {
max-width: 60%;
}
p.preview iframe {
width: 60%;
height: 300px;
}
div.old-rev {
padding: 1em 1em 0.1em 1em;
margin-bottom: 1em;
-webkit-border-radius: 5px;
}
li.old-rev {
font-style: italic;
}
.delp {
float: right;

Archive Download the corresponding diff file

Page rendered in 0.10129s using 13 queries.