Indefero

Indefero Commit Details


Date:2011-12-05 18:39:45 (13 years 16 days ago)
Author:Thomas Keller
Branch:develop, release-1.3
Commit:8fde1e4762e8ff9f36acbf8602b099c2f7bd2211
Parents: 3897d7facbf943de044249a0589e4f8c60f31bd1
Message:Render resources in markdown context properly and implement all the documented render options.

Changes:

File differences

src/IDF/Template/Markdown.php
5555
5656
5757
58
5859
59
60
61
62
63
64
65
66
67
68
6069
6170
6271
......
8089
8190
8291
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
83171
84172
85173
$text = IDF_Template_safePregReplace('#\[\[([A-Za-z0-9\-]+)\]\]#im',
array($this, 'callbackWikiPageNoName'),
$text);
$filter = new IDF_Template_MarkdownPrefilter();
echo $filter->go(Pluf_Text_MarkDown_parse($text));
$text = $filter->go(Pluf_Text_MarkDown_parse($text));
// Replace [[!ResourceName]] with corresponding HTML for the resource;
// we need to do that after the HTML filtering as we'd otherwise be unable to use
// certain HTML elements, such as iframes, that are used to display text content
// FIXME: no support for escaping yet in place
echo IDF_Template_safePregReplace('#\[\[!([A-Za-z0-9\-]+)(?:,\s*([^\]]+))?\]\]#im',
array($this, 'callbackWikiResource'),
$text);
}
function callbackWikiPageNoName($m)
return '<a href="'.Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::viewPage', array($this->project->shortname, $pages[0]->title)).'" title="'.Pluf_esc($pages[0]->summary).'">'.$m[1].'</a>';
}
function callbackWikiResource($m)
{
@list($match, $resourceName, $opts) = $m;
if (!$this->request->rights['hasWikiAccess']) {
return '<span title="'.__('You are not allowed to access the wiki.').'">'.$match.'</span>';
}
$sql = new Pluf_SQL('project=%s AND title=%s',
array($this->project->id, $resourceName));
$resources = Pluf::factory('IDF_Wiki_Resource')->getList(array('filter'=>$sql->gen()));
if ($resources->count() == 0) {
if ($this->request->user->isAnonymous()) {
return '<span title="'.__('The wiki resource has not been found.').'">'.$match.'</span>';
}
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::createResource',
array($this->project->shortname),
array('name' => $resourceName));
return '<img style="vertical-align: text-bottom;" alt=" " src="'.Pluf::f('url_media').'/idf/img/add.png" />'.
'<a href="'.$url.'" title="'.__('The wiki resource has not been found. Create it!').'">'.$match.'</a>';
}
// by default, render the most recent revision
$resourceRevision = $resources[0]->get_current_revision();
list($urlConf, $urlMatches) = $this->request->view;
// if we currently look at an existing wiki page, look up its name and find the proper resource (if any)
if ($urlConf['model'] == 'IDF_Views_Wiki' && $urlConf['method'] == 'viewPage') {
$sql = new Pluf_SQL('project=%s AND title=%s',
array($this->project->id, $urlMatches[2]));
$pages = Pluf::factory('IDF_Wiki_Page')->getList(array('filter'=>$sql->gen()));
if ($pages->count() == 0) throw new Exception('page not found');
$pageRevision = $pages[0]->get_current_revision();
// if we look at an old version of the page, figure out the resource version back then
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>';
}
}
$sql = new Pluf_SQL('wikiresource=%s AND idf_wiki_pagerevision_id=%s',
array($resources[0]->id, $pageRevision->id));
$resourceRevision = Pluf::factory('IDF_Wiki_ResourceRevision')->getOne(
array('filter' => $sql->gen(), 'view' => 'join_pagerevision'));
}
$validOpts = array(
'align' => '/^(left|right|center)$/',
'width' => '/^\d+(%|px|em)?$/',
'height' => '/^\d+(%|px|em)?$/',
'preview' => '/^yes|no$/',
'title' => '/.+/',
);
$parsedOpts = array();
// FIXME: no support for escaping yet in place
$opts = preg_split('/\s*,\s*/', $opts, -1, PREG_SPLIT_NO_EMPTY);
foreach ((array)@$opts as $opt)
{
list($key, $value) = preg_split('/\s*=\s*/', $opt, 2);
if (!array_key_exists($key, $validOpts)) {
continue;
}
if (!preg_match($validOpts[$key], $value)) {
continue;
}
$parsedOpts[$key] = $value;
}
return $resourceRevision->render($parsedOpts);
}
function callbackEmbeddedDoc($m)
{
$scm = IDF_Scm::get($this->request->project);
src/IDF/Wiki/PageRevision.php
9999
100100
101101
102
103
104
105
106
107
108
109
102110
103111
104112
'type' => 'normal',
),
);
$table = $this->_con->pfx.'idf_wiki_pagerevision_idf_wiki_resourcerevision_assoc';
$this->_a['views'] = array(
'join_pagerevision' =>
array(
'join' => 'LEFT JOIN '.$table
.' ON idf_wiki_pagerevision_id=id',
),
);
}
function changedRevision()
src/IDF/Wiki/ResourceRevision.php
101101
102102
103103
104
105
106
107
108
109
110
111
104112
105113
106114
......
165173
166174
167175
168
176
177
178
179
180
181
182
183
184
185
169186
187
170188
171189
172
190
191
173192
174193
175194
......
195214
196215
197216
198
217
199218
200
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
201278
202
203279
280
204281
205
282
206283
207284
208285
209286
210287
211288
212
289
213290
214291
'verbose' => __('creation date'),
),
);
$table = $this->_con->pfx.'idf_wiki_pagerevision_idf_wiki_resourcerevision_assoc';
$this->_a['views'] = array(
'join_pagerevision' =>
array(
'join' => 'LEFT JOIN '.$table
.' ON idf_wiki_resourcerevision_id=id',
),
);
}
function __toString()
$this->get_wikiresource()->id, $this->id, $this->fileext);
}
function getFileURL()
function getViewURL()
{
$prj = $this->get_wikiresource()->get_project();
$resource = $this->get_wikiresource();
return Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::viewResource',
array($prj->shortname, $resource->title),
array('rev' => $this->id));
}
function getRawURL($attachment = false)
{
$query = $attachment ? array('attachment' => 1) : array();
$prj = $this->get_wikiresource()->get_project();
return Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::rawResource',
array($prj->shortname, $this->id));
array($prj->shortname, $this->id),
$query);
}
/**
}
/**
* Renders the resource
* Renders the resource with the given view options, including a link to the resource' detail page
*/
function render()
function render($opts = array())
{
// give some reasonable defaults
$opts = array_merge(array(
'align' => 'left',
'width' => '',
'height' => '',
'preview' => 'yes', // if possible
'title' => '',
), $opts);
$attrs = array('class="resource-container"');
$styles = array();
if (!empty($opts['align'])) {
switch ($opts['align']) {
case 'left':
$styles[] = 'float: left';
$styles[] = 'margin-right: 10px';
break;
case 'center':
$styles[] = 'margin: 0 auto 0 auto';
break;
case 'right':
$styles[] = 'float: right';
$styles[] = 'margin-left: 10px';
break;
}
}
if (!empty($opts['width'])) {
$styles[] = 'width:'.$opts['width'];
}
if (!empty($opts['height'])) {
$styles[] = 'height:'.$opts['height'];
}
$raw = $this->renderRaw();
$viewUrl = $this->getViewURL();
$download = '';
$html = '<div class="resource-container" style="'.implode(';', $styles).'">';
if ($opts['preview'] == 'yes' && !empty($raw)) {
$html .= '<div class="preview">'.$raw.'</div>'."\n";
} else {
$rawUrl = $this->getRawURL(true);
$download = '<a href="'.$rawUrl.'" class="download" title="'.sprintf(__('Download (%s)'), Pluf_Utils::prettySize($this->filesize)).'"></a>';
}
$resource = $this->get_wikiresource();
$title = $opts['title'];
if (empty($title)) {
$title = $resource->title.' - '.$resource->mime_type.' - '.Pluf_Utils::prettySize($this->filesize);
}
$html .= '<div class="title">'.$download.'<a href="'.$viewUrl.'" title="'.__('View resource details').'">'.$title.'</a></div>'."\n";
$html .= '</div>';
return $html;
}
/**
* Renders a raw version of the resource, without any possibilities of formatting or the like
*/
function renderRaw()
{
$url = $this->getFileURL();
$resource = $this->get_wikiresource();
$url = $this->getRawURL();
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);
return sprintf('<img src="%s" alt="%s" />', $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.');
return '';
}
}
src/IDF/templates/idf/wiki/viewResource.html
1919
2020
2121
22
22
23
24
25
26
2327
24
2528
2629
2730
28
31
2932
3033
3134
<div id="wiki-resource">
<p class="desc">{$resource.summary}</p>
<p class="preview">{$rev.render()|unsafe}</p>
{assign $preview = $rev.renderRaw()}
{if $preview == ''}
{assign $preview = __('Unable to render preview for this MIME type.')}
{/if}
<p class="preview">{$preview|unsafe}</p>
{aurl 'url', 'IDF_Views_Wiki::rawResource', array($project.shortname, $rev.id), array('attachment' => 1)}
<ul>
<li>{trans 'File size'}: {$rev.filesize|size}</li>
<li>{trans 'MIME type'}: {$resource.mime_type}</li>
<li><a href="{$url}">{trans 'Download this file'}</a></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)}
<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>
www/media/idf/css/style.css
928928
929929
930930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
931965
932966
933967
margin-left: 2em;
}
.resource-container {
border: 1px solid #EEE;
padding: 5px;
}
.resource-container .preview {
margin-bottom: 5px;
}
.resource-container .preview * {
width: 100%;
height: 100%;
}
.resource-container .preview img {
height: auto;
}
.resource-container .preview + .title {
font-size: 80%;
}
.resource-container .title * {
vertical-align: middle;
}
.resource-container .title .download {
display: inline-block;
margin-right: 5px;
background: url("../img/down-large.png") no-repeat;
width: 22px;
height: 22px;
}
/**
* main menu
*/

Archive Download the corresponding diff file

Page rendered in 0.09248s using 13 queries.