Indefero

Indefero Commit Details


Date:2008-12-03 08:00:47 (16 years 19 days ago)
Author:Loic d'Anterroches
Branch:dev, develop, feature-issue_links, feature.better-home, feature.content-md5, feature.diff-whitespace, feature.download-md5, feature.issue-links, feature.issue-of-others, feature.issue-summary, feature.search-filter, feature.webrepos, feature.wiki-default-page, master, release-1.1, release-1.2, release-1.3
Commit:9c44bc5fe5c549959706b2b8a9d892398743bbf1
Parents: a79d13ee3f786913f3498a14b9fd68d222ed290d
Message:Fixed issue 71, add atom feeds.

The basic building block is here with the feed of the timeline, it is
rather easy to add the feed other elements based on this work. This will
require iterations and polishing.
Changes:

File differences

src/IDF/Commit.php
183183
184184
185185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
186218
<div class="helptext right">'.__('Commit').'&nbsp;<a href="'.$url.'" class="mono">'.$this->scm_id.'</a>, '.__('by').' '.strip_tags($this->origauthor).'</div></td></tr>';
return Pluf_Template::markSafe($out);
}
/**
* Returns the feed fragment for the commit.
*
* @param Pluf_HTTP_Request
* @return Pluf_Template_SafeString
*/
public function feedFragment($request)
{
$url = Pluf::f('url_base')
.Pluf_HTTP_URL_urlForView('IDF_Views_Source::commit',
array($request->project->shortname,
$this->scm_id));
$tag = new IDF_Template_IssueComment();
$summary = '<content type="xhtml">'."\n"
.'<div xmlns="http://www.w3.org/1999/xhtml">'
.$tag->start($this->summary, $request, false, false, false);
if ($this->fullmessage) {
$summary .= '<br /><br />'
.$tag->start($this->fullmessage, $request, false, false, false);
}
$date = Pluf_Date::gmDateToGmString($this->creation_dtime);
$summary .= '</div></content>';
$out = '<entry>
<title>'.Pluf_esc($request->project->name).': '.__('Commit').' '.$this->scm_id.'</title>
<link href="'.$url.'"/>
<id>'.$url.'</id>
<updated>'.$date.'</updated>'.$summary.'
</entry>
';
return $out;
}
}
src/IDF/Issue.php
195195
196196
197197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
198228
<div class="helptext right">'.sprintf(__('Creation of <a href="%s" class="%s">issue&nbsp;%d</a>'), $url, $ic, $this->id).', '.__('by').' '.Pluf_esc($submitter).'</div></td></tr>';
return Pluf_Template::markSafe($out);
}
public function feedFragment($request)
{
$base = '<entry>
<title>%%title%%</title>
<link href="%%url%%"/>
<id>%%url%%</id>
<updated>%%date%%</updated>
<content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">
<pre>%%content%%</pre>
</div></content>
</entry>';
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view',
array($request->project->shortname,
$this->id));
$title = sprintf(__('%s: Issue %d created - %s'),
Pluf_esc($request->project->name),
$this->id, Pluf_esc($this->summary));
// Get the first comment of this issue.
$cts = $this->get_comments_list(array('order' => 'id ASC',
'nb' => 1));
$tag = new IDF_Template_IssueComment();
$content = $tag->start($cts[0]->content, $request, false);
$date = Pluf_Date::gmDateToGmString($this->creation_dtime);
return Pluf_Translation::sprintf($base,
array('url' => $url,
'title' => $title,
'content' => $content,
'date' => $date));
}
}
src/IDF/IssueComment.php
172172
173173
174174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
175229
return Pluf_Template::markSafe($out);
}
public function feedFragment($request)
{
$base = '<entry>
<title>%%title%%</title>
<link href="%%url%%"/>
<id>%%url%%</id>
<updated>%%date%%</updated>
<content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">
%%content%%
</div></content>
</entry>';
$issue = $this->get_issue();
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view',
array($request->project->shortname,
$issue->id));
$url .= '#ic'.$this->id;
$title = sprintf(__('%s: Comment on issue %d - %s'),
Pluf_esc($request->project->name),
$issue->id, Pluf_esc($issue->summary));
$submitter = $this->get_submitter();
$tag = new IDF_Template_IssueComment();
$content = '<p><pre>'.$tag->start($this->content, $request, false).'</pre></p>';
if ($this->changedIssue()) {
$content .= '<p>';
foreach ($this->changes as $w => $v) {
$content .= '<strong>';
switch ($w) {
case 'su':
$content .= __('Summary:'); break;
case 'st':
$content .= __('Status:'); break;
case 'ow':
$content .= __('Owner:'); break;
case 'lb':
$content .= __('Labels:'); break;
}
$content .= '</strong> ';
if ($w == 'lb') {
$content .= Pluf_esc(implode(', ', $v));
} else {
$content .= Pluf_esc($v);
}
$content .= ' ';
}
$content .= '</p>';
}
$date = Pluf_Date::gmDateToGmString($this->creation_dtime);
return Pluf_Translation::sprintf($base,
array('url' => $url,
'title' => $title,
'content' => $content,
'date' => $date));
}
}
src/IDF/Middleware.php
5252
5353
5454
55
56
57
58
59
60
61
62
63
55
6456
6557
6658
59
60
61
62
63
64
65
66
67
68
69
70
71
6772
6873
6974
}
$request->conf = new IDF_Conf();
$request->conf->setProject($request->project);
$ak = array('downloads_access_rights' => 'hasDownloadsAccess',
'wiki_access_rights' => 'hasWikiAccess',
'review_access_rights' => 'hasReviewAccess',
'source_access_rights' => 'hasSourceAccess',
'issues_access_rights' => 'hasIssuesAccess');
$request->rights = array();
foreach ($ak as $key=>$val) {
$request->rights[$val] = (true === IDF_Precondition::accessTabGeneric($request, $key));
}
self::setRights($request);
}
return false;
}
public static function setRights(&$request)
{
$ak = array('downloads_access_rights' => 'hasDownloadsAccess',
'wiki_access_rights' => 'hasWikiAccess',
'review_access_rights' => 'hasReviewAccess',
'source_access_rights' => 'hasSourceAccess',
'issues_access_rights' => 'hasIssuesAccess');
$request->rights = array();
foreach ($ak as $key=>$val) {
$request->rights[$val] = (true === IDF_Precondition::accessTabGeneric($request, $key));
}
}
}
src/IDF/Precondition.php
161161
162162
163163
164
164
165165
166166
167167
......
180180
181181
182182
183
183
184184
185185
186186
......
190190
191191
192192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
193243
194244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
195259
return self::accessTabGeneric($request, 'review_access_rights');
}
/**
/**
* Based on the request, it is automatically setting the user.
*
* API calls are not translated.
$sql = new Pluf_SQL('login=%s AND active='.$true,
$request->REQUEST['_login']);
$users = Pluf::factory('Pluf_User')->getList(array('filter'=>$sql->gen()));
if ($users->count() != 1) {
if ($users->count() != 1 or !$users[0]->active) {
// Should return a special authentication error like user
// not found.
return true;
return true; // Again need authentication error
}
$request->user = $users[0];
IDF_Middleware::setRights($request);
return true;
}
/**
* Based on the request, it is automatically setting the user.
*
* Authenticated feeds have a token set at the end of the url in
* the for of 'authenticated/url/token/234092384023woeiur/'. If
* you remove 'token/234092384023woeiur/' the url is not
* authenticated.
*
* If the user is already logged in and not anonymous and no token
* is given, then the user is unset and a non authenticated user
* is loaded. This is to avoid people to not understand why a
* normally not authenticated feed is providing authenticated
* data.
*/
static public function feedSetUser($request)
{
if (!isset($request->project)) {
return true; // we do not act on non project pages at the
// moment.
}
if (!$request->user->isAnonymous()) {
// by default anonymous
$request->user = new Pluf_User();
IDF_Middleware::setRights($request);
}
$match = array();
if (!preg_match('#/token/([^/]+)/$#', $request->query, $match)) {
return true; // anonymous
}
$token = $match[1];
$hash = substr($token, 0, 2);
$encrypted = substr($token, 2);
if ($hash != substr(md5(Pluf::f('secret_key').$encrypted), 0, 2)) {
return true; // no match in the hash, anonymous
}
$cr = new Pluf_Crypt(md5(Pluf::f('secret_key')));
list($userid, $projectid) = split(':', $cr->decrypt($encrypted), 2);
if ($projectid != $request->project->id) {
return true; // anonymous
}
$user = new Pluf_User($userid);
if (!$user->active) {
return true; // anonymous
}
$request->user = $user;
IDF_Middleware::setRights($request);
return true;
}
/**
* Generate the token for the feed.
*
* @param IDF_Project
* @param Pluf_User
* @return string Token
*/
static public function genFeedToken($project, $user)
{
$cr = new Pluf_Crypt(md5(Pluf::f('secret_key')));
$encrypted = trim($cr->encrypt($user->id.':'.$project->id), '~');
return substr(md5(Pluf::f('secret_key').$encrypted), 0, 2).$encrypted;
}
}
src/IDF/Review.php
165165
166166
167167
168
169
170
171
172
168173
{
return '';
}
public function feedFragment($request)
{
return '';
}
}
src/IDF/Review/FileComment.php
110110
111111
112112
113
114
115
116
117
113118
{
return '';
}
public function feedFragment($request)
{
return '';
}
}
src/IDF/Review/Patch.php
115115
116116
117117
118
119
120
121
122
118123
public function timelineFragment($request)
{
}
public function feedFragment($request)
{
return '';
}
}
src/IDF/Upload.php
184184
185185
186186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
187213
<div class="helptext right">'.sprintf(__('Addition of <a href="%s">download&nbsp;%d</a>'), $url, $this->id).', '.__('by').' '.Pluf_esc($submitter).'</div></td></tr>';
return Pluf_Template::markSafe($out);
}
public function feedFragment($request)
{
$base = '<entry>
<title>%%title%%</title>
<link href="%%url%%"/>
<id>%%url%%</id>
<updated>%%date%%</updated>
<content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">
%%content%%
</div></content>
</entry>';
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Download::view',
array($request->project->shortname,
$this->id));
$title = sprintf(__('%s: Download %d added - %s'),
Pluf_esc($request->project->name),
$this->id, Pluf_esc($this->summary));
$content = Pluf_esc($this->summary);
$date = Pluf_Date::gmDateToGmString($this->creation_dtime);
return Pluf_Translation::sprintf($base,
array('url' => $url,
'title' => $title,
'content' => $content,
'date' => $date));
}
}
src/IDF/Views/Project.php
115115
116116
117117
118
119
120
121
122
123
124
125
126
127
128
129
130
118131
119132
120133
134
121135
122136
123137
124138
125139
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
126203
127204
128205
// the first tag is the featured, the last is the deprecated.
$downloads = $tags[0]->get_idf_upload_list();
}
$pages = array();
if ($request->rights['hasWikiAccess']) {
$tags = IDF_Views_Wiki::getWikiTags($prj);
$pages = $tags[0]->get_idf_wikipage_list();
}
if (!$request->user->isAnonymous()) {
$feedurl = Pluf_HTTP_URL_urlForView('idf_project_timeline_feed_auth',
array($prj->shortname,
IDF_Precondition::genFeedToken($prj, $request->user)));
} else {
$feedurl = Pluf_HTTP_URL_urlForView('idf_project_timeline_feed',
array($prj->shortname));
}
return Pluf_Shortcuts_RenderToResponse('idf/project/timeline.html',
array(
'page_title' => $title,
'feedurl' => $feedurl,
'timeline' => $pag,
'team' => $team,
'downloads' => $downloads,
),
$request);
}
/**
* Timeline feed.
*
* A custom view to have a bit more control on the way to handle
* it and optimize the output.
*
*/
public $timelineFeed_precond = array('IDF_Precondition::feedSetUser',
'IDF_Precondition::baseAccess');
public function timelineFeed($request, $match)
{
$prj = $request->project;
// Need to check the rights
$rights = array();
if (true === IDF_Precondition::accessSource($request)) {
$rights[] = '\'IDF_Commit\'';
IDF_Scm::syncTimeline($request);
}
if (true === IDF_Precondition::accessIssues($request)) {
$rights[] = '\'IDF_Issue\'';
$rights[] = '\'IDF_IssueComment\'';
}
if (true === IDF_Precondition::accessDownloads($request)) {
$rights[] = '\'IDF_Upload\'';
}
if (true === IDF_Precondition::accessWiki($request)) {
$rights[] = '\'IDF_WikiPage\'';
$rights[] = '\'IDF_WikiRevision\'';
}
if (count($rights) == 0) {
$rights[] = '\'IDF_Dummy\'';
}
$sqls = sprintf('model_class IN (%s)', implode(', ', $rights));
$sql = new Pluf_SQL('project=%s AND '.$sqls, array($prj->id));
$params = array(
'filter' => $sql->gen(),
'order' => 'creation_dtime DESC',
'nb' => 50,
);
$items = Pluf::factory('IDF_Timeline')->getList($params);
$set = new Pluf_Model_Set($items,
array('public_dtime' => 'public_dtime'));
$out = array();
foreach ($set as $item) {
$out[] = $item->feedFragment($request);
}
$out = Pluf_Template::markSafe(implode("\n", $out));
$tmpl = new Pluf_Template('idf/index.atom');
$title = __('Updates');
$feedurl = Pluf::f('url_base').Pluf::f('idf_base').$request->query;
$viewurl = Pluf_HTTP_URL_urlForView('IDF_Views_Project::timeline',
array($prj->shortname));
$context = new Pluf_Template_Context_Request($request,
array('body' => $out,
'title' => $title,
'feedurl' => $feedurl,
'viewurl' => $viewurl));
return new Pluf_HTTP_Response('<?xml version="1.0" encoding="utf-8"?>'
."\n".$tmpl->render($context),
'application/atom+xml; charset=utf-8');
}
src/IDF/WikiPage.php
198198
199199
200200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
201228
<div class="helptext right">'.sprintf(__('Creation of <a href="%s">page&nbsp;%s</a>'), $url, Pluf_esc($this->title)).', '.__('by').' '.Pluf_esc($submitter).'</div></td></tr>';
return Pluf_Template::markSafe($out);
}
public function feedFragment($request)
{
$base = '<entry>
<title>%%title%%</title>
<link href="%%url%%"/>
<id>%%url%%</id>
<updated>%%date%%</updated>
<content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">
%%content%%
</div></content>
</entry>';
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::view',
array($request->project->shortname,
$this->title));
$title = sprintf(__('%s: Documentation page %s added - %s'),
Pluf_esc($request->project->name),
Pluf_esc($this->title), Pluf_esc($this->summary));
$content = Pluf_esc($this->summary);
$date = Pluf_Date::gmDateToGmString($this->creation_dtime);
return Pluf_Translation::sprintf($base,
array('url' => $url,
'title' => $title,
'content' => $content,
'date' => $date));
}
}
src/IDF/WikiRevision.php
189189
190190
191191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
192220
<div class="helptext right">'.sprintf(__('Change of <a href="%s">%s</a>'), $url, Pluf_esc($page->title)).', '.__('by').' '.Pluf_esc($submitter).'</div></td></tr>';
return Pluf_Template::markSafe($out);
}
public function feedFragment($request)
{
$base = '<entry>
<title>%%title%%</title>
<link href="%%url%%"/>
<id>%%url%%</id>
<updated>%%date%%</updated>
<content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">
%%content%%
</div></content>
</entry>';
$page = $this->get_wikipage();
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::view',
array($request->project->shortname,
$page->title));
$title = sprintf(__('%s: Documentation page %s updated - %s'),
Pluf_esc($request->project->name),
Pluf_esc($page->title), Pluf_esc($page->summary));
$content = Pluf_esc($this->summary);
$date = Pluf_Date::gmDateToGmString($this->creation_dtime);
return Pluf_Translation::sprintf($base,
array('url' => $url,
'title' => $title,
'content' => $content,
'date' => $date));
}
}
src/IDF/conf/urls.php
9191
9292
9393
94
95
96
97
98
99
100
101
102
103
104
105
106
107
94108
95109
96110
'model' => 'IDF_Views_Project',
'method' => 'timeline');
$ctl[] = array('regex' => '#^/p/([\-\w]+)/feed/timeline/$#',
'base' => $base,
'priority' => 4,
'model' => 'IDF_Views_Project',
'method' => 'timelineFeed',
'name' => 'idf_project_timeline_feed');
$ctl[] = array('regex' => '#^/p/([\-\w]+)/feed/timeline/token/(.*)/$#',
'base' => $base,
'priority' => 4,
'model' => 'IDF_Views_Project',
'method' => 'timelineFeed',
'name' => 'idf_project_timeline_feed_auth');
$ctl[] = array('regex' => '#^/p/([\-\w]+)/issues/$#',
'base' => $base,
'priority' => 4,
src/IDF/templates/idf/index.atom
1
2
3
4
5
6
7
8
9
10
11
12
13
<feed xmlns="http://www.w3.org/2005/Atom">
<title>{$title}, {$project} - {$project.shortdesc}</title>
{if !$user.isAnonymous()} <subtitle>{blocktrans}Personal project feed for {$user}.{/blocktrans}</subtitle>{/if}
<link href="{$feedurl}" rel="self"/>
<link href="{$viewurl}"/>
<updated>{$updated}</updated>
<author>
<name>Not given</name>
<email>Not given</email>
</author>
<id>{$feedurl}</id>
{$body}
</feed>
src/IDF/templates/idf/project/timeline.html
11
2
23
34
45
{extends "idf/base.html"}
{block extraheader}<link rel="alternate" type="application/atom+xml" title="{trans 'Latest updates'}" href="{$feedurl}"/>{/block}
{block docclass}yui-t2{/block}
{block tabhome} class="active"{/block}
{block subtabs}

Archive Download the corresponding diff file

Page rendered in 0.11364s using 14 queries.